void RigidBody::AdvanceTransformation(float dT) { Vector3 newPosition = GetPosition() + GetVelocity()*dT; float angularSpeed = GetAngularVelocity().length(); Vector3 axis = GetAngularVelocity().normalisedCopy(); Quaternion newOrientation = Quaternion(angularSpeed * dT, axis) * GetOrientation(); newOrientation.normalise(); m_transformation.makeTransform(newPosition, Vector3::UNIT_SCALE, newOrientation); }
const PODVector<unsigned char>& RigidBody::GetNetAngularVelocityAttr() const { float maxVelocity = physicsWorld_ ? physicsWorld_->GetMaxNetworkAngularVelocity() : DEFAULT_MAX_NETWORK_ANGULAR_VELOCITY; attrBuffer_.Clear(); attrBuffer_.WritePackedVector3(GetAngularVelocity(), maxVelocity); return attrBuffer_.GetBuffer(); }
bool csBulletRigidBody::RemoveBulletObject () { if (insideWorld) { if (anchorCount > 0) { csFPrintf (stderr, "csBulletRigidBody: Please remove the soft body attached with this body first.\n"); return false; } for (size_t i = 0; i < joints.GetSize (); i++) sector->RemoveJoint (joints[i]); linearVelocity = GetLinearVelocity (); angularVelocity = GetAngularVelocity (); sector->bulletWorld->removeRigidBody (btBody); delete btBody; btBody = NULL; btObject = NULL; insideWorld = false; csBulletRigidBody* rb = dynamic_cast<csBulletRigidBody*> (objectCopy); if (objectCopy) rb->sector->RemoveRigidBody (rb); rb = dynamic_cast<csBulletRigidBody*> (objectOrigin); if (objectOrigin) rb->objectCopy = NULL; objectCopy = NULL; objectOrigin = NULL; return true; } return false; }
void RigidBody::ApplyImpulse(Vector3 const& impulse, Vector3 const& point) { if(HasInfiniteMass()) return; Vector3 deltaVelocity = impulse * GetInverseMass(); SetVelocity(GetVelocity() + deltaVelocity); Vector3 deltaOmega = GetInverseInertialTensor() * (point-GetPosition()).crossProduct(impulse); SetAngularVelocity(GetAngularVelocity() + deltaOmega); }
std::string palRevoluteLink::toString() const { std::ostringstream oss; oss << palLink::toString() << "[angle=" << GetAngle() << ",limits=(" << m_fLowerLimit << "," << m_fUpperLimit << ")" << ",omega=" << GetAngularVelocity() << ",axis=" << GetAxis() << "]"; return oss.str(); }
/* ================ idPhysics_Base::DrawVelocity ================ */ void idPhysics_Base::DrawVelocity( int id, float linearScale, float angularScale ) const { idVec3 dir, org, vec, start, end; idMat3 axis; float length, a; dir = GetLinearVelocity( id ); dir *= linearScale; if( dir.LengthSqr() > Square( 0.1f ) ) { dir = dir.Truncate( 10.0f ); org = GetOrigin( id ); gameRenderWorld->DebugArrow( colorRed, org, org + dir, 1 ); } dir = GetAngularVelocity( id ); length = dir.Normalize(); length *= angularScale; if( length > 0.1f ) { if( length < 60.0f ) { length = 60.0f; } else if( length > 360.0f ) { length = 360.0f; } axis = GetAxis( id ); vec = axis[2]; if( idMath::Fabs( dir * vec ) > 0.99f ) { vec = axis[0]; } vec -= vec * dir * vec; vec.Normalize(); vec *= 4.0f; start = org + vec; for( a = 20.0f; a < length; a += 20.0f ) { end = org + idRotation( vec3_origin, dir, -a ).ToMat3() * vec; gameRenderWorld->DebugLine( colorBlue, start, end, 1 ); start = end; } end = org + idRotation( vec3_origin, dir, -length ).ToMat3() * vec; gameRenderWorld->DebugArrow( colorBlue, start, end, 1 ); } }
void Ship::GetServerUpdateMessage(ServerShipUpdate& message) const { const std::hash<std::string> player_hash_fn; message.ship_id = player_hash_fn(GetName()); Vector3f vec = GetPosition(); message.position[0] = vec[0]; message.position[1] = vec[1]; message.position[2] = vec[2]; vec = GetVelocity(); message.velocity[0] = vec[0]; message.velocity[1] = vec[1]; message.velocity[2] = vec[2]; message.orientation = fmodf(GetOrientation(), 360.0f); message.angularVelocity = GetAngularVelocity(); message.health = health; message.shield = shield; }
bool RigidBody::ApplyQueuedImpulses() { if(HasInfiniteMass()) return false; bool significant = (m_queuedDeltaVelocity.squaredLength() > 1e-8 || m_queuedDeltaAngularVelocity.squaredLength() > 1e-8); if(significant) { SetVelocity(GetVelocity() + m_queuedDeltaVelocity); SetAngularVelocity(GetAngularVelocity() + m_queuedDeltaAngularVelocity); } m_queuedDeltaVelocity = Vector3::ZERO; m_queuedDeltaAngularVelocity = Vector3::ZERO; return significant; }
// Update the player void _Player::Update(float FrameTime) { _Object::Update(FrameTime); // Update audio const btVector3 &Position = GetPosition(); Sound->SetPosition(Position[0], Position[1], Position[2]); // Update light if(Light) { Light->setPosition(vector3df(Position[0], Position[1], Position[2])); } // Get pitch for player idle sound float Pitch = GetAngularVelocity().length(); if(Pitch < 3.0f) Pitch = 3.0f; else if(Pitch > 22.0f) Pitch = 22.0f; Pitch -= 3.0f; Pitch /= 30.0f; Pitch += 1.5f; Sound->SetPitch(Pitch); // Update jump timer if(JumpTimer > 0.0f) { JumpTimer -= FrameTime; if(JumpTimer < 0.0f) JumpTimer = 0.0f; if(TouchingGround) { RigidBody->activate(); RigidBody->applyCentralImpulse(btVector3(0.0f, JUMP_POWER, 0.0f)); JumpTimer = 0.0f; } } }
Ogre::Vector3 RigidBody::GetVelocityAtPoint(Vector3 const& p) const { Vector3 v = p-GetPosition(); return GetAngularVelocity().crossProduct(v) + GetVelocity(); }