#include <gWall.h>
Public Member Functions | |
gWallRim (eGrid *grid, REAL h=10000) | |
gWallRim (eGrid *grid, REAL tBeg, REAL tEnd, REAL h=10000) | |
virtual | ~gWallRim () |
virtual bool | Splittable () const |
virtual void | Split (eWall *&w1, eWall *&w2, REAL a) |
virtual bool | RunsParallelPassive (eWall *newWall) |
void | RenderReal (const eCamera *cam) |
Protected Member Functions | |
virtual void | OnBlocksCamera (eCamera *cam, REAL height) const |
called by the camera code when this wall is between the cycle and the camera | |
virtual REAL | Height () |
virtual REAL | SeeHeight () |
Private Attributes | |
REAL | renderHeight_ |
the height with which this wall is really rendered | |
REAL | lastUpdate_ |
time of the last render height update | |
REAL | tBeg_ |
REAL | tEnd_ |
begin and end texture coordinates |
Definition at line 45 of file gWall.h.
Definition at line 125 of file gWall.cpp.
Referenced by Split().
00126 :eWallRim(grid, false, h), renderHeight_(h), lastUpdate_(-100), tBeg_( 0 ), tEnd_( 0 ) 00127 { 00128 // std::cout << "create " << this << "\n"; 00129 }
Definition at line 131 of file gWall.cpp.
00132 :eWallRim(grid, false, h), renderHeight_(h), lastUpdate_(-100), tBeg_( tBeg ), tEnd_( tEnd ) 00133 { 00134 // std::cout << "create " << this << "\n"; 00135 }
gWallRim::~gWallRim | ( | ) | [virtual] |
bool gWallRim::Splittable | ( | ) | const [virtual] |
Reimplemented from eWall.
Definition at line 143 of file gWall.cpp.
References eWall::grid, gWallRim(), eWallRim::height, REAL, tBeg_, tEnd_, and tNEW.
00144 { 00145 // std::cout << "split " << this << "\n"; 00146 00147 REAL tMid = tEnd_ * ratio + tBeg_ * ( 1 - ratio ); 00148 w1=tNEW(gWallRim(grid, tBeg_, tMid, height)); 00149 w2=tNEW(gWallRim(grid, tMid, tEnd_, height)); 00150 }
bool gWallRim::RunsParallelPassive | ( | eWall * | newWall | ) | [virtual] |
void gWallRim::RenderReal | ( | const eCamera * | cam | ) | [virtual] |
Implements eWallRim.
Definition at line 255 of file gWall.cpp.
References abs(), BeginQuads(), eCamera::CameraDir(), eCamera::CameraGlancePos(), eCamera::CameraZ(), eCamera::CenterCamDir(), eCamera::CenterPos(), Color(), eWallRim::DestroyDisplayList(), eCoord, eWall::Edge(), eWall::EndPoint(), EPS, gWallRim_helper(), eWallRim::height, lastUpdate_, pos, REAL, RenderEnd(), renderHeight_, se_mainGameTimer, sg_arenaWallShadowDist, sg_arenaWallShadowNear, sg_arenaWallShadowSideDist, sg_arenaWallShadowSize, sg_bugTransparency, sg_bugTransparencyDemand, sg_MoviePack(), sg_MPRimStretchX, sg_MPRimStretchY, sg_RimStretchX, sg_RimStretchY, sw, Swap(), tBeg_, tEnd_, eTimer::Time(), ts, and Vertex().
00256 { 00257 if ( Edge() ){ 00258 const eCoord *p1=&EndPoint(0); 00259 const eCoord *p2=&EndPoint(1); 00260 00261 REAL X_SCALE=sg_RimStretchX; 00262 REAL Z_SCALE=sg_RimStretchY; 00263 00264 // determine height and transparency 00265 bool transparency = sg_bugTransparency || ( sg_bugTransparencyDemand && renderHeight_ < height ); 00266 REAL h = transparency ? height : renderHeight_; 00267 if ( transparency ) 00268 glDisable( GL_DEPTH_TEST ); 00269 00270 if (sg_MoviePack()){ 00271 X_SCALE=sg_MPRimStretchX; 00272 Z_SCALE=sg_MPRimStretchY; 00273 } 00274 00275 if ( tBeg_ == tEnd_ ) 00276 { 00277 tBeg_=(p1->x+p1->y); 00278 tEnd_=(p2->x+p2->y); 00279 } 00280 REAL tBeg = tBeg_/X_SCALE; 00281 REAL tEnd = tEnd_/X_SCALE; 00282 eCoord P1=*p1; 00283 eCoord P2=*p2; 00284 00285 // draw "shadow" away from camera 00286 if ( cam ) 00287 { 00288 // determine relevant position 00289 eCoord pos = cam->CenterPos(); 00290 00291 // alternative that does not look so good 00292 // eCoord pos = cam->CameraGlancePos(); 00293 00294 // calculate normal on wall 00295 eCoord normal = (P1 - P2).Turn(0,1); 00296 normal.Normalize(); 00297 00298 // determine distance of the position to the wall's line 00299 REAL side = -eCoord::F(normal, pos - P1); 00300 00301 // length scale 00302 REAL scale = pos.Norm() + 10 + (P1-P2).Norm(); 00303 00304 // add a tiny contribution from the direction to avoid side==zero 00305 // side += ( 20 * EPS * eCoord::F( normal, cam->CenterCamDir() ) 00306 // +10 * EPS * eCoord::F( normal, cam->CameraDir() ) ) * scale; 00307 00308 // fallback to camera position in case of doubt 00309 // if ( fabs(side) < EPS*scale ) 00310 // side = -eCoord::F( normal, cam->CameraGlancePos() ); 00311 00312 // get absolute value and sign of side 00313 REAL abs = fabs(side); 00314 REAL sign = side/abs; 00315 00316 // if abs is low, override the sign by considering the direction 00317 if ( abs < EPS*scale*10 ) 00318 { 00319 // the direction object and camera are facing 00320 eCoord facing = cam->CenterCamDir() * 2 + cam->CameraDir(); 00321 00322 sign = eCoord::F( normal, facing ); 00323 abs = fabs( sign ); 00324 if ( abs > EPS ) 00325 { 00326 sign/= fabs( sign ); 00327 abs = EPS*scale; 00328 } 00329 else 00330 { 00331 abs = 0; 00332 sign = 0; 00333 } 00334 } 00335 00336 // driving direction 00337 eCoord dir = cam->CenterCamDir(); 00338 00339 // the side the camera is on 00340 REAL camSide = -eCoord::F(normal, cam->CameraGlancePos() - P1); 00341 00342 // no shadow if camera and vehicle are on different sides 00343 if ( camSide * sign < -EPS*scale ) 00344 sign = 0; 00345 00346 // if the camera is closer to the wall than the vehicle, take the abs value from that 00347 if ( sign * eCoord::F( normal, dir ) > -EPS ) 00348 { 00349 if ( camSide * sign >= 0 ) 00350 { 00351 REAL camAbs = fabs( camSide ); 00352 if ( camAbs < abs ) 00353 abs = camAbs; 00354 } 00355 else 00356 { 00357 // wall lies between camera and cycle 00358 abs = 0; 00359 } 00360 } 00361 00362 // add scaled down distance of the wall and the projected path 00363 { 00364 REAL d1 = dir * (pos - P1); 00365 REAL d2 = dir * (pos - P2); 00366 if ( d1 * d2 >= 0 ) 00367 { 00368 REAL dist = fabs( d1 ); 00369 d2 = fabs( d2 ); 00370 if ( d2 < dist ) 00371 dist = d2; 00372 00373 abs += dist * sg_arenaWallShadowSideDist/sg_arenaWallShadowDist; 00374 } 00375 } 00376 00377 // add scaled down distance along the wall's direction 00378 /* 00379 { 00380 REAL a1 = -(pos - P1)*normal; 00381 REAL a2 = (pos - P2)*normal; 00382 if (a1 > 0) 00383 abs += a1 * sg_arenaWallShadowSideDist/sg_arenaWallShadowDist; 00384 if (a2 > 0) 00385 abs += a2 * sg_arenaWallShadowSideDist/sg_arenaWallShadowDist; 00386 } 00387 */ 00388 00389 if ( sign != 0 && abs < sg_arenaWallShadowSideDist ) 00390 { 00391 // determine height scale 00392 REAL heightForShadow = cam->CameraZ()+10; 00393 if ( this->renderHeight_*4 < heightForShadow ) 00394 heightForShadow = this->renderHeight_*4; 00395 00396 // determine shadow extension 00397 REAL extension = heightForShadow*sg_arenaWallShadowSize * sign/( 1 + abs/sg_arenaWallShadowNear ); 00398 extension *= ( 1 - abs/sg_arenaWallShadowSideDist ); 00399 00400 // get two more vertices for teh shadow 00401 eCoord P3=P1+normal*extension; 00402 eCoord P4=P2+normal*extension; 00403 00404 // render shadow 00405 Color(0,0,0); 00406 BeginQuads(); 00407 Vertex(P1.x, P1.y, 0); 00408 Vertex(P2.x, P2.y, 0); 00409 Vertex(P4.x, P4.y, 0); 00410 Vertex(P3.x, P3.y, 0); 00411 } 00412 } 00413 00414 { 00415 eCoord vec = P1-P2; 00416 REAL xs = vec.x*vec.x; 00417 REAL ys = vec.y*vec.y; 00418 REAL intensity = .7 + .3 * xs/(xs+ys); 00419 RenderEnd( true ); 00420 Color(intensity, intensity, intensity); 00421 } 00422 00423 if (sg_MoviePack()){ 00424 bool sw=false; 00425 00426 if (tBeg>tEnd){ 00427 Swap(P1,P2); 00428 Swap(tBeg,tEnd); 00429 //sw=true; 00430 } 00431 00432 REAL ta=tBeg; 00433 eCoord ca=P1; 00434 for (int i=int(ceil(tBeg));i<tEnd;i++){ 00435 eCoord cb=P1+(P2-P1)*((i-tBeg)/(tEnd-tBeg)); 00436 gWallRim_helper(ca,cb,ta,i,h,Z_SCALE,sw); 00437 ca=cb; 00438 ta=i; 00439 } 00440 gWallRim_helper(ca,P2,ta,tEnd,h,Z_SCALE,sw); 00441 } 00442 else{ 00443 // wrap manually in y-direction, some graphics card are bad at it 00444 REAL offset = 0; 00445 if (tBeg>tEnd) 00446 offset = -floor(tEnd); 00447 else 00448 offset = -floor(tBeg); 00449 00450 tBeg += offset; 00451 tEnd += offset; 00452 00453 gWallRim_helper(*p1,*p2,tBeg,tEnd,h,Z_SCALE,false); 00454 } 00455 00456 //eWall::Render_helper(edge,(p1->x+p1->y)/SCALE,(p2->x+p2->y)/SCALE,40,height); 00457 00458 if ( transparency ) 00459 glEnable( GL_DEPTH_TEST ); 00460 } 00461 00462 // grow the wall again 00463 if ( se_mainGameTimer ) 00464 { 00465 REAL time = se_mainGameTimer->Time(); 00466 REAL ts = time - lastUpdate_; 00467 if ( ts > 0 ) 00468 { 00469 lastUpdate_ = time; 00470 00471 if ( renderHeight_ < .25 ) 00472 { 00473 renderHeight_ = .25; 00474 } 00475 renderHeight_ *= 1 + 10 * ts; 00476 renderHeight_ += 5 * ts; 00477 if ( renderHeight_ > height ) 00478 { 00479 renderHeight_ = height; 00480 } 00481 } 00482 00483 if ( renderHeight_ < height ) 00484 { 00485 DestroyDisplayList(); 00486 } 00487 }
called by the camera code when this wall is between the cycle and the camera
cam | the camera that is blocked | |
height | the maximal height the wall would be allowed to have without blocking the view |
Reimplemented from eWall.
Definition at line 500 of file gWall.cpp.
References eWallRim::DestroyDisplayList(), and renderHeight_.
00502 { 00503 DestroyDisplayList(); 00504 00505 // lower the wall so it now longer blocks the view 00506 if ( height < renderHeight_ ) 00507 { 00508 renderHeight_ = height; 00509 } 00510 if ( renderHeight_ < .25 ) 00511 renderHeight_ = .25;
REAL gWallRim::Height | ( | void | ) | [protected, virtual] |
Reimplemented from eWallRim.
Definition at line 525 of file gWall.cpp.
References renderHeight_.
00527 { 00528 return renderHeight_;
REAL gWallRim::SeeHeight | ( | void | ) | [protected, virtual] |
Reimplemented from eWallRim.
Definition at line 540 of file gWall.cpp.
References renderHeight_.
00542 { 00543 return renderHeight_ * 2;
REAL gWallRim::renderHeight_ [mutable, private] |
the height with which this wall is really rendered
Definition at line 65 of file gWall.h.
Referenced by Height(), OnBlocksCamera(), RenderReal(), and SeeHeight().
REAL gWallRim::lastUpdate_ [mutable, private] |
time of the last render height update
Definition at line 66 of file gWall.h.
Referenced by RenderReal().
REAL gWallRim::tBeg_ [private] |
REAL gWallRim::tEnd_ [private] |
begin and end texture coordinates
Definition at line 68 of file gWall.h.
Referenced by RenderReal(), and Split().