[DEV] set physic and env work correctly (need some clean)

This commit is contained in:
Edouard DUPIN 2014-12-05 22:02:05 +01:00
parent bc20095852
commit b2a3095a2e
8 changed files with 146 additions and 62 deletions

View File

@ -291,17 +291,17 @@ void ege::Environement::generateInteraction(ege::ElementInteraction& _event) {
ege::Environement::Environement() :
signalPlayTimeChange(*this, "time-change"),
m_listElement(),
m_status(*this, "status", gameStart, "Satus of the activity of the Environement"),
m_status(*this, "status", gameStop, "Satus of the activity of the Environement"),
m_ratio(*this, "ratio", 1.0f, "game speed ratio"),
m_particuleEngine(*this) {
// nothing to do ...
m_status.add(gameStart, "start", "Scene is started");
m_status.add(gamePause, "pause", "Scene is paused");
m_status.add(gameStop, "stop", "Scene is stopped");
}
void ege::Environement::init() {
ewol::Object::init();
getObjectManager().periodicCall.bind(shared_from_this(), &ege::Environement::periodicCall);
void ege::Environement::init(const std::string& _name) {
ewol::Object::init(_name);
}
@ -339,7 +339,7 @@ void ege::Environement::periodicCall(const ewol::event::Time& _event) {
//EGE_DEBUG("stepSimulation (start)");
///step the simulation
if (m_physicEngine.getDynamicWorld() != nullptr) {
EGE_VERBOSE(" step simulation : " << curentDelta);
EGE_ERROR(" step simulation : " << curentDelta);
m_physicEngine.getDynamicWorld()->stepSimulation(curentDelta);
//optional but useful: debug drawing
m_physicEngine.getDynamicWorld()->debugDrawWorld();
@ -364,6 +364,8 @@ void ege::Environement::periodicCall(const ewol::event::Time& _event) {
} else {
++it;
}
} else {
++it;
}
}
if (0 != numberEnnemyKilled) {
@ -384,3 +386,14 @@ std::shared_ptr<ege::Camera> ege::Environement::getCamera(const std::string& _na
}
return nullptr;
}
void ege::Environement::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) {
if (_paramPointer == m_status) {
if (m_status.get() == gameStart) {
getObjectManager().periodicCall.bind(shared_from_this(), &ege::Environement::periodicCall);
} else {
getObjectManager().periodicCall.release(shared_from_this());
}
}
}

View File

@ -98,7 +98,7 @@ namespace ege {
std::vector<std::shared_ptr<ege::Element>> m_listElement; //!< List of all element added in the Game
protected:
Environement();
void init();
void init(const std::string& _name="NoName");
public:
DECLARE_FACTORY(Environement);
virtual ~Environement() { };
@ -274,6 +274,7 @@ namespace ege {
const std::vector<std::shared_ptr<ege::resource::Mesh>>& getStaticMeshToDraw() {
return m_listMeshToDrawFirst;
}
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);
};
};

View File

