[DEV] try to find bug on the physic single shape
This commit is contained in:
parent
b1c211a585
commit
d67a328fa4
@ -24,13 +24,13 @@
|
|||||||
|
|
||||||
btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh) {
|
btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh) {
|
||||||
if (_mesh == nullptr) {
|
if (_mesh == nullptr) {
|
||||||
EGE_DEBUG("Create empty shape (no mesh)");
|
EGE_ERROR("Create empty shape (no mesh)");
|
||||||
return new btEmptyShape();;
|
return new btEmptyShape();;
|
||||||
}
|
}
|
||||||
const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& physiqueProperty = _mesh->getPhysicalProperties();
|
const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& physiqueProperty = _mesh->getPhysicalProperties();
|
||||||
if (physiqueProperty.size() == 0) {
|
if (physiqueProperty.size() == 0) {
|
||||||
EGE_DEBUG("Create empty shape (no default shape)");
|
EGE_ERROR("Create empty shape (no default shape)");
|
||||||
return new btEmptyShape();;
|
return new btEmptyShape();
|
||||||
}
|
}
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
|
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;
|
btCompoundShape* outputShape = nullptr;
|
||||||
if (count>1) {
|
if (count>1) {
|
||||||
EGE_DEBUG("Create complexe shape");
|
EGE_ERROR("Create complexe shape");
|
||||||
outputShape = new btCompoundShape();
|
outputShape = new btCompoundShape();
|
||||||
} else {
|
} else {
|
||||||
EGE_DEBUG("Create simple shape");
|
EGE_ERROR("Create simple shape");
|
||||||
|
//outputShape = new btCompoundShape();
|
||||||
}
|
}
|
||||||
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
|
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
|
||||||
if (physiqueProperty[iii] == nullptr) {
|
if (physiqueProperty[iii] == nullptr) {
|
||||||
@ -52,10 +53,10 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
|
|||||||
}
|
}
|
||||||
switch (physiqueProperty[iii]->getType()) {
|
switch (physiqueProperty[iii]->getType()) {
|
||||||
case ege::PhysicsShape::box : {
|
case ege::PhysicsShape::box : {
|
||||||
EGE_DEBUG(" Box");
|
EGE_ERROR(" Box");
|
||||||
const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox();
|
const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox();
|
||||||
if (tmpElement == nullptr) {
|
if (tmpElement == nullptr) {
|
||||||
// ERROR ...
|
EGE_ERROR(" Box ==> can not cast in BOX");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize());
|
btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize());
|
||||||
@ -76,7 +77,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
|
|||||||
EGE_DEBUG(" Cylinder");
|
EGE_DEBUG(" Cylinder");
|
||||||
const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder();
|
const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder();
|
||||||
if (tmpElement == nullptr) {
|
if (tmpElement == nullptr) {
|
||||||
// ERROR ...
|
EGE_ERROR(" Cylinder ==> can not cast in Cylinder");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize());
|
btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize());
|
||||||
@ -95,7 +96,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
|
|||||||
EGE_DEBUG(" Capsule");
|
EGE_DEBUG(" Capsule");
|
||||||
const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule();
|
const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule();
|
||||||
if (tmpElement == nullptr) {
|
if (tmpElement == nullptr) {
|
||||||
// ERROR ...
|
EGE_ERROR(" Capsule ==> can not cast in Capsule");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight());
|
btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight());
|
||||||
@ -114,7 +115,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
|
|||||||
EGE_DEBUG(" Cone");
|
EGE_DEBUG(" Cone");
|
||||||
const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone();
|
const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone();
|
||||||
if (tmpElement == nullptr) {
|
if (tmpElement == nullptr) {
|
||||||
// ERROR ...
|
EGE_ERROR(" Cone ==> can not cast in Cone");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight());
|
btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight());
|
||||||
@ -133,7 +134,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
|
|||||||
EGE_DEBUG(" Sphere");
|
EGE_DEBUG(" Sphere");
|
||||||
const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere();
|
const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere();
|
||||||
if (tmpElement == nullptr) {
|
if (tmpElement == nullptr) {
|
||||||
// ERROR ...
|
EGE_ERROR(" Sphere ==> can not cast in Sphere");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
|
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
|
||||||
@ -152,7 +153,7 @@ btCollisionShape* ege::collision::createShape(const ememory::SharedPtr<ege::reso
|
|||||||
EGE_DEBUG(" convexHull");
|
EGE_DEBUG(" convexHull");
|
||||||
const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull();
|
const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull();
|
||||||
if (tmpElement == nullptr) {
|
if (tmpElement == nullptr) {
|
||||||
// ERROR ...
|
EGE_ERROR(" convexHull ==> can not cast in convexHull");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size());
|
btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size());
|
||||||
|
@ -60,9 +60,11 @@ void ege::ElementPhysic::createRigidBody(float _mass) {
|
|||||||
startTransform.setIdentity();
|
startTransform.setIdentity();
|
||||||
vec3 localInertia(0,0,0);
|
vec3 localInertia(0,0,0);
|
||||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
//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);
|
getShape()->calculateLocalInertia(_mass, localInertia);
|
||||||
}
|
}
|
||||||
|
EGE_ERROR("Create The RIGID body ...");
|
||||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||||
btDefaultMotionState* motionState = new btDefaultMotionState(startTransform);
|
btDefaultMotionState* motionState = new btDefaultMotionState(startTransform);
|
||||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(_mass, motionState, getShape(), localInertia);
|
btRigidBody::btRigidBodyConstructionInfo rbInfo(_mass, motionState, getShape(), localInertia);
|
||||||
@ -355,12 +357,15 @@ void ege::ElementPhysic::draw(int32_t _pass) {
|
|||||||
if( m_body != nullptr
|
if( m_body != nullptr
|
||||||
&& m_mesh != nullptr
|
&& m_mesh != nullptr
|
||||||
&& m_body->getMotionState() ) {
|
&& m_body->getMotionState() ) {
|
||||||
//EGE_INFO("element pos = " << getPosition());
|
EGE_INFO("element pos = " << getPosition());
|
||||||
btScalar mmm[16];
|
btScalar mmm[16];
|
||||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
|
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
|
||||||
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm);
|
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();
|
transformationMatrix.transpose();
|
||||||
m_mesh->draw(transformationMatrix);
|
m_mesh->draw(transformationMatrix);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace appl {
|
|||||||
ememory::SharedPtr<ege::camera::View> m_camera;
|
ememory::SharedPtr<ege::camera::View> m_camera;
|
||||||
protected:
|
protected:
|
||||||
Windows();
|
Windows();
|
||||||
void init();
|
void init() override;
|
||||||
public:
|
public:
|
||||||
DECLARE_FACTORY(Windows);
|
DECLARE_FACTORY(Windows);
|
||||||
virtual ~Windows() { };
|
virtual ~Windows() { };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user