[DEV] base of collision detection in component and ray test in phgysic engine

This commit is contained in:
Edouard DUPIN 2017-05-23 21:58:18 +02:00
parent 71a5e41f5a
commit 7d51944355
9 changed files with 273 additions and 136 deletions

View File

@ -36,51 +36,6 @@ std::ostream& ege::operator <<(std::ostream& _os, const ege::Ray& _obj) {
return _os;
}
std::pair<vec3,vec3> ege::Ray::testRay(ege::physics::Engine& _engine) {
vec3 start = m_origin;
vec3 stop = m_origin+m_direction*1000.0f;
// Start and End are vectors
/*
btCollisionWorld::ClosestRayResultCallback rayCallback(start, stop);
EGE_VERBOSE("Process Raycast :");
// Perform raycast
_engine.getDynamicWorld()->rayTest(start, stop, rayCallback);
if(rayCallback.hasHit()) {
vec3 end = rayCallback.m_hitPointWorld;
vec3 normal = rayCallback.m_hitNormalWorld;
EGE_VERBOSE(" hit at point=" << end << " normal=" << normal);
return std::pair<vec3,vec3>(end,normal);
}
*/
EGE_VERBOSE(" No Hit");
return std::pair<vec3,vec3>(vec3(0,0,0),vec3(0,0,0));
}
std::pair<ememory::SharedPtr<ege::Entity>, std::pair<vec3,vec3>> ege::Ray::testRayObject(ege::physics::Engine& _engine) {
vec3 start = m_origin;
vec3 stop = m_origin+m_direction*1000.0f;
// Start and End are vectors
/*
btCollisionWorld::ClosestRayResultCallback rayCallback(start, stop);
EGE_VERBOSE("Process Raycast :");
// Perform raycast
_engine.getDynamicWorld()->rayTest(start, stop, rayCallback);
if(rayCallback.hasHit()) {
vec3 end = rayCallback.m_hitPointWorld;
vec3 normal = rayCallback.m_hitNormalWorld;
ege::Entity* elem = static_cast<ege::Entity*>(rayCallback.m_collisionObject->getUserPointer());
if (elem != nullptr) {
EGE_VERBOSE(" hit at point=" << end << " normal=" << normal);
return std::pair<ememory::SharedPtr<ege::Entity>, std::pair<vec3,vec3>>(elem->sharedFromThis(), std::pair<vec3,vec3>(end,normal));
}
EGE_VERBOSE(" Can not get the entity pointer");
return std::pair<ememory::SharedPtr<ege::Entity>, std::pair<vec3,vec3>>(nullptr, std::pair<vec3,vec3>(end,normal));
}
*/
EGE_VERBOSE(" No Hit");
return std::pair<ememory::SharedPtr<ege::Entity>, std::pair<vec3,vec3>>(nullptr, std::pair<vec3,vec3>(vec3(0,0,0),vec3(0,0,0)));
}
vec3 ege::Ray::testRayZeroPlane() {
float coef = m_origin.z() / m_direction.z();

View File

@ -64,8 +64,6 @@ namespace ege {
*/
void set(const vec3& _origin, const vec3& _direction);
public:
std::pair<vec3,vec3> testRay(ege::physics::Engine& _engine);
std::pair<ememory::SharedPtr<ege::Entity>, std::pair<vec3,vec3>> testRayObject(ege::physics::Engine& _engine);
vec3 testRayZeroPlane();
};
std::ostream& operator <<(std::ostream& _os, const ege::Ray& _obj);

View File

@ -19,8 +19,12 @@ const std::string& ege::physics::Component::getType() const {
return tmp;
}
void ege::physics::Component::notifyContact(const rp3d::ContactPointInfo& _contactPointInfo) {
EGE_INFO("collision detection " << vec3(_contactPointInfo.normal.x, _contactPointInfo.normal.y, _contactPointInfo.normal.z) << " depth=" << _contactPointInfo.penetrationDepth);
void ege::physics::Component::beginContact(ege::physics::Component* _other, const vec3& _normal, const vec3& _pos, const vec3& _posOther, float _penetrationDepth) {
EGE_WARNING(" collision [BEGIN] " << _pos << " depth=" << _penetrationDepth);
}
void ege::physics::Component::newContact(ege::physics::Component* _other, const vec3& _normal, const vec3& _pos, const vec3& _posOther, float _penetrationDepth) {
EGE_WARNING(" collision [ NEW ] " << _pos << " depth=" << _penetrationDepth);
}
ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env) {
@ -31,8 +35,9 @@ ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env) {
rp3d::Transform transform(initPosition, initOrientation);
m_lastTransformEmit = etk::Transform3D(vec3(0,0,0), etk::Quaternion::identity());
m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform);
m_rigidBody->setUserData(this);
// set collision callback:
m_engine->getDynamicWorld()->testCollision(m_rigidBody, this);
//m_engine->getDynamicWorld()->testCollision(m_rigidBody, this);
}
ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env, const etk::Transform3D& _transform) {
@ -47,9 +52,10 @@ ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env, c
rp3d::Transform transform(initPosition, initOrientation);
// Create a rigid body in the world
m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform);
m_rigidBody->setUserData(this);
m_lastTransformEmit = _transform;
// set collision callback:
m_engine->getDynamicWorld()->testCollision(m_rigidBody, this);
//m_engine->getDynamicWorld()->testCollision(m_rigidBody, this);
}
void ege::physics::Component::setType(enum ege::physics::Component::type _type) {
@ -74,6 +80,7 @@ ege::physics::Component::~Component() {
return;
}
// disable callback
m_rigidBody->setUserData(nullptr);
m_engine->getDynamicWorld()->testCollision(m_rigidBody, nullptr);
m_engine->getDynamicWorld()->destroyRigidBody(m_rigidBody);
m_rigidBody = nullptr;
@ -113,6 +120,7 @@ void ege::physics::Component::generate() {
it->getQuaternion().w());
rp3d::Transform transform(position, orientation);
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
proxyShape->setUserData(this);
m_listProxyShape.push_back(proxyShape);
break;
}
@ -134,6 +142,7 @@ void ege::physics::Component::generate() {
it->getQuaternion().w());
rp3d::Transform transform(position, orientation);
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
proxyShape->setUserData(this);
m_listProxyShape.push_back(proxyShape);
break;
}
@ -155,6 +164,7 @@ void ege::physics::Component::generate() {
it->getQuaternion().w());
rp3d::Transform transform(position, orientation);
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
proxyShape->setUserData(this);
m_listProxyShape.push_back(proxyShape);
break;
}
@ -176,6 +186,7 @@ void ege::physics::Component::generate() {
it->getQuaternion().w());
rp3d::Transform transform(position, orientation);
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
proxyShape->setUserData(this);
m_listProxyShape.push_back(proxyShape);
break;
}
@ -197,6 +208,7 @@ void ege::physics::Component::generate() {
it->getQuaternion().w());
rp3d::Transform transform(position, orientation);
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, it->getMass());
proxyShape->setUserData(this);
m_listProxyShape.push_back(proxyShape);
break;
}

