~swag/armagetronad/0.2.9-sty+ct+ap-fork

« back to all changes in this revision

Viewing changes to src/render/rViewport.cpp

  • Committer: luke-jr
  • Date: 2006-05-29 01:55:42 UTC
  • Revision ID: svn-v3-list-QlpoOTFBWSZTWZvbKhsAAAdRgAAQABK6798QIABURMgAAaeoNT1TxT1DQbKaeobXKiyAmlWT7Y5MkdJOtXDtB7w7DOGFBHiOBxaUIu7HQyyQSvxdyRThQkJvbKhs:7d95bf1e-0414-0410-9756-b78462a59f44:armagetronad%2Fbranches%2F0.2.8%2Farmagetronad:4612
Unify tags/branches of modules released together

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 "rFont.h"
 
29
#include "rScreen.h"
 
30
#include "rViewport.h"
 
31
#include "rConsole.h"
 
32
#include "tConfiguration.h"
 
33
 
 
34
#ifndef DEDICATED
 
35
#include "rGL.h"
 
36
//#include <GL/glu>
 
37
#ifdef POWERPAK_DEB
 
38
#include "PowerPak/powerdraw.h"
 
39
#endif
 
40
#endif
 
41
 
 
42
#ifndef DEDICATED
 
43
void rViewport::Select(){
 
44
    if (sr_glOut)
 
45
        glViewport (GLsizei(sr_screenWidth*left),
 
46
                    GLsizei(sr_screenHeight*bottom),
 
47
                    GLsizei(sr_screenWidth*width),
 
48
                    GLsizei(sr_screenHeight*height));
 
49
}
 
50
#endif
 
51
 
 
52
 
 
53
REAL rViewport::UpDownFOV(REAL fov){
 
54
    REAL ratio=currentScreensetting.aspect*(width*sr_screenWidth)/(height*sr_screenHeight);
 
55
 
 
56
    // clamp ratio to 5/3
 
57
    REAL maxratio = 5.0/3.0;
 
58
    if (ratio > maxratio)
 
59
        ratio = maxratio;
 
60
 
 
61
    return 360*atan(tan(M_PI*fov/360)/ratio)/M_PI;
 
62
}
 
63
 
 
64
void rViewport::Perspective(REAL fov,REAL nnear,REAL ffar){
 
65
#ifndef DEDICATED
 
66
    if (!sr_glOut)
 
67
        return;
 
68
    REAL ratio=currentScreensetting.aspect*(width*sr_screenWidth)/(height*sr_screenHeight);
 
69
    // REAL udfov=360*atan(tan(M_PI*fov/360)/ratio)/M_PI;
 
70
    REAL udfov=UpDownFOV(fov);
 
71
    glMatrixMode(GL_PROJECTION);
 
72
    gluPerspective(
 
73
        udfov,
 
74
        ratio,
 
75
        nnear,
 
76
        ffar
 
77
    );
 
78
#endif
 
79
}
 
80
 
 
81
rViewport rViewport::s_viewportFullscreen(0,0,1,1);
 
82
 
 
83
rViewport rViewport::s_viewportTop(0,.5,1,.5);
 
84
rViewport rViewport::s_viewportBottom(0,0,1,.5);
 
85
 
 
86
rViewport rViewport::s_viewportLeft(0,0,.5,1);
 
87
rViewport rViewport::s_viewportRight(.5,0,.5,1);
 
88
 
 
89
rViewport rViewport::s_viewportTopLeft(0,.5,.5,.5);
 
90
rViewport rViewport::s_viewportBottomLeft(0,0,.5,.5);
 
91
rViewport rViewport::s_viewportTopRight(.5,.5,.5,.5);
 
92
rViewport rViewport::s_viewportBottomRight(.5,0,.5,.5);
 
93
rViewport rViewport::s_viewportDemonstation(.55,.05,.4,.4);
 
94
 
 
95
int   sr_viewportBelongsToPlayer[MAX_VIEWPORTS],
 
96
s_newViewportBelongsToPlayer[MAX_VIEWPORTS];
 
97
 
 
98
// ***********************************************************
 
99
 
 
100
 
 
101
rViewportConfiguration::rViewportConfiguration(rViewport *first)
 
