[DEV] nearly work but the object does not update their positions ..
This commit is contained in:
parent
d72cefd665
commit
80793fb4da
@ -499,14 +499,14 @@ void ege::Environement::render(const echrono::Duration& _delta, const std::strin
|
||||
if(it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
EGE_INFO(" render: " << it->getType());
|
||||
EGE_VERBOSE(" render: " << it->getType());
|
||||
it->render(_delta, camera);
|
||||
}
|
||||
}
|
||||
|
||||
void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event) {
|
||||
float curentDelta = _event.getDeltaCall();
|
||||
EGE_INFO("periodic call : " << _event);
|
||||
EGE_VERBOSE("periodic call : " << _event);
|
||||
// small hack to change speed ...
|
||||
curentDelta *= *propertyRatio;
|
||||
// check if the processing is availlable
|
||||
@ -517,7 +517,7 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event)
|
||||
int32_t lastGameTime = m_gameTime*0.000001f;
|
||||
m_gameTime += curentDelta;
|
||||
if (lastGameTime != (int32_t)(m_gameTime*0.000001f)) {
|
||||
EGE_INFO(" Emit Signal");
|
||||
EGE_VERBOSE(" Emit Signal");
|
||||
signalPlayTimeChange.emit(m_gameTime*0.000001f);
|
||||
}
|
||||
|
||||
@ -526,16 +526,16 @@ void ege::Environement::onCallbackPeriodicCall(const ewol::event::Time& _event)
|
||||
// update camera positions:
|
||||
for (auto &it : m_listCamera) {
|
||||
if (it.second != nullptr) {
|
||||
EGE_INFO(" update camera : '" << it.first << "'");
|
||||
EGE_VERBOSE(" update camera : '" << it.first << "'");
|
||||
it.second->periodicCall(curentDelta);
|
||||
}
|
||||
}
|
||||
EGE_INFO(" step simulation : " << curentDelta);
|
||||
EGE_VERBOSE(" step simulation : " << curentDelta);
|
||||
for (auto &it: m_engine) {
|
||||
if(it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
EGE_INFO(" update: " << it->getType());
|
||||
EGE_VERBOSE(" update: " << it->getType());
|
||||
it->update(echrono::Duration(double(curentDelta)));
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,23 @@ ege::physics::Component::Component(ememory::SharedPtr<ege::Environement> _env, c
|
||||
m_rigidBody = m_engine->getDynamicWorld()->createRigidBody(transform);
|
||||
}
|
||||
|
||||
void ege::physics::Component::setType(enum ege::physics::Component::type _type) {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return;
|
||||
}
|
||||
switch(_type) {
|
||||
case ege::physics::Component::type::bodyStatic:
|
||||
m_rigidBody->setType(rp3d::STATIC);
|
||||
break;
|
||||
case ege::physics::Component::type::bodyKinematic:
|
||||
m_rigidBody->setType(rp3d::KINEMATIC);
|
||||
break;
|
||||
case ege::physics::Component::type::bodyDynamic:
|
||||
m_rigidBody->setType(rp3d::DYNAMIC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ege::physics::Component::~Component() {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return;
|
||||
@ -73,7 +90,8 @@ void ege::physics::Component::generate() {
|
||||
tmpElement->getSize().y(),
|
||||
tmpElement->getSize().z());
|
||||
// Create the box shape
|
||||
rp3d::BoxShape shape(halfExtents);
|
||||
rp3d::BoxShape* shape = new rp3d::BoxShape(halfExtents);
|
||||
m_listShape.push_back(shape);
|
||||
rp3d::Vector3 position(tmpElement->getOrigin().x(),
|
||||
tmpElement->getOrigin().y(),
|
||||
tmpElement->getOrigin().z());
|
||||
@ -82,7 +100,8 @@ void ege::physics::Component::generate() {
|
||||
tmpElement->getQuaternion().z(),
|
||||
tmpElement->getQuaternion().w());
|
||||
rp3d::Transform transform(position, orientation);
|
||||
m_rigidBody->addCollisionShape(&shape, transform, 4.0f /* mass */);
|
||||
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, 4.0f /* mass */);
|
||||
m_listProxyShape.push_back(proxyShape);
|
||||
break;
|
||||
}
|
||||
case ege::PhysicsShape::cylinder : {
|
||||
@ -93,7 +112,7 @@ void ege::physics::Component::generate() {
|
||||
continue;
|
||||
}
|
||||
// Create the box shape
|
||||
rp3d::CylinderShape shape(tmpElement->getSize().x(), tmpElement->getSize().y());
|
||||
rp3d::CylinderShape* shape = new rp3d::CylinderShape(tmpElement->getSize().x(), tmpElement->getSize().y());
|
||||
rp3d::Vector3 position(tmpElement->getOrigin().x(),
|
||||
tmpElement->getOrigin().y(),
|
||||
tmpElement->getOrigin().z());
|
||||
@ -102,7 +121,8 @@ void ege::physics::Component::generate() {
|
||||
tmpElement->getQuaternion().z(),
|
||||
tmpElement->getQuaternion().w());
|
||||
rp3d::Transform transform(position, orientation);
|
||||
m_rigidBody->addCollisionShape(&shape, transform, 4.0f /* mass */);
|
||||
rp3d::ProxyShape* proxyShape = m_rigidBody->addCollisionShape(shape, transform, 4.0f /* mass */);
|
||||
m_listProxyShape.push_back(proxyShape);
|
||||
break;
|
||||
}
|
||||
case ege::PhysicsShape::capsule : {
|
||||
@ -197,6 +217,46 @@ void ege::physics::Component::generate() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vec3 ege::physics::Component::getLinearVelocity() const {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return vec3(0,0,0);
|
||||
}
|
||||
rp3d::Vector3 value = m_rigidBody->getLinearVelocity();
|
||||
return vec3(value.x,
|
||||
value.y,
|
||||
value.z);
|
||||
}
|
||||
|
||||
void ege::physics::Component::setLinearVelocity(const vec3& _linearVelocity) {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return;
|
||||
}
|
||||
rp3d::Vector3 value(_linearVelocity.x(),
|
||||
_linearVelocity.y(),
|
||||
_linearVelocity.z());
|
||||
m_rigidBody->setLinearVelocity(value);
|
||||
}
|
||||
|
||||
vec3 ege::physics::Component::getAngularVelocity() const {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return vec3(0,0,0);
|
||||
}
|
||||
rp3d::Vector3 value = m_rigidBody->getAngularVelocity();
|
||||
return vec3(value.x,
|
||||
value.y,
|
||||
value.z);
|
||||
}
|
||||
void ege::physics::Component::setAngularVelocity(const vec3& _angularVelocity) {
|
||||
if (m_rigidBody == nullptr) {
|
||||
return;
|
||||
}
|
||||
rp3d::Vector3 value(_angularVelocity.x(),
|
||||
_angularVelocity.y(),
|
||||
_angularVelocity.z());
|
||||
m_rigidBody->setAngularVelocity(value);
|
||||
}
|
||||
|
||||
const std::vector<ememory::SharedPtr<ege::PhysicsShape>>& ege::physics::Component::getShape() const {
|
||||
return m_shape;
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ namespace ege {
|
||||
protected:
|
||||
ememory::SharedPtr<ege::physics::Engine> m_engine;
|
||||
rp3d::RigidBody* m_rigidBody;
|
||||
std::vector<rp3d::CollisionShape*> m_listShape;
|
||||
std::vector<rp3d::ProxyShape*> m_listProxyShape;
|
||||
public:
|
||||
/**
|
||||
* @brief Create a basic position component (no orientation and position (0,0,0))
|
||||
@ -36,6 +38,13 @@ namespace ege {
|
||||
~Component();
|
||||
public:
|
||||
virtual const std::string& getType() const;
|
||||
|
||||
enum class type {
|
||||
bodyDynamic,
|
||||
bodyStatic,
|
||||
bodyKinematic
|
||||
};
|
||||
void setType(enum ege::physics::Component::type _type);
|
||||
/**
|
||||
* @brief set a new transformation
|
||||
* @param[in] _transform transformation of the position
|
||||
@ -46,6 +55,26 @@ namespace ege {
|
||||
* @return Transformation of the position
|
||||
*/
|
||||
etk::Transform3D getTransform() const;
|
||||
/**
|
||||
* @brief Get the linear velocity.
|
||||
* @return The linear velocity vector of the body
|
||||
*/
|
||||
vec3 getLinearVelocity() const;
|
||||
/**
|
||||
* @brief Set the linear velocity.
|
||||
* @param[in] _linearVelocity The linear velocity vector of the body
|
||||
*/
|
||||
void setLinearVelocity(const vec3& _linearVelocity);
|
||||
/**
|
||||
* @brief Get the angular velocity.
|
||||
* @return The angular velocity vector of the body
|
||||
*/
|
||||
vec3 getAngularVelocity() const;
|
||||
/**
|
||||
* @brief Set the angular velocity.
|
||||
* @param[in] _linearVelocity The angular velocity vector of the body
|
||||
*/
|
||||
void setAngularVelocity(const vec3& _angularVelocity);
|
||||
protected:
|
||||
std::vector<ememory::SharedPtr<ege::PhysicsShape>> m_shape; //!< collision shape module ... (independent of bullet lib)
|
||||
public:
|
||||
|
@ -80,6 +80,7 @@ void ege::render::Component::draw(int32_t _pass) {
|
||||
//EGE_INFO(" mat = " << mat4(mmm));
|
||||
mat4 transformationMatrix(mmm);
|
||||
//mat4 transformationMatrix = mat4(mmm) * etk::matScale(vec3(20,20,20));
|
||||
transformationMatrix.transpose();
|
||||
// TODO: check this : transformationMatrix.transpose();
|
||||
m_mesh->draw(transformationMatrix);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace ege {
|
||||
const std::string& _materialName="basics");
|
||||
static ememory::SharedPtr<ege::resource::Mesh> createCube(float _size=1.0f,
|
||||
const std::string& _materialName="basics",
|
||||
const etk::Color<float>& _color=etk::color::white);
|
||||
const etk::Color<float>& _color=etk::color::green);
|
||||
public:
|
||||
/**
|
||||
* @not_in_doc
|
||||
|
@ -71,6 +71,7 @@ void ege::widget::Scene::onDraw() {
|
||||
g_counterNbTimeDisplay++;
|
||||
g_startTime = echrono::Steady::now();
|
||||
#endif
|
||||
gale::openGL::clearColor(etk::color::black);
|
||||
m_env->render(echrono::Duration(1.0/60.0), m_cameraName);
|
||||
#if 0
|
||||
// draw constant object:
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <ege/position/Component.hpp>
|
||||
#include <ege/render/Component.hpp>
|
||||
#include <ege/physics/Component.hpp>
|
||||
#include <ege/Ray.hpp>
|
||||
|
||||
appl::Windows::Windows() {
|
||||
addObjectType("appl::Windows");
|
||||
@ -121,7 +122,7 @@ void appl::Windows::init() {
|
||||
m_env->addElement(element);
|
||||
}
|
||||
// create cubes ...
|
||||
myMesh = ege::resource::Mesh::createCube(3);
|
||||
myMesh = ege::resource::Mesh::createCube(3, "basics", etk::color::green);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Element> element = ememory::makeShared<ege::Element>(m_env);
|
||||
// add all component:
|
||||
@ -141,41 +142,26 @@ void appl::Windows::init() {
|
||||
element->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addElement(element);
|
||||
|
||||
/*
|
||||
//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:
|
||||
}
|
||||
myMesh = ege::resource::Mesh::createCube(3, "basics", etk::color::orange);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Element> element = ememory::makeShared<ege::Element>(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::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));
|
||||
element->setMass(1000);
|
||||
|
||||
m_env->addElement(element);
|
||||
*/
|
||||
}
|
||||
myMesh = ege::resource::Mesh::createCube(3);
|
||||
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->setMass(3000);
|
||||
|
||||
element->iaEnable();
|
||||
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
element->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addElement(element);
|
||||
}
|
||||
m_env->propertyStatus.set(ege::gameStart);
|
||||
@ -200,25 +186,34 @@ bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
|
||||
if (_event.getId() == 1) {
|
||||
if (_event.getStatus() == gale::key::status::down) {
|
||||
vec2 pos = relativePosition(_event.getPos());
|
||||
/*
|
||||
ege::Ray ray = m_camera->getRayFromScreenPosition(pos, m_size);
|
||||
|
||||
ememory::SharedPtr<ege::resource::Mesh> myMesh;
|
||||
myMesh = ege::resource::Mesh::createCube(1, "basics", etk::color::green);
|
||||
myMesh = ege::resource::Mesh::createCube(1, "basics", etk::color::orange);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<appl::ElementHerit> element = ememory::makeShared<appl::ElementHerit>(m_env);
|
||||
ememory::SharedPtr<ege::Element> element = ememory::makeShared<ege::Element>(m_env);
|
||||
// add all component:
|
||||
// 1st Position component:
|
||||
etk::Transform3D transform(ray.getOrigin(), 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::PhysicsBox> physic = ememory::makeShared<ege::PhysicsBox>();
|
||||
physic->setSize(vec3(1.01,1.01,1.01));
|
||||
myMesh->addPhysicElement(physic);
|
||||
element->setMesh(myMesh);
|
||||
element->createRigidBody(4000000);
|
||||
element->setPosition(ray.getOrigin());
|
||||
element->setMass(20);
|
||||
element->setLinearVelocity(ray.getDirection()*100);
|
||||
physic->setSize(vec3(1.1,1.1,1.1));
|
||||
componentPhysics->setType(ege::physics::Component::type::bodyDynamic);
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
// set has dynamic object (can move)
|
||||
//APPL_CRITICAL("velocity : " << ray.getDirection()*100);
|
||||
componentPhysics->setLinearVelocity(ray.getDirection()*1000);
|
||||
element->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addElement(element);
|
||||
APPL_INFO("Create cube at position " << ray.getOrigin() << " velocity: " << ray.getDirection()*100);
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
} else if (_event.getId() == 4) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user