From 23438486a650c7f51a296d9e4e39f27e7e65c273 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Mon, 5 Jul 2010 10:27:35 +0000 Subject: [PATCH] Add the restitution coefficient git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@341 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/body/RigidBody.cpp | 15 ++++++++------- sources/reactphysics3d/body/RigidBody.h | 13 +++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/sources/reactphysics3d/body/RigidBody.cpp b/sources/reactphysics3d/body/RigidBody.cpp index 1823edbd..aac6cc7f 100644 --- a/sources/reactphysics3d/body/RigidBody.cpp +++ b/sources/reactphysics3d/body/RigidBody.cpp @@ -28,15 +28,16 @@ : Body(mass), inertiaTensorLocal(inertiaTensorLocal), currentBodyState(position, orientation, inertiaTensorLocal.getInverse(), Kilogram(1.0/mass.getValue())), previousBodyState(position, orientation, inertiaTensorLocal.getInverse(), Kilogram(1.0/mass.getValue())), obb(obb) { - isMotionEnabled = true; - isCollisionEnabled = true; - interpolationFactor = 0.0; + restitution = 1.0; + isMotionEnabled = true; + isCollisionEnabled = true; + interpolationFactor = 0.0; - // Update the orientation of the OBB according to the orientation of the rigid body - this->update(); + // Update the orientation of the OBB according to the orientation of the rigid body + this->update(); - // Set the body pointer to the OBB - this->obb.setBodyPointer(this); + // Set the body pointer to the OBB + this->obb.setBodyPointer(this); } // Copy-constructor diff --git a/sources/reactphysics3d/body/RigidBody.h b/sources/reactphysics3d/body/RigidBody.h index 6a4172eb..18fda97b 100644 --- a/sources/reactphysics3d/body/RigidBody.h +++ b/sources/reactphysics3d/body/RigidBody.h @@ -49,6 +49,7 @@ class RigidBody : public Body { bool isMotionEnabled; // True if the body can move bool isCollisionEnabled; // True if the body can collide with others bodies double interpolationFactor; // Interpolation factor used for the state interpolation + double restitution; // Coefficient of restitution (between 0 and 1), 1 for a very boucing body OBB obb; // Oriented bounding box that contains the rigid body public : @@ -67,6 +68,8 @@ class RigidBody : public Body { bool getIsMotionEnabled() const; // Return if the rigid body can move void setIsMotionEnabled(bool isMotionEnabled); // Set the value to true if the body can move void setLinearVelocity(const Vector3D& linearVelocity); // Set the linear velocity of the rigid body + double getRestitution() const; // Get the restitution coefficient + void setRestitution(double restitution); // Set the restitution coefficient void updatePreviousBodyState(); // Update the previous body state of the body const OBB* const getOBB() const; // Return the oriented bounding box of the rigid body void update(); // Update the rigid body in order to reflect a change in the body state @@ -141,6 +144,16 @@ inline void RigidBody::setLinearVelocity(const Vector3D& linearVelocity) { currentBodyState.setLinearMomentum(linearVelocity * (1.0/currentBodyState.getMassInverse().getValue())); } +// Get the restitution coeffficient of the rigid body +inline double RigidBody::getRestitution() const { + return restitution; +} + +// Set the restitution coefficient +inline void RigidBody::setRestitution(double restitution) { + this->restitution = restitution; +} + // Update the previous body state of the body inline void RigidBody::updatePreviousBodyState() { // The current body state becomes the previous body state