00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "rSDL.h"
00031
00032 #include "tConfiguration.h"
00033
00034
00035 #ifndef DEDICATED
00036 static REAL sr_floorMirror_strength=.1;
00037 static tSettingItem<REAL> f_m("FLOOR_MIRROR_INT",sr_floorMirror_strength);
00038
00039 #include "tEventQueue.h"
00040 #include "uInputQueue.h"
00041 #include "eTess2.h"
00042 #include "rTexture.h"
00043 #include "eGameObject.h"
00044 #include "rFont.h"
00045 #include "eTimer.h"
00046 #include "eCamera.h"
00047 #include "rScreen.h"
00048 #include "rRender.h"
00049 #include "eWall.h"
00050 #include "eAdvWall.h"
00051 #include "eFloor.h"
00052 #include "ePath.h"
00053 #include "eGrid.h"
00054 #include "eDebugLine.h"
00055 #include "tDirectories.h"
00056 #include "eRectangle.h"
00057
00058 #define eWall_h 4
00059 #define view_h 2.7
00060
00061 #ifdef DEBUG
00062 bool debug_grid=0;
00063 #endif
00064
00065 REAL upper_height=100;
00066 REAL lower_height=50;
00067
00068
00069 #ifndef DEDICATED
00070
00071 static rFileTexture sky(rTextureGroups::TEX_FLOOR,"textures/sky.png",1,1,true);
00072 static rFileTexture sky_moviepack(rTextureGroups::TEX_FLOOR,"moviepack/sky.png",1,1,true);
00073
00074 extern bool sg_MoviePack();
00075
00076 static void sky_select(){
00077 if (sg_MoviePack()){
00078
00079
00080 tString s = tDirectories::Data().GetReadPath( "moviepack/sky.png" );
00081 if(strlen(s) > 0)
00082 sky_moviepack.Select();
00083 else
00084 sky.Select();
00085 }
00086 else {
00087 sky.Select();
00088 }
00089 }
00090
00091
00092 extern short se_bugRip;
00093
00094
00095 static inline void TexVertex( REAL x, REAL y, REAL h)
00096 {
00097 glTexCoord2f(x, y);
00098 glVertex3f (x, y, h);
00099 }
00100
00101
00102 static void finite_xy_plane( const eCoord &pos,const eCoord &dir,REAL h, eRectangle rect )
00103 {
00104
00105 if ( sr_floorMirror )
00106 rect.Include( pos );
00107
00108
00109 REAL lx = rect.GetLow().x;
00110 REAL ly = rect.GetLow().y;
00111 REAL hx = rect.GetHigh().x;
00112 REAL hy = rect.GetHigh().y;
00113
00114
00115 BeginTriangleFan();
00116 TexVertex( pos.x-dir.x, pos.y-dir.y, h );
00117 TexVertex(lx, ly, h);
00118 TexVertex(lx, hy, h);
00119 TexVertex(hx, hy, h);
00120 TexVertex(hx, ly, h);
00121 TexVertex(lx, ly, h);
00122 RenderEnd();
00123 }
00124
00125 static void infinity_xy_plane(eCoord const & pos, const eCoord &dir,REAL h=0){
00126 bool use_rim=false;
00127 REAL zero=0;
00128
00129 if (sr_highRim)
00130 use_rim=true;
00131
00132 if ( se_bugRip )
00133 use_rim=false;
00134
00135
00136 use_rim |= !sr_infinityPlane;
00137
00138 if (use_rim){
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 finite_xy_plane( pos, dir, h, eWallRim::GetBounds() );
00160 }
00161 else
00162 {
00163 if (!sr_infinityPlane)
00164 zero=.001;
00165
00166 BeginTriangleFan();
00167
00168 glTexCoord4f(pos.x-dir.x, pos.y-dir.y, h, 1);
00169 glVertex4f (pos.x-dir.x, pos.y-dir.y, h, 1);
00170
00171 glTexCoord4f(1,0.1,zero*h,zero);
00172 glVertex4f (1,0.1,zero*h,zero);
00173
00174 glTexCoord4f(0.1,1.1,zero*h,zero);
00175 glVertex4f (0.1,1.1,zero*h,zero);
00176
00177 glTexCoord4f(-1,0.1,zero*h,zero);
00178 glVertex4f (-1,0.1,zero*h,zero);
00179
00180 glTexCoord4f(0.1,-1.1,zero*h,zero);
00181 glVertex4f (0.1,-1.1,zero*h,zero);
00182
00183 glTexCoord4f(1,0.1,zero*h,zero);
00184 glVertex4f (1,0.1,zero*h,zero);
00185
00186 RenderEnd();
00187 }
00188 }
00189
00190 static REAL z=0;
00191
00192
00193 int eGrid::NumberOfCameras(){return cameras.Len();}
00194 const eCoord& eGrid::CameraPos(int i){return cameras(i)->CameraPos();}
00195 eCoord eGrid::CameraGlancePos(int i){return cameras(i)->CameraGlancePos();}
00196 const eCoord& eGrid::CameraDir(int i){return cameras(i)->CameraDir();}
00197 REAL eGrid::CameraHeight(int i){return cameras(i)->CameraZ();}
00198
00199
00200
00201
00202 eWall *displayed_eWall=0;
00203
00204 void draw_eWall(eGrid* grid, int v,int i, REAL& zNear, eCamera const * cam)
00205 {
00206 if (i<se_wallsVisible[v].Len())
00207 {
00208 eWallView *view=se_wallsVisible[v](i);
00209 #ifdef DEBUG
00210 if (view->Value()<=z)
00211 {
00212 #endif
00213 displayed_eWall = view->Belongs();
00214 REAL len = displayed_eWall->Len();
00215 if ( len > .01)
00216 {
00217 REAL zDist = z - displayed_eWall->Height();
00218 if ( zDist < zNear )
00219 {
00220 const eCoord& camPos = grid->CameraPos( v );
00221 const eCoord& camDir = grid->CameraDir( v );
00222 eCoord base = displayed_eWall->EndPoint(0);
00223 eCoord end = displayed_eWall->EndPoint(1);
00224
00225 if ( eCoord::F( base-camPos, camDir ) > 0.01f || eCoord::F( end-camPos, camDir ) > 0.01f )
00226 {
00227 eCoord dirNorm = end - base;
00228 dirNorm.Normalize();
00229 eCoord camRelative = ( camPos - base ).Turn( dirNorm.Conj() );
00230 REAL dist = fabs( camRelative.y );
00231 if ( camRelative.x < 0 )
00232 {
00233 dist -= camRelative.x;
00234 }
00235 if ( camRelative.x > len )
00236 {
00237 dist += camRelative.x - len;
00238 }
00239 if ( dist < zDist )
00240 {
00241 dist = zDist;
00242 }
00243
00244 if ( dist < zNear && dist > 0.001f )
00245 {
00246 zNear = dist;
00247 }
00248 }
00249 }
00250
00251 displayed_eWall->Render(cam);
00252 }
00253 displayed_eWall=0;
00254
00255 draw_eWall(grid,v,tHeapBase::UpperL(i),zNear,cam);
00256 draw_eWall(grid,v,tHeapBase::UpperR(i),zNear,cam);
00257
00258 #ifdef DEBUG
00259 }
00260 #endif
00261 }
00262 }
00263
00264
00265 void paint_sr_lowerSky(eGrid *grid, int viewer,bool sr_upperSky, eCoord const & camPos){
00266 TexMatrix();
00267 glLoadIdentity();
00268 glScalef(.005,.005,.005);
00269 glEnable(GL_TEXTURE_2D);
00270 glDisable(GL_CULL_FACE);
00271
00272 if (sr_skyWobble){
00273 glTranslatef(se_GameTime()*.1,se_GameTime()*.07145,0);
00274 glScalef(1+.2*sin(se_GameTime()),1+.1*cos(se_GameTime()),1);
00275 glTranslatef(-300,-200,0);
00276 }
00277
00278 sky_select();
00279
00280 REAL sa=(lower_height-z)*.1;
00281 if (sa>1) sa=1;
00282 if (!sr_upperSky){
00283 sa=1;
00284 glBlendFunc(GL_SRC_ALPHA,GL_ZERO);
00285 }
00286 if (sa>0){
00287 glColor4f(1,1,1,sa);
00288 infinity_xy_plane(camPos,grid->CameraDir(viewer),lower_height);
00289 }
00290 if (!sr_upperSky && sr_alphaBlend)
00291 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00292 }
00293
00294 void eGrid::display_simple( int viewer,bool floor,
00295 bool sr_upperSky,bool sr_lowerSky,
00296 REAL flooralpha,
00297 bool eWalls,bool gameObjects,
00298 REAL& zNear){
00299 sr_CheckGLError();
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 glDisable(GL_DEPTH_TEST);
00327 glDepthMask(GL_FALSE);
00328
00329 glDisable(GL_CULL_FACE);
00330
00331 eCoord camPos = CameraGlancePos( viewer );
00332
00333
00334 if (sr_upperSky || se_BlackSky()){
00335 if (se_BlackSky()){
00336
00337 glDisable(GL_TEXTURE_2D);
00338
00339 glColor3f(0,0,0);
00340
00341 if ( z < lower_height )
00342 infinity_xy_plane(camPos, this->CameraDir(viewer),lower_height);
00343
00344 glEnable(GL_TEXTURE_2D);
00345 }
00346 else {
00347 TexMatrix();
00348 glLoadIdentity();
00349
00350
00351 se_glFloorTexture();
00352
00353 glColor3f(.5,.5,1);
00354
00355 if ( z < upper_height )
00356 infinity_xy_plane(camPos, this->CameraDir(viewer),upper_height);
00357 }
00358 }
00359
00360 if (sr_lowerSky && !sr_highRim){
00361 paint_sr_lowerSky(this, viewer,sr_upperSky, camPos);
00362 }
00363
00364 if (floor){
00365 sr_DepthOffset(false);
00366
00367 su_FetchAndStoreSDLInput();
00368 int floorDetail = sr_floorDetail;
00369
00370
00371 if ( !sr_alphaBlend && floorDetail > rFLOOR_TEXTURE )
00372 floorDetail = rFLOOR_TEXTURE;
00373
00374 switch(floorDetail){
00375 case rFLOOR_OFF:
00376 break;
00377 case rFLOOR_GRID:
00378 {
00379 #define SIDELEN (se_GridSize())
00380 #define EXTENSION 10
00381
00382 eCoord center = CameraPos(viewer) + CameraDir(viewer) * (SIDELEN * EXTENSION * .8);
00383
00384 REAL x=center.x;
00385 REAL y=center.y;
00386 int xn=static_cast<int>(x/SIDELEN);
00387 int yn=static_cast<int>(y/SIDELEN);
00388
00389
00390
00391 glDisable(GL_TEXTURE_2D);
00392
00393 #define INTENSITY(x,xx) (1-(((x)-(xx))*((x)-(xx))/(EXTENSION*SIDELEN*EXTENSION*SIDELEN)))
00394
00395
00396 BeginLines();
00397 for(int i=xn-EXTENSION;i<=xn+EXTENSION;i++){
00398 REAL intens=INTENSITY(i*SIDELEN,x);
00399 if (intens<0) intens=0;
00400 se_glFloorColor(intens,intens);
00401 glVertex2f(i*SIDELEN,y-SIDELEN*(EXTENSION+1));
00402 glVertex2f(i*SIDELEN,y+SIDELEN*(EXTENSION+1));
00403 }
00404 for(int j=yn-EXTENSION;j<=yn+EXTENSION;j++){
00405 REAL intens=INTENSITY(j*SIDELEN,y);
00406 if (intens<0) intens=0;
00407 se_glFloorColor(intens,intens);
00408 glVertex2f(x-(EXTENSION+1)*SIDELEN,j*SIDELEN);
00409 glVertex2f(x+(EXTENSION+1)*SIDELEN,j*SIDELEN);
00410 }
00411 RenderEnd();
00412 }
00413 break;
00414
00415 case rFLOOR_TEXTURE:
00416 TexMatrix();
00417 glLoadIdentity();
00418 glScalef(1/se_GridSize(),1/se_GridSize(),1.);
00419
00420 se_glFloorTexture();
00421 se_glFloorColor(flooralpha);
00422
00423 infinity_xy_plane( camPos, CameraDir(viewer) );
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 break;
00440
00441 case rFLOOR_TWOTEXTURE:
00442 se_glFloorColor(flooralpha);
00443
00444 TexMatrix();
00445 glLoadIdentity();
00446 REAL gs = 1/se_GridSize();
00447 glScalef(0.01*gs,gs,1.);
00448
00449 se_glFloorTexture_a();
00450 infinity_xy_plane( camPos, CameraDir(viewer) );
00451
00452 se_glFloorColor(flooralpha);
00453
00454 TexMatrix();
00455 glLoadIdentity();
00456 glScalef(gs,.01*gs,1.);
00457
00458 se_glFloorTexture_b();
00459
00460 glDepthFunc(GL_LEQUAL);
00461 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00462 infinity_xy_plane( camPos, CameraDir(viewer) );
00463 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00464
00465 break;
00466 }
00467 }
00468
00469 glEnable(GL_DEPTH_TEST);
00470 glDepthMask(GL_TRUE);
00471
00472 TexMatrix();
00473 glLoadIdentity();
00474 ModelMatrix();
00475
00476
00477
00478
00479
00480
00481 if(eWalls){
00482 {
00483 su_FetchAndStoreSDLInput();
00484
00485 eWallRim::RenderAll( cameras(viewer) );
00486 }
00487
00488 if (sr_lowerSky && sr_highRim){
00489
00490
00491
00492
00493
00494 paint_sr_lowerSky(this, viewer,sr_upperSky, camPos);
00495
00496
00497
00498
00499
00500
00501 TexMatrix();
00502 glLoadIdentity();
00503 ModelMatrix();
00504 }
00505 }
00506
00507 sr_CheckGLError();
00508
00509 if (eWalls){
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 }
00539
00540 sr_CheckGLError();
00541
00542 if (gameObjects)
00543 eGameObject::RenderAll(this, cameras(viewer));
00544
00545 eDebugLine::Render();
00546 #ifdef DEBUG
00547
00548 ePath::RenderLast();
00549
00550 if (debug_grid){
00551
00552 glDisable(GL_TEXTURE_2D);
00553 glDisable(GL_LIGHTING);
00554 BeginLines();
00555
00556 int i;
00557 for(i=edges.Len()-1;i>=0;i--){
00558 eHalfEdge *e=edges[i];
00559 if (e->Face())
00560 glColor4f(1,1,1,1);
00561 else
00562 glColor4f(0,0,1,1);
00563
00564 glVertex3f(e->Point()->x,e->Point()->y,10);
00565 glVertex3f(e->Point()->x,e->Point()->y,15);
00566 glVertex3f(e->Point()->x,e->Point()->y,.1);
00567 glVertex3f(e->other->Point()->x,e->other->Point()->y,.1);
00568 glVertex3f(e->other->Point()->x,e->other->Point()->y,10);
00569 glVertex3f(e->other->Point()->x,e->other->Point()->y,15);
00570
00571 }
00572
00573 for(i=points.Len()-1;i>=0;i--){
00574 ePoint *p=points[i];
00575 glColor4f(1,0,0,1);
00576 glVertex3f(p->x,p->y,0);
00577 glVertex3f(p->x,p->y,(p->GetRefcount()+1)*5);
00578 }
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592 RenderEnd();
00593 }
00594 #endif
00595
00596 }
00597 #endif
00598
00599 void eGrid::Render( eCamera* cam, int viewer, REAL& zNear ){
00600 if (!sr_glOut)
00601 return;
00602 #ifndef DEDICATED
00603 ProjMatrix();
00604
00605 z=CameraHeight(viewer);
00606 if ( zNear > z )
00607 {
00608 zNear = z;
00609 }
00610
00611 if (sr_floorMirror){
00612 ModelMatrix();
00613 glScalef(1,1,-1);
00614
00615 if (z>10) z=10;
00616 glFrontFace(GL_CW);
00617
00618 bool us=false;
00619 bool ls=false;
00620
00621 if (sr_floorMirror>=rMIRROR_ALL){
00622 us=sr_upperSky;
00623 ls=sr_lowerSky;
00624 }
00625 else if (sr_floorMirror>=rMIRROR_WALLS){
00626 if (sr_lowerSky)
00627 ls=true;
00628 else if (sr_upperSky)
00629 us=true;
00630 }
00631
00632 cam->SetRenderingMain(false);
00633 display_simple(viewer,false,
00634 us,ls,
00635 0,
00636 sr_floorMirror>=rMIRROR_WALLS,
00637 sr_floorMirror>=rMIRROR_OBJECTS,
00638 zNear);
00639 z=CameraHeight(viewer);
00640 glFrontFace(GL_CCW);
00641 ModelMatrix();
00642 glScalef(1,1,-1);
00643
00644
00645 cam->SetRenderingMain(true);
00646 display_simple(viewer,true,
00647 sr_upperSky,sr_lowerSky,
00648 1-sr_floorMirror_strength,
00649 true,true,zNear);
00650
00651 }
00652 else
00653 {
00654 cam->SetRenderingMain(true);
00655 display_simple(viewer,true,
00656 sr_upperSky,sr_lowerSky,
00657 1,
00658 true,true,zNear);
00659 }
00660
00661
00662 #ifdef EVENT_DEB
00663
00664
00665
00666 #endif
00667 #endif
00668 }
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706 #endif
00707
00708