~ivantis/armagetronad/sty+ct+ivantis

« back to all changes in this revision

Viewing changes to src/tron/gLogo.cpp

  • Committer: ivantis
  • Date: 2008-09-09 21:33:18 UTC
  • Revision ID: ivantis@ivantis.net-20080909213318-k43y6yuq0zd6wbsa
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
*************************************************************************
 
4
 
 
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
 
6
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
 
7
 
 
8
**************************************************************************
 
9
 
 
10
This program is free software; you can redistribute it and/or
 
11
modify it under the terms of the GNU General Public License
 
12
as published by the Free Software Foundation; either version 2
 
13
of the License, or (at your option) any later version.
 
14
 
 
15
This program is distributed in the hope that it will be useful,
 
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
GNU General Public License for more details.
 
19
 
 
20
You should have received a copy of the GNU General Public License
 
21
along with this program; if not, write to the Free Software
 
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
23
  
 
24
***************************************************************************
 
25
 
 
26
*/
 
27
 
 
28
#include "gLogo.h"
 
29
 
 
30
#include "gStuff.h"
 
31
#include "rTexture.h"
 
32
#include "rRender.h"
 
33
#include "rScreen.h"
 
34
#include "eCoord.h"
 
35
#include "uMenu.h"
 
36
#include "tSysTime.h"
 
37
 
 
38
/*
 
39
#include "nConfig.h"
 
40
static tString lala_logoTexture("Anonymous/original/textures/KGN_logo.png");
 
41
static nSettingItem<tString> lalala_logoTexture("TEXTURE_LOGO", lala_logoTexture);
 
42
rFileTexture sg_LogoTexture(rTextureGroups::TEX_FONT, lala_logoTexture, 0,0,1);
 
43
*/
 
44
 
 
45
static rFileTexture sg_LogoTexture(rTextureGroups::TEX_FONT, "textures/KGN_logo.png",0,0,1);
 
46
static rISurfaceTexture* sg_LogoMPTitle = NULL;
 
47
 
 
48
static gLogo logo;
 
49
 
 
50
static bool sg_Displayed = true;
 
51
static bool sg_Spinning  = false;
 
52
static bool sg_Big       = true;
 
53
 
 
54
static eCoord sg_SpinStatus(1,0);    // current spinning position
 
55
static REAL   sg_SizeStatus(1);    // 1 -> big      , 0 -> small
 
56
static REAL   sg_DisplayStatus(-1); // 1 -> displayed, 0->invisible
 
57
 
 
58
void gLogo::SetDisplayed(bool d, bool immediately)
 
59
{
 
60
    if (sg_Displayed == false && d == true && sg_DisplayStatus < .01)
 
61
        sg_SpinStatus = eCoord(0, 1);
 
62
 
 
63
    sg_Displayed = d;
 
64
    if (immediately)
 
65
        sg_DisplayStatus = d ? 1 : 0;
 
66
}
 
67
 
 
68
void gLogo::SetSpinning(bool s)
 
69
{
 
70
    sg_Spinning = s;
 
71
    if (!s)
 
72
        sg_SpinStatus = eCoord(1, 0);
 
73
}
 
74
void gLogo::SetBig(bool b, bool immediately)
 
75
{
 
76
    sg_Big = b;
 
77
    if (immediately)
 
78
        sg_SizeStatus = b ? 1 : 0;
 
79
 
 
80
}
 
81
 
 
82
/*
 
83
static tString sg_title("Anonymous/original/textures/title.jpg");
 
84
static nSettingItem<tString> gg_title("TEXTURE_TITLE", sg_title);
 
85
 
 
86
static tString sg_mp_title("Anonymous/original/moviepack/title.jpg");
 
87
static nSettingItem<tString> gg_mp_title("TEXTURE_MP_TITLE", sg_mp_title);
 
88
*/
 
89
 
 
90
void gLogo::Display()
 
