[DEV] add AABB bounding alculation and display of it
This commit is contained in:
parent
d9317dc227
commit
d1e48b5d0d
2
build
2
build
@ -1 +1 @@
|
||||
Subproject commit b3962202f4a5075ab7eb8f27be25b515a4206be4
|
||||
Subproject commit 22c1c9d19709f643d3032bb5d7a42ea55924d50b
|
@ -7,10 +7,10 @@
|
||||
*/
|
||||
|
||||
#include <ewol/game/Bounding.h>
|
||||
#include <ewol/game/BoundingAABB.h>
|
||||
|
||||
|
||||
game::Bounding::Bounding(boundingMode mode) :
|
||||
m_markedToUpdate(true),
|
||||
m_mode(mode)
|
||||
{
|
||||
|
||||
@ -22,3 +22,13 @@ game::Bounding::~Bounding(void)
|
||||
}
|
||||
|
||||
|
||||
game::Bounding* game::CreateBounding(game::boundingMode mode)
|
||||
{
|
||||
switch(mode) {
|
||||
case game::BoundingModeAABB:
|
||||
|
||||
return new game::BoundingAABB();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "ewol/debug.h"
|
||||
#include "ewol/game/MeshObject.h"
|
||||
#include <etk/math/Matrix4.h>
|
||||
|
||||
namespace game
|
||||
{
|
||||
@ -26,7 +27,6 @@ namespace game
|
||||
class Bounding
|
||||
{
|
||||
protected :
|
||||
bool m_markedToUpdate; //!< Marked to update the bounding properties.
|
||||
boundingMode m_mode; //!< bounding mode of this system.
|
||||
public:
|
||||
/**
|
||||
@ -38,10 +38,6 @@ namespace game
|
||||
* @biref Main constructor.
|
||||
*/
|
||||
virtual ~Bounding(void);
|
||||
/**
|
||||
* @brief Request the update of the bounding for the next step
|
||||
*/
|
||||
void NeedUpdate(void) { m_markedToUpdate = true; };
|
||||
/**
|
||||
* @brief Get the bounding type
|
||||
* @return the bounding type;
|
||||
@ -50,9 +46,15 @@ namespace game
|
||||
/**
|
||||
* @brief Update Bounding properties.
|
||||
*/
|
||||
virtual void Update(game::MeshObject& object) = 0;
|
||||
virtual void Update(game::MeshObject& object, mat4& transformMatrix) {};
|
||||
/**
|
||||
* Draw the bounding ==> for test ...
|
||||
*/
|
||||
virtual void Draw(void) {};
|
||||
};
|
||||
|
||||
Bounding* CreateBounding(boundingMode mode);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -9,31 +9,161 @@
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/game/BoundingAABB.h>
|
||||
#include <etk/math/Matrix4.h>
|
||||
#include <ewol/renderer/ResourceManager.h>
|
||||
|
||||
|
||||
game::BoundingAABB::BoundingAABB(void) :
|
||||
Bounding(game::BoundingModeAABB)
|
||||
Bounding(game::BoundingModeAABB),
|
||||
m_PointStart(-1,-1,-1),
|
||||
m_PointStop(1,1,1)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
if (false == ewol::resource::Keep(m_displayBounding) ) {
|
||||
EWOL_DEBUG("Can not keep ewol::Colored3DObject ...");
|
||||
}
|
||||
// color never change ...
|
||||
draw::Color tmpColorNormal(0xFF000055);
|
||||
draw::Colorf tmpColor(tmpColorNormal);
|
||||
vec3 tmpPos(0,0,0);
|
||||
for(int32_t iii=0; iii<36; iii++) {
|
||||
m_color.PushBack(tmpColor);
|
||||
m_vertices.PushBack(tmpPos);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
game::BoundingAABB::~BoundingAABB(void)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
ewol::resource::Release(m_displayBounding);
|
||||
#endif
|
||||
}
|
||||
|
||||
void game::BoundingAABB::Update(game::MeshObject& object)
|
||||
|
||||
void game::BoundingAABB::Update(game::MeshObject& object, mat4& transformMatrix)
|
||||
{
|
||||
if (true==m_markedToUpdate) {
|
||||
/*
|
||||
mat4 transMat = etk::matRotate(property.m_angle) * etk::matTranslate(property.m_position);
|
||||
m_markedToUpdate=false;
|
||||
for (int32_t iii=0; iii<object.m_vertices.Size(); iii++) {
|
||||
vec3 point = transMat * object.m_vertices[iii];
|
||||
for (int32_t iii=0; iii<object.m_vertices.Size(); iii++) {
|
||||
vec3 point = transformMatrix * object.m_vertices[iii];
|
||||
if (0 == iii) {
|
||||
m_PointStart = point;
|
||||
m_PointStop = point;
|
||||
} else {
|
||||
if (m_PointStart.x > point.x) {
|
||||
m_PointStart.x = point.x;
|
||||
} else if (m_PointStop.x < point.x) {
|
||||
m_PointStop.x = point.x;
|
||||
}
|
||||
|
||||
if (m_PointStart.y > point.y) {
|
||||
m_PointStart.y = point.y;
|
||||
} else if (m_PointStop.y < point.y) {
|
||||
m_PointStop.y = point.y;
|
||||
}
|
||||
|
||||
if (m_PointStart.z > point.z) {
|
||||
m_PointStart.z = point.z;
|
||||
} else if (m_PointStop.z < point.z) {
|
||||
m_PointStop.z = point.z;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
#ifdef DEBUG
|
||||
vec3 tmpBB(0.001,0.001,0.001);
|
||||
vec3 tmpStart = m_PointStart - tmpBB;
|
||||
vec3 tmpStop = m_PointStop + tmpBB;
|
||||
// (start) X / Y
|
||||
vec3 tmpPos = tmpStart;
|
||||
m_vertices[0] = tmpStart;
|
||||
tmpPos.x = tmpStop.x;
|
||||
m_vertices[1] = tmpPos;
|
||||
tmpPos.y = tmpStop.y;
|
||||
m_vertices[2] = tmpPos;
|
||||
|
||||
m_vertices[3] = tmpStart;
|
||||
m_vertices[4] = tmpPos;
|
||||
tmpPos.x = tmpStart.x;
|
||||
m_vertices[5] = tmpPos;
|
||||
|
||||
// (start) Y / Z
|
||||
tmpPos = tmpStart;
|
||||
m_vertices[6] = tmpStart;
|
||||
tmpPos.z = tmpStop.z;
|
||||
m_vertices[7] = tmpPos;
|
||||
tmpPos.y = tmpStop.y;
|
||||
m_vertices[8] = tmpPos;
|
||||
|
||||
m_vertices[9] = tmpStart;
|
||||
m_vertices[10] = tmpPos;
|
||||
tmpPos.z = tmpStart.z;
|
||||
m_vertices[11] = tmpPos;
|
||||
|
||||
// (start) X / Z
|
||||
tmpPos = tmpStart;
|
||||
m_vertices[12] = tmpStart;
|
||||
tmpPos.x = tmpStop.x;
|
||||
m_vertices[13] = tmpPos;
|
||||
tmpPos.z = tmpStop.z;
|
||||
m_vertices[14] = tmpPos;
|
||||
|
||||
m_vertices[15] = tmpStart;
|
||||
m_vertices[16] = tmpPos;
|
||||
tmpPos.x = tmpStart.x;
|
||||
m_vertices[17] = tmpPos;
|
||||
|
||||
|
||||
// (stop) X / Y
|
||||
tmpPos = tmpStop;
|
||||
m_vertices[18] = tmpStop;
|
||||
tmpPos.x = tmpStart.x;
|
||||
m_vertices[19] = tmpPos;
|
||||
tmpPos.y = tmpStart.y;
|
||||
m_vertices[20] = tmpPos;
|
||||
|
||||
m_vertices[21] = tmpStop;
|
||||
m_vertices[22] = tmpPos;
|
||||
tmpPos.x = tmpStop.x;
|
||||
m_vertices[23] = tmpPos;
|
||||
|
||||
// (stop) Y / Z
|
||||
tmpPos = tmpStop;
|
||||
m_vertices[24] = tmpStop;
|
||||
tmpPos.z = tmpStart.z;
|
||||
m_vertices[25] = tmpPos;
|
||||
tmpPos.y = tmpStart.y;
|
||||
m_vertices[26] = tmpPos;
|
||||
|
||||
m_vertices[27] = tmpStop;
|
||||
m_vertices[28] = tmpPos;
|
||||
tmpPos.z = tmpStop.z;
|
||||
m_vertices[29] = tmpPos;
|
||||
|
||||
// (stop) X / Z
|
||||
tmpPos = tmpStop;
|
||||
m_vertices[30] = tmpStop;
|
||||
tmpPos.x = tmpStart.x;
|
||||
m_vertices[31] = tmpPos;
|
||||
tmpPos.z = tmpStart.z;
|
||||
m_vertices[32] = tmpPos;
|
||||
|
||||
m_vertices[33] = tmpStop;
|
||||
m_vertices[34] = tmpPos;
|
||||
tmpPos.x = tmpStop.x;
|
||||
m_vertices[35] = tmpPos;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void game::BoundingAABB::Draw(void)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (0 != m_vertices.Size()) {
|
||||
if (NULL != m_displayBounding) {
|
||||
m_displayBounding->Draw(m_vertices, m_color, false);
|
||||
}
|
||||
} else {
|
||||
EWOL_DEBUG("Bounding size is not correct...");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
#include "ewol/game/Bounding.h"
|
||||
#include "etk/math/Vector3D.h"
|
||||
#include "etk/math/Matrix4.h"
|
||||
#include "ewol/renderer/resources/Colored3DObject.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
@ -19,6 +21,11 @@ namespace game
|
||||
private :
|
||||
vec3 m_PointStart;
|
||||
vec3 m_PointStop;
|
||||
#ifdef DEBUG
|
||||
ewol::Colored3DObject* m_displayBounding;
|
||||
etk::Vector<vec3> m_vertices;
|
||||
etk::Vector<draw::Colorf> m_color;
|
||||
#endif
|
||||
public:
|
||||
/**
|
||||
* @biref Main constructor.
|
||||
@ -29,10 +36,10 @@ namespace game
|
||||
* @biref Main constructor.
|
||||
*/
|
||||
virtual ~BoundingAABB(void);
|
||||
/**
|
||||
* @brief Update Bounding properties.
|
||||
*/
|
||||
virtual void Update(game::MeshObject& object);
|
||||
// herited methodes
|
||||
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
|
||||
// herited methodes
|
||||
virtual void Draw(void);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ game::BoundingOBB::~BoundingOBB(void)
|
||||
|
||||
}
|
||||
|
||||
void game::BoundingOBB::Update(game::MeshObject& object)
|
||||
void game::BoundingOBB::Update(game::MeshObject& object, mat4& transformMatrix)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace game
|
||||
/**
|
||||
* @brief Update Bounding properties.
|
||||
*/
|
||||
virtual void Update(game::MeshObject& object);
|
||||
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ game::BoundingPlane::~BoundingPlane(void)
|
||||
|
||||
}
|
||||
|
||||
void game::BoundingPlane::Update(game::MeshObject& object)
|
||||
void game::BoundingPlane::Update(game::MeshObject& object, mat4& transformMatrix)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace game
|
||||
/**
|
||||
* @brief Update Bounding properties.
|
||||
*/
|
||||
virtual void Update(game::MeshObject& object);
|
||||
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ game::BoundingSphere::~BoundingSphere(void)
|
||||
|
||||
}
|
||||
|
||||
void game::BoundingSphere::Update(game::MeshObject& object)
|
||||
void game::BoundingSphere::Update(game::MeshObject& object, mat4& transformMatrix)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace game
|
||||
/**
|
||||
* @brief Update Bounding properties.
|
||||
*/
|
||||
virtual void Update(game::MeshObject& object);
|
||||
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,8 @@ namespace game
|
||||
* @param[in] pos Position of the camera.
|
||||
* @param[in] angles Rotations angles of the camera
|
||||
*/
|
||||
Camera(vec3 pos=vec3(0,0,2), vec3 angles=vec3(0,0,0));/**
|
||||
Camera(vec3 pos=vec3(0,0,0), vec3 angles=vec3(0,0,0));
|
||||
/**
|
||||
* @brief Set the position of the camera.
|
||||
* @param[in] pos Position of the camera.
|
||||
*/
|
||||
|
27
sources/ewol/game/Contact.cpp
Normal file
27
sources/ewol/game/Contact.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <ewol/game/Contact.h>
|
||||
|
||||
|
||||
|
||||
|
||||
game::Contact::Contact(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
game::Contact::~Contact(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
51
sources/ewol/game/Contact.h
Normal file
51
sources/ewol/game/Contact.h
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __GAME_CONTACT_H__
|
||||
#define __GAME_CONTACT_H__
|
||||
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/math/Vector3D.h>
|
||||
#include <ewol/game/Element.h>
|
||||
|
||||
namespace game
|
||||
{
|
||||
class Contact
|
||||
{
|
||||
protected:
|
||||
vec3 m_position;
|
||||
game::Element* m_element[2];
|
||||
public:
|
||||
/**
|
||||
* @brief Basic constructor.
|
||||
*/
|
||||
Contact(void);
|
||||
/**
|
||||
* @brief Basic destructor.
|
||||
*/
|
||||
virtual ~Contact(void);
|
||||
|
||||
/**
|
||||
* Recopy operator.
|
||||
*/
|
||||
const Contact& operator= (const Contact& obj ) {
|
||||
if( this == &obj ) {
|
||||
return *this;
|
||||
}
|
||||
// recopy all the element ...
|
||||
m_position = obj.m_position;
|
||||
m_element[0] = obj.m_element[0];
|
||||
m_element[1] = obj.m_element[1];
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -16,6 +16,8 @@ static int32_t uniqueId = 0;
|
||||
|
||||
game::Element::Element(etk::UString meshResource) :
|
||||
m_resource(NULL),
|
||||
m_bounding(NULL),
|
||||
m_matrixNeedUpdate(true),
|
||||
m_scale(1,1,1),
|
||||
m_mass(0.0f),
|
||||
m_uniqueId(uniqueId),
|
||||
@ -30,6 +32,7 @@ game::Element::Element(etk::UString meshResource) :
|
||||
m_resource = tmpObject;
|
||||
}
|
||||
uniqueId++;
|
||||
m_bounding = game::CreateBounding(game::BoundingModeAABB);
|
||||
}
|
||||
|
||||
game::Element::~Element(void)
|
||||
@ -39,6 +42,10 @@ game::Element::~Element(void)
|
||||
ewol::resource::Release(tmpObject);
|
||||
m_resource = NULL;
|
||||
}
|
||||
if (NULL != m_bounding) {
|
||||
delete(m_bounding);
|
||||
m_bounding = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void game::Element::Draw(void)
|
||||
@ -49,6 +56,14 @@ void game::Element::Draw(void)
|
||||
}
|
||||
}
|
||||
|
||||
void game::Element::DrawDebug(void)
|
||||
{
|
||||
if (NULL != m_bounding) {
|
||||
//EWOL_DEBUG("draw bounding" << m_uniqueId);
|
||||
m_bounding->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool game::Element::ArtificialIntelligence(int32_t deltaMicroSecond)
|
||||
{
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/game/Gravity.h>
|
||||
#include <ewol/renderer/resources/Mesh.h>
|
||||
#include <ewol/game/Bounding.h>
|
||||
|
||||
namespace game
|
||||
{
|
||||
@ -23,6 +24,7 @@ namespace game
|
||||
{
|
||||
protected:
|
||||
ewol::Mesh* m_resource; //!< Resource to display the element.
|
||||
game::Bounding* m_bounding; //!< Bounding of this element
|
||||
private:
|
||||
bool m_matrixNeedUpdate; //!< the matrix need to be regenerated
|
||||
mat4 m_matrix; //!< generated display matrix.
|
||||
@ -57,6 +59,10 @@ namespace game
|
||||
* @brief Draw the element.
|
||||
*/
|
||||
virtual void Draw(void);
|
||||
/**
|
||||
* @brief Draw Debug information of the element.
|
||||
*/
|
||||
virtual void DrawDebug(void);
|
||||
/**
|
||||
* @brief Process IA of this element.
|
||||
* @param[in] deltaMicroSecond delta from the last call.
|
||||
@ -127,7 +133,10 @@ namespace game
|
||||
{
|
||||
if (m_matrixNeedUpdate == true) {
|
||||
m_matrixNeedUpdate = false;
|
||||
m_matrix = etk::matScale(m_scale) * m_displayRotation * etk::matTranslate(m_position);
|
||||
m_matrix = etk::matTranslate(m_position) * etk::matScale(m_scale) * m_displayRotation;
|
||||
if (m_bounding!=NULL) {
|
||||
m_bounding->Update(m_resource->m_object, m_matrix);
|
||||
}
|
||||
}
|
||||
return m_matrix;
|
||||
};
|
||||
|
@ -96,6 +96,18 @@ void game::Engine::Draw(ewol::DrawProperty& displayProp)
|
||||
m_elementsDynamic[iii]->Draw();
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
for (int32_t iii=0; iii<m_elementsStatic.Size() ; iii++) {
|
||||
if (NULL != m_elementsStatic[iii]) {
|
||||
m_elementsStatic[iii]->DrawDebug();
|
||||
}
|
||||
}
|
||||
for (int32_t iii=0; iii<m_elementsDynamic.Size() ; iii++) {
|
||||
if (NULL != m_elementsDynamic[iii]) {
|
||||
m_elementsDynamic[iii]->DrawDebug();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/game/Element.h>
|
||||
#include <ewol/game/Gravity.h>
|
||||
#include <ewol/game/Contact.h>
|
||||
#include <ewol/widget/Widget.h>
|
||||
|
||||
|
||||
@ -26,6 +27,7 @@ namespace game
|
||||
etk::Vector<game::Gravity> m_gravity; //!< list of gravity element
|
||||
etk::Vector<game::Element*> m_elementsStatic; //!< List of the game element (bounding does not move)
|
||||
etk::Vector<game::Element*> m_elementsDynamic; //!< List of the game element (change position all the time)
|
||||
etk::Vector<game::Contact> m_contacts; //!< list of all contact that existe in the system
|
||||
public:
|
||||
/**
|
||||
* @brief Basic constructor.
|
||||
|
@ -73,7 +73,7 @@ void game::Geometry::SetBoundingMode(game::boundingMode type)
|
||||
void game::Geometry::BoundingUpdate(void)
|
||||
{
|
||||
if (NULL != m_bounding) {
|
||||
m_bounding->Update(m_object);
|
||||
//m_bounding->Update(m_object);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object)
|
||||
|
||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object)
|
||||
{
|
||||
EWOL_VERBOSE("KEEP : ShSimpleader : file : \"" << filename << "\"");
|
||||
EWOL_VERBOSE("KEEP : Simpleshader : file : \"" << filename << "\"");
|
||||
object = static_cast<ewol::Shader*>(LocalKeep(filename));
|
||||
if (NULL != object) {
|
||||
return true;
|
||||
@ -260,6 +260,23 @@ bool ewol::resource::Keep(ewol::Texture*& object)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ewol::resource::Keep(ewol::Colored3DObject*& object)
|
||||
{
|
||||
EWOL_VERBOSE("KEEP : direct Colored3DObject");
|
||||
etk::UString filename = "?metaObject?Colored3DObject";
|
||||
object = static_cast<ewol::Colored3DObject*>(LocalKeep(filename));
|
||||
if (NULL != object) {
|
||||
return true;
|
||||
}
|
||||
// need to crate a new one ...
|
||||
object = new ewol::Colored3DObject(filename);
|
||||
if (NULL == object) {
|
||||
EWOL_ERROR("allocation error of a resource : Colored3DObject ");
|
||||
return false;
|
||||
}
|
||||
LocalAdd(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the next power 2 if the input
|
||||
@ -431,3 +448,10 @@ void ewol::resource::Release(ewol::ConfigFile*& object)
|
||||
Release(object2);
|
||||
object = NULL;
|
||||
}
|
||||
|
||||
void ewol::resource::Release(ewol::Colored3DObject*& object)
|
||||
{
|
||||
ewol::Resource* object2 = static_cast<ewol::Resource*>(object);
|
||||
Release(object2);
|
||||
object = NULL;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <ewol/renderer/resources/Texture.h>
|
||||
#include <ewol/renderer/resources/Image.h>
|
||||
#include <ewol/renderer/resources/MeshObj.h>
|
||||
#include <ewol/renderer/resources/Colored3DObject.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
@ -46,6 +47,7 @@ namespace ewol
|
||||
bool Keep(etk::UString& accesMode, ewol::VirtualBufferObject*& object);
|
||||
bool Keep(etk::UString& filename, ewol::MeshObj*& object);
|
||||
bool Keep(etk::UString& filename, ewol::ConfigFile*& object);
|
||||
bool Keep(ewol::Colored3DObject*& object);
|
||||
|
||||
void Release(ewol::Resource*& object);
|
||||
void Release(ewol::TexturedFont*& object);
|
||||
@ -57,6 +59,7 @@ namespace ewol
|
||||
void Release(ewol::VirtualBufferObject*& object);
|
||||
void Release(ewol::MeshObj*& object);
|
||||
void Release(ewol::ConfigFile*& object);
|
||||
void Release(ewol::Colored3DObject*& object);
|
||||
}
|
||||
};
|
||||
|
||||
|
69
sources/ewol/renderer/resources/Colored3DObject.cpp
Normal file
69
sources/ewol/renderer/resources/Colored3DObject.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/debug.h>
|
||||
#include <ewol/renderer/resources/Colored3DObject.h>
|
||||
#include <ewol/renderer/ResourceManager.h>
|
||||
|
||||
|
||||
ewol::Colored3DObject::Colored3DObject(etk::UString genName) :
|
||||
ewol::Resource(genName),
|
||||
m_GLprogram(NULL)
|
||||
{
|
||||
etk::UString tmpString("DATA:color3.prog");
|
||||
// get the shader resource :
|
||||
m_GLPosition = 0;
|
||||
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
|
||||
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->GetAttribute("EW_color");
|
||||
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
|
||||
}
|
||||
}
|
||||
|
||||
ewol::Colored3DObject::~Colored3DObject(void)
|
||||
{
|
||||
// remove dynamics dependencies :
|
||||
ewol::resource::Release(m_GLprogram);
|
||||
}
|
||||
|
||||
|
||||
void ewol::Colored3DObject::Draw(etk::Vector<vec3>& vertices,
|
||||
etk::Vector<draw::Colorf>& color,
|
||||
bool updateDepthBuffer)
|
||||
{
|
||||
if (vertices.Size()<=0) {
|
||||
return;
|
||||
}
|
||||
if (m_GLprogram==NULL) {
|
||||
EWOL_ERROR("No shader ...");
|
||||
return;
|
||||
}
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
if (false==updateDepthBuffer) {
|
||||
glDepthMask(GL_FALSE);
|
||||
}
|
||||
//EWOL_DEBUG(" Display " << m_coord.Size() << " elements" );
|
||||
m_GLprogram->Use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = ewol::openGL::GetMatrix();
|
||||
mat4 camMatrix = ewol::openGL::GetCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
|
||||
// position :
|
||||
m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z*/, &vertices[0]);
|
||||
// color :
|
||||
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &color[0]);
|
||||
// Request the draw od the elements :
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.Size());
|
||||
m_GLprogram->UnUse();
|
||||
if (false==updateDepthBuffer) {
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
40
sources/ewol/renderer/resources/Colored3DObject.h
Normal file
40
sources/ewol/renderer/resources/Colored3DObject.h
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __COLORED_3D_OBJECT_H__
|
||||
#define __COLORED_3D_OBJECT_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <ewol/renderer/resources/Resource.h>
|
||||
#include <ewol/renderer/resources/Image.h>
|
||||
#include <ewol/renderer/resources/Shader.h>
|
||||
#include <ewol/renderer/resources/Program.h>
|
||||
#include <ewol/game/MeshObject.h>
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
class Colored3DObject : public ewol::Resource
|
||||
{
|
||||
protected:
|
||||
ewol::Program* m_GLprogram;
|
||||
int32_t m_GLPosition;
|
||||
int32_t m_GLMatrix;
|
||||
int32_t m_GLColor;
|
||||
public:
|
||||
Colored3DObject(etk::UString genName);
|
||||
virtual ~Colored3DObject(void);
|
||||
virtual const char* GetType(void) { return "ewol::Colored3DObject"; };
|
||||
virtual void Draw(etk::Vector<vec3>& vertices,
|
||||
etk::Vector<draw::Colorf>& color,
|
||||
bool updateDepthBuffer=true);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -27,7 +27,9 @@ namespace ewol
|
||||
int32_t m_GLColor;
|
||||
int32_t m_GLtexture;
|
||||
int32_t m_GLtexID;
|
||||
public:
|
||||
game::MeshObject m_object;
|
||||
protected:
|
||||
ewol::TextureFile* m_texture1;
|
||||
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
|
||||
public:
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
widget::Scene::Scene(game::Engine* gameEngine) :
|
||||
m_camera(vec3(-6,0,2), vec3(0,0,0)),
|
||||
m_gameEngine(gameEngine),
|
||||
m_isRunning(true),
|
||||
m_lastCallTime(-1),
|
||||
|
@ -29,6 +29,7 @@ FILE_LIST+= ewol/renderer/resources/Shader.cpp \
|
||||
ewol/renderer/resources/Mesh.cpp \
|
||||
ewol/renderer/resources/MeshObj.cpp \
|
||||
ewol/renderer/resources/Texture.cpp \
|
||||
ewol/renderer/resources/Colored3DObject.cpp \
|
||||
ewol/renderer/resources/Image.cpp \
|
||||
ewol/renderer/resources/image/ImageBMP.cpp \
|
||||
ewol/renderer/resources/image/ImagePNG.cpp \
|
||||
@ -91,6 +92,7 @@ FILE_LIST+= ewol/widget/Scene.cpp \
|
||||
ewol/game/Geometry.cpp \
|
||||
ewol/game/Gravity.cpp \
|
||||
ewol/game/Camera.cpp \
|
||||
ewol/game/Contact.cpp \
|
||||
ewol/game/Map.cpp \
|
||||
ewol/game/Mass.cpp \
|
||||
ewol/game/Sky.cpp
|
||||
|
Loading…
x
Reference in New Issue
Block a user