ephysics/tools/testbed/common/PhysicsObject.h

100 lines
3.3 KiB
C
Raw Normal View History

2017-05-11 00:40:27 +00:00
/********************************************************************************
2017-06-16 22:34:37 +02:00
* ReactPhysics3D physics library, http://www.ephysics.com *
2017-06-08 22:35:22 +02:00
* Copyright (c) 2010-2016 Daniel Chappuis *
2017-05-11 00:40:27 +00:00
*********************************************************************************
2017-06-08 22:35:22 +02:00
* *
2017-05-11 00:40:27 +00:00
* This software is provided 'as-is', without any express or implied warranty. *
* In no event will the authors be held liable for any damages arising from the *
2017-06-08 22:35:22 +02:00
* use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
2017-05-11 00:40:27 +00:00
* 1. The origin of this software must not be misrepresented; you must not claim *
2017-06-08 22:35:22 +02:00
* that you wrote the original software. If you use this software in a *
* product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source distribution. *
* *
2017-05-11 00:40:27 +00:00
********************************************************************************/
#ifndef PHYSICSOBJECT_H
#define PHYSICSOBJECT_H
// Libraries
2017-06-16 22:34:37 +02:00
#include <ephysics/openglframework.hpp>
#include <ephysics/ephysics.hpp>
2017-05-11 00:40:27 +00:00
// Class PhysicsObject
class PhysicsObject {
2017-06-08 22:35:22 +02:00
protected:
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Body used to simulate the dynamics of the box
2017-06-16 22:34:37 +02:00
ephysics::CollisionBody* m_body;
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Previous transform of the body (for int32_terpolation)
2017-06-16 22:34:37 +02:00
ephysics::etk::Transform3D mPreviousTransform;
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Main color of the box
openglframework::Color mColor;
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Sleeping color
openglframework::Color mSleepingColor;
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
// Compute the new transform matrix
openglframework::Matrix4 computeetk::Transform3D(float int32_terpolationFactor,
2017-06-08 22:35:22 +02:00
const openglframework::Matrix4 &scalingMatrix);
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
public:
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Constructor
PhysicsObject();
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Update the transform matrix of the object
virtual void updateetk::Transform3D(float int32_terpolationFactor)=0;
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Set the color of the box
void setColor(const openglframework::Color& color);
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Set the sleeping color of the box
void setSleepingColor(const openglframework::Color& color);
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Return a pointer to the collision body of the box
2017-06-16 22:34:37 +02:00
ephysics::CollisionBody* getCollisionBody();
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Return a pointer to the rigid body of the box
2017-06-16 22:34:37 +02:00
ephysics::RigidBody* getRigidBody();
2017-05-11 00:40:27 +00:00
2017-06-08 22:35:22 +02:00
/// Set the scaling of the object
virtual void setScaling(const openglframework::vec3& scaling)=0;
2017-05-11 00:40:27 +00:00
};
// Set the color of the box
inline void PhysicsObject::setColor(const openglframework::Color& color) {
2017-06-08 22:35:22 +02:00
mColor = color;
2017-05-11 00:40:27 +00:00
}
// Set the sleeping color of the box
inline void PhysicsObject::setSleepingColor(const openglframework::Color& color) {
2017-06-08 22:35:22 +02:00
mSleepingColor = color;
2017-05-11 00:40:27 +00:00
}
// Return a pointer to the collision body of the box
2017-06-16 22:34:37 +02:00
inline ephysics::CollisionBody* PhysicsObject::getCollisionBody() {
2017-06-12 23:35:50 +02:00
return m_body;
2017-05-11 00:40:27 +00:00
}
// Return a pointer to the rigid body of the box (NULL if it's not a rigid body)
2017-06-16 22:34:37 +02:00
inline ephysics::RigidBody* PhysicsObject::getRigidBody() {
return dynamic_cast<ephysics::RigidBody*>(m_body);
2017-05-11 00:40:27 +00:00
}
#endif