void CSpectator::cam_Update (CActor* A) { if (A){ const Fmatrix& M = A->XFORM(); CCameraBase* pACam = A->cam_Active(); CCameraBase* cam = cameras[cam_active]; switch(cam_active) { case eacFirstEye:{ Fvector P, D, N; pACam->Get (P, D, N); cam->Set (P, D, N); }break; case eacLookAt:{ float y,p,r; M.getHPB (y,p,r); cam->Set (pACam->yaw,pACam->pitch,-r); } case eacFreeLook:{ cam->SetParent (A); Fmatrix tmp; tmp.identity(); Fvector point, point1, dangle; point.set (0.f,1.6f,0.f); point1.set (0.f,1.6f,0.f); M.transform_tiny (point); tmp.translate_over(point); tmp.transform_tiny (point1); if (!A->g_Alive()) point.set(point1); cam->Update (point,dangle); }break; } //----------------------------------- Fvector P, D, N; cam->Get(P, D, N); cameras[eacFreeFly]->Set(P, D, N); cameras[eacFreeFly]->Set(cam->yaw, cam->pitch, 0); P.y -= 1.6f; XFORM().translate_over(P); //----------------------------------- g_pGameLevel->Cameras().Update(cam); }else{ CCameraBase* cam = cameras[eacFreeFly]; Fvector point, dangle; point.set (0.f,1.6f,0.f); XFORM().transform_tiny (point); // apply shift dangle.set (0,0,0); cam->Update (point,dangle); // cam->vPosition.set(point0); g_pGameLevel->Cameras().Update (cam); // hud output }; }
void CCar::OnMouseMove(int dx, int dy) { if (Remote()) return; CCameraBase* C = active_camera; float scale = (C->f_fov/g_fov)*psMouseSens * psMouseSensScale/50.f; if (dx){ float d = float(dx)*scale; C->Move ((d<0)?kLEFT:kRIGHT, _abs(d)); } if (dy){ float d = ((psMouseInvert.test(1))?-1:1)*float(dy)*scale*3.f/4.f; C->Move ((d>0)?kUP:kDOWN, _abs(d)); } }
void CActor::cam_Update(float dt, float fFOV) { if(m_holder) return; if( (mstate_real & mcClimb) && (cam_active!=eacFreeLook) ) camUpdateLadder(dt); on_weapon_shot_update(); float y_shift =0; if( GamePersistent().GameType() != eGameIDSingle && ik_cam_shift && character_physics_support() && character_physics_support()->ik_controller() ) { y_shift = character_physics_support()->ik_controller()->Shift(); float cam_smooth_k = 1.f; if(_abs(y_shift-current_ik_cam_shift)>ik_cam_shift_tolerance) { cam_smooth_k = 1.f - ik_cam_shift_speed * dt/0.01f; } if(_abs(y_shift)<ik_cam_shift_tolerance/2.f) cam_smooth_k = 1.f - ik_cam_shift_speed * 1.f/0.01f * dt; clamp( cam_smooth_k, 0.f, 1.f ); current_ik_cam_shift = cam_smooth_k * current_ik_cam_shift + y_shift * ( 1.f - cam_smooth_k ); } else current_ik_cam_shift = 0; Fvector point = {0,CameraHeight() + current_ik_cam_shift,0}; Fvector dangle = {0,0,0}; Fmatrix xform; xform.setXYZ (0,r_torso.yaw,0); xform.translate_over(XFORM().c); // lookout if (this == Level().CurrentControlEntity()) cam_Lookout( xform, point.y ); if (!fis_zero(r_torso.roll)) { float radius = point.y*0.5f; float valid_angle = r_torso.roll/2.f; calc_point (point,radius,0,valid_angle); dangle.z = (PI_DIV_2-((PI+valid_angle)/2)); } float flCurrentPlayerY = xform.c.y; // Smooth out stair step ups if ((character_physics_support()->movement()->Environment()==CPHMovementControl::peOnGround) && (flCurrentPlayerY-fPrevCamPos>0)){ fPrevCamPos += dt*1.5f; if (fPrevCamPos > flCurrentPlayerY) fPrevCamPos = flCurrentPlayerY; if (flCurrentPlayerY-fPrevCamPos>0.2f) fPrevCamPos = flCurrentPlayerY-0.2f; point.y += fPrevCamPos-flCurrentPlayerY; }else{ fPrevCamPos = flCurrentPlayerY; } float _viewport_near = VIEWPORT_NEAR; // calc point xform.transform_tiny (point); CCameraBase* C = cam_Active(); C->Update (point,dangle); C->f_fov = fFOV; if(eacFirstEye != cam_active) { cameras[eacFirstEye]->Update (point,dangle); cameras[eacFirstEye]->f_fov = fFOV; } if (Level().CurrentEntity() == this) { collide_camera( *cameras[eacFirstEye], _viewport_near, this ); } if( psActorFlags.test(AF_PSP) ) { Cameras().UpdateFromCamera (C); }else { Cameras().UpdateFromCamera (cameras[eacFirstEye]); } fCurAVelocity = vPrevCamDir.sub(cameras[eacFirstEye]->vDirection).magnitude()/Device.fTimeDelta; vPrevCamDir = cameras[eacFirstEye]->vDirection; #ifdef DEBUG if( dbg_draw_camera_collision ) { dbg_draw_viewport( *cameras[eacFirstEye], _viewport_near ); dbg_draw_viewport( Cameras(), _viewport_near ); } #endif if (Level().CurrentEntity() == this) { Level().Cameras().UpdateFromCamera (C); if(eacFirstEye == cam_active && !Level().Cameras().GetCamEffector(cefDemo)){ Cameras().ApplyDevice (_viewport_near); } } }
void CActor::cam_Update(float dt, float fFOV) { if(m_holder) return; if(mstate_real & mcClimb&&cam_active!=eacFreeLook) camUpdateLadder(dt); Fvector point={0,CameraHeight(),0}, dangle={0,0,0}; Fmatrix xform,xformR; xform.setXYZ (0,r_torso.yaw,0); xform.translate_over(XFORM().c); // lookout if (this == Level().CurrentControlEntity()) { if (!fis_zero(r_torso_tgt_roll)){ Fvector src_pt,tgt_pt; float radius = point.y*0.5f; float alpha = r_torso_tgt_roll/2.f; float dZ = ((PI_DIV_2-((PI+alpha)/2))); calc_point (tgt_pt,radius,0,alpha); src_pt.set (0,tgt_pt.y,0); // init valid angle float valid_angle = alpha; // xform with roll xformR.setXYZ (-r_torso.pitch,r_torso.yaw,-dZ); Fmatrix33 mat; mat.i = xformR.i; mat.j = xformR.j; mat.k = xformR.k; // get viewport params float w,h; float c = viewport_near(w,h); w/=2.f;h/=2.f; // find tris Fbox box; box.invalidate (); box.modify (src_pt); box.modify (tgt_pt); box.grow (c); // query Fvector bc,bd ; Fbox xf ; xf.xform (box,xform) ; xf.get_CD (bc,bd) ; xrXRC xrc ; xrc.box_options (0) ; xrc.box_query (Level().ObjectSpace.GetStaticModel(), bc, bd) ; u32 tri_count = xrc.r_count(); if (tri_count) { float da = 0.f; BOOL bIntersect = FALSE; Fvector ext = {w,h,VIEWPORT_NEAR/2}; if (test_point(xrc,xform,mat,ext,radius,alpha)){ da = PI/1000.f; if (!fis_zero(r_torso.roll)) da *= r_torso.roll/_abs(r_torso.roll); float angle = 0.f; for (; _abs(angle)<_abs(alpha); angle+=da) if (test_point(xrc,xform,mat,ext,radius,angle)) { bIntersect=TRUE; break; } valid_angle = bIntersect?angle:alpha; } } r_torso.roll = valid_angle*2.f; r_torso_tgt_roll = r_torso.roll; } else { r_torso_tgt_roll = 0.f; r_torso.roll = 0.f; } } if (!fis_zero(r_torso.roll)) { float radius = point.y*0.5f; float valid_angle = r_torso.roll/2.f; calc_point (point,radius,0,valid_angle); dangle.z = (PI_DIV_2-((PI+valid_angle)/2)); } float flCurrentPlayerY = xform.c.y; // Smooth out stair step ups if ((character_physics_support()->movement()->Environment()==peOnGround) && (flCurrentPlayerY-fPrevCamPos>0)){ fPrevCamPos += dt*1.5f; if (fPrevCamPos > flCurrentPlayerY) fPrevCamPos = flCurrentPlayerY; if (flCurrentPlayerY-fPrevCamPos>0.2f) fPrevCamPos = flCurrentPlayerY-0.2f; point.y += fPrevCamPos-flCurrentPlayerY; }else{ fPrevCamPos = flCurrentPlayerY; } float _viewport_near = VIEWPORT_NEAR; // calc point xform.transform_tiny (point); CCameraBase* C = cam_Active(); if(eacFirstEye == cam_active) { // CCameraBase* C = cameras[eacFirstEye]; xrXRC xrc ; xrc.box_options (0) ; xrc.box_query (Level().ObjectSpace.GetStaticModel(), point, Fvector().set(VIEWPORT_NEAR,VIEWPORT_NEAR,VIEWPORT_NEAR) ); u32 tri_count = xrc.r_count(); if (tri_count) { _viewport_near = 0.01f; } else { xr_vector<ISpatial*> ISpatialResult; g_SpatialSpacePhysic->q_box(ISpatialResult, 0, STYPE_PHYSIC, point, Fvector().set(VIEWPORT_NEAR,VIEWPORT_NEAR,VIEWPORT_NEAR)); for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++) { CPHShell* pCPHS= smart_cast<CPHShell*>(ISpatialResult[o_it]); if (pCPHS) { _viewport_near = 0.01f; break; } } } } /* { CCameraBase* C = cameras[eacFirstEye]; float oobox_size = 2*VIEWPORT_NEAR; Fmatrix _rot; _rot.k = C->vDirection; _rot.c = C->vPosition; _rot.i.crossproduct (C->vNormal, _rot.k); _rot.j.crossproduct (_rot.k, _rot.i); Fvector vbox; vbox.set (oobox_size, oobox_size, oobox_size); Level().debug_renderer().draw_aabb (C->vPosition, 0.05f, 0.051f, 0.05f, D3DCOLOR_XRGB(0,255,0)); Level().debug_renderer().draw_obb (_rot, Fvector().div(vbox,2.0f), D3DCOLOR_XRGB(255,0,0)); dMatrix3 d_rot; PHDynamicData::FMXtoDMX (_rot, d_rot); CPHActivationShape activation_shape; activation_shape.Create (point, vbox, this); dBodySetRotation (activation_shape.ODEBody(), d_rot); CPHCollideValidator::SetDynamicNotCollide(activation_shape); activation_shape.Activate (vbox,1,1.f,0.0F); point.set (activation_shape.Position()); activation_shape.Destroy (); } */ C->Update (point,dangle); C->f_fov = fFOV; if(eacFirstEye != cam_active) { cameras[eacFirstEye]->Update (point,dangle); cameras[eacFirstEye]->f_fov = fFOV; } if( psActorFlags.test(AF_PSP) ) { Cameras().Update (C); }else { Cameras().Update (cameras[eacFirstEye]); } fCurAVelocity = vPrevCamDir.sub(cameras[eacFirstEye]->vDirection).magnitude()/Device.fTimeDelta; vPrevCamDir = cameras[eacFirstEye]->vDirection; if (Level().CurrentEntity() == this) { Level().Cameras().Update (C); if(eacFirstEye == cam_active && !Level().Cameras().GetCamEffector(cefDemo)){ Cameras().ApplyDevice (_viewport_near); } } }
void CActor::cam_Update(float dt, float fFOV) { if(m_holder) return; if( (mstate_real & mcClimb) && (cam_active!=eacFreeLook) ) camUpdateLadder(dt); on_weapon_shot_update(); // Alex ADD: smooth crouch fix if (!CurrentHeight)CurrentHeight = CameraHeight(); float HeightInterpolationSpeed = 9.f; if (CurrentHeight != CameraHeight() && !Device.dwPrecacheFrame) { CurrentHeight = (CurrentHeight * (1.0f - HeightInterpolationSpeed*dt)) + (CameraHeight() * HeightInterpolationSpeed*dt); } Fvector point = { 0, CurrentHeight, 0 }; //Fvector point = {0,CameraHeight(),0}; Fvector dangle = {0,0,0}; Fmatrix xform; xform.setXYZ (0,r_torso.yaw,0); xform.translate_over(XFORM().c); // lookout if (this == Level().CurrentControlEntity()) cam_Lookout( xform, point.y ); if (!fis_zero(r_torso.roll)) { float radius = point.y*0.5f; float valid_angle = r_torso.roll/2.f; calc_point (point,radius,0,valid_angle); dangle.z = (PI_DIV_2-((PI+valid_angle)/2)); } float flCurrentPlayerY = xform.c.y; // Smooth out stair step ups if ((character_physics_support()->movement()->Environment()==peOnGround) && (flCurrentPlayerY-fPrevCamPos>0)){ fPrevCamPos += dt*1.5f; if (fPrevCamPos > flCurrentPlayerY) fPrevCamPos = flCurrentPlayerY; if (flCurrentPlayerY-fPrevCamPos>0.2f) fPrevCamPos = flCurrentPlayerY-0.2f; point.y += fPrevCamPos-flCurrentPlayerY; }else{ fPrevCamPos = flCurrentPlayerY; } float _viewport_near = VIEWPORT_NEAR; // calc point xform.transform_tiny (point); CCameraBase* C = cam_Active(); C->Update (point,dangle); C->f_fov = fFOV; if(eacFirstEye != cam_active) { cameras[eacFirstEye]->Update (point,dangle); cameras[eacFirstEye]->f_fov = fFOV; } if (Level().CurrentEntity() == this) collide_camera( *cameras[eacFirstEye], _viewport_near ); if( psActorFlags.test(AF_PSP) ) { Cameras().UpdateFromCamera (C); }else { Cameras().UpdateFromCamera (cameras[eacFirstEye]); } fCurAVelocity = vPrevCamDir.sub(cameras[eacFirstEye]->vDirection).magnitude()/Device.fTimeDelta; vPrevCamDir = cameras[eacFirstEye]->vDirection; #ifdef DEBUG if( dbg_draw_camera_collision ) { dbg_draw_viewport( *cameras[eacFirstEye], _viewport_near ); dbg_draw_viewport( Cameras(), _viewport_near ); } #endif if (Level().CurrentEntity() == this) { Level().Cameras().UpdateFromCamera (C); if(eacFirstEye == cam_active && !Level().Cameras().GetCamEffector(cefDemo)){ Cameras().ApplyDevice (_viewport_near); } } }