[DEV] collision and basic physics debug
This commit is contained in:
parent
80793fb4da
commit
c25f125dee
@ -1,180 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <ege/debug.hpp>
|
||||
#include <ege/CollisionShapeCreator.hpp>
|
||||
#include <ege/physicsShape/PhysicsShape.hpp>
|
||||
#include <ege/physicsShape/PhysicsBox.hpp>
|
||||
#include <ege/physicsShape/PhysicsCapsule.hpp>
|
||||
#include <ege/physicsShape/PhysicsCone.hpp>
|
||||
#include <ege/physicsShape/PhysicsConvexHull.hpp>
|
||||
#include <ege/physicsShape/PhysicsCylinder.hpp>
|
||||
#include <ege/physicsShape/PhysicsSphere.hpp>
|
||||
|
||||
// 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)");
|
||||
return new btEmptyShape();
|
||||
}
|
||||
const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& physiqueProperty = _mesh->getPhysicalProperties();
|
||||
if (physiqueProperty.size() == 0) {
|
||||
EGE_ERROR("Create empty shape (no default shape)");
|
||||
return new btEmptyShape();
|
||||
}
|
||||
int32_t count = 0;
|
||||
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
|
||||
if (physiqueProperty[iii] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
btCompoundShape* outputShape = nullptr;
|
||||
if (count>1) {
|
||||
EGE_ERROR("Create complexe shape");
|
||||
outputShape = new btCompoundShape();
|
||||
} else {
|
||||
EGE_ERROR("Create simple shape");
|
||||
// TODO : Remove this line ==> it is bad but it correct a bug of a single shape that has no more display
|
||||
outputShape = new btCompoundShape();
|
||||
}
|
||||
for (size_t iii=0; iii<physiqueProperty.size(); iii++) {
|
||||
if (physiqueProperty[iii] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
switch (physiqueProperty[iii]->getType()) {
|
||||
case ege::PhysicsShape::box : {
|
||||
EGE_ERROR(" Box");
|
||||
const ege::PhysicsBox* tmpElement = physiqueProperty[iii]->toBox();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Box ==> can not cast in BOX");
|
||||
continue;
|
||||
}
|
||||
btCollisionShape* tmpShape = new btBoxShape(tmpElement->getSize());
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
EGE_ERROR("Allocation shape error BOX");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ege::PhysicsShape::cylinder : {
|
||||
EGE_DEBUG(" Cylinder");
|
||||
const ege::PhysicsCylinder* tmpElement = physiqueProperty[iii]->toCylinder();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Cylinder ==> can not cast in Cylinder");
|
||||
continue;
|
||||
}
|
||||
btCollisionShape* tmpShape = new btCylinderShape(tmpElement->getSize());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::capsule : {
|
||||
EGE_DEBUG(" Capsule");
|
||||
const ege::PhysicsCapsule* tmpElement = physiqueProperty[iii]->toCapsule();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Capsule ==> can not cast in Capsule");
|
||||
continue;
|
||||
}
|
||||
btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::cone : {
|
||||
EGE_DEBUG(" Cone");
|
||||
const ege::PhysicsCone* tmpElement = physiqueProperty[iii]->toCone();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Cone ==> can not cast in Cone");
|
||||
continue;
|
||||
}
|
||||
btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::sphere : {
|
||||
EGE_DEBUG(" Sphere");
|
||||
const ege::PhysicsSphere* tmpElement = physiqueProperty[iii]->toSphere();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Sphere ==> can not cast in Sphere");
|
||||
continue;
|
||||
}
|
||||
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::convexHull : {
|
||||
EGE_DEBUG(" convexHull");
|
||||
const ege::PhysicsConvexHull* tmpElement = physiqueProperty[iii]->toConvexHull();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" convexHull ==> can not cast in convexHull");
|
||||
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;
|
||||
}
|
||||
default :
|
||||
EGE_DEBUG(" ???");
|
||||
// TODO : UNKNOW type ...
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (outputShape == nullptr) {
|
||||
EGE_DEBUG("create empty shape ...");
|
||||
return new btEmptyShape();
|
||||
}
|
||||
return outputShape;
|
||||
}
|
||||
*/
|
||||
|
@ -1,16 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ege/resource/Mesh.hpp>
|
||||
|
||||
namespace ege {
|
||||
namespace collision {
|
||||
//btCollisionShape* createShape(const ememory::SharedPtr<ege::resource::Mesh>& _mesh);
|
||||
}
|
||||
}
|
||||
|
@ -31,3 +31,7 @@ void ege::Engine::update(const echrono::Duration& _delta) {
|
||||
void ege::Engine::render(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) {
|
||||
|
||||
}
|
||||
|
||||
void ege::Engine::renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) {
|
||||
|
||||
}
|
@ -11,11 +11,14 @@
|
||||
#include <ege/Component.hpp>
|
||||
#include <echrono/Duration.hpp>
|
||||
#include <ege/camera/Camera.hpp>
|
||||
#include <eproperty/Interface.hpp>
|
||||
|
||||
namespace ege {
|
||||
class Environement;
|
||||
class Camera;
|
||||
class Engine : public ememory::EnableSharedFromThis<Engine> {
|
||||
class Engine :
|
||||
public ememory::EnableSharedFromThis<Engine>,
|
||||
public eproperty::Interface {
|
||||
protected:
|
||||
ege::Environement* m_env;
|
||||
public:
|
||||
@ -48,6 +51,12 @@ namespace ege {
|
||||
* @param[in] _camera Camera property to render the engine properties ...
|
||||
*/
|
||||
virtual void render(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera);
|
||||
/**
|
||||
* @brief Globalgame engine main cycle of draw
|
||||
* @param[in] _delta time from the last render
|
||||
* @param[in] _camera Camera property to render the engine properties ...
|
||||
*/
|
||||
virtual void renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ void ege::Environement::engineComponentAdd(const ememory::SharedPtr<ege::Compone
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
ememory::SharedPtr<ege::Element> ege::Environement::getElementNearest(ememory::SharedPtr<ege::Element> _sourceRequest, float& _distance) {
|
||||
if (_sourceRequest == nullptr) {
|
||||
return nullptr;
|
||||
@ -210,6 +210,7 @@ void ege::Environement::getElementNearestFixed(const vec3& _sourcePosition,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
static etk::Hash<ege::createElement_tf>& getHachTableCreating() {
|
||||
static etk::Hash<ege::createElement_tf> s_table;
|
||||
@ -389,60 +390,6 @@ void ege::Environement::rmElement(ememory::SharedPtr<ege::Element> _removeElemen
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : DEPRECATED ==> special function of the renderer ...
|
||||
void ege::Environement::getOrderedElementForDisplay(std::vector<ege::Environement::ResultNearestElement>& _resultList,
|
||||
const vec3& _position,
|
||||
const vec3& _direction) {
|
||||
// TODO : Set it back ... corrected...
|
||||
// remove all unneeded elements (old display...)
|
||||
_resultList.clear();
|
||||
// basic element result
|
||||
ege::Environement::ResultNearestElement result;
|
||||
result.dist = 99999999999.0f;
|
||||
result.element = nullptr;
|
||||
// for all element in the game we chek if it is needed to display it ...
|
||||
for (size_t iii=0; iii<m_listElement.size() ; iii++) {
|
||||
// check nullptr pointer
|
||||
if (m_listElement[iii] == nullptr) {
|
||||
// no pointer null are set in the output list ...
|
||||
continue;
|
||||
}
|
||||
result.element = m_listElement[iii];
|
||||
// check distance ...
|
||||
vec3 destPosition = result.element->getPosition();
|
||||
vec3 angleView = (destPosition - _position);
|
||||
angleView.safeNormalize();
|
||||
float dotResult=angleView.dot(_direction);
|
||||
//EGE_DEBUG("Dot position : " << destPosition << " == > dot=" << dotResult);
|
||||
/*
|
||||
if (dotResult <= 0.85f) {
|
||||
// they are not in the camera angle view ... == > no need to process display
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
result.dist = (_position - destPosition).length();
|
||||
/*
|
||||
if (result.dist>500.0f) {
|
||||
// The element is realy too far ... == > no need to display
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
// try to add the element at the best positions:
|
||||
size_t jjj;
|
||||
for (jjj=0; jjj<_resultList.size(); jjj++) {
|
||||
if (_resultList[jjj].dist>result.dist) {
|
||||
_resultList.insert(_resultList.begin()+jjj, result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// add element at the end :
|
||||
if (jjj >= _resultList.size()) {
|
||||
_resultList.push_back(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ege::Environement::generateInteraction(ege::ElementInteraction& _event) {
|
||||
// inform the element that an element has been removed == > this permit to keep pointer on elements ...
|
||||
for (size_t iii=0; iii<m_listElement.size() ; iii++) {
|
||||
@ -502,6 +449,13 @@ void ege::Environement::render(const echrono::Duration& _delta, const std::strin
|
||||
EGE_VERBOSE(" render: " << it->getType());
|
||||
it->render(_delta, camera);
|
||||
}
|
||||
for (auto &it: m_engine) {
|
||||
if(it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
EGE_VERBOSE(" render: " << it->getType());
|
||||
it->renderDebug(_delta, camera);
|
||||
}
|
||||
}
|
||||
|
||||
void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) {
|
||||
|
@ -181,6 +181,7 @@ namespace ege {
|
||||
* @param[in] _distance Maximum distance search == > return the element distance
|
||||
* @return Pointer on the neares element OR nullptr
|
||||
*/
|
||||
/*
|
||||
ememory::SharedPtr<ege::Element> getElementNearest(ememory::SharedPtr<ege::Element> _sourceRequest, float& _distance);
|
||||
|
||||
void getElementNearest(const vec3& _sourcePosition,
|
||||
@ -189,6 +190,7 @@ namespace ege {
|
||||
void getElementNearestFixed(const vec3& _sourcePosition,
|
||||
float _distanceMax,
|
||||
std::vector<ege::Environement::ResultNearestElement>& _resultList);
|
||||
*/
|
||||
/**
|
||||
* @brief add an element on the list availlable.
|
||||
* @param[in] _newElement Element to add.
|
||||
@ -199,13 +201,6 @@ namespace ege {
|
||||
* @param[in] _removeElement Element to remove.
|
||||
*/
|
||||
void rmElement(ememory::SharedPtr<ege::Element> _removeElement);
|
||||
/**
|
||||
* @brief get the element order from the nearest to the farest, and remove all element that are not in the camera angle and axes.
|
||||
* @param[in,out] _resultList List of the element ordered.
|
||||
* @param[in] _position Camera position in the space.
|
||||
* @param[in] _direction Camera direction of the view.
|
||||
*/
|
||||
void getOrderedElementForDisplay(std::vector<ege::Environement::ResultNearestElement>& _resultList, const vec3& _position, const vec3& _direction);
|
||||
/**
|
||||
* @brief generate an event on all the sub element of the game == > usefull for explosion, or lazer fire ...
|
||||
* @param[in] _event event that might be apply ...
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <ege/debug.hpp>
|
||||
#include <ege/elements/Element.hpp>
|
||||
#include <ege/Environement.hpp>
|
||||
#include <ege/CollisionShapeCreator.hpp>
|
||||
|
||||
|
||||
const std::string& ege::Element::getType() const {
|
||||
@ -20,16 +19,14 @@ const std::string& ege::Element::getType() const {
|
||||
ege::Element::Element(const ememory::SharedPtr<ege::Environement>& _env) :
|
||||
m_env(_env),
|
||||
m_uID(0),
|
||||
m_mesh(),
|
||||
m_life(100),
|
||||
m_lifeMax(100),
|
||||
m_group(0),
|
||||
m_fixe(true),
|
||||
m_radius(0) {
|
||||
static uint32_t unique=0;
|
||||
m_uID = unique;
|
||||
EGE_DEBUG("Create element: uId=" << m_uID);
|
||||
m_debugText.setFontSize(12);
|
||||
//m_debugText.setFontSize(12);
|
||||
unique++;
|
||||
}
|
||||
|
||||
@ -183,27 +180,6 @@ bool ege::Element::unInit() {
|
||||
}
|
||||
|
||||
|
||||
bool ege::Element::loadMesh(const std::string& _meshFileName) {
|
||||
ememory::SharedPtr<ege::resource::Mesh> tmpMesh = ege::resource::Mesh::create(_meshFileName);
|
||||
if(tmpMesh == nullptr) {
|
||||
EGE_ERROR("can not load the resources : " << _meshFileName);
|
||||
return false;
|
||||
}
|
||||
return setMesh(tmpMesh);
|
||||
}
|
||||
|
||||
bool ege::Element::setMesh(ememory::SharedPtr<ege::resource::Mesh> _mesh) {
|
||||
if (m_mesh != nullptr) {
|
||||
m_mesh.reset();
|
||||
}
|
||||
m_mesh = _mesh;
|
||||
// auto load the shape :
|
||||
if (m_mesh == nullptr) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
float ege::Element::getLifeRatio() {
|
||||
if (0 >= m_life) {
|
||||
@ -224,18 +200,12 @@ void ege::Element::setFireOn(int32_t _groupIdSource, int32_t _type, float _power
|
||||
}
|
||||
}
|
||||
|
||||
const vec3& ege::Element::getPosition() {
|
||||
// this is to prevent error like segmentation fault ...
|
||||
static vec3 emptyPosition(-1000000,-1000000,-1000000);
|
||||
return emptyPosition;
|
||||
};
|
||||
|
||||
|
||||
const float lifeBorder = 0.1f;
|
||||
const float lifeHeight = 0.3f;
|
||||
const float lifeWidth = 2.0f;
|
||||
const float lifeYPos = 1.7f;
|
||||
|
||||
#if 0
|
||||
void ege::Element::drawLife(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera) {
|
||||
if (_draw == nullptr) {
|
||||
return;
|
||||
@ -274,16 +244,20 @@ void ege::Element::drawLife(ememory::SharedPtr<ewol::resource::Colored3DObject>
|
||||
_draw->draw(localVertices, myColor, transformationMatrix, false, false);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void ege::Element::drawDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera) {
|
||||
/*
|
||||
m_debugText.clear();
|
||||
m_debugText.setColor(etk::Color<>(0x00, 0xFF, 0x00, 0xFF));
|
||||
m_debugText.setPos(vec3(-20,32,0));
|
||||
m_debugText.print(getType());
|
||||
m_debugText.setPos(vec3(-20,20,0));
|
||||
m_debugText.print("life=("+etk::to_string(getLifeRatio()));
|
||||
*/
|
||||
//m_debugText.print(std::string("Axe=(")+std::string(m_tmpAxe.x())+std::string(",")+etk::UString(m_tmpAxe.y())+etk::UString(",")+etk::UString(m_tmpAxe.z())+etk::UString(")"));
|
||||
/*
|
||||
// TODO : Keep this it can be usefull to print something in direction of the camera ...
|
||||
m_debugText.draw( etk::matTranslate(getPosition())
|
||||
* etk::matRotate(vec3(0,0,1),_camera.getAngleZ())
|
||||
* etk::matRotate(vec3(1,0,0),(M_PI/2.0f-_camera.getAngleTeta()))
|
||||
@ -291,10 +265,6 @@ void ege::Element::drawDebug(ememory::SharedPtr<ewol::resource::Colored3DObject>
|
||||
*/
|
||||
}
|
||||
|
||||
void ege::Element::drawNormalDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -74,40 +74,6 @@ namespace ege {
|
||||
inline uint32_t getUID() const {
|
||||
return m_uID;
|
||||
};
|
||||
/*
|
||||
* *********************************
|
||||
* Remove in progress .... [BEGIN]
|
||||
* *********************************
|
||||
*/
|
||||
protected:
|
||||
ememory::SharedPtr<ege::resource::Mesh> m_mesh; //!< Mesh of the Element (can be nullptr)
|
||||
public:
|
||||
/**
|
||||
* @brief Select a mesh with a specific name.
|
||||
* @param[in] _meshFileName filename of the Mesh.
|
||||
* @note Automaticly load the shape if it is specify in the mesh file
|
||||
* @return true if no error occured
|
||||
*/
|
||||
virtual bool loadMesh(const std::string& _meshFileName);
|
||||
/**
|
||||
* @brief set the the Mesh properties.
|
||||
* @param[in] _mesh The mesh pointer. (nullptr to force the mesh remove ...)
|
||||
* @note : this remove the shape and the mesh properties.
|
||||
* @return true if no error occured
|
||||
*/
|
||||
virtual bool setMesh(ememory::SharedPtr<ege::resource::Mesh> _mesh);
|
||||
/**
|
||||
* @brief get a pointer on the Mesh file.
|
||||
* @return the mesh pointer.
|
||||
*/
|
||||
inline ememory::SharedPtr<ege::resource::Mesh> getMesh() {
|
||||
return m_mesh;
|
||||
};
|
||||
/*
|
||||
* *********************************
|
||||
* Remove in progress .... [END]
|
||||
* *********************************
|
||||
*/
|
||||
protected:
|
||||
float m_life; //!< Current life of the object
|
||||
float m_lifeMax; //!< Maximum possible life of the element
|
||||
@ -160,28 +126,9 @@ namespace ege {
|
||||
inline void setGroup(int32_t _newGroup) {
|
||||
m_group=_newGroup;
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* @brief Can be call tu opdate the list of the element displayed on the scren (example : no display of the hiden triangle)
|
||||
* @param[in] the camera properties
|
||||
* @ note by default nothing to do ...
|
||||
*/
|
||||
virtual void preCalculationDraw(const ege::Camera& _camera) { };
|
||||
/**
|
||||
* @brief draw the curent element (can have multiple display)
|
||||
* @param[in] pass Id of the current pass : [0..?]
|
||||
*/
|
||||
virtual void draw(int32_t _pass=0) { };
|
||||
|
||||
/**
|
||||
* @brief draw the current life of the element
|
||||
*/
|
||||
// TODO : Remove this ...
|
||||
virtual void drawLife(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera);
|
||||
|
||||
protected:
|
||||
// For debug only ...
|
||||
ewol::compositing::Text m_debugText;
|
||||
//ewol::compositing::Text m_debugText; // ==> this is reall y a bad idea==> it is inneficient ...
|
||||
public:
|
||||
/**
|
||||
* @brief Debug display of the current element
|
||||
@ -189,45 +136,11 @@ namespace ege {
|
||||
* @param[in] _camera Current camera for display
|
||||
*/
|
||||
virtual void drawDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera);
|
||||
/**
|
||||
* @brief Debug display of the current element normal face
|
||||
* @param[in,out] _draw Basic system to draw the debug shape and informations
|
||||
* @param[in] _camera Current camera for display
|
||||
*/
|
||||
virtual void drawNormalDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera);
|
||||
|
||||
/**
|
||||
* @brief get the theoric position. Sometimes, the element has move due to an explosion or something else, then its real position in not the one that woult it be at the end ...
|
||||
* @return the theoric position
|
||||
*/
|
||||
virtual vec3 getPositionTheoric() {
|
||||
return getPosition();
|
||||
};
|
||||
/**
|
||||
* @brief get the current position of the element
|
||||
* @return the 3D position.
|
||||
*/
|
||||
virtual const vec3& getPosition();
|
||||
/**
|
||||
* @brief set the current position of the element
|
||||
* @param[in] _pos set the 3D position.
|
||||
*/
|
||||
virtual void setPosition(const vec3& _pos) {};
|
||||
/**
|
||||
* @brief Event arrive when an element has been remove from the system == > this permit to keep pointer of ennemy, and not search them every cycle ...
|
||||
* @param[in] _removedElement Pointer on the element removed.
|
||||
*/
|
||||
virtual void elementIsRemoved(ememory::SharedPtr<ege::Element> _removedElement) { };
|
||||
protected:
|
||||
bool m_fixe; //!< is a fixed element == > used for placement of every elements
|
||||
public:
|
||||
/**
|
||||
* @brief get the element if it is fixed or not. if the element is fixed this is for tower, and all thing does not really move
|
||||
* @return true : The element is fixed.
|
||||
*/
|
||||
inline bool isFixed() {
|
||||
return m_fixe;
|
||||
};
|
||||
protected:
|
||||
float m_radius; //!< Radius of the element (all element have a radius, if == 0 ==> then ghost ...
|
||||
public:
|
||||
|
@ -4,6 +4,9 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
*******************************************
|
||||
** IS REMOVED
|
||||
*******************************************
|
||||
|
||||
#include <ege/elements/ElementBase.hpp>
|
||||
#include <ege/debug.hpp>
|
||||
|
@ -3,6 +3,13 @@
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
*******************************************
|
||||
** IS REMOVED
|
||||
*******************************************
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ege/elements/Element.hpp>
|
||||
|
@ -4,6 +4,13 @@
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
*******************************************
|
||||
** IS REMOVED
|
||||
*******************************************
|
||||
|
||||
|
||||
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ege/debug.hpp>
|
||||
#include <ege/elements/ElementPhysic.hpp>
|
||||
@ -318,41 +325,6 @@ void ege::ElementPhysic::drawShape(/*const btCollisionShape* _shape,*/
|
||||
#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;
|
||||
}
|
||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
|
||||
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm);
|
||||
|
||||
mat4 transformationMatrix(mmm);
|
||||
transformationMatrix.transpose();
|
||||
|
||||
// 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() ) {
|
||||
//EGE_INFO("element pos = " << getPosition());
|
||||
btScalar mmm[16];
|
||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)m_body->getMotionState();
|
||||
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(mmm);
|
||||
|
||||
mat4 transformationMatrix(mmm);
|
||||
transformationMatrix.transpose();
|
||||
m_mesh->drawNormal(transformationMatrix, _draw);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void ege::ElementPhysic::draw(int32_t _pass) {
|
||||
if (m_elementInPhysicsSystem == false) {
|
||||
|
@ -5,6 +5,13 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
*******************************************
|
||||
** IS REMOVED
|
||||
*******************************************
|
||||
|
||||
|
||||
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
#include <etk/math/Matrix4x4.hpp>
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <ege/debug.hpp>
|
||||
#include <ege/particule/Engine.hpp>
|
||||
#include <ege/Environement.hpp>
|
||||
#include <ege/particule/Particule.hpp>
|
||||
#include <ege/particule/Component.hpp>
|
||||
|
||||
ege::particule::Engine::Engine(ege::Environement* _env) :
|
||||
ege::Engine(_env) {
|
||||
@ -88,7 +88,7 @@ void ege::particule::Engine::update(const echrono::Duration& _delta) {
|
||||
if (deltaTime>(1.0f/60.0f)) {
|
||||
deltaTime = (1.0f/60.0f);
|
||||
}
|
||||
EGE_WARNING("Update the Particule engine ... " << deltaTime);
|
||||
EGE_DEBUG("Update the Particule engine ... " << deltaTime);
|
||||
for (size_t iii=0; iii<m_particuleList.size(); ++iii) {
|
||||
if (m_particuleList[iii] == nullptr) {
|
||||
continue;
|
||||
|
@ -25,6 +25,7 @@ ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env) {
|
||||
rp3d::Vector3 initPosition(0.0f, 0.0f, 0.0f);
|
||||
rp3d::Quaternion initOrientation = rp3d::Quaternion::identity();
|
||||
rp3d::Transform transform(initPosition, initOrientation);
|
||||
m_lastTransformEmit = etk::Transform3D(vec3(0,0,0), etk::Quaternion::identity());
|
||||
m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform);
|
||||
}
|
||||
|
||||
@ -40,6 +41,7 @@ ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env, c
|
||||
rp3d::Transform transform(initPosition, initOrientation);
|
||||
// Create a rigid body in the world
|
||||
m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform);
|
||||
m_lastTransformEmit = _transform;
|
||||
}
|
||||
|
||||
void ege::physics::Component::setType(enum ege::physics::Component::type _type) {
|
||||
@ -79,7 +81,7 @@ void ege::physics::Component::generate() {
|
||||
}
|
||||
switch (it->getType()) {
|
||||
case ege::PhysicsShape::box : {
|
||||
EGE_ERROR(" Box");
|
||||
EGE_DEBUG(" Box");
|
||||
const ege::PhysicsBox* tmpElement = it->toBox();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Box ==> can not cast in BOX");
|
||||
@ -92,15 +94,15 @@ void ege::physics::Component::generate() {
|
||||
// Create the box shape
|
||||
rp3d::BoxShape* shape = new rp3d::BoxShape(halfExtents);
|
||||
m_listShape.push_back(shape);
|
||||
rp3d::Vector3 position(tmpElement->getOrigin().x(),
|
||||
tmpElement->getOrigin().y(),
|
||||
tmpElement->getOrigin().z());
|
||||
rp3d::Quaternion orientation(tmpElement->getQuaternion().x(),
|
||||
tmpElement->getQuaternion().y(),
|
||||
tmpElement->getQuaternion().z(),
|
||||
tmpElement->getQuaternion().w());
|
||||
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());
|
||||
rp3d::Transform transform(position, orientation);
|
||||
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, 4.0f /* mass */);
|
||||
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
|
||||
m_listProxyShape.push_back(proxyShape);
|
||||
break;
|
||||
}
|
||||
@ -113,15 +115,15 @@ void ege::physics::Component::generate() {
|
||||
}
|
||||
// Create the box shape
|
||||
rp3d::CylinderShape* shape = new rp3d::CylinderShape(tmpElement->getSize().x(), tmpElement->getSize().y());
|
||||
rp3d::Vector3 position(tmpElement->getOrigin().x(),
|
||||
tmpElement->getOrigin().y(),
|
||||
tmpElement->getOrigin().z());
|
||||
rp3d::Quaternion orientation(tmpElement->getQuaternion().x(),
|
||||
tmpElement->getQuaternion().y(),
|
||||
tmpElement->getQuaternion().z(),
|
||||
tmpElement->getQuaternion().w());
|
||||
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());
|
||||
rp3d::Transform transform(position, orientation);
|
||||
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, 4.0f /* mass */);
|
||||
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
|
||||
m_listProxyShape.push_back(proxyShape);
|
||||
break;
|
||||
}
|
||||
@ -218,6 +220,46 @@ void ege::physics::Component::generate() {
|
||||
}
|
||||
|
||||
|
||||
void ege::physics::Component::emitAll() {
|
||||
// emit onbly of new ...
|
||||
etk::Transform3D transform = getTransform();
|
||||
if (m_lastTransformEmit != transform) {
|
||||
m_lastTransformEmit = transform;
|
||||
signalPosition.emit(transform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ege::physics::Component::setTransform(const etk::Transform3D& _transform) {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return;
|
||||
}
|
||||
rp3d::Vector3 position(_transform.getPosition().x(),
|
||||
_transform.getPosition().y(),
|
||||
_transform.getPosition().z());
|
||||
rp3d::Quaternion orientation(_transform.getOrientation().x(),
|
||||
_transform.getOrientation().y(),
|
||||
_transform.getOrientation().z(),
|
||||
_transform.getOrientation().w());
|
||||
rp3d::Transform transform(position, orientation);
|
||||
m_rigidBody->setTransform(transform);
|
||||
}
|
||||
|
||||
etk::Transform3D ege::physics::Component::getTransform() const {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return etk::Transform3D::identity();
|
||||
}
|
||||
rp3d::Transform transform = m_rigidBody->getTransform();
|
||||
vec3 position(transform.getPosition().x,
|
||||
transform.getPosition().y,
|
||||
transform.getPosition().z);
|
||||
etk::Quaternion orientation(transform.getOrientation().x,
|
||||
transform.getOrientation().y,
|
||||
transform.getOrientation().z,
|
||||
transform.getOrientation().w);
|
||||
return etk::Transform3D(position, orientation);
|
||||
}
|
||||
|
||||
vec3 ege::physics::Component::getLinearVelocity() const {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return vec3(0,0,0);
|
||||
@ -269,33 +311,138 @@ void ege::physics::Component::addShape(const ememory::SharedPtr<ege::PhysicsShap
|
||||
m_shape.push_back(_shape);
|
||||
}
|
||||
|
||||
void ege::physics::Component::setTransform(const etk::Transform3D& _transform) {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return;
|
||||
}
|
||||
rp3d::Vector3 position(_transform.getPosition().x(),
|
||||
_transform.getPosition().y(),
|
||||
_transform.getPosition().z());
|
||||
rp3d::Quaternion orientation(_transform.getOrientation().x(),
|
||||
_transform.getOrientation().y(),
|
||||
_transform.getOrientation().z(),
|
||||
_transform.getOrientation().w());
|
||||
rp3d::Transform transform(position, orientation);
|
||||
m_rigidBody->setTransform(transform);
|
||||
}
|
||||
|
||||
etk::Transform3D ege::physics::Component::getTransform() const {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return etk::Transform3D::identity();
|
||||
void ege::physics::Component::drawShape(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera) {
|
||||
etk::Transform3D transform = getTransform();
|
||||
float mmm[16];
|
||||
// Get the OpenGL matrix array of the transform
|
||||
transform.getOpenGLMatrix(mmm);
|
||||
mat4 transformationMatrix(mmm);
|
||||
transformationMatrix.transpose();
|
||||
etk::Color<float> tmpColor(1.0, 0.0, 0.0, 0.3);
|
||||
for (auto &it: m_shape) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
switch (it->getType()) {
|
||||
case ege::PhysicsShape::box: {
|
||||
EGE_DEBUG(" Box");
|
||||
const ege::PhysicsBox* tmpElement = it->toBox();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Box ==> can not cast in BOX");
|
||||
continue;
|
||||
}
|
||||
etk::Transform3D transformLocal(it->getOrigin(), it->getOrientation());
|
||||
transformLocal.getOpenGLMatrix(mmm);
|
||||
mat4 transformationMatrixLocal(mmm);
|
||||
transformationMatrixLocal.transpose();
|
||||
transformationMatrixLocal = transformationMatrix * transformationMatrixLocal;
|
||||
_draw->drawSquare(tmpElement->getSize(), transformationMatrixLocal, tmpColor);
|
||||
break;
|
||||
}
|
||||
case ege::PhysicsShape::cylinder : {
|
||||
EGE_DEBUG(" Cylinder");
|
||||
const ege::PhysicsCylinder* tmpElement = it->toCylinder();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Cylinder ==> can not cast in Cylinder");
|
||||
continue;
|
||||
}
|
||||
etk::Transform3D transformLocal(it->getOrigin(), it->getOrientation());
|
||||
transformLocal.getOpenGLMatrix(mmm);
|
||||
mat4 transformationMatrixLocal(mmm);
|
||||
transformationMatrixLocal.transpose();
|
||||
transformationMatrixLocal = transformationMatrix * transformationMatrixLocal;
|
||||
//_draw->drawSphere(radius, 10, 10, _transformationMatrix, tmpColor);
|
||||
break;
|
||||
}
|
||||
case ege::PhysicsShape::capsule : {
|
||||
EGE_DEBUG(" Capsule");
|
||||
const ege::PhysicsCapsule* tmpElement = it->toCapsule();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Capsule ==> can not cast in Capsule");
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
btCollisionShape* tmpShape = new btCapsuleShape(tmpElement->getRadius(), tmpElement->getHeight());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::cone : {
|
||||
EGE_DEBUG(" Cone");
|
||||
const ege::PhysicsCone* tmpElement = it->toCone();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Cone ==> can not cast in Cone");
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
btCollisionShape* tmpShape = new btConeShape(tmpElement->getRadius(), tmpElement->getHeight());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::sphere : {
|
||||
EGE_DEBUG(" Sphere");
|
||||
const ege::PhysicsSphere* tmpElement = it->toSphere();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" Sphere ==> can not cast in Sphere");
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
btCollisionShape* tmpShape = new btSphereShape(tmpElement->getRadius());
|
||||
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;
|
||||
}
|
||||
case ege::PhysicsShape::convexHull : {
|
||||
EGE_DEBUG(" convexHull");
|
||||
const ege::PhysicsConvexHull* tmpElement = it->toConvexHull();
|
||||
if (tmpElement == nullptr) {
|
||||
EGE_ERROR(" convexHull ==> can not cast in convexHull");
|
||||
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;
|
||||
}
|
||||
default :
|
||||
EGE_DEBUG(" ???");
|
||||
// TODO : UNKNOW type ...
|
||||
break;
|
||||
}
|
||||
}
|
||||
rp3d::Transform transform = m_rigidBody->getTransform();
|
||||
vec3 position(transform.getPosition().x,
|
||||
transform.getPosition().y,
|
||||
transform.getPosition().z);
|
||||
etk::Quaternion orientation(transform.getOrientation().x,
|
||||
transform.getOrientation().y,
|
||||
transform.getOrientation().z,
|
||||
transform.getOrientation().w);
|
||||
return etk::Transform3D(position, orientation);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <esignal/Signal.hpp>
|
||||
#include <ephysics/reactphysics3d.h>
|
||||
#include <ege/resource/Mesh.hpp>
|
||||
#include <ege/camera/Camera.hpp>
|
||||
|
||||
namespace ege {
|
||||
class Environement;
|
||||
@ -20,6 +21,8 @@ namespace ege {
|
||||
class Component : public ege::Component {
|
||||
public:
|
||||
esignal::Signal<etk::Transform3D> signalPosition;
|
||||
protected:
|
||||
etk::Transform3D m_lastTransformEmit;
|
||||
protected:
|
||||
ememory::SharedPtr<ege::physics::Engine> m_engine;
|
||||
rp3d::RigidBody* m_rigidBody;
|
||||
@ -82,6 +85,10 @@ namespace ege {
|
||||
void setShape(const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& _prop);
|
||||
void addShape(const ememory::SharedPtr<ege::PhysicsShape>& _shape);
|
||||
void generate();
|
||||
void drawShape(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw, ememory::SharedPtr<ege::Camera> _camera);
|
||||
private:
|
||||
void emitAll();
|
||||
friend class ege::physics::Engine;
|
||||
};
|
||||
}
|
||||
}
|
@ -12,22 +12,36 @@
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <etk/math/Matrix4x4.hpp>
|
||||
|
||||
#include <ege/elements/ElementPhysic.hpp>
|
||||
|
||||
const std::string& ege::physics::Engine::getType() const {
|
||||
static std::string tmp("physics");
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void ege::physics::Engine::componentRemove(const ememory::SharedPtr<ege::Component>& _ref) {
|
||||
|
||||
ememory::SharedPtr<ege::physics::Component> ref = ememory::dynamicPointerCast<ege::physics::Component>(_ref);
|
||||
for (auto it=m_component.begin();
|
||||
it != m_component.end();
|
||||
++it) {
|
||||
if (*it == ref) {
|
||||
it->reset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ege::physics::Engine::componentAdd(const ememory::SharedPtr<ege::Component>& _ref) {
|
||||
|
||||
ememory::SharedPtr<ege::physics::Component> ref = ememory::dynamicPointerCast<ege::physics::Component>(_ref);
|
||||
for (auto it=m_component.begin();
|
||||
it != m_component.end();
|
||||
++it) {
|
||||
if (*it == nullptr) {
|
||||
*it = ref;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_component.push_back(ref);
|
||||
}
|
||||
|
||||
|
||||
// unique callback function :
|
||||
/*
|
||||
extern ContactProcessedCallback gContactProcessedCallback;
|
||||
@ -54,8 +68,11 @@ static bool handleContactsProcess(btManifoldPoint& _point, btCollisionObject* _b
|
||||
|
||||
ege::physics::Engine::Engine(ege::Environement* _env) :
|
||||
ege::Engine(_env),
|
||||
propertyDebugAABB(this, "debug-AABB", false, "display the global AABB box of every shape"),
|
||||
propertyDebugShape(this, "debug-shape", false, "display the physic shape"),
|
||||
m_dynamicsWorld(nullptr),
|
||||
m_accumulator(0.0f) {
|
||||
m_debugDrawProperty = ewol::resource::Colored3DObject::create();
|
||||
// Start engine with no gravity
|
||||
//rp3d::Vector3 gravity(0.0, -9.81, 0.0); // generic earth gravity
|
||||
rp3d::Vector3 gravity(0.0f, 0.0f, 0.0f);
|
||||
@ -92,13 +109,34 @@ void ege::physics::Engine::update(const echrono::Duration& _delta) {
|
||||
while (m_accumulator >= timeStep) {
|
||||
if (m_dynamicsWorld != nullptr) {
|
||||
// Update the Dynamics world with a constant time step
|
||||
EGE_WARNING("Update the Physic engine ... " << timeStep);
|
||||
EGE_DEBUG("Update the Physic engine ... " << timeStep);
|
||||
m_dynamicsWorld->update(timeStep);
|
||||
}
|
||||
// Decrease the accumulated time
|
||||
m_accumulator -= timeStep;
|
||||
}
|
||||
for (auto &it: m_component) {
|
||||
// check nullptr pointer
|
||||
if (it == nullptr) {
|
||||
// no pointer null are set in the output list ...
|
||||
continue;
|
||||
}
|
||||
it->emitAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ege::physics::Engine::renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) {
|
||||
if (propertyDebugShape.get() == true) {
|
||||
for (auto &it : m_component) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
it->drawShape(m_debugDrawProperty, _camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::vector<ege::physics::Engine::collisionPoints> ege::physics::Engine::getListOfCollision() {
|
||||
std::vector<collisionPoints> out;
|
||||
@ -133,3 +171,4 @@ std::vector<ege::physics::Engine::collisionPoints> ege::physics::Engine::getList
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -23,11 +23,16 @@ namespace ege {
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <ephysics/reactphysics3d.h>
|
||||
#include <ege/physics/Component.hpp>
|
||||
#include <eproperty/Value.hpp>
|
||||
|
||||
|
||||
namespace ege {
|
||||
namespace physics {
|
||||
class Engine : public ege::Engine {
|
||||
public:
|
||||
eproperty::Value<bool> propertyDebugAABB;
|
||||
eproperty::Value<bool> propertyDebugShape;
|
||||
private:
|
||||
rp3d::DynamicsWorld* m_dynamicsWorld;
|
||||
float m_accumulator; // limit call of the step rendering
|
||||
@ -74,12 +79,16 @@ namespace ege {
|
||||
rp3d::DynamicsWorld* getDynamicWorld() {
|
||||
return m_dynamicsWorld;
|
||||
}
|
||||
protected:
|
||||
std::vector<ememory::SharedPtr<ege::physics::Component>> m_component;
|
||||
//TODO : set it not in ewol ...
|
||||
ememory::SharedPtr<ewol::resource::Colored3DObject> m_debugDrawProperty;
|
||||
public:
|
||||
const std::string& getType() const override;
|
||||
void componentRemove(const ememory::SharedPtr<ege::Component>& _ref) override;
|
||||
void componentAdd(const ememory::SharedPtr<ege::Component>& _ref) override;
|
||||
void update(const echrono::Duration& _delta) override;
|
||||
//void render(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) override;
|
||||
void renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -41,15 +41,20 @@ ememory::SharedPtr<ege::PhysicsShape> ege::PhysicsShape::create(const std::strin
|
||||
|
||||
bool ege::PhysicsShape::parse(const char* _line) {
|
||||
if(strncmp(_line, "origin:", 7) == 0) {
|
||||
sscanf(&_line[9], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] );
|
||||
sscanf(&_line[7], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] );
|
||||
EGE_VERBOSE(" Origin=" << m_origin);
|
||||
return true;
|
||||
}
|
||||
if(strncmp(_line, "rotate:", 7) == 0) {
|
||||
sscanf(&_line[9], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] );
|
||||
sscanf(&_line[7], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] );
|
||||
EGE_VERBOSE(" rotate=" << m_quaternion);
|
||||
return true;
|
||||
}
|
||||
if(strncmp(_line, "mass:", 5) == 0) {
|
||||
sscanf(&_line[5], "%f", &m_mass );
|
||||
EGE_VERBOSE(" mass=" << m_mass);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/math/Vector4D.hpp>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
#include <etk/math/Quaternion.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
|
||||
|
||||
@ -35,34 +36,47 @@ namespace ege {
|
||||
public:
|
||||
PhysicsShape() :
|
||||
m_quaternion(1,0,0,0),
|
||||
m_origin(0,0,0) {
|
||||
m_origin(0,0,0),
|
||||
m_mass(1) { // by default set mass at 1g
|
||||
|
||||
};
|
||||
}
|
||||
virtual ~PhysicsShape() {
|
||||
|
||||
};
|
||||
}
|
||||
public:
|
||||
virtual enum ege::PhysicsShape::type getType() const {
|
||||
return ege::PhysicsShape::unknow;
|
||||
};
|
||||
}
|
||||
|
||||
public:
|
||||
virtual bool parse(const char* _line);
|
||||
virtual void display() {
|
||||
|
||||
};
|
||||
}
|
||||
private:
|
||||
vec4 m_quaternion;
|
||||
public:
|
||||
const vec4& getQuaternion() const {
|
||||
return m_quaternion;
|
||||
};
|
||||
}
|
||||
etk::Quaternion getOrientation() const {
|
||||
return etk::Quaternion(m_quaternion.x(), m_quaternion.y(), m_quaternion.z(), m_quaternion.w());
|
||||
}
|
||||
private:
|
||||
vec3 m_origin;
|
||||
public:
|
||||
const vec3& getOrigin() const {
|
||||
return m_origin;
|
||||
};
|
||||
private:
|
||||
float m_mass; //!< element mass in "g" then 1000 for 1kg
|
||||
public:
|
||||
float getMass() const {
|
||||
return m_mass;
|
||||
}
|
||||
void setMass(float _mass) {
|
||||
m_mass = _mass;
|
||||
}
|
||||
public:
|
||||
bool isBox() {
|
||||
return getType() == ege::PhysicsShape::box;
|
||||
|
@ -76,13 +76,22 @@ void ege::render::Component::draw(int32_t _pass) {
|
||||
float mmm[16];
|
||||
// Get the OpenGL matrix array of the transform
|
||||
m_transform.getOpenGLMatrix(mmm);
|
||||
|
||||
//EGE_INFO(" mat = " << mat4(mmm));
|
||||
mat4 transformationMatrix(mmm);
|
||||
//mat4 transformationMatrix = mat4(mmm) * etk::matScale(vec3(20,20,20));
|
||||
transformationMatrix.transpose();
|
||||
// TODO: check this : transformationMatrix.transpose();
|
||||
m_mesh->draw(transformationMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ege::render::Component::drawNormalDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw) {
|
||||
if(m_mesh != nullptr) {
|
||||
float mmm[16];
|
||||
// Get the OpenGL matrix array of the transform
|
||||
m_transform.getOpenGLMatrix(mmm);
|
||||
mat4 transformationMatrix(mmm);
|
||||
transformationMatrix.transpose();
|
||||
m_mesh->drawNormal(transformationMatrix, _draw);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,11 @@ namespace ege {
|
||||
* @param[in] pass Id of the current pass : [0..?]
|
||||
*/
|
||||
virtual void draw(int32_t _pass=0);
|
||||
|
||||
/**
|
||||
* @brief Debug display of the current element normal face
|
||||
* @param[in,out] _draw Basic system to draw the debug shape and informations
|
||||
*/
|
||||
void drawNormalDebug(ememory::SharedPtr<ewol::resource::Colored3DObject> _draw);
|
||||
public:
|
||||
const std::string& getType() const override;
|
||||
void addFriendComponent(const ememory::SharedPtr<ege::Component>& _component) override;
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include <ege/render/Engine.hpp>
|
||||
|
||||
ege::render::Engine::Engine(ege::Environement* _env) :
|
||||
ege::Engine(_env) {
|
||||
|
||||
ege::Engine(_env),
|
||||
propertyDebugNormal(this, "debug-normal", false, "display the normal debug information") {
|
||||
m_debugDrawProperty = ewol::resource::Colored3DObject::create();
|
||||
}
|
||||
|
||||
const std::string& ege::render::Engine::getType() const {
|
||||
@ -17,7 +18,7 @@ const std::string& ege::render::Engine::getType() const {
|
||||
|
||||
void ege::render::Engine::componentRemove(const ememory::SharedPtr<ege::Component>& _ref) {
|
||||
ememory::SharedPtr<ege::render::Component> ref = ememory::dynamicPointerCast<ege::render::Component>(_ref);
|
||||
for (auto it=m_component.begin();
|
||||
for (auto it = m_component.begin();
|
||||
it != m_component.end();
|
||||
++it) {
|
||||
if (*it == ref) {
|
||||
@ -95,13 +96,14 @@ void ege::render::Engine::getOrderedElementForDisplay(std::vector<ege::render::E
|
||||
#define NUMBER_OF_SUB_PASS (5)
|
||||
|
||||
void ege::render::Engine::render(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) {
|
||||
/*
|
||||
for (auto &it : m_component) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
//EGE_DEBUG("Draw (start)");
|
||||
mat4 tmpMatrix;
|
||||
getOrderedElementForDisplay(m_displayElementOrdered, _camera->getEye(), _camera->getViewVector());
|
||||
@ -118,6 +120,13 @@ void ege::render::Engine::render(const echrono::Duration& _delta, const ememory:
|
||||
it.element->draw(pass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ege::render::Engine::renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) {
|
||||
//EGE_DEBUG("Draw (start)");
|
||||
mat4 tmpMatrix;
|
||||
getOrderedElementForDisplay(m_displayElementOrdered, _camera->getEye(), _camera->getViewVector());
|
||||
EGE_VERBOSE("DRAW : " << m_displayElementOrdered.size() << "/" << m_component.size() << " elements");
|
||||
#if 0
|
||||
if (propertyDebugPhysic.get() == true) {
|
||||
// Draw debug ... (Object)
|
||||
@ -134,13 +143,14 @@ void ege::render::Engine::render(const echrono::Duration& _delta, const ememory:
|
||||
}
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
if (propertyDebugNormal.get() == true) {
|
||||
// Draw debug ... (Object)
|
||||
for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) {
|
||||
m_displayElementOrdered[iii].element->drawNormalDebug(m_debugDrawProperty, camera);
|
||||
m_displayElementOrdered[iii].element->drawNormalDebug(m_debugDrawProperty);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (propertyDebugApplication.get() == true) {
|
||||
// Draw debug ... (User)
|
||||
signalDisplayDebug.emit(m_debugDrawProperty);
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <ege/debug.hpp>
|
||||
#include <ege/render/Component.hpp>
|
||||
#include <ege/Engine.hpp>
|
||||
#include <eproperty/Value.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
|
||||
|
||||
namespace ege {
|
||||
@ -20,6 +22,7 @@ namespace ege {
|
||||
public:
|
||||
Engine(ege::Environement* _env);
|
||||
~Engine() {}
|
||||
eproperty::Value<bool> propertyDebugNormal;
|
||||
protected:
|
||||
std::vector<ememory::SharedPtr<ege::render::Component>> m_component;
|
||||
class ResultNearestElement {
|
||||
@ -28,14 +31,17 @@ namespace ege {
|
||||
float dist;
|
||||
};
|
||||
std::vector<ege::render::Engine::ResultNearestElement> m_displayElementOrdered;
|
||||
//TODO : set it not in ewol ...
|
||||
ememory::SharedPtr<ewol::resource::Colored3DObject> m_debugDrawProperty;
|
||||
public:
|
||||
const std::string& getType() const override;
|
||||
void componentRemove(const ememory::SharedPtr<ege::Component>& _ref) override;
|
||||
void componentAdd(const ememory::SharedPtr<ege::Component>& _ref) override;
|
||||
void render(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) override;
|
||||
void renderDebug(const echrono::Duration& _delta, const ememory::SharedPtr<ege::Camera>& _camera) override;
|
||||
void getOrderedElementForDisplay(std::vector<ege::render::Engine::ResultNearestElement>& _resultList,
|
||||
const vec3& _position,
|
||||
const vec3& _direction);
|
||||
const vec3& _position,
|
||||
const vec3& _direction);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <ege/resource/tools/icoSphere.hpp>
|
||||
|
||||
ege::resource::Mesh::Mesh() :
|
||||
m_normalMode(normalModeNone),
|
||||
m_normalMode(ege::resource::Mesh::normalMode::none),
|
||||
m_checkNormal(false),
|
||||
m_GLPosition(-1),
|
||||
m_GLMatrix(-1),
|
||||
@ -138,7 +138,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix,
|
||||
m_GLprogram->sendAttributePointer(m_GLtexture, m_verticesVBO, MESH_VBO_TEXTURE);
|
||||
}
|
||||
// position :
|
||||
if (m_normalMode != normalModeNone) {
|
||||
if (m_normalMode != ege::resource::Mesh::normalMode::none) {
|
||||
m_GLprogram->sendAttributePointer(m_GLNormal, m_verticesVBO, MESH_VBO_VERTICES_NORMAL);
|
||||
#if DEBUG
|
||||
// TODO : ...
|
||||
@ -184,7 +184,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix,
|
||||
std::vector<ege::Face>& tmppFaces = m_listFaces.getValue(kkk).m_faces;
|
||||
//std::vector<uint32_t>& tmppIndex = m_listFaces.getValue(kkk).m_index;
|
||||
switch(m_normalMode) {
|
||||
case normalModeFace:
|
||||
case ege::resource::Mesh::normalMode::face:
|
||||
for(size_t iii=0; iii<tmppFaces.size() ; ++iii) {
|
||||
if((mattttt * m_listFacesNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= 0.0f) {
|
||||
tmpIndexResult.push_back(iii*3);
|
||||
@ -193,7 +193,7 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case normalModeVertex:
|
||||
case ege::resource::Mesh::normalMode::vertex:
|
||||
for(size_t iii=0; iii<tmppFaces.size() ; ++iii) {
|
||||
if( ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= -0.2f)
|
||||
|| ((mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]]).dot(cameraNormal) >= -0.2f)
|
||||
@ -278,17 +278,17 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix,
|
||||
FaceIndexing& tmpFaceList = m_listFaces.getValue(kkk);
|
||||
for (size_t iii=0; iii<tmpFaceList.m_faces.size() ; iii++) {
|
||||
switch(m_normalMode) {
|
||||
case normalModeVertex:
|
||||
case ege::resource::Mesh::normalMode::vertex:
|
||||
{
|
||||
// dsplay normal for each vertice ... (TODO: not tested ...)
|
||||
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||
vec3 position = m_listVertex[tmpFaceList.m_faces[iii].m_vertex[indice]];
|
||||
vec3 normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]];
|
||||
vertices.push_back(position);
|
||||
vertices.push_back(position+normal*0.25f);
|
||||
vertices.push_back(position+normal*0.5f);
|
||||
}
|
||||
} break;
|
||||
case normalModeFace:
|
||||
case ege::resource::Mesh::normalMode::face:
|
||||
{
|
||||
vec3 center(0,0,0);
|
||||
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||
@ -296,11 +296,16 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix,
|
||||
center += position;
|
||||
}
|
||||
center /= float(nbIndicInFace);
|
||||
vec3 normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[0]];
|
||||
int32_t index = tmpFaceList.m_faces[iii].m_normal[0];
|
||||
if (index >= m_listFacesNormal.size()) {
|
||||
EGE_ERROR("not enougth normal in the buffer ... " << index << " >= " << m_listFacesNormal.size());
|
||||
return;
|
||||
}
|
||||
vec3 normal = m_listFacesNormal[index];
|
||||
vertices.push_back(center);
|
||||
vertices.push_back(center+normal*0.25f);
|
||||
vertices.push_back(center+normal*0.5f);
|
||||
} break;
|
||||
case normalModeNone:
|
||||
case ege::resource::Mesh::normalMode::none:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -308,11 +313,15 @@ void ege::resource::Mesh::drawNormal(mat4& _positionMatrix,
|
||||
_draw->drawLine(vertices, tmpColor, _positionMatrix);
|
||||
}
|
||||
|
||||
void ege::resource::Mesh::setNormalMode(enum normalMode _mode) {
|
||||
m_normalMode = _mode;
|
||||
}
|
||||
|
||||
// normal calculation of the normal face is really easy :
|
||||
// TODO : Use it for multiple Material interface
|
||||
void ege::resource::Mesh::calculateNormaleFace(const std::string& _materialName) {
|
||||
m_listFacesNormal.clear();
|
||||
if (m_normalMode == ege::resource::Mesh::normalModeFace) {
|
||||
if (m_normalMode == ege::resource::Mesh::normalMode::face) {
|
||||
EGE_VERBOSE("calculateNormaleFace(" << _materialName << ")");
|
||||
gale::openGL::renderMode tmpRenderMode = m_materials[_materialName]->getRenderMode();
|
||||
if ( tmpRenderMode == gale::openGL::renderMode::point
|
||||
@ -320,25 +329,30 @@ void ege::resource::Mesh::calculateNormaleFace(const std::string& _materialName)
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineStrip
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineLoop) {
|
||||
EGE_ERROR("calculateNormaleFace(" << _materialName << ") : can not calculate normal on lines ...");
|
||||
m_normalMode = ege::resource::Mesh::normalModeNone;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::none;
|
||||
return;
|
||||
}
|
||||
for(auto &it : m_listFaces[_materialName].m_faces) {
|
||||
// for all case, We use only the 3 vertex for quad element, in theory 3D modeler export element in triangle if it is not a real plane.
|
||||
vec3 normal = (m_listVertex[it.m_vertex[0]]-m_listVertex[it.m_vertex[1]]).cross(m_listVertex[it.m_vertex[1]]-m_listVertex[it.m_vertex[2]]);
|
||||
//EGE_INFO("normal: " << normal.normalized());
|
||||
if (normal == vec3(0,0,0)) {
|
||||
EGE_ERROR("Null vertor for a face ... " << m_listVertex[it.m_vertex[0]] << " " << m_listVertex[it.m_vertex[1]] << " " << m_listVertex[it.m_vertex[2]]);
|
||||
m_listFacesNormal.push_back(vec3(1,0,0));
|
||||
} else {
|
||||
m_listFacesNormal.push_back(normal.normalized());
|
||||
}
|
||||
int32_t normalID = m_listFacesNormal.size() - 1;
|
||||
it.m_normal[0] = normalID;
|
||||
it.m_normal[1] = normalID;
|
||||
it.m_normal[2] = normalID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName) {
|
||||
m_listVertexNormal.clear();
|
||||
if (m_normalMode == ege::resource::Mesh::normalModeVertex) {
|
||||
if (m_normalMode == ege::resource::Mesh::normalMode::vertex) {
|
||||
EGE_INFO("calculateNormaleEdge(" << _materialName << ")");
|
||||
gale::openGL::renderMode tmpRenderMode = m_materials[_materialName]->getRenderMode();
|
||||
if ( tmpRenderMode == gale::openGL::renderMode::point
|
||||
@ -346,7 +360,7 @@ void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName)
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineStrip
|
||||
|| tmpRenderMode == gale::openGL::renderMode::lineLoop) {
|
||||
EGE_ERROR("calculateNormaleEdge(" << _materialName << ") : can not calculate normal on lines ...");
|
||||
m_normalMode = ege::resource::Mesh::normalModeNone;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::none;
|
||||
return;
|
||||
}
|
||||
for(size_t iii=0 ; iii<m_listVertex.size() ; iii++) {
|
||||
@ -376,7 +390,7 @@ void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName)
|
||||
|
||||
void ege::resource::Mesh::generateVBO() {
|
||||
// calculate the normal of all faces if needed
|
||||
if ( m_normalMode != ege::resource::Mesh::normalModeNone
|
||||
if ( m_normalMode != ege::resource::Mesh::normalMode::none
|
||||
&& m_listFacesNormal.size() == 0) {
|
||||
// when no normal detected == > auto generate Face normal ....
|
||||
EGE_ERROR("Calculate normal face ... in case ????");
|
||||
@ -436,14 +450,14 @@ void ege::resource::Mesh::generateVBO() {
|
||||
// get Normal
|
||||
vec3 normal;
|
||||
switch(m_normalMode) {
|
||||
case normalModeVertex:
|
||||
case ege::resource::Mesh::normalMode::vertex:
|
||||
normal = m_listVertexNormal[tmpFaceList.m_faces[iii].m_normal[indice]];
|
||||
break;
|
||||
case normalModeFace:
|
||||
case ege::resource::Mesh::normalMode::face:
|
||||
normal = m_listFacesNormal[tmpFaceList.m_faces[iii].m_normal[indice]];
|
||||
break;
|
||||
default:
|
||||
case normalModeNone:
|
||||
case ege::resource::Mesh::normalMode::none:
|
||||
break;
|
||||
}
|
||||
// get Texture Position
|
||||
@ -471,7 +485,7 @@ void ege::resource::Mesh::generateVBO() {
|
||||
#endif
|
||||
if (elementFind == false) {
|
||||
m_verticesVBO->pushOnBuffer(MESH_VBO_VERTICES, position);
|
||||
if (m_normalMode != normalModeNone) {
|
||||
if (m_normalMode != ege::resource::Mesh::normalMode::none) {
|
||||
m_verticesVBO->pushOnBuffer(MESH_VBO_VERTICES_NORMAL, normal);
|
||||
}
|
||||
m_verticesVBO->pushOnBuffer(MESH_VBO_TEXTURE, texturepos);
|
||||
@ -493,14 +507,14 @@ void ege::resource::Mesh::generateVBO() {
|
||||
|
||||
|
||||
void ege::resource::Mesh::createViewBox(const std::string& _materialName,float _size) {
|
||||
m_normalMode = normalModeNone;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::none;
|
||||
ege::viewBox::create(m_materials, m_listFaces, m_listVertex, m_listUV,
|
||||
_materialName, _size);
|
||||
calculateNormaleFace(_materialName);
|
||||
}
|
||||
|
||||
void ege::resource::Mesh::createIcoSphere(const std::string& _materialName,float _size, int32_t _subdivision) {
|
||||
m_normalMode = normalModeNone;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::none;
|
||||
ege::icoSphere::create(m_materials, m_listFaces, m_listVertex, m_listUV,
|
||||
_materialName, _size, _subdivision);
|
||||
calculateNormaleFace(_materialName);
|
||||
|
@ -41,13 +41,16 @@ namespace ege {
|
||||
/**
|
||||
* @not_in_doc
|
||||
*/
|
||||
enum normalMode {
|
||||
normalModeNone,
|
||||
normalModeFace,
|
||||
normalModeVertex,
|
||||
enum class normalMode {
|
||||
none,
|
||||
face,
|
||||
vertex,
|
||||
};
|
||||
protected:
|
||||
enum normalMode m_normalMode; // select the normal mode of display
|
||||
public:
|
||||
void setNormalMode(enum normalMode _mode);
|
||||
protected:
|
||||
bool m_checkNormal; //!< when enable, this check the normal of the mesh before sending it at the 3d card
|
||||
protected:
|
||||
ememory::SharedPtr<gale::resource::Program> m_GLprogram;
|
||||
|
@ -23,11 +23,13 @@ ememory::SharedPtr<ege::resource::Mesh> ege::resource::Mesh::createCube(float _s
|
||||
out->addFaceIndexing(_materialName);
|
||||
|
||||
out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1, 1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1,-1,-1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1,-1, 1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3(-1, 1, 1)*_size, vec3(-1,-1, 1)*_size, vec3( 1,-1, 1)*_size, vec3( 1, 1, 1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3(-1, 1,-1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3( 1,-1,-1)*_size, vec3( 1,-1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3( 1,-1, 1)*_size, vec3( 1,-1,-1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3( 1,-1, 1)*_size, vec3( 1,-1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1, 1, 1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3(-1,-1, 1)*_size, vec3(-1,-1,-1)*_size, vec3( 1,-1,-1)*_size, vec3( 1,-1, 1)*_size, _color);
|
||||
out->addQuad(_materialName, vec3(-1, 1,-1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color);
|
||||
out->setNormalMode(ege::resource::Mesh::normalMode::face);
|
||||
out->calculateNormaleFace(_materialName);
|
||||
// generate the VBO
|
||||
out->generateVBO();
|
||||
} else {
|
||||
|
@ -141,7 +141,7 @@ enum emfModuleMode {
|
||||
// TODO : rework with string line extractor
|
||||
bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
||||
m_checkNormal = true;
|
||||
m_normalMode = normalModeNone;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::none;
|
||||
etk::FSNode fileName(_fileName);
|
||||
// get the fileSize ...
|
||||
int32_t size = fileName.fileSize();
|
||||
@ -294,7 +294,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
||||
break;
|
||||
}
|
||||
case EMFModuleMeshNormalVertex: {
|
||||
m_normalMode = normalModeVertex;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::vertex;
|
||||
vec3 normal(0,0,0);
|
||||
// find the vertex Normal list.
|
||||
while (loadNextData(inputDataLine, 2048, fileName, true, true) != nullptr) {
|
||||
@ -314,7 +314,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
||||
}
|
||||
case EMFModuleMeshNormalFace: {
|
||||
EGE_ERROR("Change mode in face mode ...");
|
||||
m_normalMode = normalModeFace; // TODO : check if it is the same mode of display the normal from the start of the file
|
||||
m_normalMode = ege::resource::Mesh::normalMode::face; // TODO : check if it is the same mode of display the normal from the start of the file
|
||||
vec3 normal(0,0,0);
|
||||
// find the face Normal list.
|
||||
while (loadNextData(inputDataLine, 2048, fileName, true, true) != nullptr) {
|
||||
@ -379,7 +379,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
||||
uvIndex[0] += offsetUV;
|
||||
uvIndex[1] += offsetUV;
|
||||
uvIndex[2] += offsetUV;
|
||||
if (m_normalMode == normalModeFace) {
|
||||
if (m_normalMode == ege::resource::Mesh::normalMode::face) {
|
||||
normalIndex[0] += offsetFaceNormal;
|
||||
normalIndex[1] += offsetFaceNormal;
|
||||
normalIndex[2] += offsetFaceNormal;
|
||||
@ -396,7 +396,7 @@ bool ege::resource::Mesh::loadEMF(const std::string& _fileName) {
|
||||
vertexIndex[0] += offsetVertexId;
|
||||
vertexIndex[1] += offsetVertexId;
|
||||
vertexIndex[2] += offsetVertexId;
|
||||
if (m_normalMode == normalModeFace) {
|
||||
if (m_normalMode == ege::resource::Mesh::normalMode::face) {
|
||||
normalIndex[0] += offsetFaceNormal;
|
||||
normalIndex[1] += offsetFaceNormal;
|
||||
normalIndex[2] += offsetFaceNormal;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
bool ege::resource::Mesh::loadOBJ(const std::string& _fileName) {
|
||||
m_normalMode = normalModeNone;
|
||||
m_normalMode = ege::resource::Mesh::normalMode::none;
|
||||
#if 0
|
||||
etk::FSNode fileName(_fileName);
|
||||
// get the fileSize ...
|
||||
|
@ -88,7 +88,7 @@ void ege::resource::ParticuleMesh::draw(mat4& _positionMatrix,
|
||||
std::vector<uint32_t> tmpIndexResult;
|
||||
std::vector<ege::Face>& tmppFaces = m_listFaces.getValue(kkk).m_faces;
|
||||
//std::vector<uint32_t>& tmppIndex = m_listFaces.getValue(kkk).m_index;
|
||||
if (normalModeFace == m_normalMode) {
|
||||
if (m_normalMode == ege::resource::Mesh::normalMode::face) {
|
||||
for(size_t iii=0; iii<tmppFaces.size() ; ++iii) {
|
||||
if((mattttt * m_listFacesNormal[tmppFaces[iii].m_normal[0]]).dot(cameraNormal) >= 0.0f) {
|
||||
tmpIndexResult.push_back(iii*3);
|
||||
|
13
lutin_ege.py
13
lutin_ege.py
@ -33,13 +33,12 @@ def configure(target, my_module):
|
||||
'ege/camera/Camera.cpp',
|
||||
'ege/camera/View.cpp',
|
||||
'ege/camera/FPS.cpp',
|
||||
'ege/CollisionShapeCreator.cpp',
|
||||
'ege/position/Component.cpp',
|
||||
'ege/physics/Component.cpp',
|
||||
'ege/physics/Engine.cpp',
|
||||
'ege/elements/Element.cpp',
|
||||
'ege/elements/ElementBase.cpp',
|
||||
'ege/elements/ElementPhysic.cpp',
|
||||
#'ege/elements/ElementBase.cpp',
|
||||
#'ege/elements/ElementPhysic.cpp',
|
||||
'ege/particule/Component.cpp',
|
||||
'ege/particule/Engine.cpp',
|
||||
'ege/particule/Simple.cpp',
|
||||
@ -71,7 +70,7 @@ def configure(target, my_module):
|
||||
])
|
||||
my_module.copy_path('data/ParticuleMesh.*')
|
||||
my_module.copy_path('data/material3D.*')
|
||||
my_module.add_depend(['ewol', 'ephysics', 'echrono'])
|
||||
my_module.add_depend(['ewol', 'ephysics', 'eproperty', 'echrono'])
|
||||
my_module.add_flag('c++', [
|
||||
'-Wno-write-strings',
|
||||
'-Wmissing-field-initializers',
|
||||
@ -84,13 +83,12 @@ def configure(target, my_module):
|
||||
'ege/camera/Camera.hpp',
|
||||
'ege/camera/View.hpp',
|
||||
'ege/camera/FPS.hpp',
|
||||
'ege/CollisionShapeCreator.hpp',
|
||||
'ege/position/Component.hpp',
|
||||
'ege/physics/Engine.hpp',
|
||||
'ege/physics/Component.hpp',
|
||||
'ege/elements/Element.hpp',
|
||||
'ege/elements/ElementBase.hpp',
|
||||
'ege/elements/ElementPhysic.hpp',
|
||||
#'ege/elements/ElementBase.hpp',
|
||||
#'ege/elements/ElementPhysic.hpp',
|
||||
'ege/particule/Component.hpp',
|
||||
'ege/particule/Engine.hpp',
|
||||
'ege/particule/Simple.hpp',
|
||||
@ -121,7 +119,6 @@ def configure(target, my_module):
|
||||
# TODO: Remove this ...
|
||||
my_module.add_flag('c++', "-Wno-unused-variable")
|
||||
my_module.add_flag('c++', "-Wno-overloaded-virtual")
|
||||
my_module.add_path(".")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -15,8 +15,7 @@
|
||||
#include <ege/widget/Scene.hpp>
|
||||
#include <ege/camera/View.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
#include <ege/elements/ElementBase.hpp>
|
||||
#include <ege/elements/ElementPhysic.hpp>
|
||||
#include <ege/elements/Element.hpp>
|
||||
#include <ege/physicsShape/PhysicsBox.hpp>
|
||||
#include <ege/physicsShape/PhysicsSphere.hpp>
|
||||
#include <ege/position/Component.hpp>
|
||||
@ -76,6 +75,10 @@ void appl::Windows::init() {
|
||||
getObjectManager().periodicCall.connect(sharedFromThis(), &appl::Windows::onCallbackPeriodicCheckCollision);
|
||||
|
||||
m_env = ege::Environement::create();
|
||||
// set the debug property on the engines
|
||||
m_env->getEngine("render")->properties.set("debug-normal", "true");
|
||||
m_env->getEngine("physics")->properties.set("debug-AABB", "true");
|
||||
m_env->getEngine("physics")->properties.set("debug-shape", "true");
|
||||
// Create basic Camera
|
||||
m_camera = ememory::makeShared<ege::camera::View>(vec3(30,30,-100), vec3(0,0,0));
|
||||
m_camera->setEye(vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),40*std::cos(m_anglePsy)));
|
||||
@ -93,7 +96,7 @@ void appl::Windows::init() {
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ege::resource::Mesh> myMesh;
|
||||
// Create an external box:
|
||||
// Create an external box: (no physics)
|
||||
myMesh = createViewBoxStar();
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Element> element = ememory::makeShared<ege::Element>(m_env);
|
||||
@ -107,7 +110,7 @@ void appl::Windows::init() {
|
||||
// add it ..
|
||||
m_env->addElement(element);
|
||||
}
|
||||
// create basic gird:
|
||||
// create basic gird: (no physics)
|
||||
myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Element> element = ememory::makeShared<ege::Element>(m_env);
|
||||
@ -128,8 +131,6 @@ void appl::Windows::init() {
|
||||
// add all component:
|
||||
// 1st Position component:
|
||||
etk::Transform3D transform(vec3(0,0,2), etk::Quaternion::identity());
|
||||
//ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
|
||||
//element->addComponent(componentPosition);
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
element->addComponent(componentRender);
|
||||
@ -137,6 +138,7 @@ void appl::Windows::init() {
|
||||
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
|
||||
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
|
||||
physic->setSize(vec3(3.2,3.2,3.2));
|
||||
physic->setMass(300000);
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
element->addComponent(componentPhysics);
|
||||
@ -158,6 +160,7 @@ void appl::Windows::init() {
|
||||
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
|
||||
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
|
||||
physic->setSize(vec3(3.2,3.2,3.2));
|
||||
physic->setMass(50000);
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
element->addComponent(componentPhysics);
|
||||
@ -166,7 +169,7 @@ void appl::Windows::init() {
|
||||
}
|
||||
m_env->propertyStatus.set(ege::gameStart);
|
||||
}
|
||||
|
||||
/*
|
||||
namespace appl {
|
||||
class ElementHerit : public ege::ElementPhysic {
|
||||
public:
|
||||
@ -179,6 +182,7 @@ namespace appl {
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
|
||||
@ -204,12 +208,13 @@ bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
|
||||
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
|
||||
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
|
||||
physic->setSize(vec3(1.1,1.1,1.1));
|
||||
physic->setMass(1000);
|
||||
componentPhysics->setType(ege::physics::Component::type::bodyDynamic);
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
// set has dynamic object (can move)
|
||||
//APPL_CRITICAL("velocity : " << ray.getDirection()*100);
|
||||
componentPhysics->setLinearVelocity(ray.getDirection()*1000);
|
||||
componentPhysics->setLinearVelocity(ray.getDirection()*100);
|
||||
element->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addElement(element);
|
||||
|
Loading…
x
Reference in New Issue
Block a user