[DEV] better camera and now can display lines and points
This commit is contained in:
parent
bdf3a56e6b
commit
790c8f6cdb
@ -10,9 +10,59 @@
|
|||||||
#include <ege/camera/Camera.h>
|
#include <ege/camera/Camera.h>
|
||||||
#include <ege/debug.h>
|
#include <ege/debug.h>
|
||||||
|
|
||||||
|
#include <ewol/openGL/openGL.h>
|
||||||
|
|
||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "Camera"
|
#define __class__ "Camera"
|
||||||
|
|
||||||
ege::Camera::Camera() {
|
ege::Camera::Camera() :
|
||||||
|
m_aspectRatio(0.5),
|
||||||
|
m_angleView(M_PI/3.0),
|
||||||
|
m_zFar(4000.0f),
|
||||||
|
m_zNear(1.0f) {
|
||||||
m_matrix.identity();
|
m_matrix.identity();
|
||||||
|
updateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ege::Camera::setAspectRatio(float _ratio) {
|
||||||
|
if (m_aspectRatio == _ratio) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_aspectRatio = _ratio;
|
||||||
|
updateProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ege::Camera::setXAngleView(float _angleRad) {
|
||||||
|
if (m_angleView == _angleRad) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_angleView = _angleRad;
|
||||||
|
updateProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ege::Camera::setZFar(float _distance) {
|
||||||
|
if (m_zFar == _distance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_zFar = _distance;
|
||||||
|
updateProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ege::Camera::setZNear(float _distance) {
|
||||||
|
if (m_zNear == _distance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_zNear = _distance;
|
||||||
|
updateProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ege::Camera::updateProjectionMatrix() {
|
||||||
|
m_matrixProjection = etk::matPerspective(m_angleView, m_aspectRatio, m_zNear, m_zFar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ege::Camera::configureOpenGL() {
|
||||||
|
ewol::openGL::setCameraMatrix(getMatrixCamera());
|
||||||
|
ewol::openGL::setMatrix(getMatrixProjection());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
namespace ege {
|
namespace ege {
|
||||||
class Camera {
|
class Camera {
|
||||||
protected:
|
|
||||||
mat4 m_matrix; //!< transformation matrix.
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Constructor.
|
* @brief Constructor.
|
||||||
@ -28,25 +26,123 @@ namespace ege {
|
|||||||
* @brief Destructor.
|
* @brief Destructor.
|
||||||
*/
|
*/
|
||||||
virtual ~Camera() {};
|
virtual ~Camera() {};
|
||||||
/**
|
public:
|
||||||
* @brief get the transformation matix for the camera.
|
|
||||||
* @return the current transformation matrix
|
|
||||||
*/
|
|
||||||
const mat4& getMatrix() const {
|
|
||||||
return m_matrix;
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* @brief It is really needed to call the camera periodicly for performing automatic movement
|
* @brief It is really needed to call the camera periodicly for performing automatic movement
|
||||||
* @param[in] _step step time of moving
|
* @param[in] _step step time of moving
|
||||||
*/
|
*/
|
||||||
virtual void periodicCall(float _step) {};
|
virtual void periodicCall(float _step) {};
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Configure projection matrix and camera matrix
|
||||||
|
*/
|
||||||
|
virtual void configureOpenGL();
|
||||||
|
protected:
|
||||||
|
mat4 m_matrix; //!< transformation matrix.
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief get the transformation matix for the camera.
|
||||||
|
* @return the current transformation matrix
|
||||||
|
*/
|
||||||
|
const mat4& getMatrixCamera() const {
|
||||||
|
return m_matrix;
|
||||||
|
};
|
||||||
|
protected:
|
||||||
|
mat4 m_matrixProjection; //!< projection matrix.
|
||||||
|
/**
|
||||||
|
* @bref Update the current projection matrix.
|
||||||
|
*/
|
||||||
|
virtual void updateProjectionMatrix();
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief get the transformation matix for the camera.
|
||||||
|
* @return the current transformation matrix
|
||||||
|
*/
|
||||||
|
const mat4& getMatrixProjection() const {
|
||||||
|
return m_matrixProjection;
|
||||||
|
};
|
||||||
|
public:
|
||||||
virtual vec3 getViewVector() const {
|
virtual vec3 getViewVector() const {
|
||||||
return vec3(0,0,-1);
|
return vec3(0,0,-1);
|
||||||
}
|
}
|
||||||
virtual vec3 getEye() const {
|
virtual vec3 getEye() const {
|
||||||
return vec3(0,0,0);
|
return vec3(0,0,0);
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
float m_aspectRatio; //!< depending to the display the aspect ratio is simply calculated x/y
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Set the aspectRatio of the camera:
|
||||||
|
* @param[in] _ratio New aspect ratio.
|
||||||
|
*/
|
||||||
|
virtual void setAspectRatio(float _ratio);
|
||||||
|
/**
|
||||||
|
* @brief Set the screen size to display OpenGl interface
|
||||||
|
* @param[in] _screenSize New screen size.
|
||||||
|
*/
|
||||||
|
virtual void setSceenSize(const vec2& _screenSize) {
|
||||||
|
setAspectRatio(_screenSize.x()/_screenSize.y());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief get the current aspect Ratio.
|
||||||
|
* @return The current aspect ratio.
|
||||||
|
*/
|
||||||
|
float getAspectRatio() const {
|
||||||
|
return m_aspectRatio;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
float m_angleView; //!< X angle view of the camera
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Set the the X angle view of the camera:
|
||||||
|
* @param[in] _angleRad New angle view in X of the camera.
|
||||||
|
*/
|
||||||
|
virtual void setXAngleView(float _angleRad);
|
||||||
|
/**
|
||||||
|
* @brief Set the the Y angle view of the camera:
|
||||||
|
* @param[in] _angleRad New angle view in Y of the camera.
|
||||||
|
* @note Pay attention that the AspectRatio parameter is set before
|
||||||
|
*/
|
||||||
|
virtual void setYAngleView(float _angleRad) {
|
||||||
|
setXAngleView(_angleRad * m_aspectRatio);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief get the current X angle view.
|
||||||
|
* @return the current X angle view.
|
||||||
|
*/
|
||||||
|
float getXAngleView() const {
|
||||||
|
return m_angleView;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
float m_zFar; //!< Z camera far view
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Set the Z far distane of the camera:
|
||||||
|
* @param[in] _distance New end distance view.
|
||||||
|
*/
|
||||||
|
virtual void setZFar(float _distance);
|
||||||
|
/**
|
||||||
|
* @brief Get the Z far distane of the camera:
|
||||||
|
* @return the current end distance view.
|
||||||
|
*/
|
||||||
|
float getZFar() {
|
||||||
|
return m_zFar;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
float m_zNear; //!< Z camera near view
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Set the Z near distane of the camera:
|
||||||
|
* @param[in] _distance New start distance view.
|
||||||
|
*/
|
||||||
|
virtual void setZNear(float _distance);
|
||||||
|
/**
|
||||||
|
* @brief Get the Z Near distane of the camera:
|
||||||
|
* @return the current start distance view.
|
||||||
|
*/
|
||||||
|
float getZNear() {
|
||||||
|
return m_zNear;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ void ege::resource::Mesh::generateVBO() {
|
|||||||
vertexVBOId[indice] = m_verticesVBO->bufferSize(MESH_VBO_VERTICES)-1;
|
vertexVBOId[indice] = m_verticesVBO->bufferSize(MESH_VBO_VERTICES)-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(size_t indice=0 ; indice<3; indice++) {
|
for(size_t indice=0 ; indice<nbIndicInFace; indice++) {
|
||||||
tmpFaceList.m_index.push_back(vertexVBOId[indice]);
|
tmpFaceList.m_index.push_back(vertexVBOId[indice]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1053,7 +1053,7 @@ void ege::resource::Mesh::addFaceIndexing(const std::string& _layerName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ege::resource::Mesh::addPoint(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color) {
|
void ege::resource::Mesh::addPoint(const std::string& _layerName, const vec3& _pos, const etk::Color<float>& _color) {
|
||||||
if ( m_listFaces.exist(_layerName) == false
|
if ( m_listFaces.exist(_layerName) == false
|
||||||
|| m_materials.exist(_layerName) == false) {
|
|| m_materials.exist(_layerName) == false) {
|
||||||
EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << m_listFaces.exist(_layerName) << " materials=" << m_listFaces.exist(_layerName) << " ...");
|
EGE_ERROR("Mesh layer : " << _layerName << " does not exist in list faces=" << m_listFaces.exist(_layerName) << " materials=" << m_listFaces.exist(_layerName) << " ...");
|
||||||
@ -1064,7 +1064,14 @@ void ege::resource::Mesh::addPoint(const std::string& _layerName, const vec3& _p
|
|||||||
EGE_ERROR("try to add Point in a mesh material section that not support Point");
|
EGE_ERROR("try to add Point in a mesh material section that not support Point");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EGE_TODO("addPoint ...");
|
// try to find position:
|
||||||
|
int32_t pos = findPositionInList(_pos);
|
||||||
|
// try to find UV mapping:
|
||||||
|
int32_t color = findColorInList(_color);
|
||||||
|
Face tmpFace;
|
||||||
|
tmpFace.setVertex(pos);
|
||||||
|
tmpFace.setColor(color, color, color);
|
||||||
|
m_listFaces[_layerName].m_faces.push_back(tmpFace);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ege::resource::Mesh::addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color) {
|
void ege::resource::Mesh::addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color) {
|
||||||
|
@ -143,8 +143,10 @@ namespace ege {
|
|||||||
*/
|
*/
|
||||||
void addFaceIndexing(const std::string& _layerName);
|
void addFaceIndexing(const std::string& _layerName);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
void addPoint(const std::string& _layerName, const vec3& _pos, const etk::Color<float>& _color);
|
||||||
|
|
||||||
void addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color);
|
void addLine(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color);
|
||||||
void addPoint(const std::string& _layerName, const vec3& _pos1, const vec3& _pos2, const etk::Color<float>& _color);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @not-in-doc
|
* @not-in-doc
|
||||||
|
@ -131,9 +131,6 @@ void ege::widget::Scene::periodicCall(const ewol::event::Time& _event) {
|
|||||||
markToRedraw();
|
markToRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GAME_Z_NEAR (1)
|
|
||||||
#define GAME_Z_FAR (4000)
|
|
||||||
|
|
||||||
//#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) {
|
||||||
@ -146,29 +143,17 @@ void ege::widget::Scene::systemDraw(const ewol::DrawProperty& _displayProp) {
|
|||||||
m_origin.y(),
|
m_origin.y(),
|
||||||
m_size.x(),
|
m_size.x(),
|
||||||
m_size.y());
|
m_size.y());
|
||||||
#ifdef SCENE_BRUT_PERFO_TEST
|
// configure render with the camera...
|
||||||
float tmp___localTime0 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f;
|
|
||||||
EWOL_DEBUG(" SCENE000 : " << tmp___localTime0 << "ms ");
|
|
||||||
#endif
|
|
||||||
std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
|
std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
|
||||||
if (camera != nullptr) {
|
if (camera != nullptr) {
|
||||||
ewol::openGL::setCameraMatrix(camera->getMatrix());
|
camera->configureOpenGL();
|
||||||
}
|
}
|
||||||
// TODO : set this in the camera ...
|
|
||||||
float ratio = m_size.x() / m_size.y();
|
|
||||||
//EWOL_INFO("ratio : " << ratio);
|
|
||||||
float angleView = (M_PI/3.0);
|
|
||||||
mat4 tmpProjection = etk::matPerspective(angleView, ratio, GAME_Z_NEAR, GAME_Z_FAR);
|
|
||||||
ewol::openGL::setMatrix(tmpProjection);
|
|
||||||
#ifdef SCENE_BRUT_PERFO_TEST
|
|
||||||
int64_t tmp___startTime3 = ewol::getTime();
|
|
||||||
#endif
|
|
||||||
onDraw();
|
onDraw();
|
||||||
#ifdef SCENE_BRUT_PERFO_TEST
|
|
||||||
float tmp___localTime3 = (float)(ewol::getTime() - tmp___startTime3) / 1000.0f;
|
|
||||||
EWOL_DEBUG(" SCENE333 : " << tmp___localTime3 << "ms ");
|
|
||||||
#endif
|
|
||||||
ewol::openGL::pop();
|
ewol::openGL::pop();
|
||||||
|
#ifdef SCENE_BRUT_PERFO_TEST
|
||||||
|
float tmp___localTime1 = (float)(ewol::getTime() - tmp___startTime0) / 1000.0f;
|
||||||
|
EWOL_DEBUG(" SCENE render : " << tmp___localTime1 << "ms ");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) {
|
void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _paramPointer) {
|
||||||
@ -181,4 +166,25 @@ void ege::widget::Scene::onParameterChangeValue(const ewol::parameter::Ref& _par
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ege::widget::Scene::setCamera(const std::string& _cameraName) {
|
||||||
|
if (m_cameraName == _cameraName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_cameraName = _cameraName;
|
||||||
|
// Update camera aspect ratio:
|
||||||
|
std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
|
||||||
|
if (camera != nullptr) {
|
||||||
|
camera->setSceenSize(m_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ege::widget::Scene::calculateSize(const vec2& _available) {
|
||||||
|
ewol::Widget::calculateSize(_available);
|
||||||
|
// Update camera aspect ratio:
|
||||||
|
std::shared_ptr<ege::Camera> camera = m_env->getCamera(m_cameraName);
|
||||||
|
if (camera != nullptr) {
|
||||||
|
camera->setSceenSize(m_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,10 +52,19 @@ namespace ege {
|
|||||||
*/
|
*/
|
||||||
virtual ~Scene();
|
virtual ~Scene();
|
||||||
protected:
|
protected:
|
||||||
std::string m_cameraName;
|
std::string m_cameraName; //!< current camera name
|
||||||
public:
|
public:
|
||||||
void setCamera(const std::string& _cameraName) {
|
/**
|
||||||
m_cameraName = _cameraName;
|
* @brief Select a Camera for the display.
|
||||||
|
* @param[in] _cameraName New name of the camera.
|
||||||
|
*/
|
||||||
|
void setCamera(const std::string& _cameraName);
|
||||||
|
/**
|
||||||
|
* @brief Get the current camera name to display the environnement.
|
||||||
|
* @return the current camera name.
|
||||||
|
*/
|
||||||
|
const std::string& getCamera() const {
|
||||||
|
return m_cameraName;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
// Note : This is only for temporary elements : on the display
|
// Note : This is only for temporary elements : on the display
|
||||||
@ -67,6 +76,7 @@ namespace ege {
|
|||||||
virtual void systemDraw(const ewol::DrawProperty& _displayProp);
|
virtual void systemDraw(const ewol::DrawProperty& _displayProp);
|
||||||
virtual void onRegenerateDisplay();
|
virtual void onRegenerateDisplay();
|
||||||
virtual void periodicCall(const ewol::event::Time& _event);
|
virtual void periodicCall(const ewol::event::Time& _event);
|
||||||
|
virtual void calculateSize(const vec2& _available);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -36,31 +36,21 @@ static std::shared_ptr<ege::resource::Mesh> createGrid(int32_t _lineCount) {
|
|||||||
material->setSpecularFactor(vec4(0,0,0,1));
|
material->setSpecularFactor(vec4(0,0,0,1));
|
||||||
material->setShininess(1);
|
material->setShininess(1);
|
||||||
material->setRenderMode(ewol::openGL::renderLine);
|
material->setRenderMode(ewol::openGL::renderLine);
|
||||||
|
//material->setRenderMode(ewol::openGL::renderPoint);
|
||||||
out->addMaterial("basics", material);
|
out->addMaterial("basics", material);
|
||||||
|
|
||||||
out->addFaceIndexing("basics");
|
out->addFaceIndexing("basics");
|
||||||
/*
|
|
||||||
out->addQuad("basics",
|
|
||||||
vec3(-10,0,0), vec3(10,0,0), vec3(10,10,-lineSize), vec3(-10,10,-lineSize),
|
|
||||||
etk::color::white, etk::color::red, etk::color::green, etk::color::blue);
|
|
||||||
*/
|
|
||||||
// create horizontal lines
|
// create horizontal lines
|
||||||
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||||
/*
|
|
||||||
out->addQuad("basics",
|
|
||||||
vec3(-_lineCount,iii,0), vec3(_lineCount,iii,0), vec3(_lineCount,iii,lineSize), vec3(-_lineCount,iii,lineSize),
|
|
||||||
etk::color::white);
|
|
||||||
*/
|
|
||||||
out->addLine("basics", vec3(-_lineCount,iii,0), vec3(_lineCount,iii,0), etk::color::white);
|
out->addLine("basics", vec3(-_lineCount,iii,0), vec3(_lineCount,iii,0), etk::color::white);
|
||||||
|
//out->addPoint("basics", vec3(-_lineCount,iii,0), etk::color::white);
|
||||||
|
//out->addPoint("basics", vec3(_lineCount,iii,0), etk::color::white);
|
||||||
}
|
}
|
||||||
// create vertical lines
|
// create vertical lines
|
||||||
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
|
||||||
/*
|
|
||||||
out->addQuad("basics",
|
|
||||||
vec3(iii,-_lineCount,0), vec3(iii,_lineCount,0), vec3(iii,_lineCount,lineSize), vec3(iii,-_lineCount,lineSize),
|
|
||||||
etk::color::white);
|
|
||||||
*/
|
|
||||||
out->addLine("basics", vec3(iii,-_lineCount,0), vec3(iii,_lineCount,0), etk::color::white);
|
out->addLine("basics", vec3(iii,-_lineCount,0), vec3(iii,_lineCount,0), etk::color::white);
|
||||||
|
//out->addPoint("basics", vec3(iii,-_lineCount,0), etk::color::white);
|
||||||
|
//out->addPoint("basics", vec3(iii,_lineCount,0), etk::color::white);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate the VBO
|
// generate the VBO
|
||||||
@ -153,7 +143,9 @@ void appl::Windows::init() {
|
|||||||
void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) {
|
void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) {
|
||||||
static float offset = 0;
|
static float offset = 0;
|
||||||
offset += 0.01;
|
offset += 0.01;
|
||||||
m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40)+vec3(50,0,0));
|
static float offset2 = 0;
|
||||||
|
offset2 += 0.003;
|
||||||
|
m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))+vec3(50,0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user