void CPhysicObject::CreateSkeleton(CSE_ALifeObjectPhysic* po) { if(m_pPhysicsShell) return; if(!Visual()) return; LPCSTR fixed_bones=*po->fixed_bones; m_pPhysicsShell=P_build_Shell(this,!po->_flags.test(CSE_PHSkeleton::flActive),fixed_bones); ApplySpawnIniToPhysicShell(&po->spawn_ini(),m_pPhysicsShell,fixed_bones[0]!='\0'); ApplySpawnIniToPhysicShell(smart_cast<IKinematics*>(Visual())->LL_UserData(),m_pPhysicsShell,fixed_bones[0]!='\0'); }
void CHelicopter::SpawnInitPhysics (CSE_Abstract *D) { PPhysicsShell()=P_build_Shell (this,false); if(g_Alive()) { PPhysicsShell()->EnabledCallbacks (FALSE); PPhysicsShell()->set_ObjectContactCallback (CollisionCallbackAlife); PPhysicsShell()->set_ContactCallback (ContactCallbackAlife); PPhysicsShell()->Disable (); } }
void CCharacterPhysicsSupport::in_NetSpawn( CSE_Abstract* e ) { m_sv_hit = SHit(); if( m_EntityAlife.use_simplified_visual ( ) ) { m_flags.set( fl_death_anim_on, TRUE ); IKinematics* ka = smart_cast<IKinematics*>( m_EntityAlife.Visual( ) ); VERIFY( ka ); ka->CalculateBones_Invalidate( ); ka->CalculateBones( TRUE ); CollisionCorrectObjPos( m_EntityAlife.Position( ) ); m_pPhysicsShell = P_build_Shell( &m_EntityAlife, false ); ka->CalculateBones_Invalidate( ); ka->CalculateBones( TRUE ); return; } CPHDestroyable::Init();//this zerows colbacks !!; IRenderVisual *pVisual = m_EntityAlife.Visual(); IKinematicsAnimated*ka= smart_cast<IKinematicsAnimated*>( pVisual ); IKinematics*pK= smart_cast<IKinematics*>( pVisual ); VERIFY( &e->spawn_ini() ); m_death_anims.setup( ka, *e->s_name , pSettings ); if( !m_EntityAlife.g_Alive() ) { if( m_eType == etStalker ) ka->PlayCycle( "waunded_1_idle_0" ); else ka->PlayCycle( "death_init" ); }else if( !m_EntityAlife.animation_movement_controlled( ) ) ka->PlayCycle( "death_init" );///непонятно зачем это вообще надо запускать ///этот хак нужен, потому что некоторым монстрам ///анимация после спона, может быть вообще не назначена pK->CalculateBones_Invalidate( ); pK->CalculateBones( TRUE ); CPHSkeleton::Spawn( e ); movement( )->EnableCharacter(); movement( )->SetPosition(m_EntityAlife.Position( ) ); movement( )->SetVelocity ( 0, 0, 0 ); if(m_eType!=etActor) { m_flags.set( fl_specific_bonce_demager, TRUE ); m_BonceDamageFactor = 1.f; } if( Type( ) == etStalker ) { m_hit_animations.SetupHitMotions( *smart_cast<IKinematicsAnimated*>( m_EntityAlife.Visual( ) ) ); } anim_mov_state.init( ); anim_mov_state.active = m_EntityAlife.animation_movement_controlled( ); }
CPhysicsShell* P_build_Shell (CGameObject* obj,bool not_active_state,BONE_P_MAP* p_bone_map,LPCSTR fixed_bones) { CPhysicsShell* pPhysicsShell; CKinematics* pKinematics=smart_cast<CKinematics*>(obj->Visual()); if(fixed_bones) { int count = _GetItemCount(fixed_bones); for (int i=0 ;i<count; ++i) { string64 fixed_bone ; _GetItem (fixed_bones,i,fixed_bone) ; u16 fixed_bone_id=pKinematics->LL_BoneID(fixed_bone) ; R_ASSERT2(BI_NONE!=fixed_bone_id,"wrong fixed bone") ; p_bone_map->insert(mk_pair(fixed_bone_id,physicsBone())) ; } pPhysicsShell=P_build_Shell(obj,not_active_state,p_bone_map); //m_pPhysicsShell->add_Joint(P_create_Joint(CPhysicsJoint::enumType::full_control,0,fixed_element)); } else pPhysicsShell=P_build_Shell(obj,not_active_state); BONE_P_PAIR_IT i=p_bone_map->begin(),e=p_bone_map->end(); if(i!=e) pPhysicsShell->SetPrefereExactIntegration(); for(;i!=e;i++) { CPhysicsElement* fixed_element=i->second.element; R_ASSERT2(fixed_element,"fixed bone has no physics"); //if(!fixed_element) continue; fixed_element->Fix(); } return pPhysicsShell; }
CPhysicsShell* P_build_Shell (CGameObject* obj,bool not_active_state,LPCSTR fixed_bones) { U16Vec f_bones; if(fixed_bones){ CKinematics* K = smart_cast<CKinematics*>(obj->Visual()); int count = _GetItemCount(fixed_bones); for (int i=0 ;i<count; ++i){ string64 fixed_bone; _GetItem (fixed_bones,i,fixed_bone); f_bones.push_back(K->LL_BoneID(fixed_bone)); R_ASSERT2(BI_NONE!=f_bones.back(),"wrong fixed bone") ; } } return P_build_Shell (obj,not_active_state,f_bones); }
BOOL CWeaponStatMgun::net_Spawn(CSE_Abstract* DC) { if(!inheritedPH::net_Spawn (DC)) return FALSE; IKinematics* K = smart_cast<IKinematics*>(Visual()); CInifile* pUserData = K->LL_UserData(); R_ASSERT2 (pUserData,"Empty WeaponStatMgun user data!"); m_rotate_x_bone = K->LL_BoneID (pUserData->r_string("mounted_weapon_definition","rotate_x_bone")); m_rotate_y_bone = K->LL_BoneID (pUserData->r_string("mounted_weapon_definition","rotate_y_bone")); m_fire_bone = K->LL_BoneID (pUserData->r_string("mounted_weapon_definition","fire_bone")); m_camera_bone = K->LL_BoneID (pUserData->r_string("mounted_weapon_definition","camera_bone")); U16Vec fixed_bones; fixed_bones.push_back (K->LL_GetBoneRoot()); PPhysicsShell() = P_build_Shell(this,false,fixed_bones); CBoneData& bdX = K->LL_GetData(m_rotate_x_bone); VERIFY(bdX.IK_data.type==jtJoint); m_lim_x_rot.set (bdX.IK_data.limits[0].limit.x,bdX.IK_data.limits[0].limit.y); CBoneData& bdY = K->LL_GetData(m_rotate_y_bone); VERIFY(bdY.IK_data.type==jtJoint); m_lim_y_rot.set (bdY.IK_data.limits[1].limit.x,bdY.IK_data.limits[1].limit.y); xr_vector<Fmatrix> matrices; K->LL_GetBindTransform (matrices); m_i_bind_x_xform.invert (matrices[m_rotate_x_bone]); m_i_bind_y_xform.invert (matrices[m_rotate_y_bone]); m_bind_x_rot = matrices[m_rotate_x_bone].k.getP(); m_bind_y_rot = matrices[m_rotate_y_bone].k.getH(); m_bind_x.set (matrices[m_rotate_x_bone].c); m_bind_y.set (matrices[m_rotate_y_bone].c); m_cur_x_rot = m_bind_x_rot; m_cur_y_rot = m_bind_y_rot; m_destEnemyDir.setHP (m_bind_y_rot,m_bind_x_rot); XFORM().transform_dir (m_destEnemyDir); inheritedShooting::Light_Create(); processing_activate (); setVisible (TRUE); setEnabled (TRUE); return TRUE; }
void CCharacterPhysicsSupport::in_NetSpawn(CSE_Abstract* e) { if(m_EntityAlife.use_simplified_visual ()) { m_flags.set(fl_death_anim_on,TRUE); CKinematics* ka=smart_cast<CKinematics*>(m_EntityAlife.Visual()); VERIFY(ka); ka->CalculateBones_Invalidate(); ka->CalculateBones(); CollisionCorrectObjPos(m_EntityAlife.Position()); m_pPhysicsShell = P_build_Shell(&m_EntityAlife,false); ka->CalculateBones_Invalidate(); ka->CalculateBones(); return; } CPHDestroyable::Init();//this zerows colbacks !!; CKinematicsAnimated*ka= smart_cast<CKinematicsAnimated*>(m_EntityAlife.Visual()); if(!m_EntityAlife.g_Alive()) { if(m_eType==etStalker) ka->PlayCycle("waunded_1_idle_0"); else ka->PlayCycle("death_init"); }else { ka->PlayCycle("death_init"); } ka->CalculateBones_Invalidate(); ka->CalculateBones(); CPHSkeleton::Spawn(e); movement()->EnableCharacter(); movement()->SetPosition(m_EntityAlife.Position()); movement()->SetVelocity (0,0,0); if(m_eType!=etActor) { m_flags.set(fl_specific_bonce_demager,TRUE); m_BonceDamageFactor=1.f; } }
CPhysicsShell* P_build_Shell (CGameObject* obj,bool not_active_state,U16Vec& fixed_bones) { bone_map.clear (); CPhysicsShell* pPhysicsShell; if(!fixed_bones.empty()) for (U16It it=fixed_bones.begin(); it!=fixed_bones.end(); it++) bone_map.insert(mk_pair(*it,physicsBone())); pPhysicsShell=P_build_Shell(obj,not_active_state,&bone_map); // fix bones BONE_P_PAIR_IT i=bone_map.begin(),e=bone_map.end(); if(i!=e) pPhysicsShell->SetPrefereExactIntegration(); for(;i!=e;i++){ CPhysicsElement* fixed_element=i->second.element; //R_ASSERT2(fixed_element,"fixed bone has no physics"); if(!fixed_element) continue; fixed_element->Fix(); } return pPhysicsShell; }
void CArtefact::create_physic_shell () { m_pPhysicsShell=P_build_Shell(this,false); m_pPhysicsShell->Deactivate(); }
void CCharacterPhysicsSupport:: AddActiveWeaponCollision () { if( m_eType!=etStalker ) return; VERIFY( !m_weapon_attach_bone ); VERIFY( !m_active_item_obj ); VERIFY( m_weapon_geoms.empty() ); VERIFY( m_weapon_bone_fixes.empty() ); CInventoryOwner*inv_owner = smart_cast<CInventoryOwner*>( &m_EntityAlife ); VERIFY( inv_owner ); PIItem active_weapon_item = inv_owner->inventory().ActiveItem(); if( !active_weapon_item ) return; int bl=-1, br=-1, br2=-1; m_EntityAlife.g_WeaponBones( bl, br, br2 ); if( br==-1 ) return; active_weapon_item->UpdateXForm(); CPhysicsShell *weapon_shell = P_build_Shell( &active_weapon_item->object(), true, (BONE_P_MAP*) (0), true ); VERIFY( m_pPhysicsShell ); CPhysicsElement* weapon_attach_bone = m_pPhysicsShell->get_PhysicsParrentElement( (u16)br ); bone_chain_disable( (u16)br, weapon_attach_bone->m_SelfID, *m_pPhysicsShell->PKinematics() ); if( bl!=-1 ) { CPhysicsElement* p = m_pPhysicsShell->get_PhysicsParrentElement( (u16) bl ); VERIFY( p ); bone_chain_disable( (u16)bl, p->m_SelfID, *m_pPhysicsShell->PKinematics() ); } if( br2!=-1 ) { CPhysicsElement* p = m_pPhysicsShell->get_PhysicsParrentElement( (u16) br2 ); VERIFY( p ); bone_chain_disable( (u16)br2, weapon_attach_bone->m_SelfID, *m_pPhysicsShell->PKinematics() ); } CPhysicsElement* weapon_element = weapon_shell->get_ElementByStoreOrder( 0 ); u16 geom_num = weapon_element->numberOfGeoms(); for( u16 i = 0; i< geom_num; ++i ) m_weapon_geoms.push_back( weapon_element->geometry( i ) ); xr_vector<CODEGeom*>::iterator ii =m_weapon_geoms.begin(), ee = m_weapon_geoms.end(); //DBG_OpenCashedDraw(); for( ;ii!=ee; ++ii ) { CODEGeom *g =(*ii); //g->dbg_draw( 0.01f, D3DCOLOR_XRGB( 255, 0, 0 ), Flags32() ); weapon_element->remove_geom( g ); g->set_bone_id( weapon_attach_bone->m_SelfID ); weapon_attach_bone->add_geom( g ); //g->dbg_draw( 0.01f, D3DCOLOR_XRGB( 0, 255, 0 ), Flags32() ); } m_weapon_attach_bone = weapon_attach_bone; m_active_item_obj = &(active_weapon_item->object()); destroy_physics_shell( weapon_shell ); //m_pPhysicsShell->dbg_draw_geometry( 1, D3DCOLOR_XRGB( 0, 0, 255 ) ); //DBG_ClosedCashedDraw( 50000 ); }