void CWeaponStatMgun::UpdateBarrelDir() { IKinematics* K = smart_cast<IKinematics*>(Visual()); m_fire_bone_xform = K->LL_GetTransform(m_fire_bone); m_fire_bone_xform.mulA_43 (XFORM()); m_fire_pos.set (0,0,0); m_fire_bone_xform.transform_tiny(m_fire_pos); m_fire_dir.set (0,0,1); m_fire_bone_xform.transform_dir (m_fire_dir); m_allow_fire = true; Fmatrix XFi; XFi.invert (XFORM()); Fvector dep; XFi.transform_dir (dep,m_destEnemyDir); {// x angle m_i_bind_x_xform.transform_dir(dep); dep.normalize(); m_tgt_x_rot = angle_normalize_signed(m_bind_x_rot-dep.getP()); float sv_x = m_tgt_x_rot; clamp (m_tgt_x_rot,-m_lim_x_rot.y,-m_lim_x_rot.x); if (!fsimilar(sv_x,m_tgt_x_rot,EPS_L)) m_allow_fire=FALSE; } {// y angle m_i_bind_y_xform.transform_dir(dep); dep.normalize(); m_tgt_y_rot = angle_normalize_signed(m_bind_y_rot-dep.getH()); float sv_y = m_tgt_y_rot; clamp (m_tgt_y_rot,-m_lim_y_rot.y,-m_lim_y_rot.x); if (!fsimilar(sv_y,m_tgt_y_rot,EPS_L)) m_allow_fire=FALSE; } m_cur_x_rot = angle_inertion_var(m_cur_x_rot,m_tgt_x_rot,0.5f,3.5f,PI_DIV_6,Device.fTimeDelta); m_cur_y_rot = angle_inertion_var(m_cur_y_rot,m_tgt_y_rot,0.5f,3.5f,PI_DIV_6,Device.fTimeDelta); }
void CCameraFirstEye::UpdateLookat() { if(!lookat_active) return; Fvector _dest_dir; _dest_dir.sub (lookat_point, vPosition); Fmatrix _m; _m.identity (); _m.k.normalize_safe (_dest_dir); Fvector::generate_orthonormal_basis (_m.k, _m.j, _m.i); Fvector xyz; _m.getXYZi (xyz); if(fsimilar(yaw, xyz.y, EPS) && fsimilar(pitch, xyz.x, EPS)) lookat_active = false; yaw = angle_inertion_var( yaw, xyz.y, 1.0f, PI, PI, Device.fTimeDelta); pitch = angle_inertion_var( pitch, xyz.x, 1.0f, PI, PI, Device.fTimeDelta); }
void CCameraLook2::UpdateAutoAim() { Fvector _dest_point; m_locked_enemy->Center (_dest_point); _dest_point.y += 0.2f; Fvector _dest_dir; _dest_dir.sub (_dest_point, vPosition); Fmatrix _m; _m.identity (); _m.k.normalize_safe (_dest_dir); Fvector::generate_orthonormal_basis (_m.k, _m.j, _m.i); Fvector xyz; _m.getXYZi (xyz); yaw = angle_inertion_var( yaw,xyz.y, m_autoaim_inertion_yaw.x, m_autoaim_inertion_yaw.y, PI, Device.fTimeDelta); pitch = angle_inertion_var( pitch,xyz.x, m_autoaim_inertion_pitch.x, m_autoaim_inertion_pitch.y, PI, Device.fTimeDelta); }
void CCarWeapon::UpdateBarrelDir() { CKinematics* K = smart_cast<CKinematics*>(m_object->Visual()); m_fire_bone_xform = K->LL_GetTransform(m_fire_bone); m_fire_bone_xform.mulA_43(m_object->XFORM()); m_fire_pos.set(0,0,0); m_fire_bone_xform.transform_tiny(m_fire_pos); m_fire_dir.set(0,0,1); m_fire_bone_xform.transform_dir(m_fire_dir); m_fire_norm.set(0,1,0); m_fire_bone_xform.transform_dir(m_fire_norm); m_allow_fire = true; Fmatrix XFi; XFi.invert (m_object->XFORM()); Fvector dep; XFi.transform_dir (dep,m_destEnemyDir); {// x angle m_i_bind_x_xform.transform_dir(dep); dep.normalize(); m_tgt_x_rot = angle_normalize_signed(m_bind_x_rot-dep.getP()); clamp (m_tgt_x_rot,-m_lim_x_rot.y,-m_lim_x_rot.x); } {// y angle m_i_bind_y_xform.transform_dir(dep); dep.normalize(); m_tgt_y_rot = angle_normalize_signed(m_bind_y_rot-dep.getH()); clamp (m_tgt_y_rot,-m_lim_y_rot.y,-m_lim_y_rot.x); } m_cur_x_rot = angle_inertion_var(m_cur_x_rot,m_tgt_x_rot,m_min_gun_speed,m_max_gun_speed,PI,Device.fTimeDelta); m_cur_y_rot = angle_inertion_var(m_cur_y_rot,m_tgt_y_rot,m_min_gun_speed,m_max_gun_speed,PI,Device.fTimeDelta); static float dir_eps = deg2rad(5.0f); if( !fsimilar(m_cur_x_rot,m_tgt_x_rot,dir_eps)|| !fsimilar(m_cur_y_rot,m_tgt_y_rot,dir_eps)) m_allow_fire=FALSE; #if (0) if(Device.dwFrame%200==0){ Msg("m_cur_x_rot=[%f]",m_cur_x_rot); Msg("m_cur_y_rot=[%f]",m_cur_y_rot); } #endif }
void UpdateCameraDirection(CGameObject* pTo) { CCameraBase* cam = Actor()->cam_Active(); Fvector des_dir; Fvector des_pt; pTo->Center(des_pt); des_pt.y+=pTo->Radius()*0.5f; des_dir.sub(des_pt,cam->vPosition); float p,h; des_dir.getHP(h,p); if(angle_difference(cam->yaw,-h)>0.2) cam->yaw = angle_inertion_var(cam->yaw, -h, 0.15f, 0.2f, PI_DIV_6, Device.fTimeDelta); if(angle_difference(cam->pitch,-p)>0.2) cam->pitch = angle_inertion_var(cam->pitch, -p, 0.15f, 0.2f, PI_DIV_6, Device.fTimeDelta); }
void CWeaponStatMgun::cam_Update (float dt, float fov) { Fvector P,Da; Da.set (0,0,0); IKinematics* K = smart_cast<IKinematics*>(Visual()); K->CalculateBones_Invalidate (); K->CalculateBones (TRUE); const Fmatrix& C = K->LL_GetTransform(m_camera_bone); XFORM().transform_tiny (P,C.c); Fvector d = C.k; XFORM().transform_dir (d); Fvector2 des_cam_dir; d.getHP(des_cam_dir.x, des_cam_dir.y); des_cam_dir.mul(-1.0f); Camera()->yaw = angle_inertion_var(Camera()->yaw, des_cam_dir.x, 0.5f, 7.5f, PI_DIV_6, Device.fTimeDelta); Camera()->pitch = angle_inertion_var(Camera()->pitch, des_cam_dir.y, 0.5f, 7.5f, PI_DIV_6, Device.fTimeDelta); if(OwnerActor()){ // rotate head OwnerActor()->Orientation().yaw = -Camera()->yaw; OwnerActor()->Orientation().pitch = -Camera()->pitch; } Camera()->Update (P,Da); Level().Cameras().UpdateFromCamera (Camera()); }