View File

@ -19,8 +19,8 @@ namespace ege {
namespace physics {
class Engine;
class Component :
public ege::Component,
public rp3d::CollisionCallback {
public ege::Component/*,
public rp3d::CollisionCallback*/ {
public:
esignal::Signal<etk::Transform3D> signalPosition;
protected:
@ -93,8 +93,24 @@ namespace ege {
void emitAll();
friend class ege::physics::Engine;
private:
// herited from rp3d::CollisionCallback to notify the contact on the current rigid body
void notifyContact(const rp3d::ContactPointInfo& _contactPointInfo) override;
/**
* @brief Called when a new contact point is found between two bodies that were separated before.
* @param[in] _other The other component that have the impact
* @param[in] _normal Normal of the impact
* @param[in] _pos Position of the impact at the current object
* @param[in] _posOther Position of the impact at the other object
* @param[in] _penetrationDepth Depth penetration in the object
*/
void beginContact(ege::physics::Component* _other, const vec3& _normal, const vec3& _pos, const vec3& _posOther, float _penetrationDepth);
/**
* @brief Called when a new contact point is found between two bodies.
* @param[in] _other The other component that have the impact
* @param[in] _normal Normal of the impact
* @param[in] _pos Position of the impact at the current object
* @param[in] _posOther Position of the impact at the other object
* @param[in] _penetrationDepth Depth penetration in the object
*/
void newContact(ege::physics::Component* _other, const vec3& _normal, const vec3& _pos, const vec3& _posOther, float _penetrationDepth);
};
}
}

View File

@ -18,13 +18,53 @@ const std::string& ege::physics::Engine::getType() const {
}
void ege::physics::Engine::beginContact(const rp3d::ContactPointInfo& _contact) {
ege::physics::Component* component1 = nullptr;
ege::physics::Component* component2 = nullptr;
vec3 normal(_contact.normal.x, _contact.normal.y, _contact.normal.z);
vec3 pos1(_contact.localPoint1.x, _contact.localPoint1.y, _contact.localPoint1.z);
vec3 pos2(_contact.localPoint2.x, _contact.localPoint2.y, _contact.localPoint2.z);
float penetrationDepth = _contact.penetrationDepth;
// Called when a new contact point is found between two bodies that were separated before.
EGE_WARNING("collision detection [BEGIN] " << vec3(_contact.normal.x, _contact.normal.y, _contact.normal.z) << " depth=" << _contact.penetrationDepth);
EGE_WARNING("collision detection [BEGIN] " << pos1 << " depth=" << penetrationDepth);
if ( _contact.shape1 != nullptr
&& _contact.shape1->getUserData() != nullptr) {
component1 = static_cast<ege::physics::Component*>(_contact.shape1->getUserData());
}
if ( _contact.shape2 != nullptr
&& _contact.shape2->getUserData() != nullptr) {
component2 = static_cast<ege::physics::Component*>(_contact.shape2->getUserData());
}
if (component1 != nullptr) {
component1->beginContact(component2, normal, pos1, pos2, penetrationDepth);
}
if (component2 != nullptr) {
component2->beginContact(component1, -normal, pos2, pos1, penetrationDepth);
}
}
void ege::physics::Engine::newContact(const rp3d::ContactPointInfo& _contact) {
ege::physics::Component* component1 = nullptr;
ege::physics::Component* component2 = nullptr;
vec3 normal(_contact.normal.x, _contact.normal.y, _contact.normal.z);
vec3 pos1(_contact.localPoint1.x, _contact.localPoint1.y, _contact.localPoint1.z);
vec3 pos2(_contact.localPoint2.x, _contact.localPoint2.y, _contact.localPoint2.z);
float penetrationDepth = _contact.penetrationDepth;
//Called when a new contact point is found between two bodies.
EGE_WARNING("collision detection [ NEW ] " << vec3(_contact.normal.x, _contact.normal.y, _contact.normal.z) << " depth=" << _contact.penetrationDepth);
EGE_WARNING("collision detection [ NEW ] " << pos1 << " depth=" << penetrationDepth);
if ( _contact.shape1 != nullptr
&& _contact.shape1->getUserData() != nullptr) {
component1 = static_cast<ege::physics::Component*>(_contact.shape1->getUserData());
}
if ( _contact.shape2 != nullptr
&& _contact.shape2->getUserData() != nullptr) {
component2 = static_cast<ege::physics::Component*>(_contact.shape2->getUserData());
}
if (component1 != nullptr) {
component1->newContact(component2, normal, pos1, pos2, penetrationDepth);
}
if (component2 != nullptr) {
component2->newContact(component1, -normal, pos2, pos1, penetrationDepth);
}
}
void ege::physics::Engine::componentRemove(const ememory::SharedPtr<ege::Component>& _ref) {
@ -132,3 +172,71 @@ void ege::physics::Engine::renderDebug(const echrono::Duration& _delta, const em
}
}
class MyCallbackClass : public rp3d::RaycastCallback {
public:
vec3 m_position;
vec3 m_normal;
bool m_haveImpact;
rp3d::CollisionBody* m_body;
MyCallbackClass():
m_haveImpact(false),
m_body(nullptr) {
}
public:
virtual float notifyRaycastHit(const rp3d::RaycastInfo& _info) {
m_haveImpact = true;
// Display the world hit point coordinates
m_position = vec3(_info.worldPoint.x, _info.worldPoint.y, _info.worldPoint.z);
m_normal = vec3(_info.worldNormal.x, _info.worldNormal.y, _info.worldNormal.z);
m_body = _info.body;
EGE_WARNING("Hit point: " << m_position);
// Return a fraction of 1.0 to gather all hits
return 1.0f;
}
};
std::pair<vec3,vec3> ege::physics::Engine::testRay(const ege::Ray& _ray) {
vec3 start = _ray.getOrigin();
vec3 stop = _ray.getOrigin()+_ray.getDirection()*1000.0f;
// Start and End are vectors
// Create the ray
rp3d::Vector3 startPoint(start.x(), start.y(), start.z());
rp3d::Vector3 endPoint(stop.x(), stop.y(), stop.z());
rp3d::Ray ray(startPoint, endPoint);
// Create an instance of your callback class
MyCallbackClass callbackObject;
// Raycast test
m_dynamicsWorld->raycast(ray, &callbackObject);
if (callbackObject.m_haveImpact == true) {
return std::pair<vec3,vec3>(callbackObject.m_position, callbackObject.m_normal);
}
EGE_VERBOSE(" No Hit");
return std::pair<vec3,vec3>(vec3(0,0,0),vec3(0,0,0));
}
std::pair<ememory::SharedPtr<ege::Component>, std::pair<vec3,vec3>> ege::physics::Engine::testRayObject(const ege::Ray& _ray) {
vec3 start = _ray.getOrigin();
vec3 stop = _ray.getOrigin()+_ray.getDirection()*1000.0f;
// Start and End are vectors
// Create the ray
rp3d::Vector3 startPoint(start.x(), start.y(), start.z());
rp3d::Vector3 endPoint(stop.x(), stop.y(), stop.z());
rp3d::Ray ray(startPoint, endPoint);
// Create an instance of your callback class
MyCallbackClass callbackObject;
// Raycast test
m_dynamicsWorld->raycast(ray, &callbackObject);
if (callbackObject.m_haveImpact == true) {
if ( callbackObject.m_body == nullptr
|| callbackObject.m_body->getUserData() == nullptr) {
std::pair<ememory::SharedPtr<ege::Component>, std::pair<vec3,vec3>>(nullptr, std::pair<vec3,vec3>(callbackObject.m_position, callbackObject.m_normal));
}
// TODO: je n'ai pas une entity, main un component ...
ege::physics::Component* elem = static_cast<ege::physics::Component*>(callbackObject.m_body->getUserData());
return std::pair<ememory::SharedPtr<ege::Component>, std::pair<vec3,vec3>>(elem->sharedFromThis(), std::pair<vec3,vec3>(callbackObject.m_position, callbackObject.m_normal));
}
EGE_VERBOSE(" No Hit");
return std::pair<ememory::SharedPtr<ege::Component>, std::pair<vec3,vec3>>(nullptr, std::pair<vec3,vec3>(vec3(0,0,0),vec3(0,0,0)));
}

View File

@ -25,6 +25,8 @@ namespace ege {
#include <ephysics/reactphysics3d.h>
#include <ege/physics/Component.hpp>
#include <eproperty/Value.hpp>
#include <ege/Ray.hpp>
namespace ege {
@ -64,6 +66,19 @@ namespace ege {
// herited from rp3D::EventListener
void beginContact(const rp3d::ContactPointInfo& _contact) override;
void newContact(const rp3d::ContactPointInfo& _contact) override;
public:
/**
* @brief Test a rayCasting on the physic engine
* @param[in] _ray Ray top test
* @return Impact position and normal of the impact (if normal == vec3(0,0,0) then no object impact...
*/
std::pair<vec3,vec3> testRay(const ege::Ray& _ray);
/**
* @brief Test a rayCasting on the physic engine
* @param[in] _ray Ray top test
* @return Impact Component, position and normal of the impact (if normal == vec3(0,0,0) then no object impact...
*/
std::pair<ememory::SharedPtr<ege::Component>, std::pair<vec3,vec3>> testRayObject(const ege::Ray& _ray);
};
}
}

View File

@ -25,49 +25,64 @@ ememory::SharedPtr<ege::resource::Mesh> ege::resource::Mesh::createGrid(int32_t
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
if (iii==0) {
out->addLine(_materialName, _position+vec3(-_lineCount,0,0)*_size, _position+vec3(_lineCount+1,0,0)*_size, etk::color::red);
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0.5f,0)*_size, etk::color::red);
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,-0.5f,0)*_size, etk::color::red);
// arrow
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0,0.5f)*_size, etk::color::red);
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0,-0.5f)*_size, etk::color::red);
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,0.5f,0)*_size, etk::color::red);
out->addLine(_materialName, _position+vec3(_lineCount+1.0f,0,0)*_size, _position+vec3(_lineCount+0.5f,-0.5f,0)*_size, etk::color::red);
// X letter
out->addLine(_materialName, _position+vec3(_lineCount+2.0f,-1.0f,1.0f)*_size, _position+vec3(_lineCount+2.0f,1.0f,-1.0f)*_size, etk::color::red);
out->addLine(_materialName, _position+vec3(_lineCount+2.0f,-1.0f,-1.0f)*_size, _position+vec3(_lineCount+2.0f,1.0f,1.0f)*_size, etk::color::red);
} else {
out->addLine(_materialName, _position+vec3(-_lineCount,iii,0)*_size, _position+vec3(_lineCount,iii,0)*_size, etk::color::gray);
out->addLine(_materialName, _position+vec3(-_lineCount,0,iii)*_size, _position+vec3(_lineCount,0,iii)*_size, etk::color::gray);
}
//out->addPoint(_materialName, vec3(-_lineCount,iii,0), etk::color::white);
//out->addPoint(_materialName, vec3(_lineCount,iii,0), etk::color::white);
}
// create Y lines
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
if (iii==0) {
out->addLine(_materialName, _position+vec3(0,-_lineCount,0)*_size, _position+vec3(0,_lineCount+1,0)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(0.5f,_lineCount+0.5f,0)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(-0.5f,_lineCount+0.5f,0)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(0,_lineCount+0.5f,0.5f)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,_lineCount+1.0f,0)*_size, _position+vec3(0,_lineCount+0.5f,-0.5f)*_size, etk::color::green);
} else {
out->addLine(_materialName, _position+vec3(iii,-_lineCount,0)*_size, _position+vec3(iii,_lineCount,0)*_size, etk::color::gray);
}
//out->addPoint(_materialName, vec3(iii,-_lineCount,0), etk::color::white);
//out->addPoint(_materialName, vec3(iii,_lineCount,0), etk::color::white);
}
// create Z lines
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
if (iii==0) {
out->addLine(_materialName, _position+vec3(0,0,-_lineCount)*_size, _position+vec3(0,0,_lineCount+1)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(0.5f,0,_lineCount+0.5f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(-0.5f,0,_lineCount+0.5f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(0,0.5f,_lineCount+0.5f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1)*_size, _position+vec3(0,-0.5f,_lineCount+0.5f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,0,-_lineCount)*_size, _position+vec3(0,0,_lineCount+1)*_size, etk::color::green);
// arrow
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(0.5f,0,_lineCount+0.5f)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(-0.5f,0,_lineCount+0.5f)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(0,0.5f,_lineCount+0.5f)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(0,0,_lineCount+1.0f)*_size, _position+vec3(0,-0.5f,_lineCount+0.5f)*_size, etk::color::green);
// Z letter
out->addLine(_materialName, _position+vec3(1,-1,_lineCount+2.0f)*_size, _position+vec3(1,1,_lineCount+2.0f)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(1,1,_lineCount+2.0f)*_size, _position+vec3(-1,-1,_lineCount+2.0f)*_size, etk::color::green);
out->addLine(_materialName, _position+vec3(-1,-1,_lineCount+2.0f)*_size, _position+vec3(-1,1,_lineCount+2.0f)*_size, etk::color::green);
} else {
out->addLine(_materialName, _position+vec3(iii,0,-_lineCount)*_size, _position+vec3(iii,0,_lineCount)*_size, etk::color::gray);
}
//out->addPoint(_materialName, vec3(iii,0,-_lineCount), etk::color::white);
//out->addPoint(_materialName, vec3(iii,0,_lineCount), etk::color::white);
}
// create Y lines
for (int32_t iii=-_lineCount; iii<=_lineCount; ++iii) {
if (iii==0) {
out->addLine(_materialName, _position+vec3(0,-_lineCount,0)*_size, _position+vec3(0,_lineCount+1,0)*_size, etk::color::blue);
// arrow
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(0.5f,_lineCount+0.5f,0)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(-0.5f,_lineCount+0.5f,0)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(0,_lineCount+0.5f,0.5f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,_lineCount+1,0)*_size, _position+vec3(0,_lineCount+0.5f,-0.5f)*_size, etk::color::blue);
// Y letter
out->addLine(_materialName, _position+vec3(0,_lineCount+2,0)*_size, _position+vec3(0.7f,_lineCount+2.0f,1.0f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,_lineCount+2,0)*_size, _position+vec3(-0.7f,_lineCount+2.0f,1.0f)*_size, etk::color::blue);
out->addLine(_materialName, _position+vec3(0,_lineCount+2,0)*_size, _position+vec3(0,_lineCount+2.0f,-1.0f)*_size, etk::color::blue);
} else {
std::vector<vec3> list;
list.push_back(_position+vec3(-1,-1,iii)*_size);
list.push_back(_position+vec3(1,-1,iii)*_size);
list.push_back(_position+vec3(1,1,iii)*_size);
list.push_back(_position+vec3(-1,1,iii)*_size);
list.push_back(_position+vec3(-1,-1,iii)*_size);
list.push_back(_position+vec3(-1,iii,-1)*_size);
list.push_back(_position+vec3(1,iii,-1)*_size);
list.push_back(_position+vec3(1,iii,1)*_size);
list.push_back(_position+vec3(-1,iii,1)*_size);
list.push_back(_position+vec3(-1,iii,-1)*_size);
out->addLines(_materialName, list, etk::color::gray);
}
//out->addPoint(_materialName, vec3(iii,-_lineCount,0), etk::color::white);
//out->addPoint(_materialName, vec3(iii,_lineCount,0), etk::color::white);
//out->addPoint(_materialName, vec3(iii,0,-_lineCount), etk::color::white);
//out->addPoint(_materialName, vec3(iii,0,_lineCount), etk::color::white);
}
// generate the VBO