@ -73,7 +73,6 @@ void ege::ElementPhysic::createRigidBody(float _mass) {
btRigidBody::btRigidBodyConstructionInfo rbInfo(_mass, motionState, getShape(), localInertia);
m_body = new btRigidBody(rbInfo);
m_body->setUserPointer((void*)this);
//m_body->applyTorqueImpulse(btVector3(0,0,0.2));
m_body->setAngularVelocity(vec3(0,0,0));
}
@ -421,7 +420,12 @@ void ege::ElementPhysic::setMass(float _value) {
if (m_body == nullptr) {
return;
}
m_body->setMassProps(_value, vec3(0,0,0));
vec3 localInertia(0,0,0);
if (_value != 0.0f && getShape()!=nullptr) {
getShape()->calculateLocalInertia(_value, localInertia);
EWOL_ERROR("Update inertia calculated : " << localInertia);
}
m_body->setMassProps(_value, localInertia);
}
void ege::ElementPhysic::setLinearVelocity(const vec3& _value) {
@ -437,7 +441,7 @@ void ege::ElementPhysic::setTorqueImpulse(const vec3& _value) {
EGE_WARNING("no body");
return;
}
m_body->applyTorqueImpulse(_value);
}
void ege::ElementPhysic::setAngularVelocity(const vec3& _value) {

View File

@ -42,8 +42,10 @@ namespace ege {
public:
/**
* @brief Constructor (when constructer is called just add element that did not change.
* The objest will be stored in a pool of element and keep a second time if needed == > redure memory allocation,
* The object will be stored in a pool of element and keep a second time if needed == > redure memory allocation,
* when needed, the system will call the init and un-init function...
* @param[in] _env glabal ege environement
* @param[in] _autoRigidBody add a basic rigid body (not availlable after befor setting a shape)
*/
ElementPhysic(const std::shared_ptr<ege::Environement>& _env, bool _autoRigidBody=true);
/**
@ -89,19 +91,22 @@ namespace ege {
* @brief draw the current life of the element
*/
// virtual void drawLife(const std::shared_ptr<ewol::resource::Colored3DObject>& _draw, const std::shared_ptr<ege::Camera>& _camera);
// TODO : Remove this ...
protected:
vec3 m_theoricPosition;
public:
/**
* @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();
return m_theoricPosition;
};
/**
* @brief set the current Theoric position of the element
* @param[in] set the 3D position.
*/
virtual void setPositionTheoric(const vec3& _pos) { };
virtual void setPositionTheoric(const vec3& _pos) { m_theoricPosition = _pos; };
/**
* @brief get the current speed of the element

View File

@ -15,7 +15,7 @@
#include <ege/resource/tools/icoSphere.h>
#undef __class__
#define __class__ "resource::Mesh"
#define __class__ "resource::Mesh"
ege::resource::Mesh::Mesh() :
m_normalMode(normalModeNone),
@ -61,7 +61,12 @@ void ege::resource::Mesh::init(const std::string& _fileName, const std::string&
}
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer
m_verticesVBO = ewol::resource::VirtualBufferObject::create(5);
if (m_verticesVBO == nullptr) {
EGE_ERROR("can not instanciate VBO ...");
return;
}
// TO facilitate some debugs we add a name of the VBO :
m_verticesVBO->setName("[VBO] of " + _fileName);
// load the curent file :
std::string tmpName = etk::tolower(_fileName);
// select the corect loader :
@ -240,14 +245,14 @@ void ege::resource::Mesh::draw(mat4& _positionMatrix,
// 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::normalModeFace) {
EGE_INFO("calculateNormaleFace(" << _materialName << ")");
ewol::openGL::renderMode tmpRenderMode = m_materials[_materialName]->getRenderMode();
if ( tmpRenderMode == ewol::openGL::renderPoint
|| tmpRenderMode == ewol::openGL::renderLine
|| tmpRenderMode == ewol::openGL::renderLineStrip
|| tmpRenderMode == ewol::openGL::renderLineLoop) {
// can not calculate normal on lines ...
EGE_ERROR("calculateNormaleFace(" << _materialName << ") : can not calculate normal on lines ...");
m_normalMode = ege::resource::Mesh::normalModeNone;
return;
}
@ -257,14 +262,22 @@ void ege::resource::Mesh::calculateNormaleFace(const std::string& _materialName)
m_listVertex[it.m_vertex[1]]-m_listVertex[it.m_vertex[2]]);
m_listFacesNormal.push_back(normal.normalized());
}
m_normalMode = ege::resource::Mesh::normalModeFace;
}
}
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::normalModeVertex) {
EGE_INFO("calculateNormaleEdge(" << _materialName << ")");
ewol::openGL::renderMode tmpRenderMode = m_materials[_materialName]->getRenderMode();
if ( tmpRenderMode == ewol::openGL::renderPoint
|| tmpRenderMode == ewol::openGL::renderLine
|| tmpRenderMode == ewol::openGL::renderLineStrip
|| tmpRenderMode == ewol::openGL::renderLineLoop) {
EGE_ERROR("calculateNormaleEdge(" << _materialName << ") : can not calculate normal on lines ...");
m_normalMode = ege::resource::Mesh::normalModeNone;
return;
}
for(size_t iii=0 ; iii<m_listVertex.size() ; iii++) {
std::vector<Face>& tmpFaceList = m_listFaces[_materialName].m_faces;
vec3 normal(0,0,0);
@ -283,7 +296,6 @@ void ege::resource::Mesh::calculateNormaleEdge(const std::string& _materialName)
m_listVertexNormal.push_back(normal.normalized());
}
}
m_normalMode = ege::resource::Mesh::normalModeVertex;
}
}

View File

@ -37,7 +37,9 @@ namespace etk {
ege::widget::Scene::Scene() :
signalDisplayDebug(*this, "drawDebug", "Call to draw debug after all elements"),
m_cameraName("default") {
m_cameraName("default"),
m_debugPhysic(*this, "debugPhysic", false, "Display debug of the physic interface"),
m_debugApplication(*this, "debugApplication", false, "Display debug of the application") {
addObjectType("ege::widget::Scene");
}
@ -116,19 +118,23 @@ void ege::widget::Scene::onDraw() {
m_displayElementOrdered[iii].element->draw(pass);
}
}
// Draw debug ... (Object)
for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) {
m_displayElementOrdered[iii].element->drawDebug(m_debugDrawProperty, camera);
}
// Draw debug ... (Camera)
std::map<std::string, std::shared_ptr<ege::Camera>> listCamera = m_env->getCameraList();
for (auto &itCam : listCamera) {
if (itCam.second != nullptr) {
itCam.second->drawDebug(m_debugDrawProperty, camera);
if (m_debugPhysic.get() == true) {
// Draw debug ... (Object)
for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) {
m_displayElementOrdered[iii].element->drawDebug(m_debugDrawProperty, camera);
}
// Draw debug ... (Camera)
std::map<std::string, std::shared_ptr<ege::Camera>> listCamera = m_env->getCameraList();
for (auto &itCam : listCamera) {
if (itCam.second != nullptr) {
itCam.second->drawDebug(m_debugDrawProperty, camera);
}
}
}
// Draw debug ... (User)
signalDisplayDebug.emit(m_debugDrawProperty);
if (m_debugApplication.get() == true) {
// Draw debug ... (User)
signalDisplayDebug.emit(m_debugDrawProperty);
}
} else {
EGE_WARNING("No Dynamic world ...");
}

View File

@ -41,7 +41,7 @@ namespace ege {
std::shared_ptr<ege::Environement> m_env;
std::shared_ptr<ewol::resource::Colored3DObject> m_debugDrawProperty;
public:
ewol::Signal<std::shared_ptr<ewol::resource::Colored3DObject>/*, std::shared_ptr<ege::Camera>*/> signalDisplayDebug;
ewol::Signal<std::shared_ptr<ewol::resource::Colored3DObject>/*, std::shared_ptr<ege::Camera>*/> signalDisplayDebug; //!< emit a signal to the application to draw the debug (@ref setDebugPhysic)
protected:
/**
* @brief Constructor of the widget classes
@ -81,6 +81,40 @@ namespace ege {
virtual void onRegenerateDisplay();
virtual void periodicCall(const ewol::event::Time& _event);
virtual void calculateSize(const vec2& _available);
protected:
ewol::parameter::Value<bool> m_debugPhysic; //!< display Physic Debug
public:
/**
* @brief Set the debug display of the physic engine
* @param[in] _status new status of the debug
*/
void setDebugPhysic(bool _status) {
m_debugPhysic.set(_status);
}
/**
* @brief Get the debug display status of the physic engine
* @return The current status of the debug.
*/
bool getDebugPhysic() {
return m_debugPhysic.get();
}
protected:
ewol::parameter::Value<bool> m_debugApplication; //!< display Application Debug
public:
/**
* @brief Set the debug display of the application
* @param[in] _status new status of the debug
*/
void setDebugApplication(bool _status) {
m_debugApplication.set(_status);
}
/**
* @brief Get the debug display status of the application
* @return The current status of the debug.
*/
bool getDebugApplication() {
return m_debugApplication.get();
}
};
};
};