102
        :num_viewports(1){
 
103
    viewports[0]=first;
 
104
}
 
105
 
 
106
rViewportConfiguration::rViewportConfiguration(rViewport *first,
 
107
        rViewport *second)
 
108
        :num_viewports(2){
 
109
    viewports[0]=first;
 
110
    viewports[1]=second;
 
111
}
 
112
 
 
113
rViewportConfiguration::rViewportConfiguration(rViewport *first,
 
114
        rViewport *second,
 
115
        rViewport *third)
 
116
        :num_viewports(3){
 
117
    viewports[0]=first;
 
118
    viewports[1]=second;
 
119
    viewports[2]=third;
 
120
}
 
121
 
 
122
rViewportConfiguration::rViewportConfiguration(rViewport *first,
 
123
        rViewport *second,
 
124
        rViewport *third,
 
125
        rViewport *forth)
 
126
        :num_viewports(4){
 
127
    viewports[0]=first;
 
128
    viewports[1]=second;
 
129
    viewports[2]=third;
 
130
    viewports[3]=forth;
 
131
}
 
132
 
 
133
#ifndef DEDICATED
 
134
void rViewportConfiguration::Select(int i){
 
135
    if (i>=0 && i <num_viewports)
 
136
        viewports[i]->Select();
 
137
}
 
138
#endif
 
139
 
 
140
rViewport * rViewportConfiguration::Port(int i){
 
141
    if (i>=0 && i <num_viewports)
 
142
        return viewports[i];
 
143
    else
 
144
        return NULL;
 
145
}
 
146
 
 
147
static rViewportConfiguration single_vp(&rViewport::s_viewportFullscreen);
 
148
static rViewportConfiguration two_vp(&rViewport::s_viewportTop,
 
149
                                     &rViewport::s_viewportBottom);
 
150
static rViewportConfiguration two_b(&rViewport::s_viewportLeft,
 
151
                                    &rViewport::s_viewportRight);
 
152
static rViewportConfiguration three_a(&rViewport::s_viewportTop,
 
153
                                      &rViewport::s_viewportBottomLeft,
 
154
                                      &rViewport::s_viewportBottomRight);
 
155
static rViewportConfiguration three_b(&rViewport::s_viewportTopLeft,
 
156
                                      &rViewport::s_viewportTopRight,
 
157
                                      &rViewport::s_viewportBottom);
 
158
static rViewportConfiguration four_vp(&rViewport::s_viewportTopLeft,
 
159
                                      &rViewport::s_viewportTopRight,
 
160
                                      &rViewport::s_viewportBottomLeft,
 
161
                                      &rViewport::s_viewportBottomRight);
 
162
 
 
163
rViewportConfiguration *rViewportConfiguration::s_viewportConfigurations[]={
 
164
            &single_vp,&two_vp,&two_b,&three_a,&three_b,&four_vp};
 
165
 
 
166
char *rViewportConfiguration::s_viewportConfigurationNames[]=
 
167
    {"$viewport_conf_name_0",
 
168
     "$viewport_conf_name_1",
 
169
     "$viewport_conf_name_2",
 
170
     "$viewport_conf_name_3",
 
171
     "$viewport_conf_name_4",
 
172
     "$viewport_conf_name_5"};
 
173
 
 
174
const int  rViewportConfiguration::s_viewportNumConfigurations=6;
 
175
 
 
176
 
 
177
 
 
178
// *******************************************************
 
179
//   Player menu
 
180
// *******************************************************
 
181
 
 
182
static int conf_num=0;
 
183
int rViewportConfiguration::next_conf_num=0;
 
184
 
 
185
static tConfItem<int> confn("VIEWPORT_CONF",
 
186
                            rViewportConfiguration::next_conf_num);
 
187
 
 
188
rViewportConfiguration *rViewportConfiguration::CurrentViewportConfiguration(){
 
189
    if (conf_num<0) conf_num=0;
 
190
    if (conf_num>=s_viewportNumConfigurations)
 
191
        conf_num=s_viewportNumConfigurations-1;
 
192
 
 
193
    return s_viewportConfigurations[conf_num];
 
194
}
 
195
 
 
196
#ifndef DEDICATED
 
