void CPhysicsActor::SetAngularDamping( float damping ) { if( !IsKinematic() ) { m_Actor->setAngularDamping( damping ); } }
//----------------------------------------------------------------------------- // MoveWorldOrientation //----------------------------------------------------------------------------- //!! void CPhysicObj::MoveWorldOrientation(const NxMat33 &mOrient) { assert( m_bActivated && IsKinematic()); for (int i=0; i<GetNumParts(); i++) { MoveWorldOrientation(i, mOrient); } }
//----------------------------------------------------------------------------- // MoveWorldPosition //----------------------------------------------------------------------------- //!! void CPhysicObj::MoveWorldPosition (const NxVec3 &vPos) { assert( m_bActivated && IsKinematic()); for (int i=0; i<GetNumParts(); i++) { MoveWorldPosition(i, vPos); } }
void CPhysicsActor::ForceKinematic() { // Make sure that the actor is not static or already kinematic if( !m_Actor->isDynamic() || IsKinematic() ) { return; } m_Actor->raiseBodyFlag( NX_BF_KINEMATIC ); m_WasDynamic = true; }
void CPhysicsActor::SetAngularMomentum( Vec3& momentum ) { if( !IsKinematic() ) { NxVec3 tmp( momentum.x, momentum.y, momentum.z ); if( !tmp.isFinite() ) { m_ToolBox->Log( LOGERROR, _T("Invalid vector given to Physics!\n")); return; } m_Actor->setAngularMomentum( tmp ); } }
void CPhysicsActor::SetAngularVelocity( Vec3& velocity ) { if( !IsKinematic() ) { NxVec3 tmp( velocity.x, velocity.y, velocity.z ); if( !tmp.isFinite() ) { m_ToolBox->Log( LOGERROR, _T("Invalid vector given to Physics!\n")); return; } m_Actor->setAngularVelocity( tmp ); } }
cpBody* RigidBody2D::Create(float mass, float moment) { cpBody* handle; if (IsKinematic()) { if (IsStatic()) handle = cpBodyNewStatic(); else handle = cpBodyNewKinematic(); } else handle = cpBodyNew(mass, moment); cpBodySetUserData(handle, this); return handle; }
void RigidBody2D::SetGeom(Collider2DRef geom, bool recomputeMoment) { // We have no public way of getting rid of an existing geom without removing the whole body // So let's save some attributes of the body, destroy it and rebuild it if (m_geom) { cpFloat mass = cpBodyGetMass(m_handle); cpFloat moment = cpBodyGetMoment(m_handle); cpBody* newHandle = Create(static_cast<float>(mass), static_cast<float>(moment)); CopyBodyData(m_handle, newHandle); Destroy(); m_handle = newHandle; } if (geom) m_geom = geom; else m_geom = NullCollider2D::New(); m_geom->GenerateShapes(this, &m_shapes); cpSpace* space = m_world->GetHandle(); for (cpShape* shape : m_shapes) cpShapeSetUserData(shape, this); if (m_isSimulationEnabled) RegisterToSpace(); if (recomputeMoment) { if (!IsStatic() && !IsKinematic()) cpBodySetMoment(m_handle, m_geom->ComputeMomentOfInertia(m_mass)); } }
//----------------------------------------------------------------------------- // MoveWorldOrientation //----------------------------------------------------------------------------- //!! void CPhysicObj::MoveWorldOrientation(int nPartIdx, const NxMat33 &mOrient) { assert( m_bActivated && IsKinematic() && (nPartIdx < GetNumParts())); GetActor(nPartIdx)->moveGlobalOrientation(mOrient); }
//----------------------------------------------------------------------------- // MoveWorldPosition //----------------------------------------------------------------------------- //!! void CPhysicObj::MoveWorldPosition (int nPartIdx, const NxVec3 &vPos) { assert( m_bActivated && IsKinematic() && (nPartIdx < GetNumParts())); GetActor(nPartIdx)->moveGlobalPosition(vPos); }