[DEV] Simplify the Game engine

This commit is contained in:
Edouard DUPIN 2013-01-03 21:03:23 +01:00
parent 549ac760d7
commit 93d3e62b8e
17 changed files with 83 additions and 557 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit ba9e2fca7bece1f46eac6f29c0ca5e2c54f59d89
Subproject commit 3b5aa7b84f5f41c72eccf3c2fecb6f8404401e9b

View File

@ -1,35 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/game/Bounding.h>
#include <ewol/game/BoundingAABB.h>
game::Bounding::Bounding(boundingMode mode) :
m_mode(mode),
m_hasContact(false)
{
}
game::Bounding::~Bounding(void)
{
}
game::Bounding* game::CreateBounding(game::boundingMode mode)
{
switch(mode) {
case game::BoundingModeAABB:
return new game::BoundingAABB();
default:
return NULL;
}
}

View File

@ -1,72 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_BOUNDING_H__
#define __GAME_BOUNDING_H__
#include <ewol/debug.h>
#include <ewol/game/MeshObject.h>
#include <etk/math/Matrix4.h>
//#include <ewol/game/Contact.h>
namespace game
{
typedef enum {
BoundingModePlane, //!< plane Bounding.
BoundingModeSphere, //!< Sphere.
BoundingModeAABB, //!< Anti-aligned Bounding Boxes.
BoundingModeOBB, //!< Oriented Bounding Box.
// TODO : Add more if needed to implement
} boundingMode;
class Bounding
{
protected:
boundingMode m_mode; //!< bounding mode of this system.
bool m_hasContact; //!< this bounding is on contact with something else ...
public:
/**
* @biref Main constructor.
* @param[in] mode Bounding mode.
*/
Bounding(boundingMode mode);
/**
* @biref Main constructor.
*/
virtual ~Bounding(void);
/**
* @brief Get the bounding type
* @return the bounding type;
*/
boundingMode GetType(void) { return m_mode; };
/**
* @brief Update Bounding properties.
*/
virtual void Update(game::MeshObject& object, mat4& transformMatrix) {};
/**
* @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<game::Contact>& 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);
};
#endif

View File

@ -13,9 +13,10 @@
game::BoundingAABB::BoundingAABB(void) :
Bounding(game::BoundingModeAABB),
m_PointStart(-1,-1,-1),
m_PointStop(1,1,1)
m_hasContact(false),
m_center(0,0,0),
m_size(1,1,1),
m_oldUserPosition(0,0,0)
{
#ifdef DEBUG
if (false == ewol::resource::Keep(m_displayBounding) ) {
@ -36,37 +37,46 @@ game::BoundingAABB::~BoundingAABB(void)
}
void game::BoundingAABB::Update(game::MeshObject& object, mat4& transformMatrix)
void game::BoundingAABB::Update(game::MeshObject& object, mat4& rotation, vec3& position, vec3& scale)
{
vec3 pointStart;
vec3 pointStop;
mat4 transformMatrix = etk::matTranslate(position)
* etk::matScale(scale)
* rotation;
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;
pointStart = point;
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 (pointStart.x > point.x) {
pointStart.x = point.x;
} else if (pointStop.x < point.x) {
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 (pointStart.y > point.y) {
pointStart.y = point.y;
} else if (pointStop.y < point.y) {
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;
if (pointStart.z > point.z) {
pointStart.z = point.z;
} else if (pointStop.z < point.z) {
pointStop.z = point.z;
}
}
}
m_size = (pointStop - pointStart) / 2;
m_center = pointStop - m_size;
m_oldUserPosition = position;
#ifdef DEBUG
vec3 tmpBB(0.001,0.001,0.001);
vec3 tmpStart = m_PointStart - tmpBB;
vec3 tmpStop = m_PointStop + tmpBB;
vec3 tmpStart = pointStart - tmpBB;
vec3 tmpStop = pointStop + tmpBB;
// (start) X / Y
vec3 tmpPos = tmpStart;
m_vertices[0] = tmpStart;
@ -167,26 +177,14 @@ void game::BoundingAABB::Draw(void)
}
bool game::BoundingAABB::HasContact(game::Bounding& otherbounding)
bool game::BoundingAABB::HasContact(game::BoundingAABB& obj)
{
switch(otherbounding.GetType()) {
case game::BoundingModeAABB:
{
game::BoundingAABB& other = static_cast<game::BoundingAABB&>(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;
if( (abs(m_center.x-obj.m_center.x) > m_size.x+obj.m_size.x)
|| (abs(m_center.y-obj.m_center.y) > m_size.y+obj.m_size.y)
|| (abs(m_center.z-obj.m_center.z) > m_size.z+obj.m_size.z) ) {
return false;
}
return true;
}

View File

@ -9,18 +9,19 @@
#ifndef __GAME_BOUNDING_AABB_H__
#define __GAME_BOUNDING_AABB_H__
#include "ewol/game/Bounding.h"
#include "etk/math/Vector3D.h"
#include "etk/math/Matrix4.h"
#include "ewol/renderer/resources/Colored3DObject.h"
namespace game
{
class BoundingAABB : public Bounding
class BoundingAABB
{
private :
vec3 m_PointStart;
vec3 m_PointStop;
bool m_hasContact; //!< this bounding is on contact with something else ...
vec3 m_center;
vec3 m_size;
vec3 m_oldUserPosition; // this is due to the fact object are never centered ...
#ifdef DEBUG
ewol::Colored3DObject* m_displayBounding;
etk::Vector<vec3> m_vertices;
@ -28,19 +29,32 @@ namespace game
public:
/**
* @biref Main constructor.
* @param[in] mode Bounding mode.
*/
BoundingAABB(void);
/**
* @biref Main constructor.
*/
virtual ~BoundingAABB(void);
// herited methodes
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
// herited methodes
/**
* @brief Update Bounding properties.
*/
virtual void Update(game::MeshObject& object, mat4& rotation, vec3& position, vec3& scale);
/**
* @brief Draw the bounding ==> for test ...
*/
virtual void Draw(void);
// herited methodes
virtual bool HasContact(game::Bounding& otherbounding);
/**
* @brief Detect the colision positions.
*/
virtual bool HasContact(game::BoundingAABB& otherbounding);
/**
* @brief Set the contact property at a specific value ...
*/
void SetContactMode(bool newStatus) { m_hasContact=newStatus; };
/**
* @brief Get the current contact status
*/
bool GetContactStatus(void) { return m_hasContact; };
};
}

