From 549ac760d7964eb8accb7731f6d3150bcf7d801a Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 1 Jan 2013 21:56:39 +0100 Subject: [PATCH] [DEV] detect bounding and display bounding simplify --- data/simple3D.frag | 10 ++ data/simple3D.prog | 2 + data/simple3D.vert | 18 +++ external/agg | 2 +- sources/ewol/game/Bounding.cpp | 3 +- sources/ewol/game/Bounding.h | 24 +++- sources/ewol/game/BoundingAABB.cpp | 32 ++++- sources/ewol/game/BoundingAABB.h | 3 +- sources/ewol/game/Element.cpp | 8 +- sources/ewol/game/Element.h | 8 +- sources/ewol/game/Engine.cpp | 130 +++++++++--------- sources/ewol/game/Engine.h | 10 +- .../renderer/resources/Colored3DObject.cpp | 8 +- .../ewol/renderer/resources/Colored3DObject.h | 2 +- sources/file.mk | 4 + 15 files changed, 169 insertions(+), 95 deletions(-) create mode 100644 data/simple3D.frag create mode 100644 data/simple3D.prog create mode 100644 data/simple3D.vert diff --git a/data/simple3D.frag b/data/simple3D.frag new file mode 100644 index 00000000..cb8e54cd --- /dev/null +++ b/data/simple3D.frag @@ -0,0 +1,10 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +varying vec4 f_color; + +void main(void) { + gl_FragColor = f_color; +} diff --git a/data/simple3D.prog b/data/simple3D.prog new file mode 100644 index 00000000..9106c328 --- /dev/null +++ b/data/simple3D.prog @@ -0,0 +1,2 @@ +simple3D.vert +simple3D.frag \ No newline at end of file diff --git a/data/simple3D.vert b/data/simple3D.vert new file mode 100644 index 00000000..cdc691a1 --- /dev/null +++ b/data/simple3D.vert @@ -0,0 +1,18 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +// Input : +attribute vec3 EW_coord3d; +uniform vec4 EW_color; +uniform mat4 EW_MatrixTransformation; + +// output : +varying vec4 f_color; + +void main(void) { + gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0); + //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0); + f_color = EW_color; +} diff --git a/external/agg b/external/agg index 4a997e47..404b68ec 160000 --- a/external/agg +++ b/external/agg @@ -1 +1 @@ -Subproject commit 4a997e47d5b724d994403f499f2258fc86e764b3 +Subproject commit 404b68ec9fcd970c3daf5aa6a43331bd852551df diff --git a/sources/ewol/game/Bounding.cpp b/sources/ewol/game/Bounding.cpp index 85f97eb1..33cfb958 100644 --- a/sources/ewol/game/Bounding.cpp +++ b/sources/ewol/game/Bounding.cpp @@ -11,7 +11,8 @@ game::Bounding::Bounding(boundingMode mode) : - m_mode(mode) + m_mode(mode), + m_hasContact(false) { } diff --git a/sources/ewol/game/Bounding.h b/sources/ewol/game/Bounding.h index b4c85268..0413fb12 100644 --- a/sources/ewol/game/Bounding.h +++ b/sources/ewol/game/Bounding.h @@ -9,25 +9,26 @@ #ifndef __GAME_BOUNDING_H__ #define __GAME_BOUNDING_H__ -#include "ewol/debug.h" -#include "ewol/game/MeshObject.h" +#include +#include #include +//#include namespace game { typedef enum { - BoundingModeNone, //!< No Bounding. BoundingModePlane, //!< plane Bounding. - BoundingModeAABB, //!< Anti-aligned Bounding Boxes. BoundingModeSphere, //!< Sphere. + BoundingModeAABB, //!< Anti-aligned Bounding Boxes. BoundingModeOBB, //!< Oriented Bounding Box. // TODO : Add more if needed to implement } boundingMode; class Bounding { - protected : + protected: boundingMode m_mode; //!< bounding mode of this system. + bool m_hasContact; //!< this bounding is on contact with something else ... public: /** * @biref Main constructor. @@ -48,9 +49,20 @@ namespace game */ virtual void Update(game::MeshObject& object, mat4& transformMatrix) {}; /** - * Draw the bounding ==> for test ... + * @brief Draw the bounding ==> for test ... */ virtual void Draw(void) {}; + /** + * @brief Detect the colision positions. + */ + //virtual void GenerateContact(game::Element* ourElement, game::Bounding* otherbounding, game::Element* otherElements, etk::Vector& contactList); + virtual bool HasContact(game::Bounding& otherbounding) { return false; }; + /** + * @brief Set the contact property at a specific value ... + */ + void SetContactMode(bool newStatus) { m_hasContact=newStatus; }; + + bool GetContactStatus(void) { return m_hasContact; }; }; Bounding* CreateBounding(boundingMode mode); diff --git a/sources/ewol/game/BoundingAABB.cpp b/sources/ewol/game/BoundingAABB.cpp index e0f365c0..ef671efd 100644 --- a/sources/ewol/game/BoundingAABB.cpp +++ b/sources/ewol/game/BoundingAABB.cpp @@ -21,12 +21,8 @@ game::BoundingAABB::BoundingAABB(void) : 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 @@ -156,9 +152,13 @@ void game::BoundingAABB::Update(game::MeshObject& object, mat4& transformMatrix) void game::BoundingAABB::Draw(void) { #ifdef DEBUG + draw::Colorf color(0.0, 1.0, 0.0, 0.2); + if (true == m_hasContact) { + color = draw::Colorf(1.0, 0.0, 0.0, 0.2); + } if (0 != m_vertices.Size()) { if (NULL != m_displayBounding) { - m_displayBounding->Draw(m_vertices, m_color, false); + m_displayBounding->Draw(m_vertices, color, false); } } else { EWOL_DEBUG("Bounding size is not correct..."); @@ -167,4 +167,26 @@ void game::BoundingAABB::Draw(void) } +bool game::BoundingAABB::HasContact(game::Bounding& otherbounding) +{ + switch(otherbounding.GetType()) { + case game::BoundingModeAABB: + { + game::BoundingAABB& other = static_cast(otherbounding); + if( m_PointStart.x > other.m_PointStop.x + || m_PointStop.x < other.m_PointStart.x + || m_PointStart.y > other.m_PointStop.y + || m_PointStop.y < other.m_PointStart.y + || m_PointStart.z > other.m_PointStop.z + || m_PointStop.z < other.m_PointStart.z) { + return false; + } + return true; + } + default: + EWOL_DEBUG("TODO ... "); + return false; + } +} + diff --git a/sources/ewol/game/BoundingAABB.h b/sources/ewol/game/BoundingAABB.h index 3617e97d..51e289ed 100644 --- a/sources/ewol/game/BoundingAABB.h +++ b/sources/ewol/game/BoundingAABB.h @@ -24,7 +24,6 @@ namespace game #ifdef DEBUG ewol::Colored3DObject* m_displayBounding; etk::Vector m_vertices; - etk::Vector m_color; #endif public: /** @@ -40,6 +39,8 @@ namespace game virtual void Update(game::MeshObject& object, mat4& transformMatrix); // herited methodes virtual void Draw(void); + // herited methodes + virtual bool HasContact(game::Bounding& otherbounding); }; } diff --git a/sources/ewol/game/Element.cpp b/sources/ewol/game/Element.cpp index c1ed122d..99f83c5a 100644 --- a/sources/ewol/game/Element.cpp +++ b/sources/ewol/game/Element.cpp @@ -19,6 +19,7 @@ game::Element::Element(etk::UString meshResource) : m_bounding(NULL), m_matrixNeedUpdate(true), m_scale(1,1,1), + m_speedMax(2000000, 2000000, 2000000), m_mass(0.0f), m_uniqueId(uniqueId), m_groupId(0), @@ -65,7 +66,7 @@ void game::Element::DrawDebug(void) } -bool game::Element::ArtificialIntelligence(int32_t deltaMicroSecond) +bool game::Element::ArtificialIntelligence(float deltaMicroSecond) { return false; } @@ -99,10 +100,15 @@ void game::Element::ProcessGravity(float delta, game::Gravity& gravity) void game::Element::ProcessPosition(float delta) { + if( NULL!=m_bounding + && true == m_bounding->GetContactStatus()) { + return; + } vec3 m_speed0(m_speed); vec3 curentAcceleration(m_gravityForce + m_userAcceleration); m_speed += curentAcceleration*delta; vec3 tmpPos = m_position +m_speed0*delta + curentAcceleration*delta*delta/2.0f ; + if (m_position != tmpPos) { m_position = tmpPos; m_matrixNeedUpdate = true; diff --git a/sources/ewol/game/Element.h b/sources/ewol/game/Element.h index d4f1b562..4cb3c31d 100644 --- a/sources/ewol/game/Element.h +++ b/sources/ewol/game/Element.h @@ -36,6 +36,7 @@ namespace game // specific for the physical engine : vec3 m_position; //!< position of the element. (in m) vec3 m_speed; //!< Speed of the element. (in m/s) + vec3 m_speedMax; //!< Speed maximum limitation. (in m/s) float m_mass; //!< object mass (in kg) vec3 m_gravityForce; //!< curent gravity force in newton of the object (m/s^2) vec3 m_userAcceleration; //!< the only one parameter that the user can change (m/s^2), if the coder want that the equation do not take stipid things ... @@ -68,7 +69,7 @@ namespace game * @param[in] deltaMicroSecond delta from the last call. * @return true if this element must be destroyed */ - virtual bool ArtificialIntelligence(int32_t deltaMicroSecond); + virtual bool ArtificialIntelligence(float delta); /** * @brief Clear the current gravity reference */ @@ -144,6 +145,11 @@ namespace game { m_speed = newSpeed; } + + game::Bounding* GetBounding(void) + { + return m_bounding; + } }; }; diff --git a/sources/ewol/game/Engine.cpp b/sources/ewol/game/Engine.cpp index 210a7967..0015f428 100644 --- a/sources/ewol/game/Engine.cpp +++ b/sources/ewol/game/Engine.cpp @@ -20,20 +20,13 @@ game::Engine::Engine(void) game::Engine::~Engine(void) { - for (int32_t iii=0; iiiProcessGravity(deltaTime, m_gravity[jjj]); + for (int32_t iii=0; iiiProcessGravity(deltaTime, m_gravity[jjj]); } - m_elementsStatic[iii]->ProcessPosition(deltaTime); - } - for (int32_t iii=0; iiiProcessGravity(deltaTime, m_gravity[jjj]); - } - m_elementsDynamic[iii]->ProcessPosition(deltaTime); + m_elements[iii]->ProcessPosition(deltaTime); } } } @@ -65,14 +52,9 @@ void game::Engine::ProcessGravity(float deltaTime) void game::Engine::ProcessIA(float deltaTime) { //EWOL_DEBUG("Artificial Intelligence management"); - for (int32_t iii=0; iiiArtificialIntelligence(deltaTime); - } - } - for (int32_t iii=0; iiiArtificialIntelligence(deltaTime); + for (int32_t iii=0; iiiArtificialIntelligence(deltaTime); } } } @@ -80,63 +62,75 @@ void game::Engine::ProcessIA(float deltaTime) void game::Engine::ProcessCollision(float deltaTime) { //EWOL_DEBUG("Collision management"); + m_contacts.Clear(); + for (int32_t iii=0; iiiGetBounding(); + if (NULL != bounding1) { + bounding1->SetContactMode(false); + } + } + } + for (int32_t iii=0; iiiGetBounding(); + if (NULL != bounding1) { + for (int32_t jjj=iii+1; jjjGetBounding(); + if (NULL != bounding2) { + bool hasContactConfirmed = false; + if (bounding1->GetType() < bounding2->GetType()) { + //bounding2->GenerateContact(m_elements[jjj], bounding1, m_elements[iii], m_contacts); + hasContactConfirmed = bounding2->HasContact(*bounding1); + } else { + //bounding1->GenerateContact(m_elements[iii], bounding2, m_elements[jjj], m_contacts); + hasContactConfirmed = bounding1->HasContact(*bounding2); + } + if (true == hasContactConfirmed) { + bounding2->SetContactMode(true); + bounding1->SetContactMode(true); + } + } + } + } + } + } + } } void game::Engine::Draw(ewol::DrawProperty& displayProp) { //EWOL_DEBUG("Drawing the system"); - for (int32_t iii=0; iiiDraw(); - } - } - for (int32_t iii=0; iiiDraw(); + for (int32_t iii=0; iiiDraw(); } } #ifdef DEBUG - for (int32_t iii=0; iiiDrawDebug(); - } - } - for (int32_t iii=0; iiiDrawDebug(); + for (int32_t iii=0; iiiDrawDebug(); } } #endif } -void game::Engine::AddElement(game::Element* newElement, bool dynamic) +void game::Engine::AddElement(game::Element* newElement) { bool find=false; - if (true == dynamic) { - for (int32_t iii=0 ; iii m_gravity; //!< list of gravity element - etk::Vector m_elementsStatic; //!< List of the game element (bounding does not move) - etk::Vector m_elementsDynamic; //!< List of the game element (change position all the time) - etk::Vector m_contacts; //!< list of all contact that existe in the system + etk::Vector m_gravity; //!< list of gravity element + etk::Vector m_elements; //!< List of the game element + etk::Vector m_contacts; //!< list of all contact that existe in the system public: /** * @brief Basic constructor. @@ -65,9 +64,8 @@ namespace game /** * @brief Add an element on the system. * @param[in] newElement element to display. - * @param[in] dynamic this element change of place. */ - void AddElement(game::Element* newElement, bool dynamic); + void AddElement(game::Element* newElement); /** * @brief Add a gravity on the system. * @param[in] gravity The gravity to add. diff --git a/sources/ewol/renderer/resources/Colored3DObject.cpp b/sources/ewol/renderer/resources/Colored3DObject.cpp index 37e58222..43c19692 100644 --- a/sources/ewol/renderer/resources/Colored3DObject.cpp +++ b/sources/ewol/renderer/resources/Colored3DObject.cpp @@ -15,12 +15,12 @@ ewol::Colored3DObject::Colored3DObject(etk::UString genName) : ewol::Resource(genName), m_GLprogram(NULL) { - etk::UString tmpString("DATA:color3.prog"); + etk::UString tmpString("DATA:simple3D.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_GLColor = m_GLprogram->GetUniform("EW_color"); m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); } } @@ -33,7 +33,7 @@ ewol::Colored3DObject::~Colored3DObject(void) void ewol::Colored3DObject::Draw(etk::Vector& vertices, - etk::Vector& color, + draw::Colorf& color, bool updateDepthBuffer) { if (vertices.Size()<=0) { @@ -57,7 +57,7 @@ void ewol::Colored3DObject::Draw(etk::Vector& vertices, // 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]); + m_GLprogram->Uniform4fv(m_GLColor, 1/*r,g,b,a*/, (float*)&color); // Request the draw od the elements : glDrawArrays(GL_TRIANGLES, 0, vertices.Size()); m_GLprogram->UnUse(); diff --git a/sources/ewol/renderer/resources/Colored3DObject.h b/sources/ewol/renderer/resources/Colored3DObject.h index e614d2cc..c2da3d87 100644 --- a/sources/ewol/renderer/resources/Colored3DObject.h +++ b/sources/ewol/renderer/resources/Colored3DObject.h @@ -30,7 +30,7 @@ namespace ewol virtual ~Colored3DObject(void); virtual const char* GetType(void) { return "ewol::Colored3DObject"; }; virtual void Draw(etk::Vector& vertices, - etk::Vector& color, + draw::Colorf& color, bool updateDepthBuffer=true); }; diff --git a/sources/file.mk b/sources/file.mk index e8316218..2ba7f55f 100644 --- a/sources/file.mk +++ b/sources/file.mk @@ -110,6 +110,10 @@ LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \ ../data/color3.frag:color3.frag \ ../data/color3.vert:color3.vert \ \ + ../data/simple3D.prog:simple3D.prog \ + ../data/simple3D.frag:simple3D.frag \ + ../data/simple3D.vert:simple3D.vert \ + \ ../data/textured.prog:textured.prog \ ../data/textured.frag:textured.frag \ ../data/textured.vert:textured.vert \