void psLinearMovement::SetSoftDRData (bool on_ground, csVector3& pos, float yrot, iSector *sector, csVector3& vel, csVector3& worldVel, float ang_vel) { if (colldet) colldet->SetOnGround (on_ground); csVector3 cur_pos; float cur_rot; iSector *cur_sect; GetLastPosition (cur_pos, cur_rot, cur_sect); if (cur_sect == sector) { offset_err = pos - cur_pos; // Check for NaN conditions: if (offset_err.x != offset_err.x) offset_err.x = 0.0f; if (offset_err.y != offset_err.y) offset_err.y = 0.0f; if (offset_err.z != offset_err.z) offset_err.z = 0.0f; offset_rate = offset_err; SetPosition (cur_pos, yrot, sector); } else { offset_rate = offset_err = csVector3 (0.0f, 0.0f ,0.0f); SetPosition (pos, yrot, sector); } SetVelocity (vel); ClearWorldVelocity (); AddVelocity (worldVel); csVector3 rot (0.0f, ang_vel, 0.0f); SetAngularVelocity (rot); lastDRUpdate = csGetTicks (); }
void psLinearMovement::SetAngularVelocity (const csVector3& angleVel, const csVector3& angleToReach) { SetAngularVelocity (angleVel); angleToReachFlag = true; this->angleToReach = angleToReach; }
RigidBody::RigidBody(Rect rect) { float width = (rect.right - rect.left); float height = (rect.bottom - rect.top); // Create a Rectangle shape - origin middle mShape = new Shape(); mShape->setOrigin(Vector(rect.left + width/2, rect.top + height/2, 0)); mShape->addPoint(Vector(-width/2, -height/2, 0)); // top - left mShape->addPoint(Vector(-width/2, height/2, 0)); // bottom - left mShape->addPoint(Vector(width/2, height/2, 0)); // bottom - right mShape->addPoint(Vector(width/2, -height/2, 0)); // top - right setStatic(false); mAlive = true; mTexture = NULL; SetMass(1); SetVelocity(0, 0); SetAngularVelocity(0.0f); SetForce(Vector(0, 0, 0)); SetTorque(Vector(0, 0, 0)); SetMomentum(Vector(0, 0, 0)); SetFriction(1.0f); SetSleeping(false); }
void CDynamics2DDifferentialSteeringControl::SetWheelVelocity(Real f_left_wheel, Real f_right_wheel) { /* * THE DIFFERENTIAL STEERING SYSTEM * * check http://rossum.sourceforge.net/papers/DiffSteer/ * for details * * Equations: * * w = (Vr - Vl) / b * v = [ ((Vr + Vl) / 2) cos(a), * ((Vr + Vl) / 2) sin(a) ] * * where: * a = body orientation * w = body angular velocity * v = body center linear velocity * Vr = right wheel velocity * Vl = left wheel velocity * b = length of wheel axis */ SetAngularVelocity((f_right_wheel - f_left_wheel) / m_fInterwheelDistance); Real fVelocity = (f_right_wheel + f_left_wheel) * 0.5f; CVector2 cVelocity(fVelocity * ::cos(m_ptControlledBody->a), fVelocity * ::sin(m_ptControlledBody->a)); SetLinearVelocity(cVelocity); }
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); }
bool csBulletRigidBody::Disable () { SetLinearVelocity (csVector3 (0.0f)); SetAngularVelocity (csVector3 (0.0f)); if (btBody) { btBody->setInterpolationWorldTransform (btBody->getWorldTransform()); btBody->setActivationState (ISLAND_SLEEPING); return true; } return false; }
void astPlayerShip::Spawn( const vsVector2D &pos_in ) { SetCollisionsActive(true); SetPosition( pos_in ); SetVelocity( vsVector2D::Zero ); SetAngularVelocity( 0.f ); RegisterOnScene(0); m_spawnInvulnerable = true; // m_colObject->Teleport(); m_timeSinceSpawn = 0.f; m_isSpawned = true; }
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; }
void psLinearMovement::SetDRData (bool on_ground, csVector3& pos, float yrot, iSector *sector, csVector3& vel, csVector3& worldVel, float ang_vel) { if (colldet) { colldet->SetOnGround (on_ground); } SetPosition (pos,yrot,sector); SetVelocity (vel); ClearWorldVelocity (); AddVelocity (worldVel); csVector3 rot (0.0f, ang_vel, 0.0f); SetAngularVelocity (rot); lastDRUpdate = csGetTicks (); lastClientDRUpdate = lastDRUpdate; lastClientPosition = pos; lastClientSector = sector; lastClientYrot = yrot; }
RigidBody::RigidBody(float x, float y, int width, int height) { // Create a Rectangle shape - origin middle mShape = new Shape(); mShape->setOrigin(Vector(x, y, 0)); mShape->addPoint(Vector(-width/2, -height/2, 0)); // top - left mShape->addPoint(Vector(-width/2, height/2, 0)); // bottom - left mShape->addPoint(Vector(width/2, height/2, 0)); // bottom - right mShape->addPoint(Vector(width/2, -height/2, 0)); // top - right SetMass(1); SetVelocity(0, 0); SetAngularVelocity(0.0f); SetForce(Vector(0, 0, 0)); SetTorque(Vector(0, 0, 0)); SetFriction(1.0f); SetFriction(0.5f), SetSimulate(true); SetOwner(NULL); }
RigidBody::RigidBody(float x, float y, int width, int height) { // Create a Rectangle shape - origin middle mShape = new Shape(); mShape->setOrigin(Vector(x, y, 0)); mShape->addPoint(Vector(-width/2, -height/2, 0)); // top - left mShape->addPoint(Vector(-width/2, height/2, 0)); // bottom - left mShape->addPoint(Vector(width/2, height/2, 0)); // bottom - right mShape->addPoint(Vector(width/2, -height/2, 0)); // top - right setStatic(false); mAlive = true; SetMass(1); SetVelocity(0, 0); SetAngularVelocity(0.0f); SetForce(Vector(0, 0, 0)); SetTorque(Vector(0, 0, 0)); SetMomentum(Vector(0, 0, 0)); SetFriction(1.0f); SetSleeping(false); SetRepeatX(false); }
void vsCollisionObject::SetVelocity( const vsVector2D &velocity, float angularVelocity ) { SetVelocity( velocity ); SetAngularVelocity( angularVelocity ); }
void RigidBody::AddBodyToWorld() { if (!physicsWorld_) return; URHO3D_PROFILE(AddBodyToWorld); if (mass_ < 0.0f) mass_ = 0.0f; if (body_) RemoveBodyFromWorld(); else { // Correct inertia will be calculated below btVector3 localInertia(0.0f, 0.0f, 0.0f); body_ = new btRigidBody(mass_, this, shiftedCompoundShape_, localInertia); body_->setUserPointer(this); // Check for existence of the SmoothedTransform component, which should be created by now in network client mode. // If it exists, subscribe to its change events smoothedTransform_ = GetComponent<SmoothedTransform>(); if (smoothedTransform_) { SubscribeToEvent(smoothedTransform_, E_TARGETPOSITION, URHO3D_HANDLER(RigidBody, HandleTargetPosition)); SubscribeToEvent(smoothedTransform_, E_TARGETROTATION, URHO3D_HANDLER(RigidBody, HandleTargetRotation)); } // Check if CollisionShapes already exist in the node and add them to the compound shape. // Do not update mass yet, but do it once all shapes have been added PODVector<CollisionShape*> shapes; node_->GetComponents<CollisionShape>(shapes); for (PODVector<CollisionShape*>::Iterator i = shapes.Begin(); i != shapes.End(); ++i) (*i)->NotifyRigidBody(false); // Check if this node contains Constraint components that were waiting for the rigid body to be created, and signal them // to create themselves now PODVector<Constraint*> constraints; node_->GetComponents<Constraint>(constraints); for (PODVector<Constraint*>::Iterator i = constraints.Begin(); i != constraints.End(); ++i) (*i)->CreateConstraint(); } UpdateMass(); UpdateGravity(); int flags = body_->getCollisionFlags(); if (trigger_) flags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; else flags &= ~btCollisionObject::CF_NO_CONTACT_RESPONSE; if (kinematic_) flags |= btCollisionObject::CF_KINEMATIC_OBJECT; else flags &= ~btCollisionObject::CF_KINEMATIC_OBJECT; body_->setCollisionFlags(flags); body_->forceActivationState(kinematic_ ? DISABLE_DEACTIVATION : ISLAND_SLEEPING); if (!IsEnabledEffective()) return; btDiscreteDynamicsWorld* world = physicsWorld_->GetWorld(); world->addRigidBody(body_, (short)collisionLayer_, (short)collisionMask_); inWorld_ = true; readdBody_ = false; if (mass_ > 0.0f) Activate(); else { SetLinearVelocity(Vector3::ZERO); SetAngularVelocity(Vector3::ZERO); } }
void RigidBody::SetNetAngularVelocityAttr(const PODVector<unsigned char>& value) { float maxVelocity = physicsWorld_ ? physicsWorld_->GetMaxNetworkAngularVelocity() : DEFAULT_MAX_NETWORK_ANGULAR_VELOCITY; MemoryBuffer buf(value); SetAngularVelocity(buf.ReadPackedVector3(maxVelocity)); }
void plPXPhysicalControllerCore::SetVelocities(const hsVector3& linearVel, float angVel) { SetLinearVelocity(linearVel); SetAngularVelocity(angVel); }