void CPhysicsObject::SetShadow( const Vector &maxVelocity, const AngularImpulse &maxAngularVelocity, bool allowPhysicsMovement, bool allowPhysicsRotation ) { if ( m_pShadow ) { m_pShadow->MaxSpeed( maxVelocity, maxAngularVelocity ); } else { // m_pObject->get_core()->rot_speed_damp_factor = IVP_U_Float_Point( 1e5f, 1e5f, 1e5f ); m_shadowTempGravityDisable = false; unsigned int flags = GetCallbackFlags() | CALLBACK_SHADOW_COLLISION; flags &= ~CALLBACK_GLOBAL_FRICTION; flags &= ~CALLBACK_GLOBAL_COLLIDE_STATIC; SetCallbackFlags( flags ); IVP_Environment *pEnv = m_pObject->get_environment(); CPhysicsEnvironment *pVEnv = (CPhysicsEnvironment *)pEnv->client_data; m_pShadow = pVEnv->CreateShadowController( this, allowPhysicsMovement, allowPhysicsRotation ); m_pShadow->MaxSpeed( maxVelocity, maxAngularVelocity ); SetRollingDrag( 0 ); EnableDrag( false ); if ( !allowPhysicsMovement ) { EnableGravity( false ); } } }
void CPhysicsObject::SetShadow(float maxSpeed, float maxAngularSpeed, bool allowPhysicsMovement, bool allowPhysicsRotation) { if (m_pShadow) { m_pShadow->MaxSpeed(maxSpeed, maxAngularSpeed); } else { unsigned int flags = GetCallbackFlags() | CALLBACK_SHADOW_COLLISION; flags &= ~CALLBACK_GLOBAL_FRICTION; flags &= ~CALLBACK_GLOBAL_COLLIDE_STATIC; SetCallbackFlags(flags); m_pShadow = (CShadowController*)m_pEnv->CreateShadowController(this, allowPhysicsMovement, allowPhysicsRotation); m_pShadow->MaxSpeed(maxSpeed, maxAngularSpeed); } }
void CPhysicsObject::InitFromTemplate( CPhysicsEnvironment *pEnvironment, void *pGameData, const vphysics_save_cphysicsobject_t &objectTemplate ) { m_collideType = objectTemplate.collideType; IVP_Template_Real_Object ivpObjectTemplate; IVP_U_Quat rotation; IVP_U_Point pos; ConvertRotationToIVP( objectTemplate.angles, rotation ); ConvertPositionToIVP( objectTemplate.origin, pos ); ivpObjectTemplate.mass = objectTemplate.mass; if ( objectTemplate.materialIndex >= 0 ) { ivpObjectTemplate.material = physprops->GetIVPMaterial( objectTemplate.materialIndex ); } else { ivpObjectTemplate.material = physprops->GetIVPMaterial( physprops->GetSurfaceIndex( "default" ) ); } Assert( ivpObjectTemplate.material ); // HACKHACK: Pass this name in for debug ivpObjectTemplate.set_name(objectTemplate.pName); ivpObjectTemplate.set_nocoll_group_ident( NULL ); ivpObjectTemplate.physical_unmoveable = objectTemplate.isStatic ? IVP_TRUE : IVP_FALSE; ivpObjectTemplate.rot_inertia_is_factor = IVP_TRUE; ivpObjectTemplate.rot_inertia.set( 1,1,1 ); ivpObjectTemplate.rot_speed_damp_factor.set( objectTemplate.rotSpeedDamping, objectTemplate.rotSpeedDamping, objectTemplate.rotSpeedDamping ); ivpObjectTemplate.speed_damp_factor = objectTemplate.speedDamping; IVP_U_Matrix massCenterMatrix; massCenterMatrix.init(); const Vector *massOverride = 0; if ( objectTemplate.massCenterOverride != vec3_origin ) { IVP_U_Point center; ConvertPositionToIVP( objectTemplate.massCenterOverride, center ); massCenterMatrix.shift_os( ¢er ); ivpObjectTemplate.mass_center_override = &massCenterMatrix; massOverride = &objectTemplate.massCenterOverride; } IVP_Real_Object *realObject = NULL; if ( m_collideType == COLLIDE_BALL ) { IVP_Template_Ball ballTemplate; ballTemplate.radius = ConvertDistanceToIVP( objectTemplate.sphereRadius ); realObject = pEnvironment->GetIVPEnvironment()->create_ball( &ballTemplate, &ivpObjectTemplate, &rotation, &pos ); } else { const IVP_Compact_Surface *pSurface = (const IVP_Compact_Surface *)objectTemplate.pCollide; IVP_SurfaceManager_Polygon *surman = new IVP_SurfaceManager_Polygon( pSurface ); realObject = pEnvironment->GetIVPEnvironment()->create_polygon(surman, &ivpObjectTemplate, &rotation, &pos); } Init( realObject, objectTemplate.materialIndex, objectTemplate.volume, objectTemplate.dragCoefficient, objectTemplate.dragCoefficient, massOverride ); SetInertia( objectTemplate.rotInertia ); // will wake up the object if ( objectTemplate.velocity.LengthSqr() != 0 || objectTemplate.angVelocity.LengthSqr() != 0 ) { Assert( !objectTemplate.isAsleep ); SetVelocity( &objectTemplate.velocity, &objectTemplate.angVelocity ); } SetCallbackFlags( (unsigned short) objectTemplate.callbacks ); SetGameFlags( (unsigned short) objectTemplate.gameFlags ); SetGameData( pGameData ); SetContents( objectTemplate.contentsMask ); if ( objectTemplate.dragEnabled ) { Assert( !objectTemplate.isStatic ); EnableDrag( true ); } if ( !objectTemplate.motionEnabled ) { Assert( !objectTemplate.isStatic ); EnableMotion( false ); } if ( objectTemplate.isTrigger ) { BecomeTrigger(); } if ( !objectTemplate.gravityEnabled ) { EnableGravity( false ); } if ( objectTemplate.collisionEnabled ) { EnableCollisions( true ); } if ( !objectTemplate.isAsleep ) { Assert( !objectTemplate.isStatic ); Wake(); } m_pShadow = NULL; }