void CInventoryItem::UpdateXForm () { if (0==object().H_Parent()) return; // Get access to entity and its visual CEntityAlive* E = smart_cast<CEntityAlive*>(object().H_Parent()); if (!E) return; if (E->cast_base_monster()) return; const CInventoryOwner *parent = smart_cast<const CInventoryOwner*>(E); if (parent && parent->use_simplified_visual()) return; if (parent->attached(this)) return; R_ASSERT (E); IKinematics* V = smart_cast<IKinematics*> (E->Visual()); VERIFY (V); // Get matrices int boneL = -1, boneR = -1, boneR2 = -1; E->g_WeaponBones(boneL,boneR,boneR2); if (boneR == -1) return; // if ((HandDependence() == hd1Hand) || (STATE == eReload) || (!E->g_Alive())) // boneL = boneR2; #pragma todo("TO ALL: serious performance problem") V->CalculateBones (); Fmatrix& mL = V->LL_GetTransform(u16(boneL)); Fmatrix& mR = V->LL_GetTransform(u16(boneR)); // Calculate Fmatrix mRes; Fvector R,D,N; D.sub (mL.c,mR.c); D.normalize_safe(); if(fis_zero(D.magnitude())) { mRes.set(E->XFORM()); mRes.c.set(mR.c); } else { D.normalize(); R.crossproduct (mR.j,D); N.crossproduct (D,R); N.normalize(); mRes.set (R,N,D,mR.c); mRes.mulA_43 (E->XFORM()); } // UpdatePosition (mRes); object().Position().set(mRes.c); }
type_motion::edirection type_motion::dir( CEntityAlive& ea, const SHit& H, float& angle ) { Fvector dir = H.direction(); dir.y = 0; float m = dir.magnitude(); if( fis_zero( m ) ) { edirection dr; dr = (edirection) ::Random.randI( 0, (s32) not_definite ); VERIFY( dr < not_definite ); return dr; } dir.mul( 1.f / m ); Fvector z_dir = { ea.XFORM().k.x, 0.f, ea.XFORM().k.z }; Fvector x_dir = { ea.XFORM().i.x, 0.f, ea.XFORM().i.z }; z_dir.normalize_safe();x_dir.normalize_safe(); float front_factor = dir.dotproduct( z_dir ); float sidefactor = dir.dotproduct( x_dir ); if( _abs( front_factor ) > M_SQRT1_2 ) { float sign = front_factor < 0.f ? -1.f : 1.f; angle = atan2( -sign * sidefactor, sign * front_factor ); return sign < 0.f ? front : back; } else { float sign = sidefactor > 0.f ? 1.f : -1.f; angle = atan2( sign * front_factor, sign * sidefactor ); return sign > 0.f ? left : right; } }
void CArtefact::UpdateXForm() { if (Device.dwFrame!=dwXF_Frame) { dwXF_Frame = Device.dwFrame; if (0==H_Parent()) return; // Get access to entity and its visual CEntityAlive* E = smart_cast<CEntityAlive*>(H_Parent()); if(!E) return ; const CInventoryOwner *parent = smart_cast<const CInventoryOwner*>(E); if (parent && parent->use_simplified_visual()) return; VERIFY (E); IKinematics* V = smart_cast<IKinematics*> (E->Visual()); VERIFY (V); if(CAttachableItem::enabled()) return; // Get matrices int boneL = -1, boneR = -1, boneR2 = -1; E->g_WeaponBones (boneL,boneR,boneR2); if (boneR == -1) return; boneL = boneR2; V->CalculateBones (); Fmatrix& mL = V->LL_GetTransform(u16(boneL)); Fmatrix& mR = V->LL_GetTransform(u16(boneR)); // Calculate Fmatrix mRes; Fvector R,D,N; D.sub (mL.c,mR.c); D.normalize_safe(); R.crossproduct (mR.j,D); R.normalize_safe(); N.crossproduct (D,R); N.normalize_safe(); mRes.set (R,N,D,mR.c); mRes.mulA_43 (E->XFORM()); // UpdatePosition (mRes); XFORM().mul (mRes,offset()); } }
void CWeapon::UpdateXForm () { if (Device.dwFrame == dwXF_Frame) return; dwXF_Frame = Device.dwFrame; if (!H_Parent()) return; // Get access to entity and its visual CEntityAlive* E = smart_cast<CEntityAlive*>(H_Parent()); if (!E) { if (!IsGameTypeSingle()) UpdatePosition (H_Parent()->XFORM()); return; } const CInventoryOwner *parent = smart_cast<const CInventoryOwner*>(E); if (parent && parent->use_simplified_visual()) return; if (parent->attached(this)) return; IKinematics* V = smart_cast<IKinematics*> (E->Visual()); VERIFY (V); // Get matrices int boneL = -1, boneR = -1, boneR2 = -1; // this ugly case is possible in case of a CustomMonster, not a Stalker, nor an Actor E->g_WeaponBones (boneL,boneR,boneR2); if (boneR == -1) return; if ((HandDependence() == hd1Hand) || (GetState() == eReload) || (!E->g_Alive())) boneL = boneR2; V->CalculateBones (); Fmatrix& mL = V->LL_GetTransform(u16(boneL)); Fmatrix& mR = V->LL_GetTransform(u16(boneR)); // Calculate Fmatrix mRes; Fvector R,D,N; D.sub (mL.c,mR.c); if(fis_zero(D.magnitude())) { mRes.set (E->XFORM()); mRes.c.set (mR.c); } else { D.normalize (); R.crossproduct (mR.j,D); N.crossproduct (D,R); N.normalize (); mRes.set (R,N,D,mR.c); mRes.mulA_43 (E->XFORM()); } UpdatePosition (mRes); }
void character_hit_animation_controller::PlayHitMotion( const Fvector &dir, const Fvector &bone_pos, u16 bi, CEntityAlive &ea )const { IRenderVisual *pV = ea.Visual( ); IKinematicsAnimated* CA = smart_cast<IKinematicsAnimated*>( pV ); IKinematics* K = smart_cast<IKinematics*>( pV ); //play_cycle(CA,all_shift_down,1,block_times[6],1) ; if( !( K->LL_BoneCount( ) > bi ) ) return; Fvector dr = dir; Fmatrix m; GetBaseMatrix( m, ea ); #ifdef DEBUG if( ph_dbg_draw_mask1.test( phDbgHitAnims ) ) { DBG_OpenCashedDraw(); DBG_DrawLine( m.c, Fvector( ).sub( m.c, Fvector( ).mul( dir, 1.5 ) ), D3DCOLOR_XRGB( 255, 0, 255 ) ); DBG_ClosedCashedDraw( 1000 ); } #endif m.invert( ); m.transform_dir( dr ); // Fvector hit_point; K->LL_GetTransform( bi ).transform_tiny( hit_point, bone_pos ); ea.XFORM( ).transform_tiny( hit_point ); m.transform_tiny( hit_point ); Fvector torqu; torqu.crossproduct( dr, hit_point ); hit_point.x = 0; float rotational_ammount = hit_point.magnitude( ) * g_params.power_factor * g_params.rotational_power_factor;//_abs(torqu.x) if( torqu.x < 0 ) play_cycle( CA, hit_downr, 3, block_blends[7], 1 ) ; else play_cycle( CA, hit_downl, 3, block_blends[6], 1 ) ; if( !IsEffected( bi, *K ) ) return; if( torqu.x<0 ) play_cycle( CA, turn_right, 2, block_blends[4], rotational_ammount ) ; else play_cycle( CA, turn_left, 2, block_blends[5], rotational_ammount ) ; //CA->LL_SetChannelFactor(3,rotational_ammount); dr.x = 0; dr.normalize_safe(); dr.mul(g_params.power_factor); if( dr.y > g_params.side_sensitivity_threshold ) play_cycle( CA, rthit_motion, 2, block_blends[0], _abs( dr.y ) ) ; else if( dr.y < -g_params.side_sensitivity_threshold ) play_cycle( CA, lthit_motion, 2, block_blends[1], _abs( dr.y ) ) ; if( dr.z<0.f ) play_cycle( CA, fvhit_motion, 2, block_blends[2], _abs(dr.z) ) ; else play_cycle( CA, bkhit_motion, 2, block_blends[3], _abs( dr.z ) ) ; CA->LL_SetChannelFactor( 2, g_params.anim_channel_factor ); }
void character_hit_animation_controller::GetBaseMatrix( Fmatrix &m,CEntityAlive &ea)const { IKinematics* CA = smart_cast<IKinematics*>(ea.Visual()); m.mul_43(ea.XFORM(),CA->LL_GetTransform(base_bone)); }