[DEV] force respond on collision detection (error)
This commit is contained in:
parent
a8b350ea5a
commit
896cdf4891
@ -181,4 +181,120 @@ bool game::BoundingAABB::HasContact(game::BoundingAABB& obj)
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,10 @@ namespace game
|
||||
* @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 ...
|
||||
*/
|
||||
|
@ -157,8 +157,10 @@ void game::Element::ProcessPosition(float delta)
|
||||
}
|
||||
}
|
||||
//EWOL_DEBUG("[" << m_uniqueId << "] New pos:" << tmpPos << "m");
|
||||
vec3 moving = tmpPos - m_position;
|
||||
m_position = tmpPos;
|
||||
UpdateMatrix();
|
||||
m_engine->ObjectMove(this, moving);
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,4 +207,12 @@ void game::Element::Rotate(etk::Vector3D<float> vect, float angleRad)
|
||||
mat4& game::Element::GetMatrix(void)
|
||||
{
|
||||
return m_matrix;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void game::Element::CollisionDetected(game::Element* elementCollide, vec3& penetrate)
|
||||
{
|
||||
m_position -= penetrate;
|
||||
UpdateMatrix();
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,12 @@ namespace game
|
||||
* @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);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -92,6 +92,9 @@ void game::Engine::ProcessCollision(float deltaTime)
|
||||
|
||||
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]) {
|
||||
@ -106,6 +109,25 @@ bool game::Engine::HasCollision(game::BoundingAABB& bounding, game::Element* cur
|
||||
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)
|
||||
|
@ -57,7 +57,18 @@ namespace game
|
||||
* @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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user