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 reset_root_bone_start_pose( CPhysicsShell& shell ) { VERIFY( &shell ); CPhysicsElement * physics_root_element = shell.get_ElementByStoreOrder( 0 ); VERIFY( physics_root_element ); IKinematics * K = shell.PKinematics(); VERIFY( K ); u16 animation_root_bone_id = K->LL_GetBoneRoot(); CODEGeom *physics_root_bone_geom = physics_root_element->geometry( 0 ); VERIFY( physics_root_bone_geom ); u16 physics_root_bone_id = physics_root_bone_geom->bone_id(); VERIFY( physics_root_bone_id != BI_NONE ); if( animation_root_bone_id == physics_root_bone_id ) return ; //u16 anim_bones_number = K->LL_BoneCount(); //buffer_vector<u32> anim_bones_bind_positions( _alloca(anim_bones_number*sizeof(u32)), // anim_bones_number // ); #pragma todo("LL_GetBindTransform shoud use buffer_vector") xr_vector<Fmatrix> anim_bones_bind_positions; K->LL_GetBindTransform( anim_bones_bind_positions ); const Fmatrix physics_root_to_anim_root_bind_transformation = Fmatrix().mul_43( Fmatrix().invert( anim_bones_bind_positions[ physics_root_bone_id ] ), anim_bones_bind_positions[ animation_root_bone_id ] ); const Fmatrix &physics_root_bone_anim_transform = K->LL_GetTransform( physics_root_bone_id ); const Fmatrix physics_root_bone_corrected_pos = Fmatrix().mul_43( physics_root_bone_anim_transform , physics_root_to_anim_root_bind_transformation ); physics_root_element->SetTransform( Fmatrix().mul_43( shell.mXFORM, physics_root_bone_corrected_pos ) ); //physics_root_element->TransformPosition( Fmatrix().mul_43( Fmatrix().invert( K->LL_GetTransform( animation_root_bone_id ) ), physics_root_bone_corrected_pos ) ); }
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); }
BOOL CHelicopter::net_Spawn(CSE_Abstract* DC) { SetfHealth(100.0f); setState(CHelicopter::eAlive); m_flame_started =false; m_light_started =false; m_exploded =false; m_ready_explode =false; m_dead =false; if (!inherited::net_Spawn(DC)) return (FALSE); CPHSkeleton::Spawn((CSE_Abstract*)(DC)); for(u32 i=0; i<4; ++i) CRocketLauncher::SpawnRocket(*m_sRocketSection, smart_cast<CGameObject*>(this)); // assigning m_animator here CSE_Abstract *abstract =(CSE_Abstract*)(DC); CSE_ALifeHelicopter *heli = smart_cast<CSE_ALifeHelicopter*>(abstract); VERIFY (heli); R_ASSERT (Visual()&&smart_cast<IKinematics*>(Visual())); IKinematics* K = smart_cast<IKinematics*>(Visual()); CInifile* pUserData = K->LL_UserData(); m_rotate_x_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","wpn_rotate_x_bone")); m_rotate_y_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","wpn_rotate_y_bone")); m_fire_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","wpn_fire_bone")); m_death_bones_to_hide = pUserData->r_string("on_death_mode","scale_bone"); m_left_rocket_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","left_rocket_bone")); m_right_rocket_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","right_rocket_bone")); m_smoke_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","smoke_bone")); m_light_bone = K->LL_BoneID (pUserData->r_string("helicopter_definition","light_bone")); CExplosive::Load (pUserData,"explosion"); CExplosive::SetInitiator(ID()); LPCSTR s = pUserData->r_string("helicopter_definition","hit_section"); if( pUserData->section_exist(s) ) { int lc = pUserData->line_count(s); LPCSTR name; LPCSTR value; s16 boneID; for (int i=0 ; i<lc; ++i) { pUserData->r_line( s, i, &name, &value); boneID =K->LL_BoneID(name); m_hitBones.insert( std::make_pair(boneID, (float)atof(value)) ); } } CBoneInstance& biX = smart_cast<IKinematics*>(Visual())->LL_GetBoneInstance(m_rotate_x_bone); biX.set_callback (bctCustom,BoneMGunCallbackX,this); CBoneInstance& biY = smart_cast<IKinematics*>(Visual())->LL_GetBoneInstance(m_rotate_y_bone); biY.set_callback (bctCustom,BoneMGunCallbackY,this); 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_rot.x = matrices[m_rotate_x_bone].k.getP(); m_bind_rot.y = 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); IKinematicsAnimated *A = smart_cast<IKinematicsAnimated*>(Visual()); if (A) { A->PlayCycle (*heli->startup_animation); K->CalculateBones (TRUE); } m_engineSound.create (*heli->engine_sound,st_Effect,sg_SourceType); m_engineSound.play_at_pos (0,XFORM().c,sm_Looped); CShootingObject::Light_Create (); setVisible (TRUE); setEnabled (TRUE); m_stepRemains = 0.0f; //lighting m_light_render = ::Render->light_create(); m_light_render->set_shadow (false); m_light_render->set_type (IRender_Light::POINT); m_light_render->set_range (m_light_range); m_light_render->set_color (m_light_color); if(g_Alive())processing_activate (); TurnEngineSound(false); if(pUserData->section_exist("destroyed")) CPHDestroyable::Load(pUserData,"destroyed"); #ifdef DEBUG Device.seqRender.Add(this,REG_PRIORITY_LOW-1); #endif return TRUE; }