197
void rViewportConfiguration::DemonstrateViewport(tString *titles){
 
198
    if (!sr_glOut)
 
199
        return;
 
200
 
 
201
    for(int i=s_viewportConfigurations[next_conf_num]->num_viewports-1;i>=0;i--){
 
202
        rViewport sub(rViewport::s_viewportDemonstation,*(s_viewportConfigurations[next_conf_num]->Port(i)));
 
203
        sub.Select();
 
204
 
 
205
        glDisable(GL_TEXTURE_2D);
 
206
        glDisable(GL_DEPTH_TEST);
 
207
 
 
208
        glColor3f(.1,.1,.4);
 
209
        glRectf(-.9,-.9,.9,.9);
 
210
 
 
211
        glColor3f(.6,.6,.6);
 
212
        glBegin(GL_LINE_LOOP);
 
213
        glVertex2f(-1,-1);
 
214
        glVertex2f(-1,1);
 
215
        glVertex2f(1,1);
 
216
        glVertex2f(1,-1);
 
217
        glEnd();
 
218
 
 
219
        glColor3f(1,1,1);
 
220
        DisplayText(0,0,.15,.5,titles[i]);
 
221
    }
 
222
 
 
223
    rViewport::s_viewportFullscreen.Select();
 
224
}
 
225
#endif
 
226
 
 
227
 
 
228
rViewport * rViewportConfiguration::CurrentViewport(int i){
 
229
    return CurrentViewportConfiguration()->Port(i);
 
230
}
 
231
 
 
232
void rViewportConfiguration::UpdateConf(){
 
233
    conf_num = next_conf_num;
 
234
}
 
235
 
 
236
 
 
237
static int vpb_dir[MAX_VIEWPORTS];
 
238
 
 
239
void rViewport::CorrectViewport(int i, int MAX_PLAYERS){
 
240
    if (vpb_dir[i]!=1 && vpb_dir[i]!=-1)
 
241
        vpb_dir[i]=1;
 
242
    s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS-vpb_dir[i];
 
243
    s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
 
244
    bool again;
 
245
    do{
 
246
        s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS+vpb_dir[i];
 
247
        s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
 
248
        again=false;
 
249
        int starta=rViewportConfiguration::s_viewportConfigurations[rViewportConfiguration::next_conf_num]->num_viewports-1;
 
250
        int startb=rViewportConfiguration::s_viewportConfigurations[     conf_num]->num_viewports-1;
 
251
        if (starta>startb)
 
252
            startb=starta;
 
253
        for(int j=starta;j>=0;j--)
 
254
            if (i!=j && s_newViewportBelongsToPlayer[i]
 
255
                    ==s_newViewportBelongsToPlayer[j])
 
256
                again=true;
 
257
    } while(again);
 
258
}
 
259
 
 
260
void rViewport::CorrectViewports(int MAX_PLAYERS){
 
261
    for (int i=rViewportConfiguration::s_viewportConfigurations[conf_num]->num_viewports-1;i>=0;i--)
 
262
        CorrectViewport(i, MAX_PLAYERS);
 
263
}
 
264
 
 
265
 
 
266
void rViewport::Update(int MAX_PLAYERS){
 
267
    rViewportConfiguration::UpdateConf();
 
268
    CorrectViewports(MAX_PLAYERS);
 
269
 
 
270
    int i;
 
271
    for(i=MAX_VIEWPORTS-1;i>=0;i--)
 
272
        sr_viewportBelongsToPlayer[i]=s_newViewportBelongsToPlayer[i];
 
273
}
 
274
 
 
275
void rViewport::SetDirectionOfCorrection(int vp, int dir){
 
276
    vpb_dir[vp] = dir;
 
277
}
 
278
 
 
279
// *******************************************************************************************
 
280
// *
 
281
// *    CorrectAspectBottom
 
282
// *
 
283
// *******************************************************************************************
 
284
//!
 
285
//!             @return
 
286
//!
 
287
// *******************************************************************************************
 
288
 
 
289
rViewport rViewport::CorrectAspectBottom( void ) const
 
290
{
 
291
    rViewport ret( *this );
 
292
    ret.height = width * 4.0 / 3.0;
 
293
 
 
294
    return ret;
 
295
}
 
296
 
 
297