bool CCharacterPhysicsSupport::CollisionCorrectObjPos(const Fvector& start_from,bool character_create/*=false*/) { //Fvector shift;shift.sub( start_from, m_EntityAlife.Position() ); Fvector shift;shift.set(0,0,0); Fbox box; if(character_create) box.set( movement()->Box() ); else { if(m_pPhysicsShell) { VERIFY(m_pPhysicsShell->isFullActive()); Fvector sz,c; get_box( m_pPhysicsShell, mXFORM, sz, c ); box.setb( Fvector().sub( c, m_EntityAlife.Position() ), Fvector(sz).mul(0.5f) ); m_pPhysicsShell->DisableCollision(); }else box.set( m_EntityAlife.BoundingBox() ); } Fvector vbox;Fvector activation_pos; box.get_CD(activation_pos,vbox); shift.add(activation_pos); vbox.mul(2.f); activation_pos.add(shift,m_EntityAlife.Position()); CPHActivationShape activation_shape; activation_shape.Create(activation_pos,vbox,&m_EntityAlife); if( !DoCharacterShellCollide() && !character_create ) { CPHCollideValidator::SetCharacterClassNotCollide(activation_shape); } if( !character_create ) activation_shape.set_rotation( mXFORM ); bool ret = activation_shape.Activate(vbox,1,1.f,M_PI/8.f); m_EntityAlife.Position().sub(activation_shape.Position(),shift); activation_shape.Destroy(); if(m_pPhysicsShell) m_pPhysicsShell->EnableCollision(); return ret; }
void CCharacterPhysicsSupport::CollisionCorrectObjPos(const Fvector& start_from,bool character_create/*=false*/) { Fvector shift;shift.sub(start_from,m_EntityAlife.Position()); Fbox box; if(character_create)box.set(movement()->Box()); else box.set(m_EntityAlife.BoundingBox()); Fvector vbox;Fvector activation_pos; box.get_CD(activation_pos,vbox);shift.add(activation_pos);vbox.mul(2.f); activation_pos.add(shift,m_EntityAlife.Position()); CPHActivationShape activation_shape; activation_shape.Create(activation_pos,vbox,&m_EntityAlife); if(!DoCharacterShellCollide()&&!character_create) { CPHCollideValidator::SetCharacterClassNotCollide(activation_shape); } activation_shape.Activate(vbox,1,1.f,M_PI/8.f); m_EntityAlife.Position().sub(activation_shape.Position(),shift); activation_shape.Destroy(); }
void CCharacterPhysicsSupport:: CreateShell ( CObject* who, Fvector& dp, Fvector & velocity ) { xr_delete( m_collision_activating_delay ); xr_delete( m_interactive_animation ); destroy_animation_collision( ); //DestroyIKController( ); IKinematics* K=smart_cast<IKinematics*>( m_EntityAlife.Visual( ) ); //animation movement controller issues bool anim_mov_ctrl =m_EntityAlife.animation_movement_controlled( ); CBoneInstance &BR = K->LL_GetBoneInstance( K->LL_GetBoneRoot( ) ); Fmatrix start_xform; start_xform.identity( ); CBlend *anim_mov_blend = 0; if( anim_mov_ctrl ) { m_EntityAlife.animation_movement( )->ObjStartXform( start_xform ); anim_mov_blend = m_EntityAlife.animation_movement( )->ControlBlend( ); m_EntityAlife.destroy_anim_mov_ctrl( ); BR.set_callback_overwrite (TRUE); } // u16 anim_root = K->LL_GetBoneRoot(); u16 physics_root = anim_root; if( m_eType != etBitting ) { physics_root = K->LL_BoneID( "bip01_pelvis" ); K->LL_SetBoneRoot( physics_root ); } // if( !m_physics_skeleton ) CreateSkeleton( m_physics_skeleton ); if( m_eType == etActor ) { CActor* A=smart_cast<CActor*>( &m_EntityAlife ); R_ASSERT2( A, "not an actor has actor type" ); if( A->Holder( ) ) return; if( m_eState==esRemoved )return; } //////////////////////this needs to evaluate object box////////////////////////////////////////////////////// if( m_eType != etBitting ) K->LL_SetBoneRoot( anim_root ); for( u16 I = K->LL_BoneCount( )-1; I!=u16(-1); --I ) K->LL_GetBoneInstance( I ).reset_callback( ); // if( anim_mov_ctrl ) //we do not whant to move by long animation in root BR.set_callback_overwrite (TRUE); // K->CalculateBones_Invalidate(); K->CalculateBones (TRUE); if( m_eType != etBitting ) K->LL_SetBoneRoot( physics_root ); //////////////////////////////////////////////////////////////////////////// if( m_pPhysicsShell ) return; m_PhysicMovementControl->GetCharacterVelocity ( velocity ); if( !m_PhysicMovementControl->CharacterExist( ) ) dp.set( m_EntityAlife.Position( ) ); else m_PhysicMovementControl->GetDeathPosition( dp ); m_PhysicMovementControl->DestroyCharacter( ); //shell create R_ASSERT2(m_physics_skeleton,"No skeleton created!!"); m_pPhysicsShell=m_physics_skeleton; m_physics_skeleton=NULL; m_pPhysicsShell->set_Kinematics(K); m_pPhysicsShell->RunSimulation(); m_pPhysicsShell->mXFORM.set(mXFORM); m_pPhysicsShell->SetCallbacks( ); // if(anim_mov_ctrl) //we do not whant to move by long animation in root BR.set_callback_overwrite (TRUE); if(!DoCharacterShellCollide()) m_pPhysicsShell->DisableCharacterCollision(); if( m_eType != etBitting ) K->LL_SetBoneRoot( anim_root ); K->CalculateBones_Invalidate(); K->CalculateBones (TRUE); if( m_eType != etBitting ) K->LL_SetBoneRoot( physics_root ); //reset_root_bone_start_pose( *m_pPhysicsShell ); m_flags.set(fl_death_anim_on,FALSE); m_eState=esDead; m_flags.set(fl_skeleton_in_shell,TRUE); if(IsGameTypeSingle()) { m_pPhysicsShell->SetPrefereExactIntegration ();//use exact integration for ragdolls in single m_pPhysicsShell->SetRemoveCharacterCollLADisable(); } else m_pPhysicsShell->SetIgnoreDynamic(); m_pPhysicsShell->SetIgnoreSmall(); AddActiveWeaponCollision(); }
void CCharacterPhysicsSupport::ActivateShell (CObject* who) { DestroyIKController(); if(!m_physics_skeleton)CreateSkeleton(m_physics_skeleton); if(m_eType==etActor) { CActor* A=smart_cast<CActor*>(&m_EntityAlife); R_ASSERT2(A,"not an actor has actor type"); if(A->Holder()) return; if(m_eState==esRemoved)return; } CKinematics* K=smart_cast<CKinematics*>(m_EntityAlife.Visual()); //////////////////////this needs to evaluate object box////////////////////////////////////////////////////// for(u16 I=K->LL_BoneCount()-1;I!=u16(-1);--I)K->LL_GetBoneInstance(I).reset_callback(); K->CalculateBones_Invalidate(); K->CalculateBones (); //////////////////////////////////////////////////////////////////////////// if(m_pPhysicsShell) return; Fvector velocity; m_PhysicMovementControl->GetCharacterVelocity (velocity); velocity.mul(1.3f); Fvector dp,start;start.set(m_EntityAlife.Position()); if(!m_PhysicMovementControl->CharacterExist()) dp.set(m_EntityAlife.Position()); else m_PhysicMovementControl->GetDeathPosition(dp); m_PhysicMovementControl->DestroyCharacter(); CollisionCorrectObjPos(dp); R_ASSERT2(m_physics_skeleton,"No skeleton created!!"); m_pPhysicsShell=m_physics_skeleton; m_physics_skeleton=NULL; m_pPhysicsShell->set_Kinematics(K); m_pPhysicsShell->RunSimulation(); m_pPhysicsShell->mXFORM.set(mXFORM); m_pPhysicsShell->SetCallbacks(m_pPhysicsShell->GetBonesCallback()); if(!smart_cast<CCustomZone*>(who)) { velocity.mul(1.25f*m_after_death_velocity_factor); } if(!DoCharacterShellCollide()) { m_pPhysicsShell->DisableCharacterCollision(); } m_pPhysicsShell->set_LinearVel(velocity); K->CalculateBones_Invalidate(); K->CalculateBones (); m_flags.set(fl_death_anim_on,FALSE); m_eState=esDead; m_flags.set(fl_skeleton_in_shell,TRUE); if(IsGameTypeSingle()) { m_pPhysicsShell->SetPrefereExactIntegration ();//use exact integration for ragdolls in single m_pPhysicsShell->SetRemoveCharacterCollLADisable(); } else { m_pPhysicsShell->SetIgnoreDynamic(); } m_pPhysicsShell->SetIgnoreSmall(); FlyTo(Fvector().sub(start,m_EntityAlife.Position())); m_pPhysicsShell->GetGlobalTransformDynamic(&mXFORM); m_pPhysicsShell->add_ObjectContactCallback(OnCharacterContactInDeath); m_pPhysicsShell->set_CallbackData((void*)this); }