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 nuiScrollView::ActivateMobileMode() { EnableDrag(true); SetHideScrollBars(true); mpHorizontal->SetBackgroundDeco(NULL); mpVertical->SetBackgroundDeco(NULL); mpHorizontal->SetForegroundDecoName(_T("nuiDefaultDecorationMobileScrollbarHandle")); mpVertical->SetForegroundDecoName(_T("nuiDefaultDecorationMobileScrollbarHandle")); SetBarSize(13); }
void CPhysicsObject::BecomeTrigger() { if ( IsTrigger() ) return; EnableDrag( false ); EnableGravity( false ); // UNDONE: Use defaults here? Do we want object sets by default? IVP_Template_Phantom trigger; trigger.manage_intruding_cores = IVP_TRUE; // manage a list of intruded objects trigger.dont_check_for_unmoveables = IVP_TRUE; trigger.exit_policy_extra_radius = 0.1f; // relatively strict exit check [m] m_pObject->convert_to_phantom( &trigger ); // hook up events IVP_Environment *pEnv = m_pObject->get_environment(); CPhysicsEnvironment *pVEnv = (CPhysicsEnvironment *)pEnv->client_data; pVEnv->PhantomAdd( this ); }
void CPhysicsObject::BecomeTrigger() { if (IsTrigger()) return; EnableDrag(false); EnableGravity(false); m_pEnv->GetBulletEnvironment()->removeRigidBody(m_pObject); m_pGhostObject = new btGhostObject; m_pGhostObject->setCollisionShape(m_pObject->getCollisionShape()); m_pGhostObject->setUserPointer(this); m_pGhostObject->setCollisionFlags(m_pGhostObject->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT); m_pGhostObject->setWorldTransform(m_pObject->getWorldTransform()); m_pGhostCallback = new CGhostTriggerCallback(this); if (m_pGhostCallback) m_pGhostObject->setCallback(m_pGhostCallback); m_pEnv->GetBulletEnvironment()->addCollisionObject(m_pGhostObject, COLGROUP_WORLD, ~COLGROUP_WORLD); }
void CPhysicsObject::RemoveTrigger() { if (!IsTrigger()) return; EnableDrag(true); EnableGravity(true); m_pObject->setWorldTransform(m_pGhostObject->getWorldTransform()); if (IsStatic()) m_pEnv->GetBulletEnvironment()->addRigidBody(m_pObject, COLGROUP_WORLD, ~COLGROUP_WORLD); else m_pEnv->GetBulletEnvironment()->addRigidBody(m_pObject); m_pGhostObject->setCallback(NULL); delete m_pGhostCallback; m_pGhostCallback = NULL; m_pEnv->GetBulletEnvironment()->removeCollisionObject(m_pGhostObject); delete m_pGhostObject; m_pGhostObject = NULL; }
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; }
// UNEXPOSED void CPhysicsObject::Init(CPhysicsEnvironment *pEnv, btRigidBody *pObject, int materialIndex, objectparams_t *pParams, bool isStatic, bool isSphere) { m_pEnv = pEnv; m_pObject = pObject; m_bIsSphere = isSphere; m_gameFlags = 0; m_fMass = (pParams && !isStatic) ? pParams->mass : 0; m_pGameData = NULL; m_pName = NULL; m_fVolume = 0; m_callbacks = CALLBACK_GLOBAL_COLLISION | CALLBACK_GLOBAL_FRICTION | CALLBACK_FLUID_TOUCH | CALLBACK_GLOBAL_TOUCH | CALLBACK_GLOBAL_COLLIDE_STATIC | CALLBACK_DO_FLUID_SIMULATION; m_iLastActivationState = -1; m_pObject->setUserPointer(this); m_pObject->setSleepingThresholds(SLEEP_LINEAR_THRESHOLD, SLEEP_ANGULAR_THRESHOLD); m_pObject->setActivationState(ISLAND_SLEEPING); // All objects start asleep. if (pParams) { m_pGameData = pParams->pGameData; m_pName = pParams->pName; m_fVolume = pParams->volume * CUBIC_METERS_PER_CUBIC_INCH; EnableCollisions(pParams->enableCollisions); m_pObject->setDebugName(m_pName); } SetMaterialIndex(materialIndex); SetContents(MASK_SOLID); // Compute our air drag values. float drag = 0; float angDrag = 0; if (pParams) { drag = pParams->dragCoefficient; angDrag = pParams->dragCoefficient; } if (isStatic || !GetCollide()) { drag = 0; angDrag = 0; } ComputeDragBasis(isStatic); if (!isStatic && drag != 0.0f) { EnableDrag(true); } m_dragCoefficient = drag; m_angDragCoefficient = angDrag; // Compute our continuous collision detection stuff (for fast moving objects, prevents tunneling) // This doesn't work on compound objects! see: btDiscreteDynamicsWorld::integrateTransforms if (!isStatic) { btVector3 mins, maxs; m_pObject->getCollisionShape()->getAabb(btTransform::getIdentity(), mins, maxs); mins = mins.absolute(); maxs = maxs.absolute(); float maxradius = min(min(maxs.getX(), maxs.getY()), maxs.getZ()); float minradius = min(min(mins.getX(), mins.getY()), mins.getZ()); float radius = min(maxradius, minradius); m_pObject->setCcdMotionThreshold((radius / 2) * (radius / 2)); m_pObject->setCcdSweptSphereRadius(0.7f * radius); } if (isStatic) { m_pObject->setCollisionFlags(m_pObject->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); m_pEnv->GetBulletEnvironment()->addRigidBody(m_pObject, COLGROUP_WORLD, ~COLGROUP_WORLD); } else { m_pEnv->GetBulletEnvironment()->addRigidBody(m_pObject); } }