3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
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.
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.
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.
24
***************************************************************************
30
#include "rViewport.h"
32
#include "tConfiguration.h"
38
#include "PowerPak/powerdraw.h"
43
void rViewport::Select(){
45
glViewport (GLsizei(sr_screenWidth*left),
46
GLsizei(sr_screenHeight*bottom),
47
GLsizei(sr_screenWidth*width),
48
GLsizei(sr_screenHeight*height));
53
REAL rViewport::UpDownFOV(REAL fov){
54
REAL ratio=currentScreensetting.aspect*(width*sr_screenWidth)/(height*sr_screenHeight);
57
REAL maxratio = 5.0/3.0;
61
return 360*atan(tan(M_PI*fov/360)/ratio)/M_PI;
64
void rViewport::Perspective(REAL fov,REAL nnear,REAL ffar){
69
// Jonathan's improved version
70
REAL aspectratio = (height * sr_screenHeight) / (width * sr_screenWidth * currentScreensetting.aspect);
71
REAL ensureverticalfov = fmax((3.0 / 5.0) * aspectratio, 1.0);
72
REAL xmul = ensureverticalfov * tan((M_PI / 360.0) * fov);
73
REAL ymul = ensureverticalfov * aspectratio * xmul;
74
glMatrixMode(GL_PROJECTION);
75
glFrustum(-nnear * xmul, nnear * xmul, -nnear * ymul, nnear * ymul, nnear, ffar);
77
#if 0 // Z-Man's old and clumsy version
78
REAL ratio=currentScreensetting.aspect*(width*sr_screenWidth)/(height*sr_screenHeight);
79
// REAL udfov=360*atan(tan(M_PI*fov/360)/ratio)/M_PI;
80
REAL udfov=UpDownFOV(fov);
81
glMatrixMode(GL_PROJECTION);
93
rViewport rViewport::s_viewportFullscreen(0,0,1,1);
95
rViewport rViewport::s_viewportTop(0,.5,1,.5);
96
rViewport rViewport::s_viewportBottom(0,0,1,.5);
98
rViewport rViewport::s_viewportLeft(0,0,.5,1);
99
rViewport rViewport::s_viewportRight(.5,0,.5,1);
101
rViewport rViewport::s_viewportTopLeft(0,.5,.5,.5);
102
rViewport rViewport::s_viewportBottomLeft(0,0,.5,.5);
103
rViewport rViewport::s_viewportTopRight(.5,.5,.5,.5);
104
rViewport rViewport::s_viewportBottomRight(.5,0,.5,.5);
105
rViewport rViewport::s_viewportDemonstation(.55,.05,.4,.4);
107
int sr_viewportBelongsToPlayer[MAX_VIEWPORTS],
108
s_newViewportBelongsToPlayer[MAX_VIEWPORTS];
110
// ***********************************************************
113
rViewportConfiguration::rViewportConfiguration(rViewport *first)
118
rViewportConfiguration::rViewportConfiguration(rViewport *first,
125
rViewportConfiguration::rViewportConfiguration(rViewport *first,
134
rViewportConfiguration::rViewportConfiguration(rViewport *first,
146
void rViewportConfiguration::Select(int i){
147
if (i>=0 && i <num_viewports)
148
viewports[i]->Select();
152
rViewport * rViewportConfiguration::Port(int i){
153
if (i>=0 && i <num_viewports)
159
static rViewportConfiguration single_vp(&rViewport::s_viewportFullscreen);
160
static rViewportConfiguration two_vp(&rViewport::s_viewportTop,
161
&rViewport::s_viewportBottom);
162
static rViewportConfiguration two_b(&rViewport::s_viewportLeft,
163
&rViewport::s_viewportRight);
164
static rViewportConfiguration three_a(&rViewport::s_viewportTop,
165
&rViewport::s_viewportBottomLeft,
166
&rViewport::s_viewportBottomRight);
167
static rViewportConfiguration three_b(&rViewport::s_viewportTopLeft,
168
&rViewport::s_viewportTopRight,
169
&rViewport::s_viewportBottom);
170
static rViewportConfiguration four_vp(&rViewport::s_viewportTopLeft,
171
&rViewport::s_viewportTopRight,
172
&rViewport::s_viewportBottomLeft,
173
&rViewport::s_viewportBottomRight);
175
rViewportConfiguration *rViewportConfiguration::s_viewportConfigurations[]={
176
&single_vp,&two_vp,&two_b,&three_a,&three_b,&four_vp};
178
char const * rViewportConfiguration::s_viewportConfigurationNames[]=
179
{"$viewport_conf_name_0",
180
"$viewport_conf_name_1",
181
"$viewport_conf_name_2",
182
"$viewport_conf_name_3",
183
"$viewport_conf_name_4",
184
"$viewport_conf_name_5"};
186
const int rViewportConfiguration::s_viewportNumConfigurations=6;
190
// *******************************************************
192
// *******************************************************
194
static int conf_num=0;
195
int rViewportConfiguration::next_conf_num=0;
197
static tConfItem<int> confn("VIEWPORT_CONF",
198
rViewportConfiguration::next_conf_num);
200
rViewportConfiguration *rViewportConfiguration::CurrentViewportConfiguration(){
201
if (conf_num<0) conf_num=0;
202
if (conf_num>=s_viewportNumConfigurations)
203
conf_num=s_viewportNumConfigurations-1;
205
return s_viewportConfigurations[conf_num];
209
void rViewportConfiguration::DemonstrateViewport(tString *titles){
213
for(int i=s_viewportConfigurations[next_conf_num]->num_viewports-1;i>=0;i--){
214
rViewport sub(rViewport::s_viewportDemonstation,*(s_viewportConfigurations[next_conf_num]->Port(i)));
217
glDisable(GL_TEXTURE_2D);
218
glDisable(GL_DEPTH_TEST);
221
glRectf(-.9,-.9,.9,.9);
224
glBegin(GL_LINE_LOOP);
232
DisplayText(0,0,.15,.5,titles[i]);
235
rViewport::s_viewportFullscreen.Select();
240
rViewport * rViewportConfiguration::CurrentViewport(int i){
241
return CurrentViewportConfiguration()->Port(i);
244
void rViewportConfiguration::UpdateConf(){
245
conf_num = next_conf_num;
249
static int vpb_dir[MAX_VIEWPORTS];
251
void rViewport::CorrectViewport(int i, int MAX_PLAYERS){
252
if (vpb_dir[i]!=1 && vpb_dir[i]!=-1)
255
int starta=rViewportConfiguration::s_viewportConfigurations[rViewportConfiguration::next_conf_num]->num_viewports-1;
256
int startb=rViewportConfiguration::s_viewportConfigurations[ conf_num]->num_viewports-1;
260
s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS-vpb_dir[i];
261
s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
263
int oldValue = s_newViewportBelongsToPlayer[i];
266
bool expectChange = false;
268
// rotate player assignemnt
269
s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS+vpb_dir[i];
270
s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
272
// check for conflicts
274
for(int j=starta;j>=0;j--)
275
if (i!=j && s_newViewportBelongsToPlayer[i]
276
==s_newViewportBelongsToPlayer[j])
283
if ( oldValue == s_newViewportBelongsToPlayer[i] && expectChange )
285
// no change? swap players.
286
s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS+vpb_dir[i];
287
s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
289
for(int j=starta;j>=0;j--)
290
if (i!=j && s_newViewportBelongsToPlayer[i]
291
==s_newViewportBelongsToPlayer[j])
293
s_newViewportBelongsToPlayer[j] = oldValue;
298
void rViewport::CorrectViewports(int MAX_PLAYERS){
299
for (int i=rViewportConfiguration::s_viewportConfigurations[conf_num]->num_viewports-1;i>=0;i--)
300
CorrectViewport(i, MAX_PLAYERS);
304
void rViewport::Update(int MAX_PLAYERS){
305
rViewportConfiguration::UpdateConf();
306
CorrectViewports(MAX_PLAYERS);
309
for(i=MAX_VIEWPORTS-1;i>=0;i--)
310
sr_viewportBelongsToPlayer[i]=s_newViewportBelongsToPlayer[i];
313
void rViewport::SetDirectionOfCorrection(int vp, int dir){
317
// *******************************************************************************************
319
// * CorrectAspectBottom
321
// *******************************************************************************************
325
// *******************************************************************************************
327
rViewport rViewport::CorrectAspectBottom( void ) const
329
rViewport ret( *this );
330
ret.height = width * 4.0 / 3.0;