2010-09-09 19:41:14 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ *
|
|
|
|
* Copyright (c) 2010 Daniel Chappuis *
|
|
|
|
*********************************************************************************
|
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy *
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal *
|
|
|
|
* in the Software without restriction, including without limitation the rights *
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included in *
|
|
|
|
* all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
|
|
|
|
* THE SOFTWARE. *
|
|
|
|
********************************************************************************/
|
2009-02-13 11:55:18 +00:00
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include "RigidBody.h"
|
2010-09-01 16:37:13 +00:00
|
|
|
#include "BroadBoundingVolume.h"
|
|
|
|
#include "NarrowBoundingVolume.h"
|
2009-02-13 11:55:18 +00:00
|
|
|
|
|
|
|
// We want to use the ReactPhysics3D namespace
|
|
|
|
using namespace reactphysics3d;
|
|
|
|
|
|
|
|
// Constructor
|
2010-09-01 16:37:13 +00:00
|
|
|
RigidBody::RigidBody(const Vector3D& position, const Quaternion& orientation, double mass, const Matrix3x3& inertiaTensorLocal,
|
|
|
|
NarrowBoundingVolume* narrowBoundingVolume)
|
|
|
|
: Body(mass), position(position), orientation(orientation.getUnit()), inertiaTensorLocal(inertiaTensorLocal),
|
2010-08-05 15:06:34 +00:00
|
|
|
inertiaTensorLocalInverse(inertiaTensorLocal.getInverse()), massInverse(1.0/mass), oldPosition(position), oldOrientation(orientation) {
|
2009-08-04 12:22:07 +00:00
|
|
|
|
2010-07-05 10:27:35 +00:00
|
|
|
restitution = 1.0;
|
|
|
|
isMotionEnabled = true;
|
|
|
|
isCollisionEnabled = true;
|
|
|
|
interpolationFactor = 0.0;
|
2009-07-21 20:29:03 +00:00
|
|
|
|
2010-09-01 16:37:13 +00:00
|
|
|
// Set the bounding volume for the narrow-phase collision detection
|
|
|
|
setNarrowBoundingVolume(narrowBoundingVolume);
|
|
|
|
|
|
|
|
// Compute the broad-phase bounding volume (an AABB)
|
|
|
|
setBroadBoundingVolume(narrowBoundingVolume->computeAABB());
|
|
|
|
|
2010-07-05 10:27:35 +00:00
|
|
|
// Update the orientation of the OBB according to the orientation of the rigid body
|
2010-08-05 15:06:34 +00:00
|
|
|
update();
|
|
|
|
|
|
|
|
assert(broadBoundingVolume);
|
|
|
|
assert(narrowBoundingVolume);
|
2010-02-05 14:39:15 +00:00
|
|
|
}
|
2009-02-13 11:55:18 +00:00
|
|
|
|
2009-11-29 11:10:05 +00:00
|
|
|
// Destructor
|
|
|
|
RigidBody::~RigidBody() {
|
2009-02-13 11:55:18 +00:00
|
|
|
|
2010-09-01 16:37:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update the rigid body in order to reflect a change in the body state
|
|
|
|
void RigidBody::update() {
|
|
|
|
// Update the orientation of the corresponding bounding volumes of the rigid body
|
|
|
|
broadBoundingVolume->update(position, orientation);
|
|
|
|
narrowBoundingVolume->update(position, orientation);
|
|
|
|
}
|