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){
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);
81
rViewport rViewport::s_viewportFullscreen(0,0,1,1);
83
rViewport rViewport::s_viewportTop(0,.5,1,.5);
84
rViewport rViewport::s_viewportBottom(0,0,1,.5);
86
rViewport rViewport::s_viewportLeft(0,0,.5,1);
87
rViewport rViewport::s_viewportRight(.5,0,.5,1);
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);
95
int sr_viewportBelongsToPlayer[MAX_VIEWPORTS],
96
s_newViewportBelongsToPlayer[MAX_VIEWPORTS];
98
// ***********************************************************
101
rViewportConfiguration::rViewportConfiguration(rViewport *first)
106
rViewportConfiguration::rViewportConfiguration(rViewport *first,
113
rViewportConfiguration::rViewportConfiguration(rViewport *first,
122
rViewportConfiguration::rViewportConfiguration(rViewport *first,
134
void rViewportConfiguration::Select(int i){
135
if (i>=0 && i <num_viewports)
136
viewports[i]->Select();
140
rViewport * rViewportConfiguration::Port(int i){
141
if (i>=0 && i <num_viewports)
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);
163
rViewportConfiguration *rViewportConfiguration::s_viewportConfigurations[]={
164
&single_vp,&two_vp,&two_b,&three_a,&three_b,&four_vp};
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"};
174
const int rViewportConfiguration::s_viewportNumConfigurations=6;
178
// *******************************************************
180
// *******************************************************
182
static int conf_num=0;
183
int rViewportConfiguration::next_conf_num=0;
185
static tConfItem<int> confn("VIEWPORT_CONF",
186
rViewportConfiguration::next_conf_num);
188
rViewportConfiguration *rViewportConfiguration::CurrentViewportConfiguration(){
189
if (conf_num<0) conf_num=0;
190
if (conf_num>=s_viewportNumConfigurations)
191
conf_num=s_viewportNumConfigurations-1;
193
return s_viewportConfigurations[conf_num];
197
void rViewportConfiguration::DemonstrateViewport(tString *titles){
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)));
205
glDisable(GL_TEXTURE_2D);
206
glDisable(GL_DEPTH_TEST);
209
glRectf(-.9,-.9,.9,.9);
212
glBegin(GL_LINE_LOOP);
220
DisplayText(0,0,.15,.5,titles[i]);
223
rViewport::s_viewportFullscreen.Select();
228
rViewport * rViewportConfiguration::CurrentViewport(int i){
229
return CurrentViewportConfiguration()->Port(i);
232
void rViewportConfiguration::UpdateConf(){
233
conf_num = next_conf_num;
237
static int vpb_dir[MAX_VIEWPORTS];
239
void rViewport::CorrectViewport(int i, int MAX_PLAYERS){
240
if (vpb_dir[i]!=1 && vpb_dir[i]!=-1)
242
s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS-vpb_dir[i];
243
s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
246
s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS+vpb_dir[i];
247
s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
249
int starta=rViewportConfiguration::s_viewportConfigurations[rViewportConfiguration::next_conf_num]->num_viewports-1;
250
int startb=rViewportConfiguration::s_viewportConfigurations[ conf_num]->num_viewports-1;
253
for(int j=starta;j>=0;j--)
254
if (i!=j && s_newViewportBelongsToPlayer[i]
255
==s_newViewportBelongsToPlayer[j])
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);
266
void rViewport::Update(int MAX_PLAYERS){
267
rViewportConfiguration::UpdateConf();
268
CorrectViewports(MAX_PLAYERS);
271
for(i=MAX_VIEWPORTS-1;i>=0;i--)
272
sr_viewportBelongsToPlayer[i]=s_newViewportBelongsToPlayer[i];
275
void rViewport::SetDirectionOfCorrection(int vp, int dir){
279
// *******************************************************************************************
281
// * CorrectAspectBottom
283
// *******************************************************************************************
287
// *******************************************************************************************
289
rViewport rViewport::CorrectAspectBottom( void ) const
291
rViewport ret( *this );
292
ret.height = width * 4.0 / 3.0;