View File

@ -1,30 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/debug.h>
#include <ewol/game/BoundingOBB.h>
game::BoundingOBB::BoundingOBB(game::MeshObject& object) :
Bounding(game::BoundingModeOBB)
{
}
game::BoundingOBB::~BoundingOBB(void)
{
}
void game::BoundingOBB::Update(game::MeshObject& object, mat4& transformMatrix)
{
}

View File

@ -1,41 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_BOUNDING_OBB_H__
#define __GAME_BOUNDING_OBB_H__
#include "ewol/game/Bounding.h"
#include "etk/math/Vector3D.h"
namespace game
{
class BoundingOBB : public Bounding
{
private :
vec3 m_PointCenter;
vec3 m_radius;
vec3 m_angle;
public:
/**
* @biref Main constructor.
* @param[in] mode Bounding mode.
*/
BoundingOBB(game::MeshObject& object);
/**
* @biref Main constructor.
*/
virtual ~BoundingOBB(void);
/**
* @brief Update Bounding properties.
*/
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
};
}
#endif

View File

@ -1,30 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/debug.h>
#include <ewol/game/BoundingPlane.h>
game::BoundingPlane::BoundingPlane(void) :
Bounding(game::BoundingModePlane)
{
}
game::BoundingPlane::~BoundingPlane(void)
{
}
void game::BoundingPlane::Update(game::MeshObject& object, mat4& transformMatrix)
{
}

View File

@ -1,39 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_BOUNDING_PLANE_H__
#define __GAME_BOUNDING_PLANE_H__
#include "ewol/game/Bounding.h"
#include "etk/math/Vector3D.h"
namespace game
{
class BoundingPlane : public Bounding
{
private :
vec3 m_equation;
public:
/**
* @biref Main constructor.
* @param[in] mode Bounding mode.
*/
BoundingPlane(void);
/**
* @biref Main constructor.
*/
virtual ~BoundingPlane(void);
/**
* @brief Update Bounding properties.
*/
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
};
}
#endif

View File

@ -1,31 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/debug.h>
#include <ewol/game/BoundingSphere.h>
game::BoundingSphere::BoundingSphere(void) :
Bounding(game::BoundingModeSphere)
{
}
game::BoundingSphere::~BoundingSphere(void)
{
}
void game::BoundingSphere::Update(game::MeshObject& object, mat4& transformMatrix)
{
}