View File

@ -25,6 +25,42 @@ appl::Windows::Windows() {
}
static std::shared_ptr<ege::resource::Mesh> createViewBoxStar() {
std::shared_ptr<ege::resource::Mesh> out = ege::resource::Mesh::create("viewBoxStar", "DATA:texturedNoMaterial.prog");
if (out != nullptr) {
std::shared_ptr<ege::Material> material = std::make_shared<ege::Material>();
// set the element material properties :
material->setAmbientFactor(vec4(1,1,1,1));
material->setDiffuseFactor(vec4(0,0,0,1));
material->setSpecularFactor(vec4(0,0,0,1));
material->setShininess(1);
// 1024 == > 1<<9
// 2048 == > 1<<10
// 4096 == > 1<<11
int32_t size = 1<<11;
//material->setTexture0(""); //"
material->setTexture0Magic(ivec2(size,size));
out->addMaterial("basics", material);
//material->setImageSize(ivec2(size,size));
egami::Image* myImage = material->get();
if (nullptr == myImage) {
return out;
}
myImage->clear(etk::color::black);
ivec2 tmpPos;
for (int32_t iii=0; iii<6000; iii++) {
tmpPos.setValue(etk::tool::frand(0,size), etk::tool::frand(0,size)) ;
myImage->set(tmpPos, etk::color::white);
}
material->flush();
// basis on cube :
out->createViewBox("basics", 1000/* distance */);
// generate the VBO
out->generateVBO();
}
return out;
}
@ -48,37 +84,10 @@ void appl::Windows::init() {
tmpWidget->setCamera("basic");
setSubWidget(tmpWidget);
}
std::shared_ptr<ege::resource::Mesh> myMesh;
// Create an external box :
std::shared_ptr<ege::resource::Mesh> myMesh = ege::resource::Mesh::create("---", "DATA:texturedNoMaterial.prog");
myMesh = createViewBoxStar();
if (myMesh != nullptr) {
std::shared_ptr<ege::Material> material = std::make_shared<ege::Material>();
// set the element material properties :
material->setAmbientFactor(vec4(1,1,1,1));
material->setDiffuseFactor(vec4(0,0,0,1));
material->setSpecularFactor(vec4(0,0,0,1));
material->setShininess(1);
material->setTexture0(""); //"
myMesh->addMaterial("basics", material);
// 1024 == > 1<<9
// 2048 == > 1<<10
// 4096 == > 1<<11
int32_t size = 1<<11;
material->setImageSize(ivec2(size,size));
egami::Image* myImage = material->get();
if (nullptr == myImage) {
return;
}
myImage->clear(etk::color::black);
ivec2 tmpPos;
for (int32_t iii=0; iii<6000; iii++) {
tmpPos.setValue(etk::tool::frand(0,size), etk::tool::frand(0,size)) ;
myImage->set(tmpPos, etk::color::white);
}
material->flush();
// basis on cube :
myMesh->createViewBox("basics", 1000/* distance */);
// generate the VBO
myMesh->generateVBO();
m_env->addStaticMeshToDraw(myMesh);
}
myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5);