#include <eCamera.h>
Public Member Functions | |
bool | CenterIncamOnTurn () |
bool | WhobbleIncam () |
bool | AutoSwitchIncam () |
bool | RenderingMain () const |
void | SetRenderingMain (bool f) |
const ePlayerNetID * | Player () const |
const ePlayer * | LocalPlayer () const |
eCamera (eGrid *grid, rViewport *vp, ePlayerNetID *owner, ePlayer *lp, eCamMode m=CAMERA_IN) | |
virtual | ~eCamera () |
eGameObject * | Center () const |
eCoord | CenterPos () const |
eCoord | CenterDir () const |
virtual eCoord | CenterCycleDir () const |
virtual REAL | SpeedMultiplier () const |
eCoord | CenterCamDir () const |
eCoord | CenterCamTop () const |
eCoord | CenterCamPos () const |
REAL | CenterCamZ () const |
REAL | CenterZ () const |
REAL | CenterSpeed () const |
const eCoord & | CameraDir () const |
const eCoord & | CameraPos () const |
eCoord | CameraGlancePos () const |
REAL | CameraZ () const |
CHECK: this method is redundant with CameraPos(). I leave removing it to you since it is called externally. | |
bool | CenterAlive () const |
bool | CenterCockpitFixedBefore () const |
void | CenterCockpitFixedAfter () const |
void | SwitchView () |
void | SwitchCenter (int d) |
bool | Act (uActionCamera *act, REAL x) |
eCamMode | GetCamMode () |
void | Render () |
virtual void | Timestep (REAL ts) |
REAL | Dist () |
Static Public Member Functions | |
static void | s_Timestep (eGrid *grid, REAL time) |
Protected Types | |
enum | { se_glances = 4 } |
Protected Member Functions | |
tCHECKED_PTR (eGrid) grid | |
tCHECKED_PTR (ePlayer) localPlayer | |
tCHECKED_PTR (rViewport) vp | |
void | Bound (REAL dt) |
make sure the camera is inside the arena and has clear line of sight | |
void | Bound (REAL dt, eCoord &pos) |
make sure pos is inside the arena and has clear line of sight | |
void | MyInit () |
Static Protected Member Functions | |
static bool | InterestingToWatch (eGameObject const *g) |
static eCoord | nextDirIfGlancing (eCoord const &dir, eCoord const &targetDir, REAL ts) |
Protected Attributes | |
int | id |
nObserverPtr< ePlayerNetID > | netPlayer |
tJUST_CONTROLLED_PTR< eGameObject > | center |
REAL | lastSwitch |
REAL | zNear |
eCamMode | mode |
eCoord | pos |
eCoord | lastPos |
eCoord | dir |
eCoord | top |
REAL | z |
REAL | rise |
REAL | fov |
REAL | turning |
REAL | smoothTurning |
REAL | distance |
REAL | lastrendertime |
REAL | smartcamSkewSmooth |
REAL | smartcamIncamSmooth |
REAL | smartcamFrontSmooth |
REAL | centerSpeedSmooth |
eCoord | centerDirSmooth |
eCoord | centerDirLast |
eCoord | centerPos |
eCoord | centerPosSmooth |
eCoord | centerPosLast |
eCoord | centerposLast |
REAL | userCameraControl |
REAL | centerIncam |
eGlanceRequest * | activeGlanceRequest |
eGlanceRequest | glanceRequests [se_glances] |
bool | renderingMain_ |
Static Protected Attributes | |
static uActionCamera | se_lookUp |
static uActionCamera | se_lookDown |
static uActionCamera | se_lookLeft |
static uActionCamera | se_lookRight |
static uActionCamera | se_moveLeft |
static uActionCamera | se_moveRight |
static uActionCamera | se_moveUp |
static uActionCamera | se_moveDown |
static uActionCamera | se_moveForward |
static uActionCamera | se_moveBack |
static uActionCamera | se_zoomIn |
static uActionCamera | se_zoomOut |
static uActionCamera | se_switchView |
static uGlanceAction | se_glance [se_glances] |
Private Types | |
enum | HitCacheSize { hitCacheSize = 3 } |
Private Member Functions | |
bool | Bound (REAL ratio, eCoord &pos, eCoord const &dirFromTarget, REAL &hitCache) |
make sure CenterPos() + dirFromTarget() is visible from pos | |
Private Attributes | |
REAL | hitCache_ [hitCacheSize] |
Definition at line 63 of file eCamera.h.
anonymous enum [protected] |
enum eCamera::HitCacheSize [private] |
eCamera::eCamera | ( | eGrid * | grid, | |
rViewport * | vp, | |||
ePlayerNetID * | owner, | |||
ePlayer * | lp, | |||
eCamMode | m = CAMERA_IN | |||
) |
Definition at line 483 of file eCamera.cpp.
References MyInit().
00485 :id(-1),grid(g),netPlayer(p),localPlayer(lp), 00486 // centerID(0), 00487 mode(m),pos(0,0),dir(1,0),top(0,0), 00488 vp(view){ 00489 /* 00490 if (p->pID>=0) 00491 localPlayer=playerConfig[p->pID]; 00492 */ 00493 MyInit(); 00494 }
eCamera::~eCamera | ( | ) | [virtual] |
Definition at line 499 of file eCamera.cpp.
References tCHECK_DEST.
00499 { 00500 // int ID=id; 00501 // tDESTROY(foot); 00502 // se_cameras.Remove(this,id); 00503 // se_ResetVisibles(se_cameras.Len()); 00504 // if (ID!=se_cameras.Len()) se_ResetVisibles(ID); 00505 00506 grid->cameras.Remove(this, id); 00507 00508 tCHECK_DEST; 00509 }
eCamera::tCHECKED_PTR | ( | eGrid | ) | [protected] |
eCamera::tCHECKED_PTR | ( | ePlayer | ) | [protected] |
eCamera::tCHECKED_PTR | ( | rViewport | ) | [protected] |
bool eCamera::InterestingToWatch | ( | eGameObject const * | g | ) | [static, protected] |
Definition at line 282 of file eCamera.cpp.
References eGameObject::Alive(), eGameObject::deathTime, and lastTime.
Referenced by Act(), SwitchCenter(), and Timestep().
00282 { 00283 return g && 00284 (g->Alive() || 00285 (lastTime - g->deathTime<1)); 00286 }
eCoord eCamera::nextDirIfGlancing | ( | eCoord const & | dir, | |
eCoord const & | targetDir, | |||
REAL | ts | |||
) | [static, protected] |
returns the next view direction if a glance towards targetDir is requested dir is the current view direction targetDir is the desired view direction ts is the time step note: directions are represented by unit-length vectors
Definition at line 303 of file eCamera.cpp.
References cos(), d, eCoord, REAL, robust_acos(), and sin().
Referenced by Timestep().
00303 { 00304 00305 switch (glanceMode) { 00306 case 0: { 00307 // glance keys rotate the camera with constant angular velocity 00308 REAL d = dir*targetDir; 00309 REAL arc = glanceAngularVelocity*ts; 00310 if (fabs(d)<arc && eCoord::F(dir,targetDir)>0) { 00311 return targetDir; 00312 } else { 00313 eCoord newdir = dir.Turn(1,(d>0) ? -arc : arc); 00314 newdir.Normalize(); 00315 return newdir; 00316 } 00317 break; 00318 } case 1: { 00319 // glance keys rotate camera with angular velocity proportional to alpha 00320 // CHECK: You wanted to fix that trigonometry? Good luck :) 00321 REAL arc = robust_acos(eCoord::F(dir,targetDir)) * ts * glanceAngularVelocity / (M_PI_2); 00322 if (dir*targetDir>0) 00323 arc=-arc; 00324 return dir.Turn(cos(arc),sin(arc)); 00325 } case 2: { 00326 // glance keys rotate camera with angular velocity = 00327 // glanceAngularVelocity * ((alpha<PI/2) ? sin(alpha) : glanceAngularVelocityBonus) 00328 REAL arc = glanceAngularVelocity*ts; 00329 eCoord newdir; 00330 if (eCoord::F(dir,targetDir)>0) { 00331 newdir = dir+targetDir*arc; 00332 } else if (dir*targetDir>0) { 00333 newdir = dir.Turn(1,-arc*glanceAngularVelocityBonus); 00334 } else { 00335 newdir = dir.Turn(1,arc*glanceAngularVelocityBonus); 00336 } 00337 newdir.Normalize(); 00338 return newdir; 00339 } default: 00340 return targetDir; 00341 } 00342 }
void eCamera::Bound | ( | REAL | dt | ) | [protected] |
make sure the camera is inside the arena and has clear line of sight
dt | the timestep taken |
Definition at line 1121 of file eCamera.cpp.
References pos.
Referenced by Act(), Bound(), Render(), and Timestep().
void eCamera::Bound | ( | REAL | dt, | |
eCoord & | pos | |||
) | [protected] |
make sure pos is inside the arena and has clear line of sight
dt | the timestep taken | |
pos | the camera position to clamp for visibility |
Definition at line 1192 of file eCamera.cpp.
References Bound(), CAMERA_IN, CAMERA_SMART_IN, Center(), centerDirSmooth, CenterSpeed(), eCoord, hitCache_, mode, REAL, se_visibilityExtension, se_visibilitySpeed, and z.
01193 { 01194 // make sure the camera is above the floor and inside the rim eWalls 01195 if (z<.1) 01196 z=.1; 01197 01198 // don't waste time on the internal cameras, they don't need clamping 01199 if(mode!=CAMERA_IN && mode !=CAMERA_SMART_IN ) 01200 { 01201 // the following is only meaningful if there is an active camera object 01202 if ( Center() ) 01203 { 01204 // gently bring points in front of the cycle into view 01205 REAL smoothBound = 1/(1+se_visibilitySpeed*dt); 01206 eCoord direction = centerDirSmooth; 01207 //eCoord direction = Center()->Direction(); 01208 //eCoord direction = CenterCamDir() + centerDirSmooth; 01209 direction.Normalize(); 01210 // z-man: I can't yet decide which of the three direction calculations is best. 01211 01212 Bound( smoothBound, pos, direction * ( CenterSpeed() * se_visibilityExtension ), hitCache_[0] ); 01213 01214 // Bound( smoothBound, pos, direction.Turn(se_visibilitySidewaysSkew, 1) * ( CenterSpeed() * se_visibilityExtension ), hitCache_[1] ); 01215 // Bound( smoothBound, pos, direction.Turn(se_visibilitySidewaysSkew,-1) * ( CenterSpeed() * se_visibilityExtension ), hitCache_[2] ); 01216 01217 // force the object itself to be in full view, try several times 01218 int timeout = 4; 01219 bool goon = true; 01220 while (goon && timeout > 0) 01221 { 01222 --timeout; 01223 goon = false; 01224 01225 REAL cache = 1; // no real cache needed here 01226 if ( Bound( 0, pos, eCoord(0,0), cache ) ) 01227 { 01228 goon = true; 01229 break; 01230 } 01231 } 01232 } 01233 } 01234 /* 01235 if ((sr_upperSky) && z>upper_height-3) 01236 z=upper_height-3.0001; 01237 01238 if ( 01239 (se_BlackSky() || (sr_lowerSky && !sr_upperSky))&& 01240 z>lower_height-3) 01241 z=lower_height-3.0001; 01242 */ 01243 }
void eCamera::MyInit | ( | ) | [protected] |
Reimplemented in gCamera.
Definition at line 387 of file eCamera.cpp.
References activeGlanceRequest, CAMERA_COUNT, CAMERA_CUSTOM, CAMERA_FOLLOW, CAMERA_FREE, CAMERA_IN, CAMERA_MER, CAMERA_SERVER_CUSTOM, CAMERA_SMART, CAMERA_SMART_IN, Center(), center, CenterDir(), centerDirLast, centerDirSmooth, centerIncam, CenterPos(), centerPos, centerposLast, centerPosLast, centerPosSmooth, centerSpeedSmooth, CenterZ(), dir, distance, eCoord, forbid_camera, fov, hitCache_, hitCacheSize, lastPos, lastrendertime, lastSwitch, mode, netPlayer, NULL, pos, eGameObject::PredictPosition(), REAL, rise, s_startFollowY, s_startFollowZ, s_startFreeY, s_startFreeZ, s_startSmartY, s_startSmartZ, se_GameTime(), smartcamFrontSmooth, smartcamIncamSmooth, smartcamSkewSmooth, smoothTurning, eGameObject::Speed(), sqrt(), SwitchView(), turning, userCameraControl, z, and zNear.
Referenced by eCamera().
00387 { 00388 if (localPlayer){ 00389 mode=localPlayer->startCamera; //PENDING: 00390 fov=localPlayer->startFOV; 00391 } 00392 00393 // find center: the object our player controls 00394 if (bool(netPlayer) && !center) 00395 { 00396 center = netPlayer->Object(); 00397 } 00398 else if ( grid->gameObjectsInteresting.Len() > 0 ) 00399 { 00400 // or an arbitrary game object 00401 center = grid->gameObjectsInteresting[0]; 00402 } 00403 00404 // switch away from forbidden camera mode 00405 if (forbid_camera[mode] && bool(netPlayer) && netPlayer->Object()==Center()) 00406 SwitchView(); 00407 00408 centerPos=eCoord(100,100); 00409 centerSpeedSmooth=0; 00410 if ( Center() ) 00411 { 00412 centerPos = Center()->PredictPosition(); 00413 centerSpeedSmooth = Center()->Speed(); 00414 } 00415 00416 pos=CenterPos(); 00417 dir=CenterDir(); 00418 centerPosSmooth=pos; 00419 centerDirLast=centerDirSmooth=dir; 00420 lastPos=pos; 00421 zNear=0.1f; 00422 // foot=tNEW(eGameObject)(pos,dir,0); 00423 distance=0; 00424 lastrendertime=se_GameTime(); 00425 grid->cameras.Add(this,id); 00426 // se_ResetVisibles(id); 00427 smoothTurning=turning=0; 00428 centerPosLast=centerposLast=CenterPos(); 00429 userCameraControl=0; 00430 centerIncam=1; 00431 smartcamSkewSmooth=0; 00432 smartcamIncamSmooth=1; 00433 smartcamFrontSmooth=0; 00434 00435 for(int i = hitCacheSize-1; i>=0; --i) 00436 hitCache_[i] = 1; 00437 00438 switch (mode){ 00439 case CAMERA_CUSTOM: 00440 case CAMERA_SERVER_CUSTOM: 00441 case CAMERA_IN: 00442 z=10; 00443 rise=0; 00444 break; 00445 case CAMERA_FOLLOW: 00446 pos=pos+dir.Turn(eCoord(s_startFollowX,s_startFollowY)) ; 00447 z=s_startFollowZ; 00448 break; 00449 case CAMERA_SMART: 00450 pos=pos+dir.Turn(eCoord(s_startSmartX,s_startSmartY)) ; 00451 z=s_startSmartZ; 00452 break; 00453 case CAMERA_FREE: 00454 pos=pos+dir.Turn(eCoord(s_startFreeX,s_startFreeY)) ; 00455 z=s_startFreeZ; 00456 break; 00457 case CAMERA_MER: 00458 pos=pos-dir*mercamxydist; 00459 z=CenterZ(); 00460 rise=0; 00461 break; 00462 case CAMERA_SMART_IN: 00463 case CAMERA_COUNT: 00464 break; 00465 } 00466 00467 if ( mode != CAMERA_IN && mode != CAMERA_CUSTOM && mode != CAMERA_SERVER_CUSTOM ){ 00468 dir=CenterPos()-pos; 00469 REAL dist=REAL(sqrt(dir.NormSquared())); 00470 if (dist<.001) dist=1; 00471 dir=dir*(1/dist); 00472 rise=(CenterZ()-z)/dist; 00473 } 00474 00475 activeGlanceRequest=NULL; 00476 00477 lastSwitch=-100; 00478 }
bool eCamera::CenterIncamOnTurn | ( | ) |
Definition at line 1245 of file eCamera.cpp.
Referenced by Timestep().
01245 { 01246 if (localPlayer) 01247 return localPlayer->centerIncamOnTurn; 01248 else 01249 return false; 01250 }
bool eCamera::WhobbleIncam | ( | ) |
Definition at line 1251 of file eCamera.cpp.
Referenced by Timestep().
01251 { 01252 if (localPlayer) 01253 return localPlayer->wobbleIncam; 01254 else 01255 return false; 01256 }
bool eCamera::AutoSwitchIncam | ( | ) |
Definition at line 1257 of file eCamera.cpp.
Referenced by Timestep().
01257 { 01258 if (localPlayer) 01259 return localPlayer->autoSwitchIncam; 01260 else 01261 return false; 01262 }
bool eCamera::RenderingMain | ( | ) | const [inline] |
Definition at line 135 of file eCamera.h.
Referenced by gCycle::RenderName().
00135 { return renderingMain_; }
void eCamera::SetRenderingMain | ( | bool | f | ) | [inline] |
Definition at line 136 of file eCamera.h.
References renderingMain_.
Referenced by eGrid::Render().
00136 { renderingMain_ = f; }
const ePlayerNetID * eCamera::Player | ( | ) | const |
Definition at line 480 of file eCamera.cpp.
References netPlayer.
Referenced by gCycle::RenderName().
00480 { return netPlayer; }
const ePlayer * eCamera::LocalPlayer | ( | ) | const |
Definition at line 481 of file eCamera.cpp.
Referenced by se_GetWatchedPlayer().
eGameObject * eCamera::Center | ( | ) | const |
Definition at line 514 of file eCamera.cpp.
References center.
Referenced by Bound(), CenterAlive(), CenterCamDir(), CenterCamPos(), CenterCamTop(), CenterCamZ(), CenterCockpitFixedAfter(), CenterCockpitFixedBefore(), gCamera::CenterCycleDir(), CenterDir(), CenterSpeed(), CenterZ(), gCamera::MyInit(), MyInit(), gCycle::Render(), Render(), SwitchView(), gCamera::Timestep(), and Timestep().
00514 { 00515 return center; 00516 }
eCoord eCamera::CenterPos | ( | ) | const |
Definition at line 2252 of file eCamera.cpp.
References centerPos.
Referenced by Bound(), gCamera::MyInit(), MyInit(), Render(), gWallRim::RenderReal(), and Timestep().
02252 { 02253 return centerPos; 02254 }
eCoord eCamera::CenterDir | ( | ) | const |
Definition at line 2260 of file eCamera.cpp.
References Center(), eGameObject::Direction(), and eCoord.
Referenced by gCamera::CenterCycleDir(), CenterCycleDir(), MyInit(), and Timestep().
02260 { 02261 eGameObject *go=Center(); 02262 if (go) 02263 return go->Direction() ; 02264 else 02265 return eCoord(1,0); 02266 }
eCoord eCamera::CenterCycleDir | ( | ) | const [virtual] |
Definition at line 2256 of file eCamera.cpp.
References CenterDir().
Referenced by Timestep().
02256 { 02257 return CenterDir(); 02258 }
virtual REAL eCamera::SpeedMultiplier | ( | ) | const [inline, virtual] |
Reimplemented in gCamera.
Definition at line 150 of file eCamera.h.
Referenced by Timestep().
eCoord eCamera::CenterCamDir | ( | ) | const |
Definition at line 2268 of file eCamera.cpp.
References eGameObject::CamDir(), Center(), and eCoord.
Referenced by Act(), gWallRim::RenderReal(), and Timestep().
02268 { 02269 eGameObject *go=Center(); 02270 if (go) 02271 return go->CamDir() ; 02272 else 02273 return eCoord(1,0); 02274 }
eCoord eCamera::CenterCamTop | ( | ) | const |
Definition at line 2276 of file eCamera.cpp.
References eGameObject::CamTop(), Center(), and eCoord.
Referenced by Timestep().
02276 { 02277 eGameObject *go=Center(); 02278 if (go) 02279 return go->CamTop(); 02280 else 02281 return eCoord(0,0); 02282 }
eCoord eCamera::CenterCamPos | ( | ) | const |
Definition at line 2284 of file eCamera.cpp.
References eGameObject::CamPos(), Center(), and eCoord.
Referenced by Timestep().
02284 { 02285 eGameObject *go=Center(); 02286 if (go) 02287 return go->CamPos(); 02288 else 02289 return eCoord(100,100); 02290 }
REAL eCamera::CenterCamZ | ( | ) | const |
Definition at line 2292 of file eCamera.cpp.
References Center().
Referenced by Timestep().
02292 { 02293 eGameObject *go=Center(); 02294 if (go) 02295 return go-> CamZ(); 02296 else 02297 return 1.5; 02298 }
REAL eCamera::CenterZ | ( | ) | const |
Definition at line 2300 of file eCamera.cpp.
References Center(), and eGameObject::z.
Referenced by MyInit(), Render(), and Timestep().
02300 { 02301 eGameObject *go=Center(); 02302 if (go) 02303 return go->z ; 02304 else 02305 return 1.5; 02306 }
REAL eCamera::CenterSpeed | ( | ) | const |
Definition at line 2308 of file eCamera.cpp.
References Center(), and eGameObject::Speed().
Referenced by Bound(), and Timestep().
02308 { 02309 eGameObject *go=Center(); 02310 if (go) 02311 return go->Speed(); 02312 else 02313 return 20; 02314 }
const eCoord& eCamera::CameraDir | ( | ) | const [inline] |
Definition at line 160 of file eCamera.h.
References dir.
Referenced by cWidget::Map::DrawMap(), and gWallRim::RenderReal().
00160 {return dir;}
const eCoord& eCamera::CameraPos | ( | ) | const [inline] |
eCoord eCamera::CameraGlancePos | ( | ) | const [inline] |
Definition at line 162 of file eCamera.h.
References pos.
Referenced by gWallRim::RenderReal().
00162 {return pos;}
REAL eCamera::CameraZ | ( | ) | const [inline] |
CHECK: this method is redundant with CameraPos(). I leave removing it to you since it is called externally.
Definition at line 163 of file eCamera.h.
References z.
Referenced by gCycle::Render(), and gWallRim::RenderReal().
00163 {return z;}
bool eCamera::CenterAlive | ( | ) | const |
Definition at line 2317 of file eCamera.cpp.
References eGameObject::Alive(), and Center().
Referenced by Timestep().
02317 { 02318 eGameObject *go=Center(); 02319 if (go) 02320 return go->Alive() ; 02321 else 02322 return false; 02323 }
bool eCamera::CenterCockpitFixedBefore | ( | ) | const |
Definition at line 2326 of file eCamera.cpp.
References Center(), and eGameObject::RenderCockpitFixedBefore().
Referenced by Render().
02326 { 02327 eGameObject *go=Center(); 02328 if (go) 02329 return go->RenderCockpitFixedBefore(); 02330 else 02331 return true; 02332 }
void eCamera::CenterCockpitFixedAfter | ( | ) | const |
Definition at line 2334 of file eCamera.cpp.
References Center(), and eGameObject::RenderCockpitFixedAfter().
Referenced by Render().
02334 { 02335 eGameObject *go=Center(); 02336 if (go) 02337 go->RenderCockpitFixedAfter() ; 02338 else 02339 return; 02340 }
void eCamera::SwitchView | ( | ) |
Definition at line 518 of file eCamera.cpp.
References CAMERA_COUNT, CAMERA_CUSTOM, CAMERA_IN, CAMERA_SERVER_CUSTOM, CAMERA_SMART, Center(), con, dir, forbid_camera, mode, netPlayer, pos, rise, smartcamIncamSmooth, userCameraControl, z, and zNear.
Referenced by Act(), and MyInit().
00518 { 00519 zNear = 0.01f; 00520 00521 int count=CAMERA_COUNT * 2; 00522 00523 userCameraControl = 0; 00524 00525 // eCamMode pre=mode; 00526 00527 bool imp=true,global_imp=true,both_imp=true; 00528 for (int i=CAMERA_COUNT-1;i>=0;i--){ 00529 if (!localPlayer || localPlayer->allowCam[i]) 00530 imp=false; 00531 if (!forbid_camera[i] || !netPlayer || netPlayer->Object()!=Center()) 00532 global_imp=false; 00533 if ((!forbid_camera[i] || !netPlayer || netPlayer->Object()!=Center()) 00534 && (!localPlayer || localPlayer->allowCam[i])) 00535 both_imp=false; 00536 } 00537 00538 if (imp) con << "impossible to meet your needs.\n"; 00539 if (global_imp) con << "impossible to meet global needs.\n"; 00540 if (both_imp) con << "impossible to meet both needs.\n"; 00541 00542 if (both_imp && !global_imp) 00543 imp=true; 00544 00545 do{ 00546 // rotate the mode 00547 int m = mode; 00548 m--; 00549 if ( m<0 ) 00550 m = CAMERA_SERVER_CUSTOM; 00551 mode = static_cast< eCamMode >( m ); 00552 00553 count--; 00554 } 00555 while ((!imp && count > CAMERA_COUNT && localPlayer && !localPlayer->allowCam[mode]) 00556 || (count >0 && !global_imp && forbid_camera[mode] && 00557 (bool( netPlayer ) && netPlayer->Object()==Center()))); 00558 00559 if ( mode == CAMERA_IN || mode == CAMERA_CUSTOM || mode == CAMERA_SERVER_CUSTOM ) 00560 rise=0; 00561 00562 if(mode==CAMERA_SMART){ 00563 smartcamIncamSmooth=1; 00564 z=z+1; 00565 pos=pos+dir.Turn(-1,.1); 00566 } 00567 }
void eCamera::SwitchCenter | ( | int | d | ) |
Definition at line 1556 of file eCamera.cpp.
References center, InterestingToWatch(), lastSwitch, lastTime, NULL, and zNear.
Referenced by Act(), and Timestep().
01556 { 01557 zNear = 0.01f; 01558 01559 int centerID = 0; 01560 if (center) 01561 centerID = center->interestingID; 01562 center = NULL; 01563 01564 if (centerID>=grid->gameObjectsInteresting.Len()) 01565 centerID=0; 01566 if (centerID<0) 01567 centerID=grid->gameObjectsInteresting.Len()-1; 01568 01569 int timeout=(grid->gameObjectsInteresting.Len()+1)*5; 01570 int oldid=centerID; 01571 if (grid->gameObjectsInteresting.Len()>0){ 01572 if (!InterestingToWatch(grid->gameObjectsInteresting(centerID))) 01573 grid->gameObjectsInteresting.Remove 01574 (grid->gameObjectsInteresting(centerID), 01575 grid->gameObjectsInteresting(centerID)->interestingID); 01576 do{ 01577 timeout--; 01578 centerID+=d; 01579 01580 if (centerID<0) 01581 centerID=grid->gameObjectsInteresting.Len()-1; 01582 if (centerID>=grid->gameObjectsInteresting.Len()) 01583 centerID=0; 01584 01585 }while(timeout >0 && grid->gameObjectsInteresting.Len()>0 && 01586 oldid!=centerID && 01587 !InterestingToWatch(grid->gameObjectsInteresting(centerID))); 01588 } 01589 else centerID=0; 01590 // con << "swtiched view from " << oldid << " to " << centerID << '\n'; 01591 01592 if ( centerID >= 0 && centerID < grid->gameObjectsInteresting.Len() ) 01593 { 01594 center = grid->gameObjectsInteresting(centerID); 01595 lastSwitch=lastTime; 01596 } 01597 }
bool eCamera::Act | ( | uActionCamera * | act, | |
REAL | x | |||
) |
Definition at line 569 of file eCamera.cpp.
References activeGlanceRequest, Bound(), CAMERA_COUNT, CAMERA_CUSTOM, CAMERA_FOLLOW, CAMERA_FREE, CAMERA_IN, CAMERA_MER, CAMERA_SERVER_CUSTOM, CAMERA_SMART, CAMERA_SMART_IN, center, CenterCamDir(), eGlanceRequest::dir, dir, eCoord, fov, glanceRequests, tListItem< T >::Insert(), InterestingToWatch(), mode, netPlayer, NULL, pos, REAL, uGlanceAction::relDir, tListItemBase::Remove(), rise, se_GameTime(), se_glance, se_glances, se_lookDown, se_lookLeft, se_lookRight, se_lookUp, se_moveBack, se_moveDown, se_moveForward, se_moveLeft, se_moveRight, se_moveUp, se_SetWatchedObject(), se_switchView, eGameObject::se_turnLeft, eGameObject::se_turnRight, se_zoomIn, se_zoomOut, sqrt(), SwitchCenter(), SwitchView(), turning, userCameraControl, and z.
00569 { 00570 eCoord objdir=CenterCamDir(); 00571 00572 int turn=0; 00573 if (eGameObject::se_turnLeft==*reinterpret_cast<uActionPlayer *>(Act)){ 00574 turn=-1; 00575 } 00576 if (eGameObject::se_turnRight==*reinterpret_cast<uActionPlayer *>(Act)){ 00577 turn=1; 00578 } 00579 00580 if (turn){ 00581 eGameObject *cent=NULL; 00582 if (se_GameTime() <= 0 ) 00583 turning+=.5; 00584 if (netPlayer) cent=netPlayer->Object(); 00585 if (!InterestingToWatch(cent) && x>0) 00586 { 00587 SwitchCenter(turn); 00588 se_SetWatchedObject( this, center ); 00589 } 00590 } 00591 00592 REAL ll=0,lu=0,ml=0,mf=0,mu=0,zi=1; 00593 00594 if (se_lookLeft==*Act && x>0) 00595 ll=x; 00596 else if (se_lookRight==*Act && x>0) 00597 ll=-x; 00598 else if (se_lookUp==*Act && x>0) 00599 lu=x; 00600 else if (se_lookDown==*Act && x>0) 00601 lu=-x; 00602 else if (se_zoomIn==*Act && x>0) 00603 zi*=1+zi*.1; 00604 else if (se_zoomOut==*Act && x>0) 00605 zi/=1+zi*.1; 00606 00607 else if (se_moveLeft==*Act && x>0) 00608 ml=x; 00609 else if (se_moveRight==*Act && x>0) 00610 ml=-x; 00611 else if (se_moveForward==*Act && x>0) 00612 mf=x; 00613 else if (se_moveBack==*Act && x>0) 00614 mf=-x; 00615 else if (se_moveUp==*Act && x>0) 00616 mu=x; 00617 else if (se_moveDown==*Act && x>0) 00618 mu=-x; 00619 else if (se_switchView==*Act && x>0) 00620 SwitchView(); 00621 else if (se_glance<=Act && Act < se_glance+se_glances) { 00622 uGlanceAction* ga = static_cast<uGlanceAction*>(Act); 00623 eGlanceRequest* gr = &glanceRequests[ga-se_glance]; 00624 if (x>0) { 00625 eCoord baseDir = grid->GetDirection(grid->DirectionWinding(dir)); // CHECK: proper focal point? 00626 gr->dir = baseDir.Turn(ga->relDir); 00627 gr->Insert(activeGlanceRequest); 00628 } else { 00629 gr->Remove(); 00630 } 00631 } else 00632 return false; 00633 00634 00635 userCameraControl+=sqrt(ll*ll+lu*lu+(1-zi)*(1-zi)+ml*ml+mf*mf+mu*mu)/20; 00636 00637 switch(mode){ 00638 case CAMERA_IN: 00639 case CAMERA_SMART_IN: 00640 lu+=mu*2; 00641 ll+=ml; 00642 mu=ml=0; 00643 break; 00644 case CAMERA_CUSTOM: 00645 case CAMERA_SERVER_CUSTOM: 00646 case CAMERA_FREE: 00647 break; 00648 case CAMERA_FOLLOW: 00649 case CAMERA_SMART: 00650 case CAMERA_MER: 00651 mu-=lu; 00652 ml-=ll; 00653 lu=ll=0; 00654 break; 00655 case CAMERA_COUNT: 00656 break; 00657 } 00658 00659 // normal actions with the given data 00660 dir=dir+dir.Turn(eCoord(0,ll*.2)); 00661 rise+=lu/80; 00662 z+=mu*.25; 00663 pos=pos+dir*mf*.25+dir.Turn(eCoord(0,ml*.25)); 00664 00665 fov/=zi; 00666 if (fov>120) fov=120; 00667 00668 if (fov<30) fov=30; 00669 00670 00671 switch(mode){ 00672 case CAMERA_IN: 00673 case CAMERA_SMART_IN: 00674 { 00675 int x=3; 00676 while (eCoord::F(dir,objdir)<-.51 && x>0){ 00677 dir=dir-objdir*(eCoord::F(dir,objdir)+.5); 00678 dir=dir*(1/sqrt(dir.NormSquared())); 00679 x--; 00680 } 00681 } 00682 break; 00683 case CAMERA_CUSTOM: 00684 case CAMERA_SERVER_CUSTOM: 00685 case CAMERA_FREE: 00686 case CAMERA_FOLLOW: 00687 case CAMERA_SMART: 00688 case CAMERA_MER: 00689 break; 00690 case CAMERA_COUNT: 00691 break; 00692 } 00693 00694 Bound(0); 00695 00696 return true; 00697 }
eCamMode eCamera::GetCamMode | ( | ) | [inline] |
void eCamera::Render | ( | ) |
Definition at line 1360 of file eCamera.cpp.
References eWallRim::Bound(), Bound(), c, CAMERA_IN, Center(), CenterCockpitFixedAfter(), CenterCockpitFixedBefore(), centerDirSmooth, centerIncam, CenterPos(), centerPosLast, centerPosSmooth, CenterZ(), eSensor::detect(), dir, distance, eCoord, fov, glMatrixMode, eSensor::hit, lastPos, lastrendertime, makefinite(), mode, pos, rise, se_cameraRise, se_cameraZ, se_ClampCamera(), se_GameTime(), smartcamFrontSmooth, smartcamIncamSmooth, smartcamSkewSmooth, smoothTurning, sqrt(), sr_glOut, top, turning, userCameraControl, z, and zNear.
01360 { 01361 if (!sr_glOut) 01362 return; 01363 displaying=true; 01364 01365 se_cameraRise=rise; 01366 se_cameraZ=z; 01367 01368 //REAL ts=ArmageTronTimer-lastrendertime; 01369 lastrendertime=se_GameTime(); 01370 01371 makefinite(pos); 01372 makefinite(lastPos); 01373 makefinite(top); 01374 makefinite(dir); 01375 makefinite(rise,0); 01376 makefinite(z,2); 01377 makefinite(distance,0); 01378 makefinite(smartcamSkewSmooth); 01379 makefinite(smartcamFrontSmooth); 01380 makefinite(smartcamIncamSmooth); 01381 makefinite(centerDirSmooth); 01382 makefinite(centerPosSmooth); 01383 makefinite(centerPosLast); 01384 makefinite(centerIncam); 01385 makefinite(userCameraControl); 01386 makefinite(turning); 01387 makefinite(smoothTurning); 01388 makefinite(fov); 01389 makefinite(distance); 01390 makefinite(lastrendertime); 01391 01392 /* 01393 eCoord glancedir=dir.Turn(1,glanceSmooth).Turn(1,glanceSmooth); 01394 glancedir=glancedir*(1/sqrt(glancedir.NormSquared())); 01395 if (glancingBack) 01396 glancedir=glancedir*(-1); 01397 01398 eCoord pos_diff=pos-CenterPos(); 01399 if (mode != CAMERA_FREE){ 01400 pos_diff = pos_diff.Turn(dir.Conj()); 01401 pos_diff = pos_diff.Turn(glancedir); 01402 } 01403 pos_diff = pos_diff + CenterPos(); 01404 */ 01405 01406 // CHECK: is this still what you intend it to be? 01407 if (!se_ClampCamera(mode)) 01408 Bound(0, pos); 01409 01410 // Bound( dt ); 01411 01412 if (z>400) z=300; 01413 if (z<0) z=0; 01414 01415 if (rise<-100) rise=-100; 01416 if (rise>100) rise=100; 01417 01418 // camera control logic 01419 /* 01420 if (center) 01421 Timestep(ts); 01422 */ 01423 01424 // foot->Move(pos_diff,0,1); 01425 01426 /* 01427 if (foot->currentFace) 01428 foot->currentFace->SetVisHeight(id,0); 01429 foot->Move(pos+dir*.01,0,1); 01430 if (foot->currentFace) 01431 foot->currentFace->SetVisHeight(id,0); 01432 */ 01433 01434 distance+=sqrt((lastPos-pos).NormSquared())*1.5; 01435 lastPos=pos; 01436 01437 #ifdef DEBUG 01438 // eEdge::UpdateVisAll(id); 01439 #endif 01440 01441 glMatrixMode(GL_PROJECTION); 01442 glLoadIdentity(); 01443 glMatrixMode(GL_MODELVIEW); 01444 glLoadIdentity(); 01445 01446 if(CenterCockpitFixedBefore()){ 01447 vp->Perspective(fov,zNear,1E+20,se_cameraEyeDistance/2.); 01448 01449 gluLookAt(0, 01450 0, 01451 0, 01452 01453 dir.x, 01454 dir.y, 01455 rise, 01456 01457 top.x,top.y, 01458 1); 01459 01460 glTranslatef(-pos.x,-pos.y,-z); 01461 glMatrixMode(GL_MODELVIEW); 01462 01463 bool draw_center=((CenterPos()-pos).NormSquared()>1 || 01464 fabs(CenterZ() - z)>1); 01465 01466 tJUST_CONTROLLED_PTR< eGameObject > c=Center(); 01467 if (!draw_center && c) c->RemoveFromList(); 01468 01469 eCoord poscopy = pos; 01470 zNear = - eWallRim::Bound( poscopy, 0.0f ); 01471 if (zNear < -.1 ) 01472 zNear = .1; 01473 01474 if(se_cameraEyeDistance) { 01475 glColorMask(se_cameraEye1Color & 1, se_cameraEye1Color & 2, se_cameraEye1Color & 4, GL_TRUE); 01476 } 01477 grid->Render( this, id, zNear ); 01478 01479 zNear *= .3f; 01480 if ( zNear < 0.0001f ) 01481 { 01482 zNear = 0.0001f; 01483 } 01484 01485 if(se_cameraEyeDistance) { 01486 glClear(GL_DEPTH_BUFFER_BIT); 01487 glColorMask(se_cameraEye2Color & 1, se_cameraEye2Color & 2, se_cameraEye2Color & 4, GL_TRUE); 01488 glMatrixMode(GL_PROJECTION); 01489 glLoadIdentity(); 01490 glMatrixMode(GL_MODELVIEW); 01491 glLoadIdentity(); 01492 01493 vp->Perspective(fov,zNear,1E+20,-se_cameraEyeDistance/2.); 01494 01495 float offset = 0; 01496 if(mode == CAMERA_IN) { 01497 eSensor test(Center(), Center()->Position(), Center()->Direction()); 01498 test.detect(se_cameraInMaxFocusDistance*Center()->Speed()); 01499 offset = test.hit; 01500 } 01501 01502 gluLookAt(0, 01503 0, 01504 0, 01505 01506 dir.x, 01507 dir.y, 01508 rise, 01509 01510 top.x,top.y, 01511 1); 01512 01513 glTranslatef(-pos.x,-pos.y,-z); 01514 glMatrixMode(GL_MODELVIEW); 01515 01516 draw_center=((CenterPos()-pos).NormSquared()>1 || 01517 fabs(CenterZ() - z)>1); 01518 01519 tJUST_CONTROLLED_PTR< eGameObject > c=Center(); 01520 if (!draw_center && c) c->RemoveFromList(); 01521 01522 eCoord poscopy = pos; 01523 zNear = - eWallRim::Bound( poscopy, 0.0f ); 01524 if (zNear < -.1 ) 01525 zNear = .1; 01526 01527 grid->Render( this, id, zNear ); 01528 01529 zNear *= .3f; 01530 if ( zNear < 0.0001f ) 01531 { 01532 zNear = 0.0001f; 01533 } 01534 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 01535 } 01536 01537 if (c) c->RenderCockpitVirtual(); 01538 if (!draw_center && c) c->AddToList(); 01539 01540 /* 01541 glDisable(GL_TEXTURE); 01542 glColor3f(1,1,1); 01543 glBegin(GL_LINES); 01544 glVertex3f(centerPosSmooth.x,centerPosSmooth.y,0); 01545 glVertex3f(centerPosSmooth.x,centerPosSmooth.y,10); 01546 glEnd(); 01547 */ 01548 01549 CenterCockpitFixedAfter(); 01550 } 01551 displaying=false; 01552 }
void eCamera::Timestep | ( | REAL | ts | ) | [virtual] |
Reimplemented in gCamera.
Definition at line 1599 of file eCamera.cpp.
References activeGlanceRequest, AutoSwitchIncam(), Bound(), c, CAMERA_COUNT, CAMERA_CUSTOM, CAMERA_FOLLOW, CAMERA_FREE, CAMERA_IN, CAMERA_MER, CAMERA_SERVER_CUSTOM, CAMERA_SMART, CAMERA_SMART_IN, Center(), center, CenterAlive(), CenterCamDir(), CenterCamPos(), CenterCamTop(), CenterCamZ(), CenterCycleDir(), CenterDir(), centerDirLast, centerDirSmooth, CenterIncamOnTurn(), CenterPos(), centerPos, centerposLast, centerPosLast, centerPosSmooth, CenterSpeed(), centerSpeedSmooth, CenterZ(), d, eSensor::detect(), eGlanceRequest::dir, dir, eGameObject::Direction(), eCoord, exp(), ff, fov, eSensor::hit, hitCache_, hitCacheSize, InterestingToWatch(), eGameObject::LastDirection(), lastSwitch, lastTime, maxcontrol, maxs, mode, netPlayer, nextDirIfGlancing(), pos, eGameObject::PredictPosition(), REAL, relax, rise, s_customBackSpeed, s_customPitch, s_customRise, s_customRiseSpeed, s_customTurnSpeed, s_customTurnSpeed180, s_customZoom, s_serverCustomBackSpeed, s_serverCustomPitch, s_serverCustomRise, s_serverCustomRiseSpeed, s_serverCustomTurnSpeed, s_serverCustomTurnSpeed180, se_ClampCamera(), se_GameTime(), se_GetWatchedObject(), se_hitCacheSpeed, SMART_FRONT_SPEED, SMART_INCAM_SPEED, smartcamFrontSmooth, smartcamIncamSmooth, smartcamSkewSmooth, SMOOTH_SPEED, smoothTurning, eGameObject::Speed(), SpeedMultiplier(), sqrt(), SwitchCenter(), top, turning, userCameraControl, WhobbleIncam(), x, and z.
Referenced by s_Timestep(), and gCamera::Timestep().
01599 { 01600 // find net player 01601 if (!netPlayer && localPlayer) 01602 { 01603 netPlayer = localPlayer->netPlayer; 01604 } 01605 01606 // the best center is always our own vehicle. Focus on it if possible. 01607 if (netPlayer) 01608 { 01609 eGameObject * bestCenter = netPlayer->Object(); 01610 if ( InterestingToWatch(bestCenter) ) 01611 { 01612 if ( bestCenter != center ) 01613 { 01614 center = bestCenter; 01615 if ( mode != CAMERA_FREE ) 01616 mode=localPlayer->startCamera; 01617 } 01618 } 01619 } 01620 01621 eCamMode newmode = mode; 01622 01624 // compute suggestions for the next camera state using eCamMode newmode 01626 01627 // determine camera custom parameters based on speed 01628 REAL customBack = 0, customRise = 0, customPitch = 0, customTurnSpeed = s_customTurnSpeed, customTurnSpeed180 = s_customTurnSpeed180; 01629 { 01630 REAL speed = centerSpeedSmooth; 01631 if ( newmode == CAMERA_SERVER_CUSTOM ) 01632 { 01633 customBack = s_serverCustomBack + speed * s_serverCustomBackSpeed; 01634 customRise = s_serverCustomRise + speed * s_serverCustomRiseSpeed; 01635 customPitch = s_serverCustomPitch; 01636 01637 if ( s_serverCustomTurnSpeed >= 0 ) 01638 { 01639 customTurnSpeed = s_serverCustomTurnSpeed; 01640 customTurnSpeed180 = s_serverCustomTurnSpeed180; 01641 } 01642 } 01643 else 01644 { 01645 customBack = s_customBack + speed * s_customBackSpeed; 01646 customRise = s_customRise + speed * s_customRiseSpeed; 01647 customPitch = s_customPitch; 01648 } 01649 } 01650 01651 // switch away from dead players 01652 if (lastSwitch>lastTime) 01653 lastSwitch=lastTime; 01654 01655 if (!InterestingToWatch(Center()) && lastTime-lastSwitch>2 && (center==0 || lastTime-center->deathTime > 4)){ // CHECK: not glancing-related. gives the player a chance to analyse the cause of his death before the camera switches away. 01656 center = se_GetWatchedObject( this ); 01657 if ( !center || !InterestingToWatch(center) ) 01658 SwitchCenter(1); 01659 01660 if (!InterestingToWatch(Center())) 01661 { 01662 newmode=CAMERA_FREE; 01663 } 01664 // Did not work as expected, more work needs to be done to reset the settings 01665 // else 01666 // { 01667 // if (localPlayer) 01668 // { 01669 // mode=localPlayer->startCamera; 01670 // } 01671 // } 01672 } 01673 01674 if (!Center()) 01675 return; 01676 01677 // watch for turns of the center game object 01678 if ( fabs( centerDirLast * Center()->Direction() ) > .01 ) 01679 { 01680 turning+=.5; 01681 centerDirLast = Center()->Direction(); 01682 } 01683 01684 for(int i = hitCacheSize-1; i>=0; --i) 01685 { 01686 hitCache_[i] += ts * se_hitCacheSpeed; 01687 if (hitCache_[i] > 1) 01688 hitCache_[i] = 1; 01689 } 01690 01691 // flag telling someone at the end of the function whether Bound() was already called 01692 bool bound = false; 01693 01694 eCoord objdir=CenterCamDir(); 01695 01696 // update center positions 01697 if ( Center() ) 01698 { 01699 #define SMOOTH_SPEED 1 01700 centerSpeedSmooth = ( centerSpeedSmooth + Center()->Speed() * ts * SMOOTH_SPEED)/( 1 + ts * SMOOTH_SPEED ); 01701 01702 centerPos = Center()->PredictPosition(); 01703 01704 // move it a bit to the side (disabled for now, does not have the desired effect of making walls visible) 01705 //eCoord side = Center()->Direction().Turn(0,1); 01706 //REAL displace = eCoord::F( Center()->CamPos() - centerPos, side ); 01707 //centerPos = centerPos + side * displace; 01708 } 01709 centerPosSmooth=(centerPosSmooth+ CenterPos()*(ts*se_cameraSmartCenterPosSmooth)) 01710 *(1/(1+ts*se_cameraSmartCenterPosSmooth)); 01711 01712 //centerPosSmooth=centerPosition(); 01713 01714 //REAL dist_from_center=sqrt((centerPos-pos).NormSquared()+ 01715 //(CenterZ() - z)*(CenterZ() - z)); 01716 01717 if (!CenterAlive() && (newmode==CAMERA_IN || newmode==CAMERA_SMART_IN)){// || newmode==CAMERA_CUSTOM || newmode==CAMERA_SERVER_CUSTOM)){ 01718 pos=pos-dir.Turn(eCoord(5,1)); 01719 z+=2; 01720 newmode=CAMERA_SMART; 01721 } 01722 01723 const REAL dirSmooth = se_cameraSmartCenterDirSmooth; 01724 centerDirSmooth=(centerDirSmooth+(CenterDir()*dirSmooth*ts))* 01725 (1/(1+dirSmooth*ts)); 01726 01727 // eCoord centerpos=centerPosSmooth+centerDirSmooth * ( this->CenterSpeed() * .05f ); 01728 REAL speedFactor = se_GameTime() * this->CenterSpeed() * se_cameraSmartCenterLookahead; 01729 if ( speedFactor < 0.0f ) 01730 { 01731 speedFactor = 0.0f; 01732 } 01733 if ( speedFactor > se_cameraSmartCenterMaxLookahead ) 01734 { 01735 speedFactor = se_cameraSmartCenterMaxLookahead; 01736 } 01737 eCoord centerpos=CenterPos(); //centerPosSmooth + centerDirSmooth * speedFactor; 01738 // CHECK: Smoothing disabled because it causes artifacts while glancing 01739 01740 #define SMART_INCAM_SPEED 1 01741 #define SMART_FRONT_SPEED 4 01742 01743 userCameraControl/=(1+ts*5); 01744 #define maxcontrol 10 01745 if (userCameraControl>maxcontrol) 01746 userCameraControl=maxcontrol; 01747 01748 smartcamFrontSmooth/=(1+SMART_FRONT_SPEED*ts); 01749 smartcamSkewSmooth/=(1+2*ts); 01750 smartcamIncamSmooth/=(1+SMART_INCAM_SPEED*ts); 01751 01752 eCoord newpos=pos,newdir=dir; 01753 REAL newz=z,newrise=rise; 01754 01755 eCoord usernewpos=pos; 01756 eCoord usernewdir=dir; 01757 REAL usernewz=z; 01758 REAL usernewrise=rise; 01759 01760 REAL relax=se_cameraSmartDistance;//1 + 34/(CenterSpeed() + 1); 01761 // REAL wish_h=2*vp->UpDownFOV(fov)/60 * SpeedMultiplier(); 01762 REAL wish_h=se_cameraSmartHeight*vp->UpDownFOV(fov)/60 * ( this->CenterSpeed() * .02 + SpeedMultiplier() ); 01763 REAL min_dist=se_cameraSmartMinDistance; 01764 01765 turning/=(1+2*ts); 01766 smoothTurning+=3*turning*ts; 01767 smoothTurning/=1+ts; 01768 01769 #define maxs 5 01770 if (smoothTurning>maxs) smoothTurning=maxs; 01771 01772 REAL side; 01773 REAL eturn; 01774 01775 top=eCoord(0,0); 01776 01777 // temporarily use free cam code if nothing interesting to watch exists 01778 eCamMode effectiveMode = mode; 01779 if (!InterestingToWatch(Center())) 01780 { 01781 effectiveMode=CAMERA_FREE; 01782 } 01783 01784 switch (effectiveMode){ 01785 case CAMERA_FREE: 01786 newpos=pos; 01787 newdir=dir; 01788 newz=z; 01789 newrise=rise; 01790 break; 01791 case CAMERA_SMART_IN: 01792 case CAMERA_CUSTOM: 01793 case CAMERA_SERVER_CUSTOM: 01794 case CAMERA_IN: 01795 if (WhobbleIncam()){ 01796 top=CenterCamTop(); 01797 newpos=CenterCamPos(); 01798 } 01799 else 01800 newpos=CenterPos(); 01801 01802 if (CenterIncamOnTurn() || newmode==CAMERA_SMART_IN || newmode == CAMERA_CUSTOM || newmode == CAMERA_SERVER_CUSTOM ) 01803 { 01804 // fetch the relevant turning speed 01805 REAL turnSpeed = ( newmode == CAMERA_IN || newmode == CAMERA_SMART_IN ) ? s_inTurnSpeed : customTurnSpeed; 01806 01807 eCoord cycleDir = CenterCamDir(); 01808 newdir=dir+cycleDir*(turnSpeed*ts); 01809 01810 // test if we're looking against the current driving direction 01811 REAL wrongDirection = -eCoord::F( cycleDir, newdir ); 01812 if ( Center() && wrongDirection > 0 ) 01813 { 01814 // if so, turn to the side using the last driving direction 01815 newdir = newdir + Center()->LastDirection()*(wrongDirection*ts*turnSpeed*s_customTurnSpeed180); 01816 } 01817 } 01818 else 01819 newdir=dir; 01820 01821 if ( newmode == CAMERA_IN || newmode == CAMERA_SMART_IN ) 01822 { 01823 const REAL forwardCheck = .1; 01824 01825 // cast ray forward; don't be too close to a wall 01826 eSensor forward( Center(), newpos, newdir ); 01827 forward.detect( forwardCheck ); 01828 if ( forward.ehit ) 01829 { 01830 REAL backwardCheck = ( forwardCheck - forward.hit ) * 2; 01831 eSensor backward( Center(), newpos, -newdir ); 01832 backward.detect( backwardCheck ); 01833 newpos = newpos - newdir * ( backward.hit * .5 ); 01834 } 01835 } 01836 01837 if (newmode != CAMERA_CUSTOM && newmode != CAMERA_SERVER_CUSTOM) 01838 { 01839 newz=CenterCamZ(); 01840 newrise=rise; 01841 if (newrise>2) newrise=2; 01842 if (newrise<-2) newrise=-2; 01843 01844 usernewpos=newpos; 01845 usernewz=newz; 01846 } 01847 01848 01849 if (newmode==CAMERA_SMART_IN){ 01850 REAL space[2]; 01851 01852 REAL dist = CenterSpeed() * .2f; 01853 if (dist < 5) 01854 dist = 5; 01855 01856 for(int i=0;i<2;i++){ 01857 eSensor s(Center(),CenterPos(),CenterDir().Turn(1,2*i-1)); 01858 s.detect(dist); 01859 space[i]=s.hit; 01860 } 01861 smartcamIncamSmooth+=(space[0]+space[1])*ts*SMART_INCAM_SPEED/dist; 01862 01863 if (smartcamIncamSmooth>.8){ 01864 eSensor s(Center(),CenterPos(),CenterCycleDir()); 01865 s.detect(5.5); 01866 01867 if (s.hit>5){ 01868 newmode=CAMERA_SMART; 01869 usernewz=newz=z+.5; 01870 usernewpos=newpos=pos+dir.Turn(-1,.1); 01871 } 01872 } 01873 } 01874 01875 if (newmode != CAMERA_CUSTOM && newmode != CAMERA_SERVER_CUSTOM) 01876 { 01877 int x=3; 01878 while (eCoord::F(newdir,objdir)<-.5001 && x>0){ 01879 newdir=newdir-objdir*(eCoord::F(newdir,objdir)+.5); 01880 newdir=newdir*(1/sqrt(newdir.NormSquared())); 01881 x--; 01882 } 01883 } 01884 else if ( newmode == CAMERA_CUSTOM || newmode == CAMERA_SERVER_CUSTOM ) 01885 { 01886 REAL zoom = lastTime > 0 ? 1 : exp( s_customZoom * lastTime ); 01887 01888 newdir=newdir*(1/sqrt(newdir.NormSquared())); 01889 newpos = newpos - newdir * customBack * zoom; 01890 usernewpos = usernewpos + CenterPos() - centerPosLast; 01891 newrise = customPitch; 01892 newz = CenterCamZ() + customRise * zoom; 01893 } 01894 01895 break; 01896 case CAMERA_SMART: 01897 if (activeGlanceRequest) { 01898 newdir = dir; 01899 newpos = CenterPos()+newdir*smartcamGlancingBack; 01900 newz = smartcamGlancingHeight; 01901 newrise = (CenterZ()-newz)/smartcamGlancingBack; 01902 } else { 01903 REAL dist = CenterSpeed() * se_cameraSmartDistanceScale; 01904 if (dist < se_cameraSmartMinDistanceScale) 01905 dist = se_cameraSmartMinDistanceScale; 01906 01907 REAL space[2]; 01908 01909 for(int i=0;i<2;i++){ 01910 eSensor s(Center(),CenterPos(),CenterDir().Turn(1,2*i-1)); 01911 s.detect(dist); 01912 space[i]=s.hit; 01913 } 01914 01915 REAL slowFactor = this->CenterSpeed() / se_cameraSmartCycleSpeed; 01916 if ( slowFactor > 1.0f ) 01917 { 01918 slowFactor = 1.0f; 01919 } 01920 01921 eSensor front(Center(), CenterPos(), CenterDir()); 01922 front.detect(dist * 4); 01923 REAL ff = (4 * dist - front.hit)/(3*dist); 01924 ff *= ff; 01925 smartcamFrontSmooth+=ff*SMART_FRONT_SPEED*ts; 01926 01927 smartcamSkewSmooth+=(space[0]-space[1])*ts * slowFactor; 01928 smartcamIncamSmooth+=(space[0]+space[1])*ts*SMART_INCAM_SPEED/dist; 01929 01930 REAL sk = fabs(smartcamSkewSmooth)/5; 01931 if (sk > 1) 01932 sk = 1; 01933 01934 REAL rf = .15+.1*smoothTurning - sk * .15 - .05 * smartcamFrontSmooth; 01935 if (rf < .05) 01936 rf = .05; 01937 01938 relax*=rf; 01939 relax/=slowFactor; 01940 // wish_h*=.5+1.5*smoothTurning + 2 * sk + smartcamFrontSmooth; 01941 wish_h*=se_cameraSmartHeightExtra + se_cameraSmartHeightTurning*smoothTurning + se_cameraSmartHeightGrinding * sk + smartcamFrontSmooth * se_cameraSmartHeightObstacle; 01942 min_dist/=3; // +smoothTurning; 01943 01944 { 01945 if (!CenterAlive()) wish_h+=3; 01946 REAL front=eCoord::F(pos-centerpos,CenterDir()); 01947 side=((pos-centerpos)*CenterDir()) * front; 01948 //eCoord::F(pos-centerpos,CenterDir); 01949 eturn=ts/relax * (1 + .5 * smartcamFrontSmooth); 01950 if (side>0) eturn*=-1; 01951 01952 newz=z; 01953 01954 // we do not want to look at the cycle front 01955 01956 //eCoord skew; 01957 if (front>0){ // increase skew 01958 if (front>2.5) front=2.5; 01959 if (fabs(smartcamSkewSmooth)>1 || smartcamSkewSmooth*eturn>0) 01960 smartcamSkewSmooth*=(1+ts); 01961 if (fabs(smartcamSkewSmooth)<1) 01962 smartcamSkewSmooth -= se_cameraSmartAvoidFront * eturn; 01963 newz+=ts*front*.1; 01964 //if ( Center() ) 01965 // skew = -Center()->LastDirection()*(front*dist*.2); 01966 } 01967 01968 if (se_GameTime()>0){ 01969 newpos=pos + CenterDir().Turn(eCoord(0,eturn*se_cameraSmartAvoidFront2)); 01970 newpos=newpos+CenterDir().Turn(0,-1)*smartcamSkewSmooth*ts*se_cameraSmartTurn; 01971 //newpos=newpos+skew*ts*5; 01972 newpos=newpos+centerpos*(ts/relax); 01973 newpos=newpos*(1/(1+ts/relax)); 01974 } 01975 else{ 01976 newpos=pos+ (pos-centerpos).Turn(-ts*.5,ts*.5); 01977 } 01978 01979 if ( userCameraControl < .25 && se_ClampCamera(newmode) ) 01980 { 01981 bound = true; 01982 Bound( ts, newpos ); 01983 // Bound( ts, newpos ); 01984 } 01985 01986 newz=newz+(CenterZ()+wish_h)*(ts/relax); 01987 newz=newz/(1+ts/relax); 01988 newdir=centerpos-newpos; 01989 REAL dist=sqrt(newdir.NormSquared()); 01990 if (dist<.001) dist=.01; 01991 // newdir=dir+(centerDirSmooth*16+newdir)*ts; 01992 newdir=dir+newdir*ts*5.0; 01993 newdir=newdir*(1/sqrt(newdir.NormSquared())); 01994 01995 if (dist<min_dist){ 01996 //newpos=newpos-newdir*((min_dist-dist)*(min_dist-dist)*ts); 01997 REAL dz=(min_dist*min_dist-dist*dist-.5*z*z); 01998 if (dz>0) 01999 newz+=dz*ts; 02000 } 02001 02002 REAL d=eCoord::F(newdir,centerpos - newpos); 02003 if (d<.0001) d=.0001; 02004 newrise=(CenterZ()-newz)/d; 02005 02006 usernewpos=pos + centerpos - centerPosLast; 02007 // usernewdir=newdir; 02008 // usernewrise=newrise; 02009 // 02010 // // use custom camera settings when glancing 02011 // if ( localPlayer && localPlayer->smartCustomGlance && ( glancingBack || glancingRight || glancingLeft || glanceSmoothAbs > .01 )) 02012 // { 02013 // // update blending factor raw data 02014 // REAL abs = fabs(glanceSmooth); 02015 // glanceSmoothAbs = abs > glanceSmoothAbs ? abs : glanceSmoothAbs; 02016 // 02017 // // calculate blending factor c. c=0 will take the smart cam position, c=1 the custom cam. 02018 // REAL b = 1 - glanceSmoothAbs; 02019 // REAL c = 1 - b/(b + ts * GLANCE_SPEED); 02020 // 02021 // // override: go all the way when glancing back 02022 // if ( glancingBack ) 02023 // { 02024 // c = 1; 02025 // glanceSmoothAbs = 1; 02026 // } 02027 // 02028 // // the camera pitch is calculated anew every frame, blend it accordingly 02029 // usernewrise = newrise = newrise * ( 1-glanceSmoothAbs) + customPitch * glanceSmoothAbs; 02030 // 02031 // // the other values are updated every frame, blend them softer 02032 // if ( glancingBack || glancingRight || glancingLeft ) 02033 // { 02034 // usernewpos = newpos = pos * (1-c) + (CenterPos() - CenterCamDir() * customBack) * c; 02035 // usernewz = newz = z * (1-c) + (CenterCamZ() + customRise) * c; 02036 // 02037 // newdir=centerpos-newpos; 02038 // REAL dist=sqrt(newdir.NormSquared()); 02039 // if (dist<.001) dist=.01; 02040 // usernewdir=newdir=newdir*(1/sqrt(newdir.NormSquared())); 02041 // } 02042 // } 02043 02044 if (AutoSwitchIncam()){ 02045 if (smartcamIncamSmooth<.7 && CenterAlive()){ 02046 eSensor s(Center(),CenterPos(),CenterDir()); 02047 s.detect(5.5); 02048 if (s.hit>5){ 02049 usernewrise=newrise=0; 02050 newmode=CAMERA_SMART_IN; 02051 usernewdir=newdir=objdir; 02052 } 02053 } 02054 } 02055 else 02056 if (smartcamIncamSmooth<.7) 02057 newz+=ts*(.7-smartcamIncamSmooth); 02058 } 02059 } 02060 break; 02061 case CAMERA_FOLLOW:{ 02062 newpos=usernewpos=pos + centerpos - centerposLast; 02063 newz=z; 02064 newdir=centerpos-newpos; 02065 REAL dist=sqrt(newdir.NormSquared()); 02066 newdir=newdir*(1/dist); 02067 newrise=(CenterZ()-newz)/dist; 02068 } 02069 break; 02070 case CAMERA_MER: { 02071 // perform initial animation if lastTime<0 02072 REAL zoom = lastTime > 0 ? 1 : exp( s_customZoom * lastTime ); 02073 REAL dist = mercamxydist*zoom; 02074 02075 eCoord t = CenterPos()-pos; 02076 t.Normalize(); 02077 02078 // update camera state 02079 newpos = usernewpos=CenterPos()-t*dist; 02080 newz = CenterZ()*(1-zoom) +mercamz*zoom; 02081 newdir = t; 02082 newrise = (CenterZ()-newz)/dist; 02083 } 02084 break; 02085 case CAMERA_COUNT: 02086 break; 02087 } 02088 02090 // now that we have suggestions for the next camera state 02091 // we modify them to account for manual camera control 02092 // and then commit them 02094 02095 if (activeGlanceRequest) { 02096 bool internal = mode==CAMERA_IN || mode==CAMERA_SMART_IN; 02097 02098 if (internal) { 02099 pos = newpos; 02100 dir = nextDirIfGlancing(dir,activeGlanceRequest->dir,ts); 02101 z = newz; 02102 rise = newrise; 02103 } else { 02104 REAL c = 5*ts; 02105 eCoord focusTarget = (mode==CAMERA_SMART) ? centerpos : CenterPos(); 02106 eCoord focusTargetLast = (mode==CAMERA_SMART) ? centerposLast : centerPosLast; 02107 02108 // reconstruct focal point 02109 //std::cout << (pos-centerpos).Norm()*rise+z << " "; 02110 REAL focusZ = (newpos-focusTarget).Norm()*newrise+newz; 02111 eCoord focus = dir*((focusZ-z)/rise) + pos; 02112 02113 // move focal point towards focusTargetLast 02114 focus = focus * (1-c) + focusTargetLast * c; 02115 02116 // rotate camera 02117 eCoord t = focus-pos; 02118 REAL tnorm = t.Norm(); 02119 t.Normalize(); 02120 t = nextDirIfGlancing(t,activeGlanceRequest->dir,ts); 02121 02122 // advance time 02123 focus = focus + focusTarget - focusTargetLast; 02124 02125 // adjust distance to camera 02126 tnorm = tnorm * (1-c) + (newpos-focusTarget).Norm() * c; 02127 02128 // update camera state 02129 pos = focus - t * tnorm; 02130 dir = t; 02131 z = z * (1-c) + newz * c; 02132 rise = (focusZ-z) / tnorm; 02133 02134 //std::cout << activeGlanceRequest->dir << " " << t << " " << tnorm << "\t"; 02135 } 02136 02137 } else { 02138 02139 /* 02140 REAL ratio=1 - exp(-4*userCameraControl); 02141 ratio*=ts; 02142 ratio*=100; 02143 ratio=exp(-ratio); 02144 */ 02145 02146 // calcualte ratios under which user and automatic camera positions should be blended 02147 REAL aratio = exp(-4*userCameraControl); 02148 REAL ratio = 1 - aratio; 02149 02150 // blend 02151 pos=newpos*aratio + usernewpos*ratio; 02152 dir=newdir*aratio + usernewdir*ratio; 02153 z =newz *aratio + usernewz *ratio; 02154 02155 // newrise rise is calculated anew every frame, use a different blending 02156 if (userCameraControl > .01) 02157 { 02158 rise=newrise + (usernewrise-newrise)*exp(-ts/userCameraControl); 02159 } 02160 else 02161 { 02162 rise=newrise; 02163 } 02164 02165 // normalize direction 02166 dir=dir*(1/sqrt(dir.NormSquared())); 02167 } 02168 02169 #ifdef CAMERA_LOGGING 02170 std::cout << (activeGlanceRequest ? "g " : " ") << (pos-CenterPos()).Norm() << " " << (newpos-CenterPos()).Norm() << " " << z << " " << rise << "\n"; 02171 #endif 02172 dir.Normalize(); 02173 centerposLast=centerpos; 02174 centerPosLast=CenterPos(); 02175 02176 // bound camera if that was not already done earlier 02177 if (!bound && se_ClampCamera(mode) ) // CHECK: That condition is affected by glancing? 02178 Bound( ts ); 02179 }
REAL eCamera::Dist | ( | ) | [inline] |
Definition at line 2183 of file eCamera.cpp.
References c, eGrid::cameras, lastTime, GrowingArrayBase::Len(), su_FetchAndStoreSDLInput(), Timestep(), and eDebugLine::Update().
Referenced by gGame::GameLoop(), and s_Timestep().
02183 { 02184 if (fabs(time-lastTime)>1) lastTime=time-.1; 02185 if (time>lastTime){ 02186 eDebugLine::Update(time-lastTime); 02187 02188 for(int i=grid->cameras.Len()-1;i>=0;i--){ 02189 //con << time-lastTime<< '\n'; 02190 eCamera *c = grid->cameras(i); 02191 c->Timestep(time-lastTime); 02192 su_FetchAndStoreSDLInput(); 02193 } 02194 lastTime=time; 02195 } 02196 }
bool eCamera::Bound | ( | REAL | ratio, | |
eCoord & | pos, | |||
eCoord const & | dirFromTarget, | |||
REAL & | hitCache | |||
) | [private] |
make sure CenterPos() + dirFromTarget() is visible from pos
make sure CenterPos() + dirFromTarget is visible from pos
ratio | mixing ratio of old and best position: 0 means to take the best position, 1 to leave the old. | |
pos | the camera positon to clamp for visibility | |
dirFromTarget | the point CenterPos() + dirFromTarget is supposed to be visible | |
hitCache | if the caller persists this number, the real visibility target will not "snap" when it suddenly gets more room |
Definition at line 1142 of file eCamera.cpp.
References activeGlanceRequest, eSensor::before_hit, eWallRim::Bound(), Center(), CenterPos(), eSensor::detect(), eCoord, eCameraSensor::GetLowerWall(), eSensor::hit, mode, eCameraSensor::moved_, REAL, rimDistance, rimDistanceHeight, se_ClampCamera(), se_visibilityWallDistance, eCameraSensor::SetCamera(), eCameraSensor::SetLowerWall(), eCameraSensor::SetRatio(), eCameraSensor::SetZLimit(), and z.
01143 { 01144 // the target position that should be visible 01145 eCoord target = CenterPos(); 01146 01147 // move it as requested, but not into walls 01148 if ( dirFromTarget.NormSquared() > 0.0001f ) 01149 { 01150 eSensor test( Center(), target, dirFromTarget ); 01151 test.detect( hitCache ); 01152 target = test.before_hit * (1-se_visibilityWallDistance) + target * se_visibilityWallDistance; 01153 hitCache = test.hit; 01154 } 01155 01156 // prepare camera clamping sensor 01157 eCameraSensor toObject( Center(), pos, target ); 01158 toObject.SetZLimit( z ).SetRatio( ratio ).SetCamera( this ); 01159 01160 // if not glancing, switch from wall lowering to camera clipping if the user desires 01161 // CHECK: the following if-statement should be a faithful translation of 01162 // if ( !glancingBack && fabs( glanceSmooth ) < .001 ) 01163 if (!activeGlanceRequest) 01164 { 01165 toObject.SetLowerWall( !se_ClampCamera(mode) ); 01166 01167 // clamp at outer boundary 01168 if ( !toObject.GetLowerWall() ) 01169 { 01170 REAL offset = rimDistance + rimDistanceHeight * z; 01171 eWallRim::Bound(pos,offset); 01172 } 01173 } 01174 01175 // execute clamping 01176 toObject.detect( 1 ); 01177 01178 return toObject.moved_; 01179 }
uActionCamera eCamera::se_lookUp [static, protected] |
uActionCamera eCamera::se_lookDown [static, protected] |
uActionCamera eCamera::se_lookLeft [static, protected] |
uActionCamera eCamera::se_lookRight [static, protected] |
uActionCamera eCamera::se_moveLeft [static, protected] |
uActionCamera eCamera::se_moveRight [static, protected] |
uActionCamera eCamera::se_moveUp [static, protected] |
uActionCamera eCamera::se_moveDown [static, protected] |
uActionCamera eCamera::se_moveForward [static, protected] |
uActionCamera eCamera::se_moveBack [static, protected] |
uActionCamera eCamera::se_zoomIn [static, protected] |
uActionCamera eCamera::se_zoomOut [static, protected] |
uActionCamera eCamera::se_switchView [static, protected] |
uGlanceAction eCamera::se_glance [static, protected] |
Initial value:
{ uGlanceAction("GLANCE_FORWARD",-85,eCoord(1,0)), uGlanceAction("GLANCE_BACK",-90,eCoord(-1,0)), uGlanceAction("GLANCE_RIGHT",-100,eCoord(0,-1)), uGlanceAction("GLANCE_LEFT",-110,eCoord(0,1)) }
Definition at line 69 of file eCamera.h.
Referenced by Act().
int eCamera::id [protected] |
nObserverPtr< ePlayerNetID> eCamera::netPlayer [protected] |
Definition at line 75 of file eCamera.h.
Referenced by Act(), MyInit(), Player(), SwitchView(), gCamera::Timestep(), and Timestep().
tJUST_CONTROLLED_PTR<eGameObject> eCamera::center [protected] |
Definition at line 78 of file eCamera.h.
Referenced by Act(), Center(), MyInit(), SwitchCenter(), gCamera::Timestep(), and Timestep().
REAL eCamera::lastSwitch [protected] |
REAL eCamera::zNear [protected] |
Definition at line 83 of file eCamera.h.
Referenced by MyInit(), Render(), SwitchCenter(), and SwitchView().
eCamMode eCamera::mode [protected] |
Definition at line 84 of file eCamera.h.
Referenced by Act(), Bound(), GetCamMode(), gCamera::MyInit(), MyInit(), Render(), SwitchView(), and Timestep().
eCoord eCamera::pos [protected] |
Definition at line 86 of file eCamera.h.
Referenced by Act(), Bound(), CameraGlancePos(), CameraPos(), gCamera::MyInit(), MyInit(), Render(), SwitchView(), and Timestep().
eCoord eCamera::lastPos [protected] |
eCoord eCamera::dir [protected] |
Definition at line 88 of file eCamera.h.
Referenced by Act(), CameraDir(), gCamera::MyInit(), MyInit(), Render(), SwitchView(), and Timestep().
eCoord eCamera::top [protected] |
REAL eCamera::z [protected] |
Definition at line 90 of file eCamera.h.
Referenced by Act(), Bound(), CameraZ(), MyInit(), Render(), SwitchView(), and Timestep().
REAL eCamera::rise [protected] |
Definition at line 90 of file eCamera.h.
Referenced by Act(), MyInit(), Render(), SwitchView(), and Timestep().
REAL eCamera::fov [protected] |
REAL eCamera::turning [protected] |
REAL eCamera::smoothTurning [protected] |
REAL eCamera::distance [protected] |
REAL eCamera::lastrendertime [protected] |
REAL eCamera::smartcamSkewSmooth [protected] |
REAL eCamera::smartcamIncamSmooth [protected] |
Definition at line 100 of file eCamera.h.
Referenced by MyInit(), Render(), SwitchView(), and Timestep().
REAL eCamera::smartcamFrontSmooth [protected] |
REAL eCamera::centerSpeedSmooth [protected] |
eCoord eCamera::centerDirSmooth [protected] |
eCoord eCamera::centerDirLast [protected] |
eCoord eCamera::centerPos [protected] |
eCoord eCamera::centerPosSmooth [protected] |
eCoord eCamera::centerPosLast [protected] |
eCoord eCamera::centerposLast [protected] |
REAL eCamera::userCameraControl [protected] |
Definition at line 109 of file eCamera.h.
Referenced by Act(), MyInit(), Render(), SwitchView(), and Timestep().
REAL eCamera::centerIncam [protected] |
eGlanceRequest* eCamera::activeGlanceRequest [protected] |
eGlanceRequest eCamera::glanceRequests[se_glances] [protected] |
bool eCamera::renderingMain_ [protected] |
REAL eCamera::hitCache_[hitCacheSize] [private] |