[DEV] try to find bug on the physic single shape

This commit is contained in:
Edouard DUPIN 2017-03-20 23:11:38 +01:00
parent b1c211a585
commit d67a328fa4
3 changed files with 22 additions and 16 deletions

View File

@ -24,13 +24,13 @@
btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh) {
if (_mesh == nullptr) {
EGE_DEBUG("Create empty shape (no mesh)");
EGE_ERROR("Create empty shape (no mesh)");
return new btEmptyShape();;
}
const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& physiqueProperty = _mesh->getPhysicalProperties();
if (physiqueProperty.size() == 0) {
EGE_DEBUG("Create empty shape (no default shape)");
return new btEmptyShape();;
EGE_ERROR("Create empty shape (no default shape)");
return new btEmptyShape();
}
int32_t count = 0;
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
@ -41,10 +41,11 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
}
btCompoundShape* outputShape = nullptr;
if (count>1) {
EGE_DEBUG("Create complexe shape");
EGE_ERROR("Create complexe shape");
outputShape = new btCompoundShape();
} else {
EGE_DEBUG("Create simple shape");
EGE_ERROR("Create simple shape");
//outputShape = new btCompoundShape();
}
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
if (physiqueProperty[iii] == nullptr) {
@ -52,10 +53,10 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
}
switch (physiqueProperty[iii]->getType()) {
case ege::PhysicsShape::box : {
EGE_DEBUG(" Box");
EGE_ERROR(" Box");
const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox();
if (tmpElement == nullptr) {
// ERROR ...
EGE_ERROR(" Box ==> can not cast in BOX");
continue;
}
btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize());
@ -76,7 +77,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
EGE_DEBUG(" Cylinder");
const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder();
if (tmpElement == nullptr) {
// ERROR ...
EGE_ERROR(" Cylinder ==> can not cast in Cylinder");
continue;
}
btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize());
@ -95,7 +96,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
EGE_DEBUG(" Capsule");
const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule();
if (tmpElement == nullptr) {
// ERROR ...
EGE_ERROR(" Capsule ==> can not cast in Capsule");
continue;
}
btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight());
@ -114,7 +115,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
EGE_DEBUG(" Cone");
const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone();
if (tmpElement == nullptr) {
// ERROR ...
EGE_ERROR(" Cone ==> can not cast in Cone");
continue;
}
btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight());
@ -133,7 +134,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
EGE_DEBUG(" Sphere");
const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere();
if (tmpElement == nullptr) {
// ERROR ...
EGE_ERROR(" Sphere ==> can not cast in Sphere");
continue;
}
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
@ -152,7 +153,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
EGE_DEBUG(" convexHull");
const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull();
if (tmpElement == nullptr) {
// ERROR ...
EGE_ERROR(" convexHull ==> can not cast in convexHull");
continue;
}
btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size());

View File

@ -60,9 +60,11 @@ void ege::ElementPhysic::createRigidBody(float _mass) {
startTransform.setIdentity();
vec3 localInertia(0,0,0);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
if (_mass != 0.0f && getShape()!=nullptr) {
if ( _mass != 0.0f
&& getShape()!=nullptr) {
getShape()->calculateLocalInertia(_mass, localInertia);
}
EGE_ERROR("Create The RIGID body ...");
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* motionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(_mass, motionState, getShape(), localInertia);
@ -355,12 +357,15 @@ void ege::ElementPhysic::draw(int32_t _pass) {
if( m_body != nullptr
&& m_mesh != nullptr
&& m_body->getMotionState() ) {
//EGE_INFO("element pos = " << getPosition());
EGE_INFO("element pos = " << getPosition());
btScalar mmm[16];
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm);
mat4 transformationMatrix(mmm);
EGE_INFO(" mat = " << mat4(mmm));
//mat4 transformationMatrix(mmm);
mat4 transformationMatrix = mat4(mmm) * etk::matScale(vec3(20,20,20));
transformationMatrix.transpose();
m_mesh->draw(transformationMatrix);
}

View File

@ -18,7 +18,7 @@ namespace appl {
ememory::SharedPtr<ege::camera::View> m_camera;
protected:
Windows();
void init();
void init() override;
public:
DECLARE_FACTORY(Windows);
virtual ~Windows() { };