[DEV] continue update to the new physic engine

This commit is contained in:
Edouard DUPIN 2017-05-16 21:09:14 +02:00
parent 4a64ced041
commit fe17517d7c
14 changed files with 67 additions and 97 deletions

View File

@ -6,11 +6,6 @@
#include <ege/debug.hpp>
#include <ege/CollisionShapeCreator.hpp>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <ege/physicsShape/PhysicsShape.hpp>
#include <ege/physicsShape/PhysicsBox.hpp>
#include <ege/physicsShape/PhysicsCapsule.hpp>
@ -21,7 +16,7 @@
// Documentetion of bullet library :
// http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Shapes
/*
btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh) {
if (_mesh == nullptr) {
EGE_ERROR("Create empty shape (no mesh)");
@ -181,5 +176,5 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
}
return outputShape;
}
*/

View File

@ -7,11 +7,10 @@
#include <etk/types.hpp>
#include <ege/resource/Mesh.hpp>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
namespace ege {
namespace collision {
btCollisionShape* createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh);
//btCollisionShape* createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh);
}
}

View File

@ -10,19 +10,7 @@
#include <ewol/object/Manager.hpp>
#include <gale/renderer/openGL/openGL.hpp>
#include <etk/math/Matrix4.hpp>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btTransformUtil.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <etk/math/Matrix4x4.hpp>
ememory::SharedPtr<ege::Element> ege::Environement::getElementNearest(ememory::SharedPtr<ege::Element> _sourceRequest, float& _distance) {
if (_sourceRequest == nullptr) {

View File

@ -11,11 +11,7 @@ namespace ege {
};
#include <ege/camera/Camera.hpp>
#include <ege/ParticuleEngine.hpp>
#include <etk/types.hpp>
#include <BulletDynamics/Dynamics/btActionInterface.h>
class btDynamicsWorld;
#include <vector>
#include <etk/math/Vector3D.hpp>
#include <ejson/ejson.hpp>

View File

@ -8,8 +8,6 @@
#include <ege/debug.hpp>
#include <ege/elements/Element.hpp>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
ege::Ray::Ray(const vec3& _origin, const vec3& _direction) :
m_origin(_origin),
@ -41,6 +39,7 @@ std::pair<vec3,vec3> ege::Ray::testRay(ege::physics::Engine& _engine) {
vec3 start = m_origin;
vec3 stop = m_origin+m_direction*1000.0f;
// Start and End are vectors
/*
btCollisionWorld::ClosestRayResultCallback rayCallback(start, stop);
EGE_VERBOSE("Process Raycast :");
// Perform raycast
@ -51,6 +50,7 @@ std::pair<vec3,vec3> ege::Ray::testRay(ege::physics::Engine& _engine) {
EGE_VERBOSE(" hit at point=" << end << " normal=" << normal);
return std::pair<vec3,vec3>(end,normal);
}
*/
EGE_VERBOSE(" No Hit");
return std::pair<vec3,vec3>(vec3(0,0,0),vec3(0,0,0));
}
@ -60,6 +60,7 @@ std::pair<ememory::SharedPtr<ege::Element>, std::pair<vec3,vec3>> ege::Ray::test
vec3 start = m_origin;
vec3 stop = m_origin+m_direction*1000.0f;
// Start and End are vectors
/*
btCollisionWorld::ClosestRayResultCallback rayCallback(start, stop);
EGE_VERBOSE("Process Raycast :");
// Perform raycast
@ -74,9 +75,9 @@ std::pair<ememory::SharedPtr<ege::Element>, std::pair<vec3,vec3>> ege::Ray::test
}
EGE_VERBOSE(" Can not get the element pointer");
return std::pair<ememory::SharedPtr<ege::Element>, std::pair<vec3,vec3>>(nullptr, std::pair<vec3,vec3>(end,normal));
} else {
EGE_VERBOSE(" No Hit");
}
*/
EGE_VERBOSE(" No Hit");
return std::pair<ememory::SharedPtr<ege::Element>, std::pair<vec3,vec3>>(nullptr, std::pair<vec3,vec3>(vec3(0,0,0),vec3(0,0,0)));
}

View File

@ -9,7 +9,7 @@
#include <etk/types.hpp>
#include <etk/math/Vector3D.hpp>
#include <etk/math/Vector2D.hpp>
#include <etk/math/Matrix4.hpp>
#include <etk/math/Matrix4x4.hpp>
#include <ege/Ray.hpp>
#include <ewol/resource/Colored3DObject.hpp>

View File

@ -8,19 +8,6 @@
#include <ege/debug.hpp>
#include <ege/elements/Element.hpp>
#include <ege/Environement.hpp>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btTransformUtil.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <ege/CollisionShapeCreator.hpp>

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp>
#include <etk/math/Vector3D.hpp>
#include <etk/math/Matrix4.hpp>
#include <etk/math/Matrix4x4.hpp>
#include <vector>
#include <ewol/debug.hpp>
#include <ewol/widget/Widget.hpp>

View File

@ -8,18 +8,6 @@
#include <ege/debug.hpp>
#include <ege/elements/ElementPhysic.hpp>
#include <ege/Environement.hpp>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btTransformUtil.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <ege/CollisionShapeCreator.hpp>
@ -32,7 +20,7 @@ const std::string& ege::ElementPhysic::getType() const {
ege::ElementPhysic::ElementPhysic(const ememory::SharedPtr<ege::Environement>& _env, bool _autoRigidBody) ://, float _mass) :
ege::Element(_env),
m_body(nullptr),
m_shape(nullptr),
//m_shape(nullptr),
m_elementInPhysicsSystem(false),
m_IA(nullptr),
m_detectCollisionEnable(false) {
@ -45,12 +33,12 @@ ege::ElementPhysic::ElementPhysic(const ememory::SharedPtr<ege::Environement>& _
ege::ElementPhysic::~ElementPhysic() {
// in every case remove IA
iaDisable();
//iaDisable();
// same ...
dynamicDisable();
removeShape();
//dynamicDisable();
//removeShape();
// Destroy the rigid body
m_dynamicsWorld->destroyRigidBody(m_body);
//m_dynamicsWorld->destroyRigidBody(m_body);
m_body = nullptr;
}
@ -62,8 +50,8 @@ void ege::ElementPhysic::createRigidBody(float _mass, bool _static) {
rp3d::Transform transform(initPosition, initOrientation);
// Create a rigid body in the world
m_body = m_dynamicsWorld->createRigidBody(transform);
m_body = nullptr;//m_dynamicsWorld->createRigidBody(transform);
/*
if (_static = true) {
m_body->setType(STATIC);
//m_body->setType(KINEMATIC);
@ -72,18 +60,20 @@ void ege::ElementPhysic::createRigidBody(float _mass, bool _static) {
} else {
m_body->setType(DYNAMIC);
}
*/
}
bool ege::ElementPhysic::setMesh(ememory::SharedPtr<ege::resource::Mesh> _mesh) {
EGE_WARNING("Set Mesh");
if (m_mesh != nullptr) {
removeShape();
//removeShape();
}
ege::Element::setMesh(_mesh);
// auto load the shape:
if (m_mesh == nullptr) {
return true;
}
/*
if (m_mesh->getShape() != nullptr) {
EGE_WARNING("create shape whith mesh internal shape ...");
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
@ -96,10 +86,11 @@ bool ege::ElementPhysic::setMesh(ememory::SharedPtr<ege::resource::Mesh> _mesh)
m_shape = static_cast<btCollisionShape*>(m_mesh->getShape());
vec3 localInertia(0,0,0);
m_shape->calculateLocalInertia(50000000, localInertia); // TODO : BETTER ///
*/
return true;
}
/*
bool ege::ElementPhysic::setShape(btCollisionShape* _shape) {
EGE_DEBUG("Set Shape");
removeShape();
@ -140,47 +131,55 @@ void ege::ElementPhysic::FunctionFreeShape(void* _pointer) {
}
delete(static_cast<btCollisionShape*>(_pointer));
}
*/
void ege::ElementPhysic::setPosition(const vec3& _pos) {
if (m_body != nullptr) {
/*
btTransform transformation = m_body->getCenterOfMassTransform();
transformation.setOrigin(_pos);
m_body->setCenterOfMassTransform(transformation);
*/
}
}
const vec3& ege::ElementPhysic::getPosition() {
/*
if (m_body != nullptr) {
return m_body->getCenterOfMassPosition();
}
*/
return ege::Element::getPosition();
};
const vec3& ege::ElementPhysic::getSpeed() {
static vec3 emptySpeed(0,0,0);
/*
if (m_body != nullptr) {
return m_body->getLinearVelocity();
}
*/
return emptySpeed;
};
const float ege::ElementPhysic::getInvMass() {
/*
if (m_body != nullptr) {
return m_body->getInvMass();
}
*/
return 0.0000000001f;
};
void ege::ElementPhysic::drawShape(const btCollisionShape* _shape,
void ege::ElementPhysic::drawShape(/*const btCollisionShape* _shape,*/
ememory::SharedPtr<ewol::resource::Colored3DObject> _draw,
mat4 _transformationMatrix,
std::vector<vec3> _tmpVertices) {
#if 0
if( _draw == nullptr
|| _shape == nullptr) {
return;
}
etk::Color<float> tmpColor(1.0, 0.0, 0.0, 0.3);
//EGE_DEBUG(" draw (6): !btIDebugDraw::DBG_DrawWireframe");
int shapetype=_shape->getShapeType();
switch (shapetype) {
@ -316,10 +315,12 @@ void ege::ElementPhysic::drawShape(const btCollisionShape* _shape,
EGE_DEBUG(" draw (09): default");
}
}
#endif
}
void ege::ElementPhysic::drawDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera) {
ege::Element::drawDebug(_draw, _camera);
/*
btScalar mmm[16];
if (m_body == nullptr) {
return;
@ -333,9 +334,11 @@ void ege::ElementPhysic::drawDebug(ememory::SharedPtr<ewol::resource::Colored3DO
// note : set the vertice here to prevent multiple allocations...
std::vector<vec3> EwolVertices;
drawShape(m_shape, _draw, transformationMatrix, EwolVertices);
*/
}
void ege::ElementPhysic::drawNormalDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera) {
/*
if( m_body != nullptr
&& m_mesh != nullptr
&& m_body->getMotionState() ) {
@ -348,12 +351,14 @@ void ege::ElementPhysic::drawNormalDebug(ememory::SharedPtr<ewol::resource::Colo
transformationMatrix.transpose();
m_mesh->drawNormal(transformationMatrix, _draw);
}
*/
}
void ege::ElementPhysic::draw(int32_t _pass) {
if (m_elementInPhysicsSystem == false) {
return;
}
/*
//EGE_INFO("draw : " << _pass );
if (_pass == 0) {
if( m_body != nullptr
@ -372,6 +377,7 @@ void ege::ElementPhysic::draw(int32_t _pass) {
m_mesh->draw(transformationMatrix);
}
}
*/
}
void ege::ElementPhysic::dynamicEnable() {
@ -438,12 +444,14 @@ void ege::ElementPhysic::setMass(float _value) {
if (m_body == nullptr) {
return;
}
/*
vec3 localInertia(0,0,0);
if (_value != 0.0f && getShape()!=nullptr) {
//getShape()->calculateLocalInertia(_value, localInertia);
EWOL_ERROR("Update inertia calculated : " << localInertia);
}
//m_body->setMassProps(_value, localInertia);
m_body->setMassProps(_value, localInertia);
*/
}
void ege::ElementPhysic::setLinearVelocity(const vec3& _value) {
@ -454,7 +462,7 @@ void ege::ElementPhysic::setLinearVelocity(const vec3& _value) {
// Force vector (in Newton)
rp3d::Vector3 force(_value.x(), _value.y(), _value.z());
// Apply a force to the center of the body
m_body->applyForceToCenter(force);
m_body->applyForceToCenterOfMass(force);
}
void ege::ElementPhysic::setTorqueImpulse(const vec3& _value) {
@ -475,7 +483,7 @@ void ege::ElementPhysic::setAngularVelocity(const vec3& _value) {
}
//m_body->setAngularVelocity(_value);
}
/*
btQuaternion ege::ElementPhysic::getOrientation() const {
if (m_body == nullptr) {
EGE_WARNING("no body");
@ -484,6 +492,7 @@ btQuaternion ege::ElementPhysic::getOrientation() const {
//return m_body->getOrientation();
return btQuaternion(0,0,0,0);
}
*/
void ege::ElementPhysic::setCollisionDetectionStatus(bool _status) {
if (m_body == nullptr) {

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp>
#include <etk/math/Vector3D.hpp>
#include <etk/math/Matrix4.hpp>
#include <etk/math/Matrix4x4.hpp>
#include <vector>
#include <ewol/debug.hpp>
#include <ewol/widget/Widget.hpp>
@ -53,7 +53,7 @@ namespace ege {
*/
virtual const std::string& getType() const;
protected:
btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
//btCollisionShape* m_shape; //!< shape of the element (set a copy here to have the debug display of it)
public:
/**
* @brief set the shape properties.
@ -61,19 +61,21 @@ namespace ege {
* @note : this remove the shape properties.
* @return true if no error occured
*/
bool setShape(btCollisionShape* _shape);
//bool setShape(btCollisionShape* _shape);
/**
* @brief get a pointer on the bullet collision shape.
* @return the collision pointer.
*/
/*
inline btCollisionShape* getShape() {
return m_shape;
};
*/
private:
/**
* @brief remove the curent selected shape.
*/
void removeShape();
//void removeShape();
public:
virtual bool setMesh(ememory::SharedPtr<ege::resource::Mesh> _mesh);
/**
@ -121,7 +123,7 @@ namespace ege {
virtual void setTorqueImpulse(const vec3& _value);
virtual void setAngularVelocity(const vec3& _value);
btQuaternion getOrientation() const;
//btQuaternion getOrientation() const;
protected:
bool m_elementInPhysicsSystem;
@ -129,7 +131,7 @@ namespace ege {
virtual void dynamicEnable();
virtual void dynamicDisable();
private:
class localIA : public btActionInterface {
class localIA {
private:
ege::ElementPhysic& m_element;
public:
@ -147,12 +149,14 @@ namespace ege {
};
public: // herited function
/*
void debugDraw(btIDebugDraw* _debugDrawer) {
};
void updateAction(btCollisionWorld* _collisionWorld, btScalar _step) {
m_element.iaAction(_step);
};
*/
};
localIA* m_IA;
public:
@ -177,7 +181,7 @@ namespace ege {
virtual void setPosition(const vec3& _pos);
virtual void drawDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera);
protected:
void drawShape(const btCollisionShape* _shape,
void drawShape(/*const btCollisionShape* _shape,*/
ememory::SharedPtr<ewol::resource::Colored3DObject> _draw,
mat4 _transformationMatrix,
std::vector<vec3> _tmpVertices);

View File

@ -9,24 +9,13 @@
#include <ege/debug.hpp>
#include <gale/renderer/openGL/openGL.hpp>
#include <etk/math/Matrix4.hpp>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btDynamicsWorld.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletCollisionCommon.h>
#include <BulletCollision/CollisionShapes/btConvexPolyhedron.h>
#include <BulletCollision/CollisionShapes/btShapeHull.h>
#include <LinearMath/btTransformUtil.h>
#include <LinearMath/btIDebugDraw.h>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include <etk/math/Matrix4x4.hpp>
#include <ege/elements/ElementPhysic.hpp>
// unique callback function :
/*
extern ContactProcessedCallback gContactProcessedCallback;
// TODO : remove double collision call ...
@ -47,7 +36,7 @@ static bool handleContactsProcess(btManifoldPoint& _point, btCollisionObject* _b
}
return true;
}
*/
ege::physics::Engine::Engine():
m_dynamicsWorld(nullptr),
@ -68,7 +57,8 @@ ege::physics::Engine::~Engine() {
void ege::physics::Engine::setGravity(const vec3& _axePower) {
if (m_dynamicsWorld != nullptr) {
m_dynamicsWorld->setGravity(rp3d::Vector3(_axePower.x(), _axePower.y(), _axePower.z()));
rp3d::Vector3 gravity(_axePower.x(), _axePower.y(), _axePower.z());
m_dynamicsWorld->setGravity(gravity);
}
}

View File

@ -12,7 +12,7 @@ namespace ege {
};
#include <etk/types.hpp>
#include <etk/math/Vector3D.hpp>
#include <etk/math/Matrix4.hpp>
#include <etk/math/Matrix4x4.hpp>
#include <vector>
#include <ewol/debug.hpp>
#include <ege/camera/Camera.hpp>
@ -20,6 +20,7 @@ namespace ege {
#include <gale/renderer/openGL/openGL.hpp>
#include <gale/resource/Manager.hpp>
#include <gale/Dimension.hpp>
#include <ephysics/reactphysics3d.h>
namespace ege {

View File

@ -14,7 +14,7 @@
#include <ewol/ewol.hpp>
#include <ewol/object/Manager.hpp>
#include <gale/renderer/openGL/openGL.hpp>
#include <etk/math/Matrix4.hpp>
#include <etk/math/Matrix4x4.hpp>
namespace etk {
template<> std::string to_string<ememory::SharedPtr<ewol::resource::Colored3DObject> >(const ememory::SharedPtr<ewol::resource::Colored3DObject>& _value) {

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp>
#include <etk/math/Vector3D.hpp>
#include <etk/math/Matrix4.hpp>
#include <etk/math/Matrix4x4.hpp>
#include <vector>
#include <ewol/debug.hpp>
#include <ege/camera/Camera.hpp>