[DEV] first display

This commit is contained in:
Edouard DUPIN 2014-11-05 21:03:26 +01:00
parent 95e13b8126
commit 6e2e30de90
6 changed files with 108 additions and 172 deletions

View File

@ -27,6 +27,8 @@ class btDynamicsWorld;
#include <ewol/object/Object.h> #include <ewol/object/Object.h>
#include <ewol/signal/Signal.h> #include <ewol/signal/Signal.h>
#include <ewol/event/Time.h> #include <ewol/event/Time.h>
#include <ewol/parameter/Value.h>
#include <ege/resource/Mesh.h>
namespace ege { namespace ege {
enum property { enum property {
@ -116,7 +118,7 @@ namespace ege {
m_status.set(_value); m_status.set(_value);
} }
protected: protected:
ewol::parameter::List<float> m_ratio; //!< Speed ratio ewol::parameter::Value<float> m_ratio; //!< Speed ratio
public: public:
/** /**
* @brief Get the game speed ratio. * @brief Get the game speed ratio.
@ -135,7 +137,17 @@ namespace ege {
protected: protected:
std::map<std::string, std::shared_ptr<ege::Camera>> m_listCamera; //!< list of all camera in the world std::map<std::string, std::shared_ptr<ege::Camera>> m_listCamera; //!< list of all camera in the world
public: public:
/**
* @brief Add a camera in the camera pool.
* @param[in] _name Name of the camera.
* @param[in] _camera Pointer on the camera to add.
*/
void addCamera(const std::string& _name, const std::shared_ptr<ege::Camera>& _camera); void addCamera(const std::string& _name, const std::shared_ptr<ege::Camera>& _camera);
/**
* @brief Get a specific camera.
* @param[in] _name Name of the camera.
* @return A pointer on the camera requested.
*/
std::shared_ptr<ege::Camera> getCamera(const std::string& _name); std::shared_ptr<ege::Camera> getCamera(const std::string& _name);
public: public:
/** /**
@ -239,6 +251,15 @@ namespace ege {
private: private:
void periodicCall(const ewol::event::Time& _event); void periodicCall(const ewol::event::Time& _event);
protected:
std::vector<std::shared_ptr<ege::resource::Mesh>> m_listMeshToDrawFirst;
public:
void addStaticMeshToDraw(const std::shared_ptr<ege::resource::Mesh>& _mesh) {
m_listMeshToDrawFirst.push_back(_mesh);
}
const std::vector<std::shared_ptr<ege::resource::Mesh>>& getStaticMeshToDraw() {
return m_listMeshToDrawFirst;
}
}; };
}; };

View File

@ -30,15 +30,7 @@
#undef __class__ #undef __class__
#define __class__ "Scene" #define __class__ "Scene"
ege::widget::Scene::Scene() //: ege::widget::Scene::Scene() {
//signalKillEnemy(*this, "kill-ennemy"),
//m_gameTime(0),
//m_angleView(M_PI/3.0),
//m_dynamicsWorld(nullptr),
//m_camera(nullptr),
//m_debugMode(false),
//m_debugDrawing(nullptr)
{
addObjectType("ege::widget::Scene"); addObjectType("ege::widget::Scene");
} }
@ -48,46 +40,10 @@ void ege::widget::Scene::init(std::shared_ptr<ege::Environement> _env) {
setKeyboardRepeate(false); setKeyboardRepeate(false);
setCanHaveFocus(true); setCanHaveFocus(true);
periodicCallEnable(); periodicCallEnable();
//m_debugDrawing = ewol::resource::Colored3DObject::create();
/*
m_ratioTime = 1.0f;
if (_setAutoBullet == true) {
setBulletConfig();
}
if (_setAutoCamera == true) {
setCamera();
}
*/
} }
/*
void ege::widget::Scene::setCamera(ege::Camera* _camera) {
if (nullptr != _camera) {
m_camera = _camera;
} else {
m_camera = new ege::Camera(vec3(0,0,0), 0, DEG_TO_RAD(45) ,50);
// SET THE STATION ..
m_camera->setEye(vec3(0,0,0));
}
}
*/
ege::widget::Scene::~Scene() { ege::widget::Scene::~Scene() {
/*
ewol::resource::release(m_directDrawObject);
//cleanup in the reverse order of creation/initialization
//remove the rigidbodies from the dynamics world and delete them
for (int32_t iii=m_dynamicsWorld->getNumCollisionObjects()-1; iii >= 0 ;iii--) {
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[iii];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState()) {
delete body->getMotionState();
}
m_dynamicsWorld->removeCollisionObject( obj );
delete obj;
}
*/
} }
void ege::widget::Scene::onRegenerateDisplay() { void ege::widget::Scene::onRegenerateDisplay() {
@ -112,6 +68,17 @@ void ege::widget::Scene::onDraw() {
g_counterNbTimeDisplay++; g_counterNbTimeDisplay++;
g_startTime = ewol::getTime(); g_startTime = ewol::getTime();
#endif #endif
// draw constant object :
{
mat4 tmpMatrix;
for (auto &it : m_env->getStaticMeshToDraw()) {
if (it != nullptr) {
it->draw(tmpMatrix);
}
}
}
// get camera : // get camera :
std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName); std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
//EGE_DEBUG("Draw (start)"); //EGE_DEBUG("Draw (start)");
@ -128,12 +95,7 @@ void ege::widget::Scene::onDraw() {
} }
// note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen // note : the first pass is done at the reverse way to prevent multiple display od the same point in the screen
// (and we remember that the first pass is to display all the non transparent elements) // (and we remember that the first pass is to display all the non transparent elements)
#if 0 for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) {
// note : We keep this one for the test only ...
for (int32_t iii=0; iii<m_displayElementOrdered.size(); iii++) {
#else
for (int32_t iii=m_displayElementOrdered.size()-1; iii >= 0; iii--) {
#endif
m_displayElementOrdered[iii].element->draw(0); m_displayElementOrdered[iii].element->draw(0);
} }
// for the other pass the user can draw transparent elements ... // for the other pass the user can draw transparent elements ...
@ -142,20 +104,6 @@ void ege::widget::Scene::onDraw() {
m_displayElementOrdered[iii].element->draw(pass); m_displayElementOrdered[iii].element->draw(pass);
} }
} }
/*
for (size_t iii=0; iii<m_displayElementOrdered.size(); iii++) {
m_displayElementOrdered[iii].element->drawLife(m_debugDrawing, *m_camera);
}
*/
/*
#ifdef DEBUG
if (true == m_debugMode) {
for (size_t iii=0; iii<m_displayElementOrdered.size(); iii++) {
m_displayElementOrdered[iii].element->drawDebug(m_debugDrawing, *m_camera);
}
}
#endif
*/
} }
if (camera != nullptr) { if (camera != nullptr) {
m_env->getParticuleEngine().draw(*camera); m_env->getParticuleEngine().draw(*camera);
@ -168,7 +116,6 @@ void ege::widget::Scene::onDraw() {
EWOL_DEBUG(" scene : " << localTime << "ms " << g_counterNbTimeDisplay); EWOL_DEBUG(" scene : " << localTime << "ms " << g_counterNbTimeDisplay);
} }
#endif #endif
//EGE_DEBUG("Draw (stop)");
} }
// I really does not know what is this ... // I really does not know what is this ...
@ -187,78 +134,41 @@ void ege::widget::Scene::periodicCall(const ewol::event::Time& _event) {
//#define SCENE_BRUT_PERFO_TEST //#define SCENE_BRUT_PERFO_TEST
void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) {
{ #ifdef SCENE_BRUT_PERFO_TEST
#ifdef SCENE_BRUT_PERFO_TEST int64_t tmp___startTime0 = ewol::getTime();
int64_t tmp___startTime0 = ewol::getTime(); #endif
#endif
ewol::openGL::push(); ewol::openGL::push();
// here we invert the reference of the standard openGl view because the reference in the common display is Top left and not buttom left // here we invert the reference of the standard openGl view because the reference in the common display is Top left and not buttom left
glViewport( m_origin.x(), glViewport( m_origin.x(),
m_origin.y(), m_origin.y(),
m_size.x(), m_size.x(),
m_size.y()); m_size.y());
#ifdef SCENE_BRUT_PERFO_TEST #ifdef SCENE_BRUT_PERFO_TEST
float tmp___localTime0 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f; float tmp___localTime0 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f;
EWOL_DEBUG(" SCENE000 : " << tmp___localTime0 << "ms "); EWOL_DEBUG(" SCENE000 : " << tmp___localTime0 << "ms ");
int64_t tmp___startTime1 = ewol::getTime(); #endif
#endif std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
if (camera != nullptr) {
ewol::openGL::setCameraMatrix(camera->getMatrix());
}
// TODO : set this in the camera ...
float ratio = m_size.x() / m_size.y(); float ratio = m_size.x() / m_size.y();
//EWOL_INFO("ratio : " << ratio); //EWOL_INFO("ratio : " << ratio);
// TODO : mat4 tmpProjection = etk::matPerspective(m_angleView, ratio, GAME_Z_NEAR, GAME_Z_FAR); float angleView = (M_PI/3.0);
#ifdef SCENE_BRUT_PERFO_TEST mat4 tmpProjection = etk::matPerspective(angleView, ratio, GAME_Z_NEAR, GAME_Z_FAR);
float tmp___localTime1 = (float)(ewol::getTime() - tmp___startTime1) / 1000.0f; ewol::openGL::setMatrix(tmpProjection);
EWOL_DEBUG(" SCENE111 : " << tmp___localTime1 << "ms "); #ifdef SCENE_BRUT_PERFO_TEST
int64_t tmp___startTime2 = ewol::getTime(); int64_t tmp___startTime3 = ewol::getTime();
#endif #endif
// TODO : ewol::openGL::setCameraMatrix(m_camera->getMatrix());
//mat4 tmpMat = tmpProjection * m_camera->getMatrix();
// set internal matrix system :
//ewol::openGL::setMatrix(tmpMat);
// TODO : ewol::openGL::setMatrix(tmpProjection);
#ifdef SCENE_BRUT_PERFO_TEST
float tmp___localTime2 = (float)(ewol::getTime() - tmp___startTime2) / 1000.0f;
EWOL_DEBUG(" SCENE222 : " << tmp___localTime2 << "ms ");
#endif
#ifdef SCENE_BRUT_PERFO_TEST
int64_t tmp___startTime3 = ewol::getTime();
#endif
onDraw(); onDraw();
#ifdef SCENE_BRUT_PERFO_TEST #ifdef SCENE_BRUT_PERFO_TEST
float tmp___localTime3 = (float)(ewol::getTime() - tmp___startTime3) / 1000.0f; float tmp___localTime3 = (float)(ewol::getTime() - tmp___startTime3) / 1000.0f;
EWOL_DEBUG(" SCENE333 : " << tmp___localTime3 << "ms "); EWOL_DEBUG(" SCENE333 : " << tmp___localTime3 << "ms ");
int64_t tmp___startTime4 = ewol::getTime(); #endif
#endif
ewol::openGL::pop(); ewol::openGL::pop();
#ifdef SCENE_BRUT_PERFO_TEST
float tmp___localTime4 = (float)(ewol::getTime() - tmp___startTime4) / 1000.0f;
EWOL_DEBUG(" SCENE444 : " << tmp___localTime4 << "ms ");
#endif
} }
/*
vec2 ege::widget::Scene::calculateDeltaAngle(const vec2& _posScreen) {
double ratio = m_size.x() / m_size.y();
vec2 pos = vec2(m_size.x()/-2.0, m_size.y()/-2.0) + _posScreen;
double xmax = tan(m_angleView/2.0);
double ymax = xmax / ratio;
double newX = pos.x() * xmax / m_size.x()*2.0;
double newY = pos.y() * ymax / m_size.y()*2.0;
double angleX = atan(newX);
double angleY = atan(newY);
return vec2(angleX,
angleY);
}
*/
/*
vec3 ege::widget::Scene::convertScreenPositionInMapPosition(const vec2& _posScreen) {
return m_camera->projectOnZGround(calculateDeltaAngle(_posScreen));
}
*/
void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) { void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) {
ewol::Widget::onParameterChangeValue(_paramPointer); ewol::Widget::onParameterChangeValue(_paramPointer);
/* /*

View File

@ -60,48 +60,6 @@ namespace ege {
protected: protected:
// Note : This is only for temporary elements : on the display // Note : This is only for temporary elements : on the display
std::vector<ege::Environement::ResultNearestElement> m_displayElementOrdered; std::vector<ege::Environement::ResultNearestElement> m_displayElementOrdered;
protected:
//bool m_debugMode;
//std::shared_ptr<ewol::resource::Colored3DObject> m_debugDrawing; //!< for the debug draw elements
public:
/**
* @brief Toggle the debug mode == > usefull for DEBUG only ...
*/
/*
void debugToggle() {
m_debugMode = m_debugMode?false:true;
};
*/
protected:
// Derived function
//virtual void ScenePeriodicCall(int64_t _localTime, int32_t _deltaTime) { };
public:
//vec2 calculateDeltaAngle(const vec2& _posScreen);
//vec3 convertScreenPositionInMapPosition(const vec2& _posScreen);
/**
* @brief get the current camera reference for the scene rendering
*/
/*
ege::Camera& getCamera() {
return *m_camera;
};
*/
/*
void renderscene(int pass);
void drawOpenGL(btScalar* m,
const btCollisionShape* _shape,
const btVector3& _color,
int32_t _debugMode,
const btVector3& _worldBoundsMin,
const btVector3& _worldBoundsMax);
void drawSphere(btScalar _radius,
int _lats,
int _longs,
mat4& _transformationMatrix,
etk::Color<float>& _tmpColor);
void getElementAroundNewElement(vec3 _sourcePosition,
std::vector<ege::Environement::ResultNearestElement>& _resultList);
*/
protected: // Derived function protected: // Derived function
virtual void onDraw(); virtual void onDraw();
virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer); virtual void onParameterChangeValue(const ewol::parameter::Ref& _paramPointer);

