From 0624c33c285cf20ee5872351eb3745f98a571def Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Tue, 4 Aug 2009 12:22:07 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@190 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/body/BodyState.cpp | 7 +++---- sources/reactphysics3d/body/BodyState.h | 8 ++++---- sources/reactphysics3d/body/OBB.cpp | 2 +- sources/reactphysics3d/body/RigidBody.cpp | 10 +++++++--- sources/reactphysics3d/body/RigidBody.h | 6 +++--- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/sources/reactphysics3d/body/BodyState.cpp b/sources/reactphysics3d/body/BodyState.cpp index 31d08962..cbb0865a 100644 --- a/sources/reactphysics3d/body/BodyState.cpp +++ b/sources/reactphysics3d/body/BodyState.cpp @@ -26,9 +26,8 @@ using namespace reactphysics3d; // Constructor - BodyState::BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse) - : position(position), orientation(Quaternion(0,1,0, 0.0)), inertiaTensorInverse(inertiaTensorInverse), massInverse(massInverse) { - // TODO : orientation will be initialized in another way + BodyState::BodyState(const Vector3D& position, const Quaternion& orientation, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse) + : position(position), orientation(orientation), inertiaTensorInverse(inertiaTensorInverse), massInverse(massInverse) { // Recalculate the secondary values from the primary values recalculate(); @@ -92,5 +91,5 @@ Vector3D BodyState::computeForce(Time time) const { // Return the torque on the body at time Vector3D BodyState::computeTorque(Time time) const { // TODO : Implement this method - return force + Vector3D(0.0, 0.0 ,0.0); + return Vector3D(0.0, 0.0 ,0.0); } diff --git a/sources/reactphysics3d/body/BodyState.h b/sources/reactphysics3d/body/BodyState.h index b03081ca..4f197f72 100644 --- a/sources/reactphysics3d/body/BodyState.h +++ b/sources/reactphysics3d/body/BodyState.h @@ -49,12 +49,12 @@ class BodyState { // Constants Matrix3x3 inertiaTensorInverse; // Inverse of the inertia tensor of the body - Kilogram massInverse; // Inverse of the mass of the body + Kilogram massInverse; // Inverse of the mass of the body public : - BodyState(const Vector3D& position, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse); // Constructor - BodyState(const BodyState& bodyState); // Copy-constructor - virtual ~BodyState(); // Destructor + BodyState(const Vector3D& position, const Quaternion& orientation, const Matrix3x3& inertiaTensorInverse, const Kilogram& massInverse); // Constructor + BodyState(const BodyState& bodyState); // Copy-constructor + virtual ~BodyState(); // Destructor Vector3D getPosition() const; // Return the position of the body void setPosition(const Vector3D& position); // Set the position of the body diff --git a/sources/reactphysics3d/body/OBB.cpp b/sources/reactphysics3d/body/OBB.cpp index dfe838a1..d5d15760 100644 --- a/sources/reactphysics3d/body/OBB.cpp +++ b/sources/reactphysics3d/body/OBB.cpp @@ -124,7 +124,7 @@ void OBB::draw() const { glVertex3f(s6.getX(), s6.getY(), s6.getZ()); glVertex3f(center.getX(), center.getY(), center.getZ()); - glVertex3f(center.getX() + 8.0 * axis[1].getX(), center.getY() + 8.0 * axis[1].getY(), center.getZ() + 8.0 * axis[1].getZ()); + glVertex3f(center.getX() + 8.0 * axis[2].getX(), center.getY() + 8.0 * axis[2].getY(), center.getZ() + 8.0 * axis[2].getZ()); glEnd(); } diff --git a/sources/reactphysics3d/body/RigidBody.cpp b/sources/reactphysics3d/body/RigidBody.cpp index 135ffd88..0b47f30b 100644 --- a/sources/reactphysics3d/body/RigidBody.cpp +++ b/sources/reactphysics3d/body/RigidBody.cpp @@ -24,16 +24,20 @@ using namespace reactphysics3d; // Constructor - RigidBody::RigidBody(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb) + RigidBody::RigidBody(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb) : Body(mass), inertiaTensor(inertiaTensor), obb(obb), - currentBodyState(position, inertiaTensor.getInverse(),Kilogram(1.0/mass.getValue())), - previousBodyState(position, inertiaTensor.getInverse(), Kilogram(1.0/mass.getValue())) { + currentBodyState(position, orientation, inertiaTensor.getInverse(),Kilogram(1.0/mass.getValue())), + previousBodyState(position, orientation, inertiaTensor.getInverse(), Kilogram(1.0/mass.getValue())) { + isMotionEnabled = true; isCollisionEnabled = true; interpolationFactor = 0.0; // Set the body pointer to the OBB this->obb.setBodyPointer(this); + + // Update the orientation of the OBB according to the orientation of the rigid body + this->update(); } // Copy-constructor diff --git a/sources/reactphysics3d/body/RigidBody.h b/sources/reactphysics3d/body/RigidBody.h index 6d552499..d82f2e39 100644 --- a/sources/reactphysics3d/body/RigidBody.h +++ b/sources/reactphysics3d/body/RigidBody.h @@ -49,9 +49,9 @@ class RigidBody : public Body { OBB obb; // Oriented bounding box that contains the rigid body public : - RigidBody(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb); // Constructor - RigidBody(const RigidBody& rigidBody); // Copy-constructor - virtual ~RigidBody(); // Destructor + RigidBody(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb); // Constructor + RigidBody(const RigidBody& rigidBody); // Copy-constructor + virtual ~RigidBody(); // Destructor Matrix3x3 getInertiaTensor() const; // Return the inertia tensor of the body void setInertiaTensor(const Matrix3x3& inertiaTensor); // Set the inertia tensor of the body