IC void get_box_mat( Fmatrix33 &mat, float alpha, const SRotation &r_torso ) { float dZ = ((PI_DIV_2-((PI+alpha)/2))); Fmatrix xformR; xformR.setXYZ (-r_torso.pitch,r_torso.yaw,-dZ); mat.i = xformR.i; mat.j = xformR.j; mat.k = xformR.k; }
void CActor::HeadCallback(CBoneInstance* B) { CActor* A = static_cast<CActor*>(B->Callback_Param); VERIFY (A); Fmatrix spin; float bone_yaw = angle_normalize_signed(A->r_torso.yaw - A->r_model_yaw - A->r_model_yaw_delta)*y_head_factor; float bone_pitch = angle_normalize_signed(A->r_torso.pitch)*p_head_factor; float bone_roll = angle_normalize_signed(A->r_torso.roll)*r_head_factor; Fvector c = B->mTransform.c; spin.setXYZ (-bone_pitch,bone_yaw,bone_roll); B->mTransform.mulA_43(spin); B->mTransform.c = c; }
TEMPLATE_SPECIALIZATION void _detail::callback (CBoneInstance *B) { CAI_Stalker* A = static_cast<CAI_Stalker*>(B->Callback_Param); VERIFY (_valid(B->mTransform)); Fvector c = B->mTransform.c; Fmatrix spin; float yaw_factor = 0, pitch_factor = 0; if (A->sight().use_torso_look()) { yaw_factor = yaw_factor_fire/100.f; pitch_factor = pitch_factor_fire/100.f; } else { yaw_factor = yaw_factor_non_fire/100.f; pitch_factor = pitch_factor_non_fire/100.f; } float effector_yaw = 0.f, effector_pitch = 0.f; if (A->weapon_shot_effector().IsActive()) { Fvector temp; A->weapon_shot_effector().GetDeltaAngle(temp); effector_yaw = temp.y; VERIFY (_valid(effector_yaw)); effector_pitch = temp.x; VERIFY (_valid(effector_pitch)); } VERIFY (_valid(A->movement().head_orientation().current.yaw)); VERIFY (_valid(A->movement().body_orientation().current.yaw)); VERIFY (_valid(A->NET_Last.o_torso.pitch)); float yaw = angle_normalize_signed(-yaw_factor * angle_normalize_signed(A->movement().head_orientation().current.yaw + effector_yaw - (A->movement().body_orientation().current.yaw))); float pitch = angle_normalize_signed(-pitch_factor * angle_normalize_signed(A->NET_Last.o_torso.pitch + effector_pitch)); VERIFY (_valid(yaw)); VERIFY (_valid(pitch)); spin.setXYZ (pitch, yaw, 0); VERIFY (_valid(spin)); B->mTransform.mulA_43 (spin); B->mTransform.c = c; }
void CStalkerAnimationManager::add_script_animation (LPCSTR animation, bool hand_usage, Fvector position, Fvector rotation, bool local_animation) { const MotionID &motion = m_skeleton_animated->ID_Cycle_Safe(animation); if (!motion) { ai().script_engine().script_log(eLuaMessageTypeError,"There is no animation %s (object %s)!",animation,*object().cName()); return; } // Msg("add_script_animation %f,%f,%f %f,%f,%f local=%s [%s]", // position.x,position.y,position.z, // rotation.x,rotation.y,rotation.z, // local_animation ? "true" : "false", // m_object->animation_movement() ? "true" : "false" // ); Fmatrix transform; rotation.mul (PI/180.f); transform.setXYZ (rotation); transform.c = position; m_script_animations.push_back ( CStalkerAnimationScript( motion, hand_usage, true, &transform, local_animation ) ); }
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); } } }
void CParticleEffect::Render(float ) { u32 dwOffset,dwCount; // Get a pointer to the particles in gp memory PAPI::Particle* particles; u32 p_cnt; ParticleManager()->GetParticles(m_HandleEffect,particles,p_cnt); if(p_cnt>0){ if (m_Def&&m_Def->m_Flags.is(CPEDef::dfSprite)){ FVF::LIT* pv_start = (FVF::LIT*)RCache.Vertex.Lock(p_cnt*4*4,geom->vb_stride,dwOffset); FVF::LIT* pv = pv_start; for(u32 i = 0; i < p_cnt; i++){ PAPI::Particle &m = particles[i]; Fvector2 lt,rb; lt.set (0.f,0.f); rb.set (1.f,1.f); if (m_Def->m_Flags.is(CPEDef::dfFramed)) m_Def->m_Frame.CalculateTC(iFloor(float(m.frame)/255.f),lt,rb); float r_x = m.size.x*0.5f; float r_y = m.size.y*0.5f; if (m_Def->m_Flags.is(CPEDef::dfVelocityScale)){ float speed = m.vel.magnitude(); r_x += speed*m_Def->m_VelocityScale.x; r_y += speed*m_Def->m_VelocityScale.y; } if (m_Def->m_Flags.is(CPEDef::dfAlignToPath)){ float speed = m.vel.magnitude(); if ((speed<EPS_S)&&m_Def->m_Flags.is(CPEDef::dfWorldAlign)){ Fmatrix M; M.setXYZ (m_Def->m_APDefaultRotation); if (m_RT_Flags.is(flRT_XFORM)){ Fvector p; m_XFORM.transform_tiny(p,m.pos); M.mulA_43 (m_XFORM); FillSprite (pv,M.k,M.i,p,lt,rb,r_x,r_y,m.color,m.rot.x); }else{ FillSprite (pv,M.k,M.i,m.pos,lt,rb,r_x,r_y,m.color,m.rot.x); } }else if ((speed>=EPS_S)&&m_Def->m_Flags.is(CPEDef::dfFaceAlign)){ Fmatrix M; M.identity(); M.k.div (m.vel,speed); M.j.set (0,1,0); if (_abs(M.j.dotproduct(M.k))>.99f) M.j.set(0,0,1); M.i.crossproduct (M.j,M.k); M.i.normalize (); M.j.crossproduct (M.k,M.i); M.j.normalize (); if (m_RT_Flags.is(flRT_XFORM)){ Fvector p; m_XFORM.transform_tiny(p,m.pos); M.mulA_43 (m_XFORM); FillSprite (pv,M.j,M.i,p,lt,rb,r_x,r_y,m.color,m.rot.x); }else{ FillSprite (pv,M.j,M.i,m.pos,lt,rb,r_x,r_y,m.color,m.rot.x); } }else{ Fvector dir; if (speed>=EPS_S) dir.div (m.vel,speed); else dir.setHP(-m_Def->m_APDefaultRotation.y,-m_Def->m_APDefaultRotation.x); if (m_RT_Flags.is(flRT_XFORM)){ Fvector p,d; m_XFORM.transform_tiny (p,m.pos); m_XFORM.transform_dir (d,dir); FillSprite (pv,p,d,lt,rb,r_x,r_y,m.color,m.rot.x); }else{ FillSprite (pv,m.pos,dir,lt,rb,r_x,r_y,m.color,m.rot.x); } } }else{ if (m_RT_Flags.is(flRT_XFORM)){ Fvector p; m_XFORM.transform_tiny (p,m.pos); FillSprite (pv,Device.vCameraTop,Device.vCameraRight,p,lt,rb,r_x,r_y,m.color,m.rot.x); }else{ FillSprite (pv,Device.vCameraTop,Device.vCameraRight,m.pos,lt,rb,r_x,r_y,m.color,m.rot.x); } } } dwCount = u32(pv-pv_start); RCache.Vertex.Unlock(dwCount,geom->vb_stride); if (dwCount) { RCache.set_xform_world (Fidentity); RCache.set_Geometry (geom); // u32 cm = RCache.get_CullMode(); RCache.set_CullMode (m_Def->m_Flags.is(CPEDef::dfCulling)?(m_Def->m_Flags.is(CPEDef::dfCullCCW)?CULL_CCW:CULL_CW):CULL_NONE); RCache.Render (D3DPT_TRIANGLELIST,dwOffset,0,dwCount,0,dwCount/2); RCache.set_CullMode (CULL_CCW ); } } } }