[DEV] manage convex shape
This commit is contained in:
parent
e8d16c380e
commit
ff4e7ac001
@ -42,7 +42,7 @@ void ege::Entity::addComponent(const ememory::SharedPtr<ege::Component>& _ref) {
|
|||||||
ememory::SharedPtr<ege::Component> componentRemoved;
|
ememory::SharedPtr<ege::Component> componentRemoved;
|
||||||
int32_t findId = -1;
|
int32_t findId = -1;
|
||||||
// check if not exist
|
// check if not exist
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ void ege::Entity::addComponent(const ememory::SharedPtr<ege::Component>& _ref) {
|
|||||||
}
|
}
|
||||||
// try to add in an empty slot
|
// try to add in an empty slot
|
||||||
if (findId == -1) {
|
if (findId == -1) {
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] != nullptr) {
|
if (m_component[iii] != nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ void ege::Entity::addComponent(const ememory::SharedPtr<ege::Component>& _ref) {
|
|||||||
findId = m_component.size();
|
findId = m_component.size();
|
||||||
m_component.push_back(_ref);
|
m_component.push_back(_ref);
|
||||||
}
|
}
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ void ege::Entity::addComponent(const ememory::SharedPtr<ege::Component>& _ref) {
|
|||||||
}
|
}
|
||||||
// notify new component of all previously added component:
|
// notify new component of all previously added component:
|
||||||
componentRemoved = _ref;
|
componentRemoved = _ref;
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ void ege::Entity::rmComponent(const ememory::SharedPtr<ege::Component>& _ref) {
|
|||||||
}
|
}
|
||||||
int32_t findId = -1;
|
int32_t findId = -1;
|
||||||
// check if not exist
|
// check if not exist
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ void ege::Entity::rmComponent(const ememory::SharedPtr<ege::Component>& _ref) {
|
|||||||
EGE_ERROR("try to remove an unexisting component");
|
EGE_ERROR("try to remove an unexisting component");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ void ege::Entity::rmComponent(const std::string& _type) {
|
|||||||
int32_t findId = -1;
|
int32_t findId = -1;
|
||||||
ememory::SharedPtr<ege::Component> componentRemoved;
|
ememory::SharedPtr<ege::Component> componentRemoved;
|
||||||
// check if not exist
|
// check if not exist
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ void ege::Entity::rmComponent(const std::string& _type) {
|
|||||||
EGE_ERROR("try to remove an unexisting component type : '" << _type << "'");
|
EGE_ERROR("try to remove an unexisting component type : '" << _type << "'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int32_t iii=0; iii<m_component.size(); ++iii) {
|
for (size_t iii=0; iii<m_component.size(); ++iii) {
|
||||||
if (m_component[iii] == nullptr) {
|
if (m_component[iii] == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -200,18 +200,14 @@ void ege::physics::Component::generate() {
|
|||||||
EGE_ERROR(" Concave ==> can not cast in Concave");
|
EGE_ERROR(" Concave ==> can not cast in Concave");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
/*
|
|
||||||
float* vertices = (float*)&tmpElement->getVertex()[0];
|
|
||||||
int* indices = (int*)&tmpElement->getIndices()[0];
|
|
||||||
|
|
||||||
int32_t nbVertices = tmpElement->getVertex().size();
|
|
||||||
int32_t nbTriangles = tmpElement->getIndices().size()/3;
|
|
||||||
*/
|
|
||||||
static const std::vector<vec3> vertices = {vec3(-100.0f,-100.0f,-50.0f),vec3(100.0f,-100.0f,-50.0f),vec3(100.0f,100.0f,-50.0f)};
|
static const std::vector<vec3> vertices = {vec3(-100.0f,-100.0f,-50.0f),vec3(100.0f,-100.0f,-50.0f),vec3(100.0f,100.0f,-50.0f)};
|
||||||
static const std::vector<size_t> indices = {1,2,3};
|
static const std::vector<uint32_t> indices = {0,1,2};
|
||||||
|
|
||||||
ephysics::TriangleVertexArray* triangleArray = new ephysics::TriangleVertexArray(vertices, indices);
|
ephysics::TriangleVertexArray* triangleArray = new ephysics::TriangleVertexArray(vertices, indices);
|
||||||
|
#else
|
||||||
|
ephysics::TriangleVertexArray* triangleArray = new ephysics::TriangleVertexArray(tmpElement->getVertex(), tmpElement->getIndices());
|
||||||
|
#endif
|
||||||
// Now that we have a TriangleVertexArray, we need to create a TriangleMesh and add the TriangleVertexArray into it as a subpart.
|
// Now that we have a TriangleVertexArray, we need to create a TriangleMesh and add the TriangleVertexArray into it as a subpart.
|
||||||
// Once this is done, we can create the actual ConcaveMeshShape and add it to the body we want to simulate as in the following example:
|
// Once this is done, we can create the actual ConcaveMeshShape and add it to the body we want to simulate as in the following example:
|
||||||
ephysics::TriangleMesh* triangleMesh = new ephysics::TriangleMesh();
|
ephysics::TriangleMesh* triangleMesh = new ephysics::TriangleMesh();
|
||||||
@ -221,7 +217,7 @@ void ege::physics::Component::generate() {
|
|||||||
// TODO : Manage memory leak ...
|
// TODO : Manage memory leak ...
|
||||||
ephysics::ConcaveShape* shape = new ephysics::ConcaveMeshShape(triangleMesh);
|
ephysics::ConcaveShape* shape = new ephysics::ConcaveMeshShape(triangleMesh);
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
// The ephysic use Y as UP ==> ege use Z as UP
|
||||||
//etk::Quaternion orientation = it->getOrientation() * ephysics::Quaternion(-0.707107, 0, 0, 0.707107);
|
etk::Quaternion orientation = it->getOrientation() * etk::Quaternion(-0.707107, 0, 0, 0.707107);
|
||||||
etk::Transform3D transform(it->getOrigin(), it->getOrientation());
|
etk::Transform3D transform(it->getOrigin(), it->getOrientation());
|
||||||
ephysics::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
|
ephysics::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
|
||||||
proxyShape->setUserData(this);
|
proxyShape->setUserData(this);
|
||||||
@ -490,6 +486,22 @@ void ege::physics::Component::drawShape(ememory::SharedPtr<ewol::resource::Color
|
|||||||
_draw->drawSphere(tmpElement->getRadius(), 10, 10, transformationMatrixLocal, tmpColor);
|
_draw->drawSphere(tmpElement->getRadius(), 10, 10, transformationMatrixLocal, tmpColor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ege::physics::Shape::type::concave: {
|
||||||
|
EGE_DEBUG(" concave");
|
||||||
|
const ege::physics::shape::Concave* tmpElement = it->toConcave();
|
||||||
|
if (tmpElement == nullptr) {
|
||||||
|
EGE_ERROR(" concave ==> can not cast in convexHull");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
etk::Transform3D transformLocal(it->getOrigin(), it->getOrientation());
|
||||||
|
transformLocal.getOpenGLMatrix(mmm);
|
||||||
|
mat4 transformationMatrixLocal(mmm);
|
||||||
|
transformationMatrixLocal.transpose();
|
||||||
|
transformationMatrixLocal = transformationMatrix * transformationMatrixLocal;
|
||||||
|
|
||||||
|
_draw->drawTriangles(tmpElement->getVertex(), tmpElement->getIndices(), transformationMatrixLocal, tmpColor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ege::physics::Shape::type::convexHull: {
|
case ege::physics::Shape::type::convexHull: {
|
||||||
EGE_DEBUG(" convexHull");
|
EGE_DEBUG(" convexHull");
|
||||||
const ege::physics::shape::ConvexHull* tmpElement = it->toConvexHull();
|
const ege::physics::shape::ConvexHull* tmpElement = it->toConvexHull();
|
||||||
@ -497,18 +509,6 @@ void ege::physics::Component::drawShape(ememory::SharedPtr<ewol::resource::Color
|
|||||||
EGE_ERROR(" convexHull ==> can not cast in convexHull");
|
EGE_ERROR(" convexHull ==> can not cast in convexHull");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
btConvexHullShape* tmpShape = new btConvexHullShape(&(tmpElement->getPointList()[0].x()), tmpElement->getPointList().size());
|
|
||||||
if (tmpShape != nullptr) {
|
|
||||||
if (outputShape == nullptr) {
|
|
||||||
return tmpShape;
|
|
||||||
} else {
|
|
||||||
vec4 qqq = tmpElement->getQuaternion();
|
|
||||||
const btTransform localTransform(btQuaternion(qqq.x(),qqq.y(),qqq.z(),qqq.w()), tmpElement->getOrigin());
|
|
||||||
outputShape->addChildShape(localTransform, tmpShape);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default :
|
default :
|
||||||
|
@ -33,7 +33,7 @@ namespace ege {
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::vector<vec3> m_listVertex;
|
std::vector<vec3> m_listVertex;
|
||||||
std::vector<int> m_indices; // TODO : do it better: this is dependent of ephysics
|
std::vector<uint32_t> m_indices;
|
||||||
public:
|
public:
|
||||||
void clear() {
|
void clear() {
|
||||||
m_listVertex.clear();
|
m_listVertex.clear();
|
||||||
@ -49,6 +49,10 @@ namespace ege {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
if (_index.size()%3 != 0 ) {
|
||||||
|
EGE_ERROR("wrong number of faces : " << _index.size() << " ==> not a multiple of 3");
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto &it: _index) {
|
for (auto &it: _index) {
|
||||||
m_indices.push_back(it);
|
m_indices.push_back(it);
|
||||||
}
|
}
|
||||||
@ -56,7 +60,7 @@ namespace ege {
|
|||||||
const std::vector<vec3>& getVertex() const {
|
const std::vector<vec3>& getVertex() const {
|
||||||
return m_listVertex;
|
return m_listVertex;
|
||||||
}
|
}
|
||||||
const std::vector<int>& getIndices() const {
|
const std::vector<uint32_t>& getIndices() const {
|
||||||
return m_indices;
|
return m_indices;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -159,7 +159,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix,
|
|||||||
int32_t nbElementDrawTheoric = 0;
|
int32_t nbElementDrawTheoric = 0;
|
||||||
int32_t nbElementDraw = 0;
|
int32_t nbElementDraw = 0;
|
||||||
#endif
|
#endif
|
||||||
for (int32_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
for (size_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
||||||
if (m_materials.exist(m_listFaces.getKey(kkk)) == false) {
|
if (m_materials.exist(m_listFaces.getKey(kkk)) == false) {
|
||||||
EGE_WARNING("missing materials : '" << m_listFaces.getKey(kkk) << "'");
|
EGE_WARNING("missing materials : '" << m_listFaces.getKey(kkk) << "'");
|
||||||
continue;
|
continue;
|
||||||
@ -250,9 +250,9 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix,
|
|||||||
// generate element in 2 pass :
|
// generate element in 2 pass :
|
||||||
// - create new index dependeng a vertex is a unique componenet of position, texture, normal
|
// - create new index dependeng a vertex is a unique componenet of position, texture, normal
|
||||||
// - the index list generation (can be dynamic ... (TODO later)
|
// - the index list generation (can be dynamic ... (TODO later)
|
||||||
for (int32_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
for (size_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
||||||
// clean faces indexes :
|
// clean faces indexes :
|
||||||
int32_t nbIndicInFace = 3;
|
size_t nbIndicInFace = 3;
|
||||||
switch (m_materials[m_listFaces.getKey(kkk)]->getRenderMode()) {
|
switch (m_materials[m_listFaces.getKey(kkk)]->getRenderMode()) {
|
||||||
case gale::openGL::renderMode::triangle:
|
case gale::openGL::renderMode::triangle:
|
||||||
case gale::openGL::renderMode::triangleStrip:
|
case gale::openGL::renderMode::triangleStrip:
|
||||||
@ -296,7 +296,7 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix,
|
|||||||
center += position;
|
center += position;
|
||||||
}
|
}
|
||||||
center /= float(nbIndicInFace);
|
center /= float(nbIndicInFace);
|
||||||
int32_t index = tmpFaceList.m_faces[iii].m_normal[0];
|
size_t index = tmpFaceList.m_faces[iii].m_normal[0];
|
||||||
if (index >= m_listFacesNormal.size()) {
|
if (index >= m_listFacesNormal.size()) {
|
||||||
EGE_ERROR("not enougth normal in the buffer ... " << index << " >= " << m_listFacesNormal.size());
|
EGE_ERROR("not enougth normal in the buffer ... " << index << " >= " << m_listFacesNormal.size());
|
||||||
return;
|
return;
|
||||||
@ -401,7 +401,7 @@ void ege::resource::Mesh::generateVBO() {
|
|||||||
// generate element in 2 pass:
|
// generate element in 2 pass:
|
||||||
// - create new index depending on a vertex is a unique component of position, texture, normal
|
// - create new index depending on a vertex is a unique component of position, texture, normal
|
||||||
// - the index list generation (can be dynamic ... (TODO later))
|
// - the index list generation (can be dynamic ... (TODO later))
|
||||||
for (int32_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
for (size_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
||||||
// clean faces indexes :
|
// clean faces indexes :
|
||||||
m_listFaces.getValue(kkk).m_index.clear();
|
m_listFaces.getValue(kkk).m_index.clear();
|
||||||
int32_t nbIndicInFace = 3;
|
int32_t nbIndicInFace = 3;
|
||||||
@ -723,12 +723,23 @@ const std::vector<ememory::SharedPtr<ege::physics::Shape>>& ege::resource::Mesh:
|
|||||||
return m_physics;
|
return m_physics;
|
||||||
}
|
}
|
||||||
tmpElement->clear();
|
tmpElement->clear();
|
||||||
|
//EGE_INFO(" add vertices : " << m_listVertex);
|
||||||
tmpElement->setListOfVertex(m_listVertex);
|
tmpElement->setListOfVertex(m_listVertex);
|
||||||
for (int32_t kkk=0; kkk<m_listFaces.size(); kkk++) {
|
for (size_t kkk=0; kkk<m_listFaces.size(); ++kkk) {
|
||||||
tmpElement->addTriangle(m_listFaces.getValue(kkk).m_index);
|
std::vector<uint32_t> index;
|
||||||
|
for (auto &it : m_listFaces.getValue(kkk).m_faces) {
|
||||||
|
index.push_back(it.m_vertex[0]);
|
||||||
|
index.push_back(it.m_vertex[1]);
|
||||||
|
index.push_back(it.m_vertex[2]);
|
||||||
}
|
}
|
||||||
|
//EGE_INFO(" add triangle : " << m_listFaces.getValue(kkk).m_index);
|
||||||
|
|
||||||
|
//tmpElement->addTriangle(m_listFaces.getValue(kkk).m_index);
|
||||||
|
tmpElement->addTriangle(index);
|
||||||
|
}
|
||||||
|
//EGE_CRITICAL("kjlkj");
|
||||||
// Can have only one concave element in a mesh ...
|
// Can have only one concave element in a mesh ...
|
||||||
return m_physics;
|
//return m_physics;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_physics;
|
return m_physics;
|
||||||
|
@ -9,7 +9,7 @@ namespace ege {
|
|||||||
class FaceIndexing {
|
class FaceIndexing {
|
||||||
public:
|
public:
|
||||||
std::vector<Face> m_faces;
|
std::vector<Face> m_faces;
|
||||||
std::vector<uint32_t> m_index;
|
std::vector<uint32_t> m_index; //!< index of the vertex in the VBO not in the Mesh.m_listVertex
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user