View File

@ -1,40 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_BOUNDING_SPHERE_H__
#define __GAME_BOUNDING_SPHERE_H__
#include "ewol/game/Bounding.h"
#include "etk/math/Vector3D.h"
namespace game
{
class BoundingSphere : public Bounding
{
private :
vec3 m_position; //!< Position of the center of the bounding
float m_radius; //!< Radius of the Bounding
public:
/**
* @biref Main constructor.
* @param[in] mode Bounding mode.
*/
BoundingSphere(void);
/**
* @biref Main constructor.
*/
virtual ~BoundingSphere(void);
/**
* @brief Update Bounding properties.
*/
virtual void Update(game::MeshObject& object, mat4& transformMatrix);
};
}
#endif

View File

@ -16,7 +16,6 @@ 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_speedMax(2000000, 2000000, 2000000),
@ -33,7 +32,6 @@ game::Element::Element(etk::UString meshResource) :
m_resource = tmpObject;
}
uniqueId++;
m_bounding = game::CreateBounding(game::BoundingModeAABB);
}
game::Element::~Element(void)
@ -43,10 +41,6 @@ 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)
@ -59,10 +53,8 @@ void game::Element::Draw(void)
void game::Element::DrawDebug(void)
{
if (NULL != m_bounding) {
//EWOL_DEBUG("draw bounding" << m_uniqueId);
m_bounding->Draw();
}
//EWOL_DEBUG("draw bounding" << m_uniqueId);
m_bounding.Draw();
}
@ -100,15 +92,14 @@ void game::Element::ProcessGravity(float delta, game::Gravity& gravity)
void game::Element::ProcessPosition(float delta)
{
if( NULL!=m_bounding
&& true == m_bounding->GetContactStatus()) {
if(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 ;
vec3 tmpPos = m_position +m_speed*delta;
// TODO : Detect collision of other elements ...
if (m_position != tmpPos) {
m_position = tmpPos;
m_matrixNeedUpdate = true;

View File

@ -16,7 +16,7 @@
#include <ewol/debug.h>
#include <ewol/game/Gravity.h>
#include <ewol/renderer/resources/Mesh.h>
#include <ewol/game/Bounding.h>
#include <ewol/game/BoundingAABB.h>
namespace game
{
@ -24,12 +24,11 @@ namespace game
{
protected:
ewol::Mesh* m_resource; //!< Resource to display the element.
game::Bounding* m_bounding; //!< Bounding of this element
game::BoundingAABB m_bounding; //!< Bounding of this element
private:
bool m_matrixNeedUpdate; //!< the matrix need to be regenerated
mat4 m_matrix; //!< generated display matrix.
vec3 m_scale; //!< scale of the element. (change the size in dynamic from the loaded model)
vec3 m_displayAngle; //!< Rotate the model.
mat4 m_displayRotation; //!< Associated matrix of totation associated with m_displayAngle.
protected:
@ -93,7 +92,6 @@ namespace game
{
m_position = vec3(0,0,0);
m_speed = vec3(0,0,0);
m_displayAngle = vec3(0,0,0);
m_displayRotation.Identity();
m_matrix.Identity();
};
@ -116,13 +114,12 @@ namespace game
m_matrixNeedUpdate = true;
}
/**
* @brief Rotate the curent object
* @brief Rotate the current object
* @param[in] vect rotation angle
* @param[in] angleRad radian angle
*/
void Rotate(etk::Vector3D<float> vect, float angleRad=0.0)
{
m_displayAngle.RotateAxis(angleRad, vect);
m_displayRotation = etk::matRotate(vect, angleRad) * m_displayRotation;
m_matrixNeedUpdate = true;
}
@ -134,10 +131,10 @@ namespace game
{
if (m_matrixNeedUpdate == true) {
m_matrixNeedUpdate = false;
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);
}
m_matrix = etk::matTranslate(m_position)
* etk::matScale(m_scale)
* m_displayRotation;
m_bounding.Update(m_resource->m_object, m_displayRotation, m_position, m_scale);
}
return m_matrix;
};
@ -146,7 +143,7 @@ namespace game
m_speed = newSpeed;
}
game::Bounding* GetBounding(void)
game::BoundingAABB& GetBounding(void)
{
return m_bounding;
}

View File

@ -65,34 +65,20 @@ void game::Engine::ProcessCollision(float deltaTime)
m_contacts.Clear();
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
game::Bounding* bounding1 = m_elements[iii]->GetBounding();
if (NULL != bounding1) {
bounding1->SetContactMode(false);
}
game::BoundingAABB& bounding1 = m_elements[iii]->GetBounding();
bounding1.SetContactMode(false);
}
}
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
game::Bounding* bounding1 = m_elements[iii]->GetBounding();
if (NULL != bounding1) {
for (int32_t jjj=iii+1; jjj<m_elements.Size() ; jjj++) {
if (NULL!=m_elements[jjj]) {
game::Bounding* bounding2 = m_elements[jjj]->GetBounding();
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);
}
}
game::BoundingAABB& bounding1 = m_elements[iii]->GetBounding();
for (int32_t jjj=iii+1; jjj<m_elements.Size() ; jjj++) {
if (NULL!=m_elements[jjj]) {
game::BoundingAABB& bounding2 = m_elements[jjj]->GetBounding();
if (true == bounding2.HasContact(bounding1)) {
bounding2.SetContactMode(true);
bounding1.SetContactMode(true);
}
}
}

View File

@ -1,80 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/game/Geometry.h>
#include <ewol/game/BoundingAABB.h>
#include <ewol/game/BoundingOBB.h>
#include <ewol/game/BoundingPlane.h>
#include <ewol/game/BoundingSphere.h>
game::Geometry::Geometry(game::MeshObject& object) :
m_dynamic(false),
m_object(object),
m_bounding(NULL),
m_mass(NULL)
{
}
game::Geometry::~Geometry(void)
{
}
void game::Geometry::SetStatic(void)
{
m_dynamic = false;
}
void game::Geometry::SetDynamic(void)
{
m_dynamic = true;
}
void game::Geometry::SetBoundingMode(game::boundingMode type)
{
if (NULL != m_bounding) {
if (m_bounding->GetType() != type) {
delete(m_bounding);
m_bounding = NULL;
} else {
return;
}
}
/*
switch(type)
{
default:
case BoundingModeNone:
break;
case BoundingModePlane:
EWOL_TODO("Implement plane...");
break;
case BoundingModeAABB:
m_bounding = new game::BoundingAABB();
break;
case BoundingModeSphere:
m_bounding = new game::BoundingSphere();
break;
case BoundingModeOBB:
m_bounding = new game::BoundingOBB(m_object, m_property);
break;
}
*/
}
void game::Geometry::BoundingUpdate(void)
{
if (NULL != m_bounding) {
//m_bounding->Update(m_object);
}
}

View File

@ -1,57 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_GEOMETRY_H__
#define __GAME_GEOMETRY_H__
#include <ewol/debug.h>
#include <ewol/game/Bounding.h>
#include <ewol/game/Mass.h>
namespace game
{
class Geometry
{
private :
bool m_dynamic; //!< Set at true if the Geometry can move or not (bounding can change)
game::MeshObject& m_object; //!< Object vertex/ normal and other properties
game::Bounding* m_bounding; //!< Bounding interface.
game::Mass* m_mass; //!< Mass properties.
public:
/**
* @brief main constructor
* @param[in] object the reference mesh object (must not be NULL)
*/
Geometry(game::MeshObject& object);
/**
* @brief main destructor
*/
~Geometry(void);
/**
* @brief Set this object static (the bounding does not change)
*/
void SetStatic(void);
/**
* @brief Set this object Dynamic (the bounding change...)
*/
void SetDynamic(void);
/**
* @brief Set bounding type
* @param[in] type Selected bounding methode (if no set, by default it does not have one)
*/
void SetBoundingMode(game::boundingMode type);
/**
* @brief Update the bounding properties.
*/
void BoundingUpdate(void);
};
};
#endif

View File

@ -84,12 +84,7 @@ FILE_LIST+= ewol/widget/Widget.cpp \
FILE_LIST+= ewol/widget/Scene.cpp \
ewol/game/Engine.cpp \
ewol/game/Element.cpp \
ewol/game/Bounding.cpp \
ewol/game/BoundingAABB.cpp \
ewol/game/BoundingOBB.cpp \
ewol/game/BoundingPlane.cpp \
ewol/game/BoundingSphere.cpp \
ewol/game/Geometry.cpp \
ewol/game/Gravity.cpp \
ewol/game/Camera.cpp \
ewol/game/Contact.cpp \