diff --git a/ege/Environement.hpp b/ege/Environement.hpp index 428d1da..aaa4905 100644 --- a/ege/Environement.hpp +++ b/ege/Environement.hpp @@ -70,6 +70,7 @@ namespace ege { m_groupSource(_groupSource), m_positionSource(_pos) { }; + virtual ~EntityInteraction() = default; public: virtual void applyEvent(ege::Entity& _entity) { }; }; diff --git a/ege/physics/Component.cpp b/ege/physics/Component.cpp index f36cdf9..5baa1c4 100644 --- a/ege/physics/Component.cpp +++ b/ege/physics/Component.cpp @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include const std::string& ege::physics::Component::getType() const { static std::string tmp("physics"); @@ -63,7 +66,13 @@ ege::physics::Component::Component(ememory::SharedPtr _env, c EGE_ERROR("Bounciness=" << m_rigidBody->getMaterial().getBounciness()); EGE_ERROR("FrictionCoefficient=" << m_rigidBody->getMaterial().getFrictionCoefficient()); EGE_ERROR("RollingResistance=" << m_rigidBody->getMaterial().getRollingResistance()); - m_rigidBody->getMaterial().setFrictionCoefficient(0.5); + EGE_ERROR("LinearDamping=" << m_rigidBody->getLinearDamping()); + EGE_ERROR("AngularDamping=" << m_rigidBody->getAngularDamping()); + m_rigidBody->getMaterial().setBounciness(0.4); + //m_rigidBody->getMaterial().setFrictionCoefficient(0.01); + //m_rigidBody->getMaterial().setRollingResistance(0.01); + m_rigidBody->setAngularDamping(0.9); + m_rigidBody->setLinearDamping(0.9); } void ege::physics::Component::setType(enum ege::physics::Component::type _type) { @@ -117,7 +126,7 @@ void ege::physics::Component::generate() { tmpElement->getSize().y(), tmpElement->getSize().z()); // Create the box shape - rp3d::BoxShape* shape = new rp3d::BoxShape(halfExtents); + rp3d::BoxShape* shape = new rp3d::BoxShape(halfExtents, 0.0001); m_listShape.push_back(shape); rp3d::Vector3 position(it->getOrigin().x(), it->getOrigin().y(), @@ -230,24 +239,52 @@ void ege::physics::Component::generate() { m_listProxyShape.push_back(proxyShape); break; } - case ege::physics::Shape::type::convexHull: { - EGE_DEBUG(" convexHull"); - const ege::physics::shape::ConvexHull* tmpElement = it->toConvexHull(); + case ege::physics::Shape::type::concave: { + EGE_DEBUG(" Concave"); + const ege::physics::shape::Concave* tmpElement = it->toConcave(); if (tmpElement == nullptr) { - EGE_ERROR(" convexHull ==> can not cast in convexHull"); + EGE_ERROR(" Concave ==> can not cast in Concave"); continue; } + + 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; + // TODO : Manage memory leak ... + //we have an error here ... + + rp3d::TriangleVertexArray* triangleArray = new rp3d::TriangleVertexArray(nbVertices, + vertices, + 4 * sizeof(float), + nbTriangles, + indices, + sizeof(int32_t), + rp3d::TriangleVertexArray::VERTEX_FLOAT_TYPE, + rp3d::TriangleVertexArray::INDEX_INTEGER_TYPE); + // 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: + rp3d::TriangleMesh triangleMesh; + // Add the triangle vertex array to the triangle mesh + triangleMesh.addSubpart(triangleArray); + // Create the concave mesh shape /* - 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); - } - } + // TODO : Manage memory leak ... + reactphysics3d::ConcaveShape* shape = new reactphysics3d::ConcaveMeshShape(&triangleMesh); + rp3d::Vector3 position(it->getOrigin().x(), + it->getOrigin().y(), + it->getOrigin().z()); + rp3d::Quaternion orientation(it->getQuaternion().x(), + it->getQuaternion().y(), + it->getQuaternion().z(), + it->getQuaternion().w()); + // The ephysic use Y as UP ==> ege use Z as UP + orientation = orientation * rp3d::Quaternion(-0.707107, 0, 0, 0.707107); + rp3d::Transform transform(position, orientation); + rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass()); + proxyShape->setUserData(this); + m_listProxyShape.push_back(proxyShape); */ break; } diff --git a/ege/physics/shape/Concave.cpp b/ege/physics/shape/Concave.cpp new file mode 100644 index 0000000..dc728bb --- /dev/null +++ b/ege/physics/shape/Concave.cpp @@ -0,0 +1,16 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#include +#include + + + +bool ege::physics::shape::Concave::parse(const char* _line) { + if (ege::physics::Shape::parse(_line) == true) { + return true; + } + return false; +} diff --git a/ege/physics/shape/Concave.hpp b/ege/physics/shape/Concave.hpp new file mode 100644 index 0000000..c5917a8 --- /dev/null +++ b/ege/physics/shape/Concave.hpp @@ -0,0 +1,66 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +#pragma once + + +#include +#include + + +namespace ege { + namespace physics { + namespace shape { + class Concave : public ege::physics::Shape { + public: + Concave() {}; + virtual ~Concave() {}; + public: + virtual bool parse(const char* _line); + virtual void display() {}; + public: + virtual enum ege::physics::Shape::type getType() const { + return ege::physics::Shape::type::concave; + } + public: + virtual const ege::physics::shape::Concave* toConcave() const { + return this; + } + virtual ege::physics::shape::Concave* toConcave() { + return this; + } + private: + std::vector m_listVertex; + std::vector m_indices; // TODO : do it better: this is dependent of ephysics + public: + void clear() { + m_listVertex.clear(); + m_indices.clear(); + } + void setListOfVertex(const std::vector& _listVertex) { + m_listVertex = _listVertex; + } + void addTriangle(const std::vector& _index) { + /* + if (m_indices.size() == 0) { + m_indices = _index; + return; + } + */ + for (auto &it: _index) { + m_indices.push_back(it); + } + } + const std::vector& getVertex() const { + return m_listVertex; + } + const std::vector& getIndices() const { + return m_indices; + } + }; + } + } +} + diff --git a/ege/physics/shape/ConvexHull.cpp b/ege/physics/shape/ConvexHull.cpp index 2928499..347be02 100644 --- a/ege/physics/shape/ConvexHull.cpp +++ b/ege/physics/shape/ConvexHull.cpp @@ -31,6 +31,7 @@ bool ege::physics::shape::ConvexHull::parse(const char* _line) { EGE_VERBOSE(" parsed " << m_points[iii]); } */ + return true; } if(strncmp(_line, "scale:", 6) == 0) { diff --git a/ege/physics/shape/Shape.cpp b/ege/physics/shape/Shape.cpp index f754468..9d55511 100644 --- a/ege/physics/shape/Shape.cpp +++ b/ege/physics/shape/Shape.cpp @@ -11,6 +11,7 @@ #include #include #include +#include ememory::SharedPtr ege::physics::Shape::create(const std::string& _name) { @@ -28,8 +29,10 @@ ememory::SharedPtr ege::physics::Shape::create(const std::s tmpp = ememory::makeShared(); } else if (name == "convexhull") { tmpp = ememory::makeShared(); + } else if (name == "autoconcave") { + tmpp = ememory::makeShared(); } else { - EGE_ERROR("Create an unknow element : '" << _name << "' availlable : [BOX,SPHERE,CONE,CYLINDER,CAPSULE,CONVEXHULL]"); + EGE_ERROR("Create an unknow element : '" << _name << "' availlable : [BOX,SPHERE,CONE,CYLINDER,CAPSULE,CONVEXHULL,autoConcave]"); return nullptr; } if (tmpp == nullptr) { diff --git a/ege/physics/shape/Shape.hpp b/ege/physics/shape/Shape.hpp index 33ada00..bab86ee 100644 --- a/ege/physics/shape/Shape.hpp +++ b/ege/physics/shape/Shape.hpp @@ -21,6 +21,7 @@ namespace ege { class Cone; class ConvexHull; class Sphere; + class Concave; } class Shape { @@ -34,7 +35,8 @@ namespace ege { cone, convexHull, cylinder, - sphere + sphere, + concave }; public: Shape() : @@ -97,6 +99,9 @@ namespace ege { bool isSphere() { return getType() == ege::physics::Shape::type::sphere; }; + bool isConcave() { + return getType() == ege::physics::Shape::type::concave; + }; virtual const ege::physics::shape::Box* toBox() const { return nullptr; @@ -139,6 +144,12 @@ namespace ege { virtual ege::physics::shape::Sphere* toSphere() { return nullptr; }; + virtual const ege::physics::shape::Concave* toConcave() const { + return nullptr; + }; + virtual ege::physics::shape::Concave* toConcave() { + return nullptr; + }; }; } } diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index ba573e9..030822e 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -398,9 +398,9 @@ void ege::resource::Mesh::generateVBO() { } EGE_WARNING("Generate VBO for nb faces layers: " << m_listFaces.size() << " list layer=" << etk::to_string(m_listFaces.getKeys())); - // generate element in 2 pass : - // - create new index dependeng a vertex is a unique componenet of position, texture, normal - // - the index list generation (can be dynamic ... (TODO later) + // generate element in 2 pass: + // - create new index depending on a vertex is a unique component of position, texture, normal + // - the index list generation (can be dynamic ... (TODO later)) for (int32_t kkk=0; kkk +const std::vector>& ege::resource::Mesh::getPhysicalProperties() { + for (auto &it: m_physics) { + if (it->getType() == ege::physics::Shape::type::concave) { + // need to generate the internal list of point and triangle needed: + ege::physics::shape::Concave* tmpElement = it->toConcave(); + if (tmpElement == nullptr) { + EGE_ERROR(" Concave ==> can not cast in Concave"); + return m_physics; + } + tmpElement->clear(); + tmpElement->setListOfVertex(m_listVertex); + for (int32_t kkk=0; kkkaddTriangle(m_listFaces.getValue(kkk).m_index); + } + // Can have only one concave element in a mesh ... + return m_physics; + } + } + return m_physics; +} + diff --git a/ege/resource/Mesh.hpp b/ege/resource/Mesh.hpp index ab80ee5..dab3631 100644 --- a/ege/resource/Mesh.hpp +++ b/ege/resource/Mesh.hpp @@ -28,6 +28,20 @@ namespace ege { namespace resource { + /* TODO: A mesh is composed with: + * - a geometric property: + * * list of points + * * list of normals + * * List of texture UV mapping + * + List of triangle + * + List of quad + * + List of polygones + * - List of material + * - Physics shapes + * - UV texture + * - Normal texture + * - open GL shaders + */ class Mesh : public gale::Resource { public: static ememory::SharedPtr createGrid(int32_t _lineCount, @@ -149,9 +163,7 @@ namespace ege { bool getCheckNormal() { return m_checkNormal; }; - const std::vector>& getPhysicalProperties() const { - return m_physics; - }; + const std::vector>& getPhysicalProperties(); void addPhysicElement(const ememory::SharedPtr& _shape) { m_physics.push_back(_shape); } diff --git a/lutin_ege.py b/lutin_ege.py index 82934ec..702863e 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -72,6 +72,7 @@ def configure(target, my_module): 'ege/physics/shape/ConvexHull.cpp', 'ege/physics/shape/Cylinder.cpp', 'ege/physics/shape/Sphere.cpp', + 'ege/physics/shape/Concave.cpp', 'ege/Ray.cpp', ]) my_module.copy_path('data/ParticuleMesh.*') @@ -121,6 +122,7 @@ def configure(target, my_module): 'ege/physics/shape/ConvexHull.hpp', 'ege/physics/shape/Cylinder.hpp', 'ege/physics/shape/Sphere.hpp', + 'ege/physics/shape/Concave.hpp', 'ege/Ray.hpp', ]) # TODO: Remove this ...