View File

@ -75,8 +75,6 @@ static ememory::SharedPtr<ege::resource::Mesh> createViewBoxStar() {
void appl::Windows::init() {
ewol::widget::Windows::init();
getObjectManager().periodicCall.connect(sharedFromThis(), &appl::Windows::onCallbackPeriodicCheckCollision);
m_env = ege::Environement::create();
// set the debug property on the engines
m_env->getEngine("render")->properties.set("debug-normal", "true");
@ -390,18 +388,5 @@ bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
return false;
}
void appl::Windows::onCallbackPeriodicCheckCollision(const ewol::event::Time& _event) {
/*
std::vector<ege::physics::Engine::collisionPoints> list = m_env->getPhysicEngine().getListOfCollision();
if (list.size() != 0) {
APPL_INFO("num contact =" << list.size());
}
for (size_t iii=0;iii<list.size();++iii) {
APPL_ERROR(" [" << list[iii].elem1->getUID() << "]:point1=" << list[iii].positionElem1 << " [" << list[iii].elem1->getUID() << "]:point2=" << list[iii].positionElem2 << " normal=" << list[iii].normalElem2);
}
*/
}

View File

@ -68,6 +68,11 @@ void appl::Windows::init() {
m_env = ege::Environement::create();
// set the debug property on the engines
m_env->getEngine("render")->properties.set("debug-normal", "true");
m_env->getEngine("physics")->properties.set("debug-AABB", "true");
m_env->getEngine("physics")->properties.set("debug-shape", "true");
// Create basic Camera
m_camera = ememory::makeShared<ege::camera::View>(vec3(30,30,-100), vec3(0,0,0));
m_camera->setEye(vec3(100*std::sin(m_angleTetha),100*std::cos(m_angleTetha),40*std::cos(m_anglePsy)));
@ -85,50 +90,78 @@ void appl::Windows::init() {
tmpWidget->signalDisplayDebug.connect(sharedFromThis(), &appl::Windows::onCallbackDisplayDebug);
}
ememory::SharedPtr<ege::resource::Mesh> myMesh;
// Create an external box :
// Create an external box: (no physics)
myMesh = createViewBoxStar();
if (myMesh != nullptr) {
m_env->addStaticMeshToDraw(myMesh);
ememory::SharedPtr<ege::Entity> element = ememory::makeShared<ege::Entity>(m_env);
// 1st Position component:
etk::Transform3D transform(vec3(0,0,0), etk::Quaternion::identity());
ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
element->addComponent(componentPosition);
// 2nd something to diplay:
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
element->addComponent(componentRender);
// add it ..
m_env->addEntity(element);
}
// create basic gird:
// create basic gird: (no physics)
myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5);
if (myMesh != nullptr) {
m_env->addStaticMeshToDraw(myMesh);
ememory::SharedPtr<ege::Entity> element = ememory::makeShared<ege::Entity>(m_env);
// 1st Position component:
etk::Transform3D transform(vec3(0,0,0), etk::Quaternion::identity());
ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
element->addComponent(componentPosition);
// 2nd something to diplay:
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
element->addComponent(componentRender);
// add it ..
m_env->addEntity(element);
}
myMesh = ege::resource::Mesh::createCube(3);
myMesh = ege::resource::Mesh::createCube(3, "basics", etk::color::orange);
if (myMesh != nullptr) {
//ememory::SharedPtr<ege::ElementBase> element = ememory::makeShared<ege::ElementBase>(m_env);
ememory::SharedPtr<ege::ElementPhysic> element = ememory::makeShared<ege::ElementPhysic>(m_env);
// add physic interface:
ememory::SharedPtr<ege::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
physic->setSize(vec3(3.2,3.2,3.2));
myMesh->addPhysicElement(physic);
element->setMesh(myMesh);
element->createRigidBody(4000000);
element->setPosition(vec3(20,10,10));
m_env->addElement(element);
ememory::SharedPtr<ege::Entity> element = ememory::makeShared<ege::Entity>(m_env);
// add all component:
// 1st Position component:
etk::Transform3D transform(vec3(20,-10,10), etk::Quaternion::identity());
//ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
//element->addComponent(componentPosition);
// 2nd something to diplay:
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
element->addComponent(componentRender);
// 3rd some physic:
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
ememory::SharedPtr<ege::physics::shape::Box> physic = ememory::makeShared<ege::physics::shape::Box>();
physic->setSize(vec3(3.01,3.01,3.01));
physic->setMass(50000);
componentPhysics->addShape(physic);
componentPhysics->generate();
element->addComponent(componentPhysics);
// add it ..
m_env->addEntity(element);
}
myMesh = ege::resource::Mesh::createCube(3);
myMesh = ege::resource::Mesh::createSphere(4, "basics", etk::color::blue);
if (myMesh != nullptr) {
//element = ememory::makeShared<ege::ElementBase>(m_env);
ememory::SharedPtr<ege::ElementPhysic> element = ememory::makeShared<ege::ElementPhysic>(m_env);
// add physic interface:
ememory::SharedPtr<ege::PhysicsSphere> physic = ememory::makeShared<ege::PhysicsSphere>();
physic->setRadius(4.5f);
myMesh->addPhysicElement(physic);
element->setMesh(myMesh);
element->createRigidBody(4000000);
element->setPosition(vec3(20,-10,10));
element->iaEnable();
m_env->addElement(element);
ememory::SharedPtr<ege::Entity> element = ememory::makeShared<ege::Entity>(m_env);
// add all component:
// 1st Position component:
etk::Transform3D transform(vec3(-20,10,10), etk::Quaternion::identity());
//ememory::SharedPtr<ege::position::Component> componentPosition = ememory::makeShared<ege::position::Component>(transform);
//element->addComponent(componentPosition);
// 2nd something to diplay:
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
element->addComponent(componentRender);
// 3rd some physic:
ememory::SharedPtr<ege::physics::Component> componentPhysics = ememory::makeShared<ege::physics::Component>(m_env, transform);
ememory::SharedPtr<ege::physics::shape::Sphere> physic = ememory::makeShared<ege::physics::shape::Sphere>();
physic->setRadius(4.01);
physic->setMass(500000);
componentPhysics->addShape(physic);
componentPhysics->generate();
element->addComponent(componentPhysics);
// add it ..
m_env->addEntity(element);
}
m_env->propertyStatus.set(ege::gameStart);
}