//--------------------------------------------------------------------- void CPhantom::UpdatePosition(const Fvector& tgt_pos) { float tgt_h,tgt_p; Fvector tgt_dir,cur_dir; tgt_dir.sub (tgt_pos,Position()); tgt_dir.getHP (tgt_h,tgt_p); angle_lerp (vHP.x,tgt_h,fASpeed,Device.fTimeDelta); angle_lerp (vHP.y,tgt_p,fASpeed,Device.fTimeDelta); cur_dir.setHP (vHP.x,vHP.y); Fvector prev_pos=Position(); XFORM().rotateY (-vHP.x); Position().mad (prev_pos,cur_dir,fSpeed*Device.fTimeDelta); }
void CHelicopter::UpdateWeapons () { if( isOnAttack() ){ UpdateMGunDir(); }else{ m_tgt_rot.set (0.0f,0.0f); }; // lerp angle angle_lerp (m_cur_rot.x, m_tgt_rot.x, PI, Device.fTimeDelta); angle_lerp (m_cur_rot.y, m_tgt_rot.y, PI, Device.fTimeDelta); if( isOnAttack() ){ if(m_allow_fire){ float d = XFORM().c.distance_to_xz(m_enemy.destEnemyPos); if( between(d,m_min_mgun_dist,m_max_mgun_dist) ) MGunFireStart(); if( between(d,m_min_rocket_dist,m_max_rocket_dist) && (Device.dwTimeGlobal-m_last_rocket_attack > m_time_between_rocket_attack) ) { if(m_syncronize_rocket) { startRocket(1); startRocket(2); }else{ if(m_last_launched_rocket==1) startRocket(2); else startRocket(1); } m_last_rocket_attack = Device.dwTimeGlobal; } }else{ MGunFireEnd(); } }else MGunFireEnd(); MGunUpdateFire(); }
void CWeaponStatMgun::UpdateFire() { fShotTimeCounter -= Device.fTimeDelta; inheritedShooting::UpdateFlameParticles(); inheritedShooting::UpdateLight(); if(!IsWorking()){ clamp(fShotTimeCounter,0.0f, flt_max); return; } if(fShotTimeCounter<=0) { OnShot (); fShotTimeCounter += fOneShotTime; }else { angle_lerp (m_dAngle.x,0.f,5.f,Device.fTimeDelta); angle_lerp (m_dAngle.y,0.f,5.f,Device.fTimeDelta); } }
// ****************************** 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::g_Orientate (u32 mstate_rl, float dt) { static float fwd_l_strafe_yaw = deg2rad(pSettings->r_float(ACTOR_ANIM_SECT, "fwd_l_strafe_yaw")); static float back_l_strafe_yaw = deg2rad(pSettings->r_float(ACTOR_ANIM_SECT, "back_l_strafe_yaw")); static float fwd_r_strafe_yaw = deg2rad(pSettings->r_float(ACTOR_ANIM_SECT, "fwd_r_strafe_yaw")); static float back_r_strafe_yaw = deg2rad(pSettings->r_float(ACTOR_ANIM_SECT, "back_r_strafe_yaw")); static float l_strafe_yaw = deg2rad(pSettings->r_float(ACTOR_ANIM_SECT, "l_strafe_yaw")); static float r_strafe_yaw = deg2rad(pSettings->r_float(ACTOR_ANIM_SECT, "r_strafe_yaw")); if(!g_Alive())return; // visual effect of "fwd+strafe" like motion float calc_yaw = 0; if(mstate_real&mcClimb) { if(g_LadderOrient()) return; } switch(mstate_rl&mcAnyMove) { case mcFwd+mcLStrafe: calc_yaw = +fwd_l_strafe_yaw;//+PI_DIV_4; break; case mcBack+mcRStrafe: calc_yaw = +back_r_strafe_yaw;//+PI_DIV_4; break; case mcFwd+mcRStrafe: calc_yaw = -fwd_r_strafe_yaw;//-PI_DIV_4; break; case mcBack+mcLStrafe: calc_yaw = -back_l_strafe_yaw;//-PI_DIV_4; break; case mcLStrafe: calc_yaw = +l_strafe_yaw;//+PI_DIV_3-EPS_L; break; case mcRStrafe: calc_yaw = -r_strafe_yaw;//-PI_DIV_4+EPS_L; break; } // lerp angle for "effect" and capture torso data from camera angle_lerp (r_model_yaw_delta,calc_yaw,PI_MUL_4,dt); // build matrix Fmatrix mXFORM; mXFORM.rotateY (-(r_model_yaw + r_model_yaw_delta)); mXFORM.c.set (Position()); XFORM().set (mXFORM); //------------------------------------------------- float tgt_roll = 0.f; if (mstate_rl&mcLookout) { tgt_roll = (mstate_rl&mcLLookout)?-ACTOR_LOOKOUT_ANGLE:ACTOR_LOOKOUT_ANGLE; if( (mstate_rl&mcLLookout) && (mstate_rl&mcRLookout) ) tgt_roll = 0.0f; } if (!fsimilar(tgt_roll,r_torso_tgt_roll,EPS)){ angle_lerp (r_torso_tgt_roll,tgt_roll,PI_MUL_2,dt); r_torso_tgt_roll= angle_normalize_signed(r_torso_tgt_roll); } }
void CAI_Boar::UpdateCL() { inherited::UpdateCL(); angle_lerp(_cur_delta, _target_delta, _velocity, client_update_fdelta()); }
BOOL CAlienEffector::ProcessCam(SCamEffectorInfo& info) { // »нициализаци¤ Fmatrix Mdef; Mdef.identity (); Mdef.j.set (info.n); Mdef.k.set (info.d); Mdef.i.crossproduct (info.n, info.d); Mdef.c.set (info.p); // set angle if (angle_lerp(dangle_current.x, dangle_target.x, ANGLE_SPEED, Device.fTimeDelta)) { dangle_target.x = angle_normalize(Random.randFs(DELTA_ANGLE_X)); } if (angle_lerp(dangle_current.y, dangle_target.y, ANGLE_SPEED, Device.fTimeDelta)) { dangle_target.y = angle_normalize(Random.randFs(DELTA_ANGLE_Y)); } if (angle_lerp(dangle_current.z, dangle_target.z, ANGLE_SPEED, Device.fTimeDelta)) { dangle_target.z = angle_normalize(Random.randFs(DELTA_ANGLE_Z)); } // update inertion Fmatrix cur_matrix; cur_matrix.k = monster->Direction(); cur_matrix.c = get_head_position(monster); float rel_dist = m_prev_eye_matrix.c.distance_to(cur_matrix.c) / MAX_CAMERA_DIST; clamp (rel_dist, 0.f, 1.f); def_lerp(m_inertion, 1 - rel_dist, rel_dist, Device.fTimeDelta); // set pos and dir with inertion m_prev_eye_matrix.c.inertion(cur_matrix.c, m_inertion); m_prev_eye_matrix.k.inertion(cur_matrix.k, m_inertion); Fvector::generate_orthonormal_basis_normalized(m_prev_eye_matrix.k,m_prev_eye_matrix.j,m_prev_eye_matrix.i); // apply position and direction Mdef = m_prev_eye_matrix; //set fov float rel_speed = monster->m_fCurSpeed / 15.f; clamp (rel_speed,0.f,1.f); float m_target_fov = MIN_FOV + (MAX_FOV-MIN_FOV) * rel_speed; def_lerp(m_current_fov, m_target_fov, FOV_SPEED, Device.fTimeDelta); info.fFov = m_current_fov; ////////////////////////////////////////////////////////////////////////// // ”становить углы смещени¤ Fmatrix R; R.setHPB (dangle_current.x,dangle_current.y,dangle_current.z); Fmatrix mR; mR.mul (Mdef,R); info.d.set (mR.k); info.n.set (mR.j); info.p.set (mR.c); return TRUE; }
void CHelicopter::MoveStep() { Fvector dir, pathDir; float desired_H = m_movement.currPathH; float desired_P; if(m_movement.type != eMovNone) { float dist = m_movement.currP.distance_to(m_movement.desiredPoint); dir.sub(m_movement.desiredPoint,m_movement.currP); dir.normalize_safe(); pathDir = dir; dir.getHP(desired_H, desired_P); float speed_ = _min(m_movement.GetSpeedInDestPoint(), GetMaxVelocity() ); static float ang = pSettings->r_float (cNameSect(),"magic_angle"); if(m_movement.curLinearSpeed>GetMaxVelocity() || angle_difference(m_movement.currPathH,desired_H)>ang) m_movement.curLinearAcc = -m_movement.LinearAcc_bk; else m_movement.curLinearAcc = GetCurrAcc( m_movement.curLinearSpeed, speed_, dist*0.95f, m_movement.LinearAcc_fw, -m_movement.LinearAcc_bk); angle_lerp (m_movement.currPathH, desired_H, m_movement.GetAngSpeedHeading(m_movement.curLinearSpeed), STEP); angle_lerp (m_movement.currPathP, desired_P, m_movement.GetAngSpeedPitch(m_movement.curLinearSpeed), STEP); dir.setHP(m_movement.currPathH, m_movement.currPathP); float vp = m_movement.curLinearSpeed*STEP+(m_movement.curLinearAcc*STEP*STEP)/2.0f; m_movement.currP.mad (dir, vp); m_movement.curLinearSpeed += m_movement.curLinearAcc*STEP; static bool aaa = false; if(aaa) Log("1-m_movement.curLinearSpeed=",m_movement.curLinearSpeed); clamp(m_movement.curLinearSpeed,0.0f,1000.0f); if(aaa) Log("2-m_movement.curLinearSpeed=",m_movement.curLinearSpeed); } else { //go stopping if( !fis_zero(m_movement.curLinearSpeed) ) { m_movement.curLinearAcc = -m_movement.LinearAcc_bk; float vp = m_movement.curLinearSpeed*STEP+(m_movement.curLinearAcc*STEP*STEP)/2.0f; dir.setHP(m_movement.currPathH, m_movement.currPathP); dir.normalize_safe(); m_movement.currP.mad (dir, vp); m_movement.curLinearSpeed += m_movement.curLinearAcc*STEP; clamp(m_movement.curLinearSpeed,0.0f,1000.0f); // clamp(m_movement.curLinearSpeed,0.0f,m_movement.maxLinearSpeed); } else { m_movement.curLinearAcc = 0.0f; m_movement.curLinearSpeed = 0.0f; } }; if( m_body.b_looking_at_point) { Fvector desired_dir; desired_dir.sub(m_body.looking_point, m_movement.currP ).normalize_safe(); float center_desired_H,tmp_P; desired_dir.getHP(center_desired_H, tmp_P); angle_lerp (m_body.currBodyHPB.x, center_desired_H, m_movement.GetAngSpeedHeading(m_movement.curLinearSpeed), STEP); } else { angle_lerp (m_body.currBodyHPB.x, m_movement.currPathH, m_movement.GetAngSpeedHeading(m_movement.curLinearSpeed), STEP); } float needBodyP = -m_body.model_pitch_k*m_movement.curLinearSpeed; if(m_movement.curLinearAcc < 0) needBodyP*=-1; angle_lerp (m_body.currBodyHPB.y, needBodyP, m_body.model_angSpeedPitch, STEP); float sign; Fvector cp; cp.crossproduct (pathDir,dir); (cp.y>0.0)?sign=1.0f:sign=-1.0f; float ang_diff = angle_difference (m_movement.currPathH, desired_H); float needBodyB = -ang_diff*sign*m_body.model_bank_k*m_movement.curLinearSpeed; angle_lerp (m_body.currBodyHPB.z, needBodyB, m_body.model_angSpeedBank, STEP); XFORM().setHPB(m_body.currBodyHPB.x,m_body.currBodyHPB.y,m_body.currBodyHPB.z); XFORM().translate_over(m_movement.currP); }
void CControlDirection::update_frame() { pitch_correction (); SRotationEventData event_data; event_data.angle = 0; bool heading_similar = false; bool pitch_similar = false; // difference float diff = angle_difference(m_pitch.current_angle, m_data.pitch.target_angle) * 4.0f; clamp(diff, PI_DIV_6, 5 * PI_DIV_6); m_data.pitch.target_speed = m_pitch.current_speed = diff; // поправка угловой скорости в соответствии с текущей и таргетовой линейной скоростями // heading speed correction if (!fis_zero(m_man->movement().velocity_current()) && !fis_zero(m_man->movement().velocity_target()) && m_data.linear_dependency) m_heading.current_speed = m_data.heading.target_speed * m_man->movement().velocity_current() / (m_man->movement().velocity_target() + EPS_L); else velocity_lerp (m_heading.current_speed, m_data.heading.target_speed, m_heading.current_acc, m_object->client_update_fdelta()); m_heading.current_angle = angle_normalize(m_heading.current_angle); m_data.heading.target_angle = angle_normalize(m_data.heading.target_angle); if (fsimilar(m_heading.current_angle, m_data.heading.target_angle)) heading_similar = true; angle_lerp(m_heading.current_angle, m_data.heading.target_angle, m_heading.current_speed, m_object->client_update_fdelta()); if (!heading_similar && fsimilar(m_heading.current_angle, m_data.heading.target_angle)) { event_data.angle |= SRotationEventData::eHeading; } // update pitch velocity_lerp (m_pitch.current_speed, m_data.pitch.target_speed, m_pitch.current_acc, m_object->client_update_fdelta()); m_pitch.current_angle = angle_normalize_signed (m_pitch.current_angle); m_data.pitch.target_angle = angle_normalize_signed (m_data.pitch.target_angle); if (fsimilar(m_pitch.current_angle, m_data.pitch.target_angle)) pitch_similar = true; angle_lerp (m_pitch.current_angle, m_data.pitch.target_angle, m_pitch.current_speed, m_object->client_update_fdelta()); if (!pitch_similar && fsimilar(m_pitch.current_angle, m_data.pitch.target_angle)) { event_data.angle |= SRotationEventData::ePitch; } // set m_man->path_builder().m_body.speed = m_heading.current_speed; m_man->path_builder().m_body.current.yaw = m_heading.current_angle; m_man->path_builder().m_body.target.yaw = m_heading.current_angle; m_man->path_builder().m_body.current.pitch = m_pitch.current_angle; m_man->path_builder().m_body.target.pitch = m_pitch.current_angle; // save object position Fvector P = m_object->Position(); // set angles if(!m_object->animation_movement_controlled()) m_object->XFORM().setHPB (-m_man->path_builder().m_body.current.yaw,-m_man->path_builder().m_body.current.pitch,0); // restore object position m_object->Position() = P; // if there is an event if (event_data.angle) m_man->notify(ControlCom::eventRotationEnd, &event_data); }