View File

@ -11,6 +11,7 @@
#include <appl/Windows.h> #include <appl/Windows.h>
#include <ewol/widget/Label.h> #include <ewol/widget/Label.h>
#include <ege/widget/Scene.h> #include <ege/widget/Scene.h>
#include <etk/tool.h>
#undef __class__ #undef __class__
#define __class__ "Windows" #define __class__ "Windows"
@ -35,4 +36,50 @@ void appl::Windows::init() {
tmpWidget->setCamera("basic"); tmpWidget->setCamera("basic");
setSubWidget(tmpWidget); setSubWidget(tmpWidget);
} }
// Create an external box :
std::shared_ptr<ege::resource::Mesh> myMesh = ege::resource::Mesh::create("---", "DATA:texturedNoMaterial.prog");
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::create("---");
if (myMesh != nullptr) {
std::shared_ptr<ege::Material> material = std::make_shared<ege::Material>();
material->setAmbientFactor(vec4(0.112f,0.112f,0.112f,1.0f));
material->setDiffuseFactor(vec4(0.512f,0.512f,0.512f,1.0f));
material->setSpecularFactor(vec4(0.5f,0.5f,0.5f,1.0f));
material->setShininess(96.078431f);
material->setTexture0("DATA:texture_mars.png");
myMesh->addMaterial("basics", material);
myMesh->createIcoSphere("basics", 16, 3);
myMesh->generateVBO();
m_env->addStaticMeshToDraw(myMesh);
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 KiB

View File

@ -22,7 +22,7 @@ def create(target):
myModule.add_path(tools.get_current_path(__file__)) myModule.add_path(tools.get_current_path(__file__))
#myModule.copy_folder("data/*") myModule.copy_folder("data/*")
# set the package properties : # set the package properties :
myModule.pkg_set("VERSION", "0.0.0") myModule.pkg_set("VERSION", "0.0.0")