91
{
 
92
#ifndef DEDICATED
 
93
    if (!sr_glOut)
 
94
        return;
 
95
 
 
96
    if (sg_MoviePack() && !sg_LogoMPTitle)
 
97
    {
 
98
        sg_LogoMPTitle = tNEW(rFileTexture)(rTextureGroups::TEX_FONT, "moviepack/title.jpg",0,0,1);
 
99
        // sg_LogoMPTitle = tNEW(rFileTexture)(rTextureGroups::TEX_FONT, sg_mp_title, 0,0,1);
 
100
        sg_DisplayStatus = 1;
 
101
    }
 
102
 
 
103
    renderer->SetFlag(rRenderer::DEPTH_TEST, false);
 
104
 
 
105
    static REAL lasttime = 0;
 
106
    REAL time = tSysTimeFloat();
 
107
    REAL dt = time - lasttime;
 
108
    lasttime = time;
 
109
 
 
110
    if (!sg_Displayed && sg_DisplayStatus < .00001)
 
111
        return;
 
112
 
 
113
    if (sg_LogoMPTitle)
 
114
    {
 
115
        // update state variables
 
116
        if (sg_Displayed && sg_Big)
 
117
        {
 
118
            sg_DisplayStatus += dt;
 
119
            if (sg_DisplayStatus > 1)
 
120
                sg_DisplayStatus = 1;
 
121
        }
 
122
        else
 
123
        {
 
124
            sg_DisplayStatus -= dt;
 
125
            if (sg_DisplayStatus < 0)
 
126
                sg_DisplayStatus = 0;
 
127
        }
 
128
 
 
129
        sg_LogoMPTitle->Select();
 
130
 
 
131
        if (sg_DisplayStatus <= .01 || !sg_LogoMPTitle->Loaded())
 
132
            return;
 
133
 
 
134
        Color(1,1,1, sg_DisplayStatus);
 
135
 
 
136
        BeginQuads();
 
137
        TexCoord(0,0);
 
138
        Vertex(-1, 1);
 
139
 
 
140
        TexCoord(0,1);
 
141
        Vertex(-1, -1);
 
142
 
 
143
        TexCoord(1,1);
 
144
        Vertex(1, -1);
 
145
 
 
146
        TexCoord(1,0);
 
147
        Vertex(1, 1);
 
148
 
 
149
        RenderEnd();
 
150
    }
 
151
    else
 
152
    {
 
153
#ifndef KRAWALL
 
154
        sg_LogoMPTitle = tNEW(rFileTexture)(rTextureGroups::TEX_FONT, "textures/title.jpg",0,0,1);
 
155
        // sg_LogoMPTitle = tNEW(rFileTexture)(rTextureGroups::TEX_FONT, sg_title,0,0,1);
 
156
 
 
157
        sg_DisplayStatus = 1;
 
158
 
 
159
        // update state variables
 
160
        if (sg_Displayed && sg_Big)
 
161
        {
 
162
            sg_DisplayStatus += dt;
 
163
            if (sg_DisplayStatus > 1)
 
164
                sg_DisplayStatus = 1;
 
165
        }
 
166
        else
 
167
        {
 
168
            sg_DisplayStatus -= dt;
 
169
            if (sg_DisplayStatus < 0)
 
170
                sg_DisplayStatus = 0;
 
171
        }
 
172
 
 
173
        sg_LogoMPTitle->Select();
 
174
 
 
175
        if (sg_DisplayStatus <= .01 || !sg_LogoMPTitle->Loaded())
 
176
            return;
 
177
 
 
178
        Color(1,1,1, sg_DisplayStatus);
 
179
 
 
180
        BeginQuads();
 
181
        TexCoord(0,0);
 
182
        Vertex(-1, 1);
 
183
 
 
184
        TexCoord(0,1);
 
185
        Vertex(-1, -1);
 
186
 
 
187
        TexCoord(1,1);
 
188
        Vertex(1, -1);
 
189
 
 
190
        TexCoord(1,0);
 
191
        Vertex(1, 1);
 
192
 
 
193
        RenderEnd();
 
194
#endif    
 
195
 
 
196
#ifdef KRAWALL
 
197
        sg_LogoTexture.Select();
 
198
 
 
199
        if ( !sg_LogoTexture.Loaded() )
 
200
        {
 
201
            return;
 
202
        }
 
203
 
 
204
        // update state variables
 
205
        if (sg_Spinning)
 
206
        {
 
207
            sg_SpinStatus = sg_SpinStatus.Turn(1, dt * 2 * .2 / (sg_SizeStatus + .2));
 
208
            sg_SpinStatus = sg_SpinStatus * (1/sqrt(sg_SpinStatus.NormSquared()));
 
209
        }
 
210
 
 
211
        if (sg_Big)
 
212
        {
 
213
            sg_SizeStatus += dt;
 
214
            if (sg_SizeStatus > 1)
 
215
                sg_SizeStatus = 1;
 
216
        }
 
217
        else
 
218
        {
 
219
            sg_SizeStatus *= (1 - 2 * dt);
 
220
            //      if (sg_SizeStatus < 0)
 
221
            //  sg_SizeStatus = 0;
 
222
        }
 
223
 
 
224
        if (sg_Displayed)
 
225
        {
 
226
            sg_DisplayStatus += dt;
 
227
            if (sg_DisplayStatus > 1)
 
228
                sg_DisplayStatus = 1;
 
229
        }
 
230
        else
 
231
        {
 
232
            sg_DisplayStatus -= dt*.3;
 
233
            if (sg_DisplayStatus < 0)
 
234
                sg_DisplayStatus = 0;
 
235
        }
 
236
 
 
237
        if (sg_DisplayStatus < 0)
 
238
            return;
 
239
 
 
240
        eCoord center(.8*(sg_SizeStatus*sg_SizeStatus-1), .8*(1-sg_SizeStatus));
 
241
        REAL e =.8 * (sg_SizeStatus + .1);
 
242
        eCoord extension(e, - .7 * e * fabs(sg_SpinStatus.x));
 
243
 
 
244
        eCoord ur = center - extension;
 
245
        eCoord ll = center + extension;
 
246
 
 
247
        Color(1,1,1, sg_DisplayStatus);
 
248
 
 
249
        BeginQuads();
 
250
        TexCoord(0,0);
 
251
        Vertex(ur.x, ur.y);
 
252
 
 
253
        TexCoord(0,1);
 
254
        Vertex(ur.x, ll.y);
 
255
 
 
256
        TexCoord(1,1);
 
257
        Vertex(ll.x, ll.y);
 
258
 
 
259
        TexCoord(1,0);
 
260
        Vertex(ll.x, ur.y);
 
261
 
 
262
        RenderEnd();
 
263
#endif
 
264
 
 
265
    }
 
266
 
 
267
#endif
 
268
}
 
269
 
 
270
gLogo::~gLogo()
 
271
{
 
272
    if (sg_LogoMPTitle)
 
273
    {
 
274
        tDESTROY(sg_LogoMPTitle);
 
275
    }
 
276
}