[DEV] remove old game engine ==> deprecated ...

This commit is contained in:
Edouard DUPIN 2013-01-11 23:18:05 +01:00
parent d021b82631
commit 38932b616b
24 changed files with 15 additions and 1309 deletions

2
build

@ -1 +1 @@
Subproject commit b6377e0477014e8dbec14d73e7be86e062fb8065 Subproject commit 3f4ee97584169819c4fbe95dea80ba83508fce15

View File

@ -1,300 +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/BoundingAABB.h>
#include <etk/math/Matrix4.h>
#include <ewol/renderer/ResourceManager.h>
game::BoundingAABB::BoundingAABB(void) :
m_PointStart(-1,-1,-1),
m_PointStop(1,1,1),
m_hasContact(false)
{
#ifdef DEBUG
if (false == ewol::resource::Keep(m_displayBounding) ) {
EWOL_DEBUG("Can not keep ewol::Colored3DObject ...");
}
vec3 tmpPos(0,0,0);
for(int32_t iii=0; iii<36; iii++) {
m_vertices.PushBack(tmpPos);
}
#endif
}
game::BoundingAABB::~BoundingAABB(void)
{
#ifdef DEBUG
ewol::resource::Release(m_displayBounding);
#endif
}
void game::BoundingAABB::Update(game::MeshObject& object, mat4& transformMatrix)
{
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
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, color, false);
}
} else {
EWOL_DEBUG("Bounding size is not correct...");
}
#endif
}
bool game::BoundingAABB::HasContact(game::BoundingAABB& obj)
{
if( m_PointStart.x > obj.m_PointStop.x
|| m_PointStop.x < obj.m_PointStart.x
|| m_PointStart.y > obj.m_PointStop.y
|| m_PointStop.y < obj.m_PointStart.y
|| m_PointStart.z > obj.m_PointStop.z
|| m_PointStop.z < obj.m_PointStart.z) {
return false;
}
return true;
}
vec3 game::BoundingAABB::CalculatePetetration(game::BoundingAABB& bbb, vec3& movingVect)
{
float tmin = 0;
// note : We considere the AAA has this is the moving element...
// B is condered has a fixed element ...
vec3 penetration(0,0,0);
// X
if (movingVect.x >= 0) {
// case 1 :
// ==>
// AAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 2 :
// ==>
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 3 :
// ==>
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBB
// case 4 :
// ==>
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
penetration.x = m_PointStop.x - bbb.m_PointStart.x;
} else {
// case 1 :
// <==
// AAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 2 :
// <==
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 3 :
// <==
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBB
// case 4 :
// <==
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
penetration.x = m_PointStart.x - bbb.m_PointStop.x;
}
// Y
if (movingVect.y >= 0) {
penetration.y = m_PointStop.y - bbb.m_PointStart.y;
} else {
penetration.y = m_PointStart.y - bbb.m_PointStop.y;
}
// Z
if (movingVect.z >= 0) {
penetration.z = m_PointStop.z - bbb.m_PointStart.z;
} else {
penetration.z = m_PointStart.z - bbb.m_PointStop.z;
}
return penetration;
/*
// note : We considere the AAA has this is the moving element...
// B is condered has a fixed element ...
vec3 penetration(0,0,0);
// X
if (movingVect.x >= 0) {
// case 1 :
// ==>
// AAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 2 :
// ==>
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 3 :
// ==>
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBB
// case 4 :
// ==>
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
penetration.x = m_PointStop.x - bbb.m_PointStart.x;
} else {
// case 1 :
// <==
// AAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 2 :
// <==
// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
// BBBBBBBBBBBBB
// case 3 :
// <==
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBB
// case 4 :
// <==
// AAAAAAAAAAAAA
// BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
penetration.x = m_PointStart.x - bbb.m_PointStop.x;
}
// Y
if (movingVect.y >= 0) {
penetration.y = m_PointStop.y - bbb.m_PointStart.y;
} else {
penetration.y = m_PointStart.y - bbb.m_PointStop.y;
}
// Z
if (movingVect.z >= 0) {
penetration.z = m_PointStop.z - bbb.m_PointStart.z;
} else {
penetration.z = m_PointStart.z - bbb.m_PointStop.z;
}
return penetration;
*/
}

View File

@ -1,68 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_BOUNDING_AABB_H__
#define __GAME_BOUNDING_AABB_H__
#include "etk/math/Vector3D.h"
#include "etk/math/Matrix4.h"
#include "ewol/renderer/resources/Colored3DObject.h"
namespace game
{
class BoundingAABB
{
private :
vec3 m_PointStart;
vec3 m_PointStop;
bool m_hasContact; //!< this bounding is on contact with something else ...
vec3 m_oldUserPosition; // this is due to the fact object are never centered ...
#ifdef DEBUG
ewol::Colored3DObject* m_displayBounding;
etk::Vector<vec3> m_vertices;
#endif
public:
/**
* @biref Main constructor.
*/
BoundingAABB(void);
/**
* @biref Main constructor.
*/
virtual ~BoundingAABB(void);
/**
* @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 bool HasContact(game::BoundingAABB& otherbounding);
/**
* @brief Calculate the penetration size in 2 bounding.
*/
virtual vec3 CalculatePetetration(game::BoundingAABB& otherbounding, vec3& movingVect);
/**
* @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; };
vec3 Size(void) { return m_PointStop-m_PointStart; };
};
}
#endif

View File

@ -1,27 +0,0 @@
/**
* @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)
{
}

View File

@ -1,51 +0,0 @@
/**
* @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

View File

@ -1,218 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/game/Element.h>
#include <ewol/game/Engine.h>
#include <ewol/renderer/ResourceManager.h>
static int32_t uniqueId = 0;
game::Element::Element(etk::UString meshResource) :
m_engine(NULL),
m_resource(NULL),
m_scale(1,1,1),
m_speedMax(2000000, 2000000, 2000000),
m_mass(0.0f),
m_uniqueId(uniqueId),
m_groupId(0),
m_type(0),
m_visible(true),
m_static(false)
{
ewol::MeshObj* tmpObject = NULL;
// get a resources :
if (meshResource != "") {
ewol::resource::Keep(meshResource, tmpObject);
m_resource = tmpObject;
}
uniqueId++;
UpdateMatrix();
}
game::Element::~Element(void)
{
if (NULL != m_resource) {
ewol::MeshObj* tmpObject = static_cast<ewol::MeshObj*>(m_resource);
ewol::resource::Release(tmpObject);
m_resource = NULL;
}
}
void game::Element::Draw(void)
{
if (NULL != m_resource) {
//EWOL_DEBUG("draw " << m_uniqueId);
m_resource->Draw(GetMatrix());
}
}
void game::Element::DrawDebug(void)
{
//EWOL_DEBUG("draw bounding" << m_uniqueId);
m_bounding.Draw();
}
bool game::Element::ArtificialIntelligence(float deltaMicroSecond)
{
return false;
}
void game::Element::ProcessGravityClear(void)
{
m_gravityForce = vec3(0,0,0);
}
void game::Element::ProcessGravity(float delta, game::Gravity& gravity)
{
if (0==m_mass) {
return;
}
if (gravity.m_uniform==true) {
m_gravityForce += gravity.m_vect;//*m_mass;
} else {
vec3 vectSeparation = m_position - gravity.m_vect;
float squareDistance = vectSeparation.GetSquaredLength();
// calculate gravity equation :
float force = game::GravityConst * gravity.m_mass * m_mass / squareDistance;
vectSeparation.Normalize();
// generate the force vector
vectSeparation *= force;
m_gravityForce += vectSeparation;
}
}
void game::Element::ProcessPosition(float delta)
{
if(true == m_bounding.GetContactStatus()) {
//EWOL_DEBUG("[" << m_uniqueId << "] ==> colisionDetection");
return;
}
vec3 m_speed0(m_speed);
vec3 curentAcceleration(m_gravityForce + m_userAcceleration);
m_speed += curentAcceleration*delta;
vec3 tmpPos = m_position +m_speed*delta;
if (m_position != tmpPos) {
//EWOL_DEBUG("[" << m_uniqueId << "] pos=" << m_position << "m ==>" << tmpPos << "m");
// TODO : Detect collision of other elements ...
vec3 size = m_bounding.Size();
vec3 move = tmpPos - m_position;
vec3 moveAbs = move;
moveAbs.Abs();
if( ( 0 < size.x
&& moveAbs.x > size.x*0.75 )
|| ( 0 < size.y
&& moveAbs.y > size.y*0.75 )
|| ( 0 < size.z
&& moveAbs.z > size.z*0.75 )) {
int32_t maxIterations = 0;
// generate a subdivide channel to prevent tunel effects ...
// Get the smallest axis to test :
if( moveAbs.x >= moveAbs.y
&& moveAbs.x >= moveAbs.z) {
//Test on X :
//estimate the number of subdivision needed in recursive mode :
maxIterations = moveAbs.x/abs(size.x);
//EWOL_DEBUG("[" << m_uniqueId << "] XXX move with dist=" << move << "m <" << size*0.75 << "m");
} else if ( moveAbs.y >= moveAbs.x
&& moveAbs.y >= moveAbs.z) {
//Test on Y :
//estimate the number of subdivision needed in recursive mode :
maxIterations = moveAbs.y/abs(size.y);
//EWOL_DEBUG("[" << m_uniqueId << "] YYY move with dist=" << move << "m <" << size*0.75 << "m");
} else {
//Test on Z :
//estimate the number of subdivision needed in recursive mode :
maxIterations = moveAbs.z/abs(size.z);
//EWOL_DEBUG("[" << m_uniqueId << "] ZZZ move with dist=" << move << "m <" << size*0.75 << "m");
}
vec3 deltaMove = move/maxIterations;
vec3 tmppppPos = m_position;
game::BoundingAABB tmpBounding;
// linear test :
for (int32_t iii=0; iii<maxIterations-1 ; iii++) {
tmppppPos+=deltaMove;
mat4 transformMatrix = etk::matTranslate(tmppppPos)
* etk::matScale(m_scale)
* m_displayRotation;
tmpBounding.Update(m_resource->m_object, transformMatrix);
if (true == m_engine->HasCollision(tmpBounding, this)) {
tmpPos = tmppppPos;
// the tunnel effect is catch ...
EWOL_CRITICAL("[" << m_uniqueId << "] Tunel effect catch : (" << iii << "/" << maxIterations-1 << ") ==> " << tmppppPos);
break;
}
}
}
//EWOL_DEBUG("[" << m_uniqueId << "] New pos:" << tmpPos << "m");
vec3 moving = tmpPos - m_position;
m_position = tmpPos;
UpdateMatrix();
m_engine->ObjectMove(this, moving);
}
}
void game::Element::UpdateMatrix(void)
{
m_matrix = etk::matTranslate(m_position)
* etk::matScale(m_scale)
* m_displayRotation;
m_bounding.Update(m_resource->m_object, m_matrix);
}
void game::Element::Identity(void)
{
m_position = vec3(0,0,0);
m_speed = vec3(0,0,0);
m_displayRotation.Identity();
m_matrix.Identity();
}
void game::Element::Translate(etk::Vector3D<float> vect)
{
m_position += vect;
UpdateMatrix();
}
void game::Element::Scale(etk::Vector3D<float> vect)
{
m_scale = vect;
UpdateMatrix();
}
void game::Element::Scale(float proportion)
{
m_scale = vec3(proportion,proportion,proportion);
UpdateMatrix();
}
void game::Element::Rotate(etk::Vector3D<float> vect, float angleRad)
{
m_displayRotation = etk::matRotate(vect, angleRad) * m_displayRotation;
UpdateMatrix();
}
mat4& game::Element::GetMatrix(void)
{
return m_matrix;
}
void game::Element::CollisionDetected(game::Element* elementCollide, vec3& penetrate)
{
m_position -= penetrate;
UpdateMatrix();
}

View File

@ -1,157 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_ELEMENT_H__
#define __GAME_ELEMENT_H__
#include <etk/types.h>
#include <etk/math/Vector3D.h>
#include <etk/Vector.h>
#include <ewol/debug.h>
#include <ewol/game/Gravity.h>
#include <ewol/renderer/resources/Mesh.h>
#include <ewol/game/BoundingAABB.h>
namespace game
{
class Engine;
class Element
{
protected:
game::Engine* m_engine;
ewol::Mesh* m_resource; //!< Resource to display the element.
game::BoundingAABB m_bounding; //!< Bounding of this element
private:
mat4 m_matrix; //!< generated display matrix.
vec3 m_scale; //!< scale of the element. (change the size in dynamic from the loaded model)
mat4 m_displayRotation; //!< Associated matrix of totation associated with m_displayAngle.
protected:
// 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 ...
protected:
uint32_t m_uniqueId; //!< General element ID (uint16_t, because all is reference with the groupId like this only a uint32_t reference an element)
uint32_t m_groupId; //!< General group Id More than 65000 group can be really interesting to create supid game ...
int32_t m_type; //!< type of this element
bool m_visible; //!< This is to know if the element is displayed or not ==> TODO : check if usefull ...
bool m_static; //!< This element is static...
public:
/**
* @brief Basic constructor.
* @param[in] meshResource Resource name.
*/
Element(etk::UString meshResource);
/**
* @brief Basic destructor.
*/
virtual ~Element(void);
/**
* @brief Link with a specific engine.
* @param[in] engine Engine pointer
*/
void SetEngine(game::Engine* engine) { m_engine = engine; };
/**
* @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.
* @return true if this element must be destroyed
*/
virtual bool ArtificialIntelligence(float delta);
/**
* @brief Clear the current gravity reference
*/
void ProcessGravityClear(void);
/**
* @brief Update the gravity properties.
* @param[in] delta delta from the last call.
* @param[in] gravity reference on all the gravity point.
*/
virtual void ProcessGravity(float delta, game::Gravity& gravity);
/**
* @brief Update the position of the element
* @param[in] delta delta from the last call.
*/
virtual void ProcessPosition(float delta);
/**
* @param reset the position / speed / angle / and result matrix
*/
void Identity(void);
/**
* @brief Translate The curent element to a new position
* @param[in] vect new position
*/
void Translate(etk::Vector3D<float> vect);
/**
* @brief Scale the element to an other size
* @param[in] vect new object scaling
*/
void Scale(etk::Vector3D<float> vect);
/**
* @brief Scale the element to an other size
* @param[in] proportion scale value in all direction ...
*/
void Scale(float proportion);
/**
* @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);
/**
* @brief Get the Current matrix of the element (never access it directly, it might be sometime updated)
* @return the reference on the matrix (updated if needed)
*/
mat4& GetMatrix(void);
private:
/**
* @brief when position or rotation is set, the system call this function ...
*/
void UpdateMatrix(void);
public:
void SetSpeed(vec3 newSpeed)
{
m_speed = newSpeed;
}
game::BoundingAABB& GetBounding(void)
{
return m_bounding;
}
/**
* @brief Set this element Static or not
*/
void SetStaticMode(bool newMode) { m_static = newMode; };
/**
* @brief Get the current static or dynamic mode
*/
bool GetStaticMode(void) { return m_static; };
/**
* @brief A collision has bee detected ...
* @param[in] elementCollide the element that has been collided
* @param[in] penetrate The size of the penetration ...
*/
virtual void CollisionDetected(game::Element* elementCollide, vec3& penetrate);
};
};
#endif

View File

@ -1,175 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/game/Engine.h>
game::Engine::Engine(void)
{
}
game::Engine::~Engine(void)
{
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
delete(m_elements[iii]);
m_elements[iii] = NULL;
}
}
m_elements.Clear();
}
void game::Engine::Process(double lastTime, float deltaTime)
{
ProcessGravity(deltaTime);
ProcessCollision(deltaTime);
ProcessIA(deltaTime);
}
void game::Engine::ProcessGravity(float deltaTime)
{
//EWOL_DEBUG("Gravity management");
for(int32_t jjj=0 ; jjj<m_gravity.Size() ; jjj++) {
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
m_elements[iii]->ProcessGravity(deltaTime, m_gravity[jjj]);
}
m_elements[iii]->ProcessPosition(deltaTime);
}
}
}
void game::Engine::ProcessIA(float deltaTime)
{
//EWOL_DEBUG("Artificial Intelligence management");
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
m_elements[iii]->ArtificialIntelligence(deltaTime);
}
}
}
void game::Engine::ProcessCollision(float deltaTime)
{
//EWOL_DEBUG("Collision management");
m_contacts.Clear();
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
game::BoundingAABB& bounding1 = m_elements[iii]->GetBounding();
bounding1.SetContactMode(false);
}
}
// Brut force bounding detection :
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
// If the element is static, the bounding detection is not needed...
if (true) {//false == m_elements[iii]->GetStaticMode()) {
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);
}
}
}
}
}
}
}
bool game::Engine::HasCollision(game::BoundingAABB& bounding, game::Element* currentElement)
{
if (NULL == currentElement) {
return false;
}
// Brut force bounding detection :
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (currentElement == m_elements[iii]) {
continue;
}
if (NULL != m_elements[iii]) {
if (true == bounding.HasContact(m_elements[iii]->GetBounding())) {
return true;
}
}
}
return false;
}
void game::Engine::ObjectMove(game::Element* currentElement, vec3& movingVect)
{
if (NULL == currentElement) {
return;
}
game::BoundingAABB& bounding = currentElement->GetBounding();
// Brut force bounding detection :
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (currentElement == m_elements[iii]) {
continue;
}
if (NULL != m_elements[iii]) {
if (true == bounding.HasContact(m_elements[iii]->GetBounding())) {
vec3 penetrate = bounding.CalculatePetetration(m_elements[iii]->GetBounding(), movingVect);
currentElement->CollisionDetected(m_elements[iii], penetrate);
}
}
}
}
void game::Engine::Draw(ewol::DrawProperty& displayProp)
{
//EWOL_DEBUG("Drawing the system");
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
m_elements[iii]->Draw();
}
}
#ifdef DEBUG
for (int32_t iii=0; iii<m_elements.Size() ; iii++) {
if (NULL != m_elements[iii]) {
m_elements[iii]->DrawDebug();
}
}
#endif
}
void game::Engine::AddElement(game::Element* newElement)
{
bool find=false;
if (NULL == newElement) {
EWOL_ERROR("try to set a NULL pointer game::Element");
}
for (int32_t iii=0 ; iii<m_elements.Size() ; iii++) {
if (NULL == m_elements[iii]) {
m_elements[iii] = newElement;
find = true;
break;
}
}
if (false==find) {
m_elements.PushBack(newElement);
newElement->SetEngine(this);
}
}
void game::Engine::AddGravity(game::Gravity gravity)
{
m_gravity.PushBack(gravity);
}

View File

@ -1,91 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_ENGINE_H__
#define __GAME_ENGINE_H__
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/game/Element.h>
#include <ewol/game/Gravity.h>
#include <ewol/game/Contact.h>
#include <ewol/widget/Widget.h>
namespace game
{
class Engine
{
private:
etk::Vector<game::Gravity> m_gravity; //!< list of gravity element
etk::Vector<game::Element*> m_elements; //!< List of the game element
etk::Vector<game::Contact> m_contacts; //!< list of all contact that existe in the system
public:
/**
* @brief Basic constructor.
*/
Engine(void);
/**
* @brief Basic destructor.
*/
~Engine(void);
/**
* @brief periodic call for processing.
* @param[in] lastTime Previous call time (if the system is in pause this time does restart at the same time the next time.
* @param[in] deltaTime delta time in µs from the previous call.
*/
void Process(double lastTime, float deltaTime);
/**
* @brief Processing the gravity properties.
* @param[in] deltaTime delta time in µs from the previous call.
*/
void ProcessGravity(float deltaTime);
/**
* @brief Processing the Artificial Intelligence.
* @param[in] deltaTime delta time in µs from the previous call.
*/
void ProcessIA(float deltaTime);
/**
* @brief Processing the collision.
* @param[in] deltaTime delta time in µs from the previous call.
*/
void ProcessCollision(float deltaTime);
/**
* @brief parse all the element to know if a bounding has a contact with some other elements ...
* @param[in] bounding the reference bounding
* @param[in] currentElement The element that request the detection ==> permit to not detect itself...
*/
bool HasCollision(game::BoundingAABB& bounding, game::Element* currentElement);
/**
* @brief : this object has move, we need to update some collition, and some other things ...
* @param[in] currentElement The element that request the detection ==> permit to not detect itself...
* @param[in] movingVect : the vector that has move the current element.
*/
void ObjectMove(game::Element* currentElement, vec3& movingVect);
/**
* @brief Display the environement.
*/
void Draw(ewol::DrawProperty& displayProp);
/**
* @brief Add an element on the system.
* @param[in] newElement element to display.
*/
void AddElement(game::Element* newElement);
/**
* @brief Add a gravity on the system.
* @param[in] gravity The gravity to add.
*/
void AddGravity(game::Gravity gravity);
};
};
#endif

View File

@ -1,46 +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/Gravity.h>
game::Gravity::Gravity(void) :
m_uniform(false),
m_mass(0),
m_vect(0,0,0)
{
}
game::Gravity::Gravity(bool uniform, float mass, vec3 vect) :
m_uniform(uniform),
m_mass(mass),
m_vect(vect)
{
}
// gravity force is :
// F = G*m1*m2 / radius^2.
extern const float game::GravityConst = 0.0000000000667f;
// Earth
extern const float game::earthMass = 5973600000000000000000000.0f; // in kg
extern const float game::earthRadius = 6378137.0f; // in meter
extern const game::Gravity game::gravityEarth(true, earthMass, vec3(0, 0, -(float)((GravityConst*earthMass)/(earthRadius*earthRadius))) );
// Mars
extern const float game::marsMass = 25000000000000000.0f; // in kg
extern const float game::marsRadius = 3396200.0f; // in meter
extern const game::Gravity game::gravityMars(true, marsMass, vec3(0, 0, -(float)((GravityConst*marsMass)/(marsRadius*marsRadius))) );

View File

@ -1,42 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_GRAVITY_H__
#define __GAME_GRAVITY_H__
#include <etk/types.h>
#include <etk/math/Vector3D.h>
namespace game
{
class Gravity
{
public:
bool m_uniform; //!< The gravity is not a stelar object
float m_mass; //!< Masse of the stelar object.
vec3 m_vect; //!< Position of the stelar object or gravity(acceleration) force when it is uniform.
Gravity(void);
Gravity(bool uniform, float mass, vec3 vect);
};
extern const float GravityConst;
// Earth
extern const float earthMass;
extern const float earthRadius;
extern const Gravity gravityEarth;
// Mars
extern const float marsMass;
extern const float marsRadius;
extern const Gravity gravityMars;
};
#endif

View File

@ -1,7 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/

View File

@ -1,15 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_MAP_H__
#define __GAME_MAP_H__
#include "ewol/debug.h"
#endif

View File

@ -1,7 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/

View File

@ -1,25 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_MASS_H__
#define __GAME_MASS_H__
#include "ewol/debug.h"
namespace game
{
class Mass
{
};
};
#endif

View File

@ -1,35 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __GAME_MESH_OBJECT_H__
#define __GAME_MESH_OBJECT_H__
#include <etk/types.h>
#include <etk/Vector.h>
#include <etk/math/Vector3D.h>
#include <etk/math/Vector2D.h>
namespace game
{
class MeshObject
{
public:
etk::Vector<uint32_t> m_indices;
etk::Vector<vec3> m_vertices;
etk::Vector<vec2> m_uvTextures;
etk::Vector<vec3> m_normals;
public:
MeshObject(void) {};
virtual ~MeshObject(void) {};
};
};
#endif

View File

@ -1,7 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/

View File

@ -1,15 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EPHYSICS_SKY_H__
#define __EPHYSICS_SKY_H__
#include "ewol/debug.h"
#endif

View File

@ -14,7 +14,6 @@
#include <ewol/renderer/resources/Image.h> #include <ewol/renderer/resources/Image.h>
#include <ewol/renderer/resources/Shader.h> #include <ewol/renderer/resources/Shader.h>
#include <ewol/renderer/resources/Program.h> #include <ewol/renderer/resources/Program.h>
#include <ewol/game/MeshObject.h>
namespace ewol namespace ewol
{ {

View File

@ -39,7 +39,7 @@ ewol::Mesh::~Mesh(void)
void ewol::Mesh::Draw(mat4& positionMatrix) void ewol::Mesh::Draw(mat4& positionMatrix)
{ {
if (m_object.m_vertices.Size()<=0) { if (m_vertices.Size()<=0) {
return; return;
} }
if (NULL == m_texture1) { if (NULL == m_texture1) {
@ -61,13 +61,13 @@ void ewol::Mesh::Draw(mat4& positionMatrix)
// TextureID // TextureID
m_GLprogram->SetTexture0(m_GLtexID, m_texture1->GetId()); m_GLprogram->SetTexture0(m_GLtexID, m_texture1->GetId());
// position : // position :
m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z*/, &m_object.m_vertices[0]); m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z*/, &m_vertices[0]);
// Texture : // Texture :
m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_object.m_uvTextures[0]); m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_uvTextures[0]);
// color : // color :
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
// Request the draw od the elements : // Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_object.m_vertices.Size()); glDrawArrays(GL_TRIANGLES, 0, m_vertices.Size());
m_GLprogram->UnUse(); m_GLprogram->UnUse();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} }

View File

@ -14,7 +14,6 @@
#include <ewol/renderer/resources/Image.h> #include <ewol/renderer/resources/Image.h>
#include <ewol/renderer/resources/Shader.h> #include <ewol/renderer/resources/Shader.h>
#include <ewol/renderer/resources/Program.h> #include <ewol/renderer/resources/Program.h>
#include <ewol/game/MeshObject.h>
namespace ewol namespace ewol
{ {
@ -28,7 +27,10 @@ namespace ewol
int32_t m_GLtexture; int32_t m_GLtexture;
int32_t m_GLtexID; int32_t m_GLtexID;
public: public:
game::MeshObject m_object; etk::Vector<uint32_t> m_indices;
etk::Vector<vec3> m_vertices;
etk::Vector<vec2> m_uvTextures;
etk::Vector<vec3> m_normals;
protected: protected:
ewol::TextureFile* m_texture1; ewol::TextureFile* m_texture1;
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point

View File

@ -180,15 +180,17 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
uint32_t uvIndex = indicesUv[iii]; uint32_t uvIndex = indicesUv[iii];
// Put the attributes in buffers // Put the attributes in buffers
m_object.m_vertices.PushBack(vertices[vertexIndex-1]); m_vertices.PushBack(vertices[vertexIndex-1]);
m_object.m_uvTextures.PushBack(uvTextures[uvIndex-1]); m_uvTextures.PushBack(uvTextures[uvIndex-1]);
draw::Color tmpppp(0xFFFFFFFF); draw::Color tmpppp(0xFFFFFFFF);
draw::Colorf tmppppp(tmpppp); draw::Colorf tmppppp(tmpppp);
m_coordColor.PushBack(tmppppp); m_coordColor.PushBack(tmppppp);
if (indicesNormal.Size()>iii) { if (indicesNormal.Size()>iii) {
uint32_t normalIndex = indicesNormal[iii]; uint32_t normalIndex = indicesNormal[iii];
m_object.m_normals.PushBack(normals[normalIndex-1]); m_normals.PushBack(normals[normalIndex-1]);
} }
} }
} }

View File

@ -14,8 +14,6 @@
#include <etk/math/Matrix4.h> #include <etk/math/Matrix4.h>
#include <etk/Vector.h> #include <etk/Vector.h>
#include <ewol/debug.h> #include <ewol/debug.h>
#include <ewol/game/Engine.h>
#include <ewol/game/Element.h>
#include <ewol/game/Camera.h> #include <ewol/game/Camera.h>
#include <ewol/widget/Widget.h> #include <ewol/widget/Widget.h>
#include <ewol/renderer/openGL.h> #include <ewol/renderer/openGL.h>
@ -45,7 +43,6 @@ namespace widget {
//keep the collision shapes, for deletion/cleanup //keep the collision shapes, for deletion/cleanup
etk::Vector<btCollisionShape*> m_collisionShapes; etk::Vector<btCollisionShape*> m_collisionShapes;
game::Camera m_camera; //!< Display point of view game::Camera m_camera; //!< Display point of view
//game::Engine* m_gameEngine; //!< display engine system
bool m_isRunning; //!< the display is running (not in pause) bool m_isRunning; //!< the display is running (not in pause)
double m_lastCallTime; //!< previous call Time double m_lastCallTime; //!< previous call Time
float m_ratioTime; //!< Ratio time for the speed of the game ... float m_ratioTime; //!< Ratio time for the speed of the game ...

View File

@ -82,15 +82,7 @@ FILE_LIST+= ewol/widget/Widget.cpp \
# game mode area : # game mode area :
FILE_LIST+= ewol/widget/Scene.cpp \ FILE_LIST+= ewol/widget/Scene.cpp \
ewol/game/Engine.cpp \ ewol/game/Camera.cpp
ewol/game/Element.cpp \
ewol/game/BoundingAABB.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
LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \ LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \