void CActor::cam_Set (EActorCameras style) { CCameraBase* old_cam = cam_Active(); cam_active = style; old_cam->OnDeactivate(); cam_Active()->OnActivate(old_cam); }
void CActor::IR_OnMouseMove(int dx, int dy) { if(hud_adj_mode) { g_player_hud->tune (Ivector().set(dx,dy,0)); return; } PIItem iitem = inventory().ActiveItem(); if(iitem && iitem->cast_hud_item()) iitem->cast_hud_item()->ResetSubStateTime(); if (Remote()) return; if(m_holder) { m_holder->OnMouseMove(dx,dy); return; } float LookFactor = GetLookFactor(); CCameraBase* C = cameras [cam_active]; float scale = (C->f_fov/g_fov)*psMouseSens * psMouseSensScale/50.f / LookFactor; if (dx){ float d = float(dx)*scale; cam_Active()->Move((d<0)?kLEFT:kRIGHT, _abs(d)); } if (dy){ float d = ((psMouseInvert.test(1))?-1:1)*float(dy)*scale*3.f/4.f; cam_Active()->Move((d>0)?kUP:kDOWN, _abs(d)); } }
void CActor::IR_OnKeyboardHold(int cmd) { if(hud_adj_mode && pInput->iGetAsyncKeyState(DIK_LSHIFT)) return; if (Remote() || !g_Alive()) return; if (m_input_external_handler && !m_input_external_handler->authorized(cmd)) return; if (IsTalking()) return; if(m_holder) { m_holder->OnKeyboardHold(cmd); return; } #ifdef DEBUG if(psActorFlags.test(AF_NO_CLIP) && (cmd==kFWD || cmd==kBACK || cmd==kL_STRAFE || cmd==kR_STRAFE || cmd==kJUMP || cmd==kCROUCH)) { NoClipFly(cmd); return; } #endif //DEBUG float LookFactor = GetLookFactor(); switch(cmd) { case kUP: case kDOWN: cam_Active()->Move( (cmd==kUP) ? kDOWN : kUP, 0, LookFactor); break; case kCAM_ZOOM_IN: case kCAM_ZOOM_OUT: cam_Active()->Move(cmd); break; case kLEFT: case kRIGHT: if (eacFreeLook!=cam_active) cam_Active()->Move(cmd, 0, LookFactor); break; case kACCEL: mstate_wishful |= mcAccel; break; case kL_STRAFE: mstate_wishful |= mcLStrafe; break; case kR_STRAFE: mstate_wishful |= mcRStrafe; break; case kL_LOOKOUT:mstate_wishful |= mcLLookout; break; case kR_LOOKOUT:mstate_wishful |= mcRLookout; break; case kFWD: mstate_wishful |= mcFwd; break; case kBACK: mstate_wishful |= mcBack; break; case kCROUCH: { if( !psActorFlags.test(AF_CROUCH_TOGGLE) ) mstate_wishful |= mcCrouch; }break; } }
// ****************************** Update actor orientation according to camera orientation void CActor::g_cl_Orientate (u32 mstate_rl, float dt) { // capture camera into torso (only for FirstEye & LookAt cameras) if (eacFreeLook!=cam_active) { r_torso.yaw = cam_Active()->GetWorldYaw (); r_torso.pitch = cam_Active()->GetWorldPitch (); } else { r_torso.yaw = cam_FirstEye()->GetWorldYaw (); r_torso.pitch = cam_FirstEye()->GetWorldPitch (); } unaffected_r_torso.yaw = r_torso.yaw; unaffected_r_torso.pitch = r_torso.pitch; unaffected_r_torso.roll = r_torso.roll; CWeaponMagazined *pWM = smart_cast<CWeaponMagazined*>(inventory().GetActiveSlot() != NO_ACTIVE_SLOT ? inventory().ItemFromSlot(inventory().GetActiveSlot())/*inventory().m_slots[inventory().GetActiveSlot()].m_pIItem*/ : NULL); if (pWM && pWM->GetCurrentFireMode() == 1 && eacFirstEye != cam_active) { Fvector dangle = weapon_recoil_last_delta(); r_torso.yaw = unaffected_r_torso.yaw + dangle.y; r_torso.pitch = unaffected_r_torso.pitch + dangle.x; } // если есть движение - выровнять модель по камере if (mstate_rl&mcAnyMove) { r_model_yaw = angle_normalize(r_torso.yaw); mstate_real &=~mcTurn; } else { // if camera rotated more than 45 degrees - align model with it float ty = angle_normalize(r_torso.yaw); if (_abs(r_model_yaw-ty)>PI_DIV_4) { r_model_yaw_dest = ty; // mstate_real |= mcTurn; } if (_abs(r_model_yaw-r_model_yaw_dest)<EPS_L){ mstate_real &=~mcTurn; } if (mstate_rl&mcTurn){ angle_lerp (r_model_yaw,r_model_yaw_dest,PI_MUL_2,dt); } } }
void CActor::IR_OnKeyboardHold(int cmd) { if (m_blocked_actions.find((EGameActions)cmd) != m_blocked_actions.end() ) return; // Real Wolf. 14.10.2014 if (Remote() || !g_Alive()) return; // if (conditions().IsSleeping()) return; if (m_input_external_handler && !m_input_external_handler->authorized(cmd)) return; if (IsTalking()) return; if(m_holder) { m_holder->OnKeyboardHold(cmd); return; } float LookFactor = GetLookFactor(); switch(cmd) { case kUP: case kDOWN: cam_Active()->Move( (cmd==kUP) ? kDOWN : kUP, 0, LookFactor); break; case kCAM_ZOOM_IN: case kCAM_ZOOM_OUT: cam_Active()->Move(cmd); break; case kLEFT: case kRIGHT: if (eacFreeLook!=cam_active) cam_Active()->Move(cmd, 0, LookFactor); break; case kACCEL: mstate_wishful |= mcAccel; break; case kL_STRAFE: mstate_wishful |= mcLStrafe; break; case kR_STRAFE: mstate_wishful |= mcRStrafe; break; case kL_LOOKOUT:mstate_wishful |= mcLLookout; break; case kR_LOOKOUT:mstate_wishful |= mcRLookout; break; case kFWD: mstate_wishful |= mcFwd; break; case kBACK: mstate_wishful |= mcBack; break; case kCROUCH: mstate_wishful |= mcCrouch; break; } }
void CActor::IR_OnMouseMove(int dx, int dy) { if (Remote()) return; // if (conditions().IsSleeping()) return; if(m_holder) { m_holder->OnMouseMove(dx,dy); return; } float LookFactor = GetLookFactor(); CCameraBase* C = cameras [cam_active]; float scale = (C->f_fov/g_fov)*psMouseSens * psMouseSensScale/50.f / LookFactor; if (dx){ float d = float(dx)*scale; cam_Active()->Move((d<0)?kLEFT:kRIGHT, _abs(d)); } if (dy){ float d = ((psMouseInvert.test(1))?-1:1)*float(dy)*scale*3.f/4.f; cam_Active()->Move((d>0)?kUP:kDOWN, _abs(d)); } }
void CActor::MoveActor (Fvector NewPos, Fvector NewDir) { Fmatrix M = XFORM(); M.translate(NewPos); r_model_yaw = NewDir.y; r_torso.yaw = NewDir.y; r_torso.pitch = -NewDir.x; unaffected_r_torso.yaw = r_torso.yaw; unaffected_r_torso.pitch= r_torso.pitch; unaffected_r_torso.roll = 0;//r_torso.roll; r_torso_tgt_roll = 0; cam_Active()->Set (-unaffected_r_torso.yaw,unaffected_r_torso.pitch,unaffected_r_torso.roll); ForceTransform(M); m_bInInterpolation = false; }
void CActorMP::net_Import ( NET_Packet &P) { net_update N; m_state_holder.read (P); R_ASSERT2(valid_pos(m_state_holder.state().position), "imported bad position"); /*if (m_i_am_dead) return;*/ if (OnClient()) { /*#ifdef DEBUG if (GetfHealth() != m_state_holder.state().health) Msg("net_Import: [%d][%s], is going to set health to %2.04f", this->ID(), Name(), m_state_holder.state().health); #endif*/ game_PlayerState* ps = Game().GetPlayerByGameID(this->object_id()); float new_health = m_state_holder.state().health; if (GetfHealth() < new_health) { SetfHealth(new_health); } else { if (!ps || !ps->testFlag(GAME_PLAYER_FLAG_INVINCIBLE)) { SetfHealth(new_health); } } } if (PPhysicsShell() != NULL) { return; } if (OnClient()) SetfRadiation (m_state_holder.state().radiation*100.0f); u16 ActiveSlot = m_state_holder.state().inventory_active_slot; if (OnClient() && (inventory().GetActiveSlot()!=ActiveSlot) ) { #ifdef DEBUG Msg("Client-SetActiveSlot[%d][%d]",ActiveSlot, Device.dwFrame); #endif // #ifdef DEBUG inventory().SetActiveSlot(ActiveSlot); } N.mstate = m_state_holder.state().body_state_flags; N.dwTimeStamp = m_state_holder.state().time; N.p_pos = m_state_holder.state().position; N.o_model = m_state_holder.state().model_yaw; N.o_torso.yaw = m_state_holder.state().camera_yaw; N.o_torso.pitch = m_state_holder.state().camera_pitch; N.o_torso.roll = m_state_holder.state().camera_roll; if (N.o_torso.roll > PI) N.o_torso.roll -= PI_MUL_2; { if (Level().IsDemoPlay() || OnServer() || Remote()) { unaffected_r_torso.yaw = N.o_torso.yaw; unaffected_r_torso.pitch = N.o_torso.pitch; unaffected_r_torso.roll = N.o_torso.roll; cam_Active()->yaw = -N.o_torso.yaw; cam_Active()->pitch = N.o_torso.pitch; }; }; //CSE_ALifeCreatureActor N.p_accel = m_state_holder.state().logic_acceleration; process_packet (N); net_update_A N_A; m_States.clear (); N_A.State.enabled = m_state_holder.state().physics_state_enabled; N_A.State.angular_vel = m_state_holder.state().physics_angular_velocity; N_A.State.linear_vel = m_state_holder.state().physics_linear_velocity; N_A.State.force = m_state_holder.state().physics_force; N_A.State.torque = m_state_holder.state().physics_torque; N_A.State.position = m_state_holder.state().physics_position; N_A.State.quaternion = m_state_holder.state().physics_quaternion; // interpolcation postprocess_packet (N_A); }
void CActor::PickupModeUpdate_COD () { if (Level().CurrentViewEntity() != this || !g_b_COD_PickUpMode) return; if (!g_Alive() || eacFirstEye != cam_active) { CurrentGameUI()->UIMainIngameWnd->SetPickUpItem(NULL); return; }; CFrustum frustum; frustum.CreateFromMatrix (Device.mFullTransform, FRUSTUM_P_LRTB|FRUSTUM_P_FAR); ISpatialResult.clear_not_free (); g_SpatialSpace->q_frustum (ISpatialResult, 0, STYPE_COLLIDEABLE, frustum); float maxlen = 1000.0f; CInventoryItem* pNearestItem = NULL; for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++) { ISpatial* spatial = ISpatialResult[o_it]; CInventoryItem* pIItem = smart_cast<CInventoryItem*> (spatial->dcast_CObject ()); if (0 == pIItem) continue; if (pIItem->object().H_Parent() != NULL) continue; if (!pIItem->CanTake()) continue; if ( smart_cast<CExplosiveRocket*>( &pIItem->object() ) ) continue; CGrenade* pGrenade = smart_cast<CGrenade*> (spatial->dcast_CObject ()); if (pGrenade && !pGrenade->Useful()) continue; CMissile* pMissile = smart_cast<CMissile*> (spatial->dcast_CObject ()); if (pMissile && !pMissile->Useful()) continue; Fvector A, B, tmp; pIItem->object().Center (A); if (A.distance_to_sqr(Position())>4) continue; tmp.sub(A, cam_Active()->vPosition); B.mad(cam_Active()->vPosition, cam_Active()->vDirection, tmp.dotproduct(cam_Active()->vDirection)); float len = B.distance_to_sqr(A); if (len > 1) continue; if (maxlen>len && !pIItem->object().getDestroy()) { maxlen = len; pNearestItem = pIItem; }; } if(pNearestItem) { CFrustum frustum; frustum.CreateFromMatrix (Device.mFullTransform,FRUSTUM_P_LRTB|FRUSTUM_P_FAR); if (!CanPickItem(frustum, Device.vCameraPosition, &pNearestItem->object())) pNearestItem = NULL; } if (pNearestItem && pNearestItem->cast_game_object()) { if (Level().m_feel_deny.is_object_denied(pNearestItem->cast_game_object())) pNearestItem = NULL; } if (pNearestItem && pNearestItem->cast_game_object()) { if(!pNearestItem->cast_game_object()->getVisible()) pNearestItem = NULL; } CurrentGameUI()->UIMainIngameWnd->SetPickUpItem(pNearestItem); if (pNearestItem && m_bPickupMode) { CUsableScriptObject* pUsableObject = smart_cast<CUsableScriptObject*>(pNearestItem); if(pUsableObject && (!m_pUsableObject)) pUsableObject->use(this); //подбирание объекта Game().SendPickUpEvent(ID(), pNearestItem->object().ID()); } };
void CActor::HitMark (float P, Fvector dir, CObject* who, s16 element, Fvector position_in_bone_space, float impulse, ALife::EHitType hit_type) { // hit marker if ( (hit_type==ALife::eHitTypeFireWound||hit_type==ALife::eHitTypeWound_2) && g_Alive() && Local() && /*(this!=who) && */(Level().CurrentEntity()==this) ) { HUD().Hit(0, P, dir); { CEffectorCam* ce = Cameras().GetCamEffector((ECamEffectorType)effFireHit); if(!ce) { int id = -1; Fvector cam_pos,cam_dir,cam_norm; cam_Active()->Get (cam_pos,cam_dir,cam_norm); cam_dir.normalize_safe (); dir.normalize_safe (); float ang_diff = angle_difference (cam_dir.getH(), dir.getH()); Fvector cp; cp.crossproduct (cam_dir,dir); bool bUp =(cp.y>0.0f); Fvector cross; cross.crossproduct (cam_dir, dir); VERIFY (ang_diff>=0.0f && ang_diff<=PI); float _s1 = PI_DIV_8; float _s2 = _s1+PI_DIV_4; float _s3 = _s2+PI_DIV_4; float _s4 = _s3+PI_DIV_4; if(ang_diff<=_s1){ id = 2; }else if(ang_diff>_s1 && ang_diff<=_s2){ id = (bUp)?5:7; }else if(ang_diff>_s2 && ang_diff<=_s3){ id = (bUp)?3:1; }else if(ang_diff>_s3 && ang_diff<=_s4){ id = (bUp)?4:6; }else if(ang_diff>_s4){ id = 0; }else{ VERIFY(0); } string64 sect_name; sprintf(sect_name,"effector_fire_hit_%d",id); AddEffector(this, effFireHit, sect_name, P/100.0f); } } } }
void CActor::NoClipFly(int cmd) { Fvector cur_pos;// = Position(); cur_pos.set(0,0,0); float scale = 1.0f; if(pInput->iGetAsyncKeyState(DIK_LSHIFT)) scale = 0.25f; else if(pInput->iGetAsyncKeyState(DIK_LMENU)) scale = 4.0f; switch(cmd) { case kJUMP: cur_pos.y += 0.1f; break; case kCROUCH: cur_pos.y -= 0.1f; break; case kFWD: cur_pos.z += 0.1f; break; case kBACK: cur_pos.z -= 0.1f; break; case kL_STRAFE: cur_pos.x -= 0.1f; break; case kR_STRAFE: cur_pos.x += 0.1f; break; case kCAM_1: cam_Set(eacFirstEye); break; case kCAM_2: cam_Set(eacLookAt); break; case kCAM_3: cam_Set(eacFreeLook); break; case kNIGHT_VISION: SwitchNightVision(); break; case kTORCH: SwitchTorch(); break; case kDETECTOR: { PIItem det_active = inventory().ItemFromSlot(DETECTOR_SLOT); if(det_active) { CCustomDetector* det = smart_cast<CCustomDetector*>(det_active); det->ToggleDetector(g_player_hud->attached_item(0)!=NULL); return; } } break; case kUSE: ActorUse(); break; } cur_pos.mul(scale); Fmatrix mOrient; mOrient.rotateY(-(cam_Active()->GetWorldYaw())); mOrient.transform_dir(cur_pos); Position().add(cur_pos); character_physics_support()->movement()->SetPosition(Position()); }
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(); 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); 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); } } }