void CCharacterPhysicsSupport::CreateSkeleton(CPhysicsShell* &pShell) { R_ASSERT2(!pShell,"pShell already initialized!!"); if (!m_EntityAlife.Visual()) return; #ifdef DEBUG CTimer t;t.Start(); #endif pShell = P_create_Shell(); IKinematics* k = smart_cast<IKinematics*>(m_EntityAlife.Visual()); phys_shell_verify_object_model ( m_EntityAlife ); pShell->preBuild_FromKinematics(k); pShell->mXFORM.set(mXFORM); pShell->SmoothElementsInertia(0.3f); pShell->set_PhysicsRefObject(&m_EntityAlife); SAllDDOParams disable_params; disable_params.Load(smart_cast<IKinematics*>(m_EntityAlife.Visual())->LL_UserData()); pShell->set_DisableParams(disable_params); pShell->Build(); #ifdef DEBUG Msg("shell for %s[%d] created in %f ms",*m_EntityAlife.cName(),m_EntityAlife.ID(),t.GetElapsed_sec()*1000.f); #endif }
void CCar::CreateSkeleton(CSE_Abstract *po) { if (!Visual()) return; IRenderVisual *pVis = Visual(); IKinematics* pK = smart_cast<IKinematics*>(pVis); IKinematicsAnimated* pKA = smart_cast<IKinematicsAnimated*>(pVis); if(pKA) { pKA->PlayCycle ("idle"); pK->CalculateBones (TRUE); } phys_shell_verify_object_model ( *this ); #pragma todo(" replace below by P_build_Shell or call inherited") m_pPhysicsShell = P_create_Shell(); m_pPhysicsShell->build_FromKinematics(pK,&bone_map); m_pPhysicsShell->set_PhysicsRefObject(this); m_pPhysicsShell->mXFORM.set(XFORM()); m_pPhysicsShell->Activate(true); m_pPhysicsShell->SetAirResistance(0.f,0.f); m_pPhysicsShell->SetPrefereExactIntegration(); ApplySpawnIniToPhysicShell(&po->spawn_ini(),m_pPhysicsShell,false); ApplySpawnIniToPhysicShell(pK->LL_UserData(),m_pPhysicsShell,false); }
void CCharacterPhysicsSupport::CreateSkeleton() { if(m_pPhysicsShell) return; Fvector velocity; m_PhysicMovementControl->GetCharacterVelocity(velocity); m_PhysicMovementControl->GetDeathPosition (m_EntityAlife.Position()); m_PhysicMovementControl->DestroyCharacter(); if (!m_EntityAlife.Visual()) return; m_pPhysicsShell = P_create_Shell(); m_pPhysicsShell->build_FromKinematics(smart_cast<CKinematics*>(m_EntityAlife.Visual())); m_pPhysicsShell->mXFORM.set(mXFORM); m_pPhysicsShell->SetAirResistance(skel_airr_lin_factor, skel_airr_ang_factor); m_pPhysicsShell->set_PhysicsRefObject(&m_EntityAlife); SAllDDOParams disable_params; disable_params.Load(smart_cast<CKinematics*>(m_EntityAlife.Visual())->LL_UserData()); m_pPhysicsShell->set_DisableParams(disable_params); m_pPhysicsShell->set_JointResistance(0.f); m_pPhysicsShell->Activate(true); velocity.mul(1.25f*m_after_death_velocity_factor); m_pPhysicsShell->set_LinearVel(velocity); smart_cast<CKinematics*>(m_EntityAlife.Visual())->CalculateBones(); //b_death_anim_on=false; m_flags.set(fl_death_anim_on,FALSE); m_eState=esDead; }
CPhysicsShell* P_build_SimpleShell(CGameObject* obj,float mass,bool not_active_state) { CPhysicsShell* pPhysicsShell = P_create_Shell(); #ifdef DEBUG pPhysicsShell->dbg_obj=smart_cast<CPhysicsShellHolder*>(obj); #endif Fobb obb; obj->Visual()->vis.box.get_CD(obb.m_translate,obb.m_halfsize); obb.m_rotate.identity(); CPhysicsElement* E = P_create_Element(); R_ASSERT(E); E->add_Box(obb); pPhysicsShell->add_Element(E); pPhysicsShell->setMass(mass); pPhysicsShell->set_PhysicsRefObject(smart_cast<CPhysicsShellHolder*>(obj)); if(!obj->H_Parent()) pPhysicsShell->Activate(obj->XFORM(),0,obj->XFORM(),not_active_state); return pPhysicsShell; }
void CHangingLamp::CreateBody(CSE_ALifeObjectHangingLamp *lamp) { if (!Visual()) return; if (m_pPhysicsShell) return; CKinematics* pKinematics= smart_cast<CKinematics*> (Visual()); m_pPhysicsShell = P_create_Shell(); bone_map .clear(); LPCSTR fixed_bones=*lamp->fixed_bones; 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") ; bone_map.insert(mk_pair(fixed_bone_id,physicsBone())) ; } }else{ bone_map.insert(mk_pair(pKinematics->LL_GetBoneRoot(),physicsBone())) ; } m_pPhysicsShell->build_FromKinematics(pKinematics,&bone_map); m_pPhysicsShell->set_PhysicsRefObject(this); m_pPhysicsShell->mXFORM.set(XFORM()); m_pPhysicsShell->Activate(true);//, //m_pPhysicsShell->SmoothElementsInertia(0.3f); m_pPhysicsShell->SetAirResistance();//0.0014f,1.5f ///////////////////////////////////////////////////////////////////////////// BONE_P_PAIR_IT i=bone_map.begin(),e=bone_map.end(); for(;i!=e;i++){ CPhysicsElement* fixed_element=i->second.element; ///R_ASSERT2(fixed_element,"fixed bone has no physics"); if(fixed_element)fixed_element->Fix(); } m_pPhysicsShell->mXFORM.set(XFORM()); m_pPhysicsShell->SetAirResistance(0.001f, 0.02f); SAllDDOParams disable_params; disable_params.Load(smart_cast<CKinematics*>(Visual())->LL_UserData()); m_pPhysicsShell->set_DisableParams(disable_params); ApplySpawnIniToPhysicShell(&lamp->spawn_ini(),m_pPhysicsShell,fixed_bones[0]!='\0'); }
CPhysicsShell* P_build_Shell (CGameObject* obj,bool not_active_state,BONE_P_MAP* bone_map) { CKinematics* pKinematics=smart_cast<CKinematics*>(obj->Visual()); CPhysicsShell* pPhysicsShell = P_create_Shell(); #ifdef DEBUG pPhysicsShell->dbg_obj=smart_cast<CPhysicsShellHolder*>(obj); #endif pPhysicsShell->build_FromKinematics(pKinematics,bone_map); pPhysicsShell->set_PhysicsRefObject(smart_cast<CPhysicsShellHolder*>(obj)); pPhysicsShell->mXFORM.set(obj->XFORM()); pPhysicsShell->Activate(not_active_state);//, //m_pPhysicsShell->SmoothElementsInertia(0.3f); pPhysicsShell->SetAirResistance();//0.0014f,1.5f return pPhysicsShell; }
void CPhysicItem::create_box_physic_shell () { // Physics (Box) Fobb obb; Visual()->vis.box.get_CD(obb.m_translate,obb.m_halfsize); obb.m_rotate.identity(); // Physics (Elements) CPhysicsElement* E = P_create_Element(); R_ASSERT(E); E->add_Box(obb); // Physics (Shell) m_pPhysicsShell = P_create_Shell(); R_ASSERT(m_pPhysicsShell); m_pPhysicsShell->add_Element(E); m_pPhysicsShell->setDensity(2000.f); }
void CPHShellSimpleCreator::CreatePhysicsShell() { CPhysicsShellHolder* owner = smart_cast<CPhysicsShellHolder*>(this); VERIFY(owner); if (!owner->Visual()) return; CKinematics* pKinematics = smart_cast<CKinematics*>(owner->Visual()); VERIFY (pKinematics); if(owner->PPhysicsShell()) return; owner->PPhysicsShell() = P_create_Shell(); #ifdef DEBUG owner->PPhysicsShell()->dbg_obj=owner; #endif owner->m_pPhysicsShell->build_FromKinematics (pKinematics,0); owner->PPhysicsShell()->set_PhysicsRefObject (owner); //m_pPhysicsShell->SmoothElementsInertia(0.3f); owner->PPhysicsShell()->mXFORM.set (owner->XFORM()); owner->PPhysicsShell()->SetAirResistance (0.001f, 0.02f); }
//the simpliest case - a joint to be destroied shell_root CPHShellSplitterHolder::SplitJoint(u16 aspl) { //create _new physics shell CPhysicsShell *new_shell=P_create_Shell(); CPHShell *new_shell_desc=smart_cast<CPHShell*>(new_shell); new_shell_desc->mXFORM.set(m_pShell->mXFORM); new_shell_desc->m_object_in_root.set(m_pShell->m_object_in_root); SPLITTER_I splitter=m_splitters.begin()+aspl; u16 start_element=splitter->m_element; u16 start_joint=splitter->m_joint; u16 end_element=m_pShell->joints[start_joint]->JointDestroyInfo()->m_end_element; u16 end_joint=m_pShell->joints[start_joint]->JointDestroyInfo()->m_end_joint; shell_root ret = mk_pair(new_shell,(m_pShell->joints[start_joint])->BoneID()); CShellSplitInfo split_inf; split_inf.m_bone_id=m_pShell->joints[start_joint]->BoneID(); split_inf.m_start_el_num=start_element; split_inf.m_end_el_num=end_element; split_inf.m_start_jt_num=start_joint; split_inf.m_end_jt_num=end_joint; m_splitters.erase(splitter); PassEndSplitters(split_inf,new_shell_desc,1,0); InitNewShell(new_shell_desc); m_pShell->PassEndElements(start_element,end_element,new_shell_desc); m_pShell->PassEndJoints(start_joint+1,end_joint,new_shell_desc); new_shell_desc->set_PhysicsRefObject(0); new_shell_desc->PureActivate(); //new_shell_desc->ObjectInRoot().identity(); m_pShell->DeleteJoint(start_joint); new_shell->set_ObjectContactCallback(NULL); new_shell->set_PhysicsRefObject(NULL); return ret; }
void CPhysicObject::CreateBody(CSE_ALifeObjectPhysic* po) { if(m_pPhysicsShell) return; IKinematics* pKinematics=smart_cast<IKinematics*>(Visual()); switch(m_type) { case epotBox : { m_pPhysicsShell=P_build_SimpleShell(this,m_mass,!po->_flags.test(CSE_ALifeObjectPhysic::flActive)); } break; case epotFixedChain : case epotFreeChain : { m_pPhysicsShell = P_create_Shell(); m_pPhysicsShell->set_Kinematics(pKinematics); AddElement(0,pKinematics->LL_GetBoneRoot()); m_pPhysicsShell->setMass1(m_mass); } break; case epotSkeleton: { //pKinematics->LL_SetBoneRoot(0); CreateSkeleton(po); }break; default : { } break; } m_pPhysicsShell->mXFORM.set(XFORM()); m_pPhysicsShell->SetAirResistance(0.001f, 0.02f); if(pKinematics) { SAllDDOParams disable_params; disable_params.Load(pKinematics->LL_UserData()); m_pPhysicsShell->set_DisableParams(disable_params); } //m_pPhysicsShell->SetAirResistance(0.002f, 0.3f); }
void CPhysicItem::create_box2sphere_physic_shell() { // Physics (Box) Fobb obb; Visual()->vis.box.get_CD (obb.m_translate,obb.m_halfsize); obb.m_rotate.identity (); // Physics (Elements) CPhysicsElement *E = P_create_Element (); R_ASSERT (E); Fvector ax; float radius; CHOOSE_MAX( obb.m_halfsize.x,ax.set(obb.m_rotate.i) ; ax.mul(obb.m_halfsize.x); radius=_min(obb.m_halfsize.y,obb.m_halfsize.z) ;obb.m_halfsize.y/=2.f;obb.m_halfsize.z/=2.f, obb.m_halfsize.y,ax.set(obb.m_rotate.j) ; ax.mul(obb.m_halfsize.y); radius=_min(obb.m_halfsize.x,obb.m_halfsize.z) ;obb.m_halfsize.x/=2.f;obb.m_halfsize.z/=2.f, obb.m_halfsize.z,ax.set(obb.m_rotate.k) ; ax.mul(obb.m_halfsize.z); radius=_min(obb.m_halfsize.y,obb.m_halfsize.x) ;obb.m_halfsize.y/=2.f;obb.m_halfsize.x/=2.f ) //radius*=1.4142f; Fsphere sphere1,sphere2; sphere1.P.add (obb.m_translate,ax); sphere1.R =radius*1.4142f; sphere2.P.sub (obb.m_translate,ax); sphere2.R =radius/2.f; E->add_Box (obb); E->add_Sphere (sphere1); E->add_Sphere (sphere2); // Physics (Shell) m_pPhysicsShell = P_create_Shell (); R_ASSERT (m_pPhysicsShell); m_pPhysicsShell->add_Element (E); m_pPhysicsShell->setDensity (2000.f); m_pPhysicsShell->SetAirResistance(); }
shell_root CPHShellSplitterHolder::ElementSingleSplit(const element_fracture &split_elem,const CPHElement* source_element) { //const CPHShellSplitter& splitter=m_splitters[aspl]; //CPHElement* element=m_pShell->elements[splitter.m_element]; CPhysicsShell *new_shell_last=P_create_Shell(); CPHShell *new_shell_last_desc=smart_cast<CPHShell*>(new_shell_last); new_shell_last->mXFORM.set(m_pShell->mXFORM); const u16 start_joint=split_elem.second.m_start_jt_num; R_ASSERT(_valid(new_shell_last->mXFORM)); const u16 end_joint=split_elem.second.m_end_jt_num; //it is not right for multiple joints attached to the unsplited part becource all these need to be reattached if(start_joint!=end_joint) { JOINT_STORAGE& joints=m_pShell->joints; JOINT_I i=joints.begin()+ start_joint,e=joints.begin()+ end_joint; for(;i!=e;++i) { CPHJoint* joint=(*i); if(joint->PFirst_element()==source_element) { IKinematics* K = m_pShell->PKinematics(); dVector3 safe_pos1, safe_pos2; dQuaternion safe_q1, safe_q2; CPhysicsElement* el1=cast_PhysicsElement(split_elem.first),*el2=joint->PSecond_element(); dBodyID body1=el1->get_body(), body2=el2->get_body(); dVectorSet(safe_pos1,dBodyGetPosition(body1)); dVectorSet(safe_pos2,dBodyGetPosition(body2)); dQuaternionSet(safe_q1,dBodyGetQuaternion(body1)); dQuaternionSet(safe_q2,dBodyGetQuaternion(body2)); //m_pShell->PlaceBindToElForms(); K->LL_GetBindTransform(bones_bind_forms); el1->SetTransform(bones_bind_forms[el1->m_SelfID]); el2->SetTransform(bones_bind_forms[el2->m_SelfID]); joint->ReattachFirstElement(split_elem.first); dVectorSet(const_cast<dReal*>(dBodyGetPosition(body1)),safe_pos1); dVectorSet(const_cast<dReal*>(dBodyGetPosition(body2)),safe_pos2); dQuaternionSet(const_cast<dReal*>(dBodyGetQuaternion(body1)),safe_q1); dQuaternionSet(const_cast<dReal*>(dBodyGetQuaternion(body2)),safe_q2); dBodySetPosition(body1,safe_pos1[0],safe_pos1[1],safe_pos1[2]); dBodySetPosition(body2,safe_pos2[0],safe_pos2[1],safe_pos2[2]); dBodySetQuaternion(body1,safe_q1); dBodySetQuaternion(body2,safe_q2); } } // m_pShell->joints[split_elem.second.m_start_jt_num]->ReattachFirstElement(split_elem.first); } //the last new shell will have all splitted old elements end joints and one new element reattached to old joint //m_splitters.erase(m_splitters.begin()+aspl); //now aspl points to the next splitter if((split_elem.first)->FracturesHolder())//if this element can be splitted add a splitter for it new_shell_last_desc->AddSplitter(CPHShellSplitter::splElement,0,u16(-1));// new_shell_last_desc->add_Element(split_elem.first); //pass splitters taking into account that one element was olready added PassEndSplitters(split_elem.second,new_shell_last_desc,0,0); InitNewShell(new_shell_last_desc); m_pShell->PassEndElements(split_elem.second.m_start_el_num,split_elem.second.m_end_el_num,new_shell_last_desc); m_pShell->PassEndJoints(split_elem.second.m_start_jt_num,split_elem.second.m_end_jt_num,new_shell_last_desc); new_shell_last_desc->set_PhysicsRefObject(0); ///////////////////temporary for initialization set old Kinematics in new shell///////////////// new_shell_last->set_Kinematics(m_pShell->PKinematics()); new_shell_last_desc->AfterSetActive(); new_shell_last->set_Kinematics(NULL); VERIFY2(split_elem.second.m_bone_id<64,"strange root"); VERIFY(_valid(new_shell_last->mXFORM)); VERIFY(dBodyStateValide(source_element->get_bodyConst())); VERIFY(dBodyStateValide(split_elem.first->get_body())); new_shell_last->set_ObjectContactCallback(NULL); new_shell_last->set_PhysicsRefObject(NULL); return mk_pair(new_shell_last,split_elem.second.m_bone_id); }