[DEV] add a sample to test apply force
This commit is contained in:
parent
ff4e7ac001
commit
54529a3efd
@ -13,4 +13,5 @@ sample/Particle
|
||||
sample/RayTest
|
||||
sample/Script
|
||||
sample/StereoVision
|
||||
sample/TorqueApply
|
||||
sample/LowPoly
|
1
sample/TorqueApply/README.md
Normal file
1
sample/TorqueApply/README.md
Normal file
@ -0,0 +1 @@
|
||||
Apply Torque on an object (check of the physics)
|
249
sample/TorqueApply/appl/Windows.cpp
Normal file
249
sample/TorqueApply/appl/Windows.cpp
Normal file
@ -0,0 +1,249 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <appl/debug.hpp>
|
||||
#include <appl/Windows.hpp>
|
||||
#include <ewol/widget/Label.hpp>
|
||||
#include <ewol/widget/Sizer.hpp>
|
||||
#include <ewol/object/Manager.hpp>
|
||||
#include <ege/widget/Scene.hpp>
|
||||
#include <ege/camera/View.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
#include <ege/Entity.hpp>
|
||||
#include <ege/physics/shape/Box.hpp>
|
||||
#include <ege/physics/shape/Sphere.hpp>
|
||||
#include <ege/physics/shape/Cylinder.hpp>
|
||||
#include <ege/physics/shape/Capsule.hpp>
|
||||
#include <ege/physics/shape/Cone.hpp>
|
||||
#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");
|
||||
propertyTitle.setDirectCheck("example ege : Collision");
|
||||
}
|
||||
|
||||
|
||||
static ememory::SharedPtr<ege::resource::Mesh> createViewBoxStar() {
|
||||
ememory::SharedPtr<ege::resource::Mesh> out = ege::resource::Mesh::create("viewBoxStar", "DATA:texturedNoMaterial.prog");
|
||||
if (out == nullptr) {
|
||||
return out;
|
||||
}
|
||||
ememory::SharedPtr<ege::Material> material = ememory::makeShared<ege::Material>();
|
||||
// set the entity material properties :
|
||||
material->setAmbientFactor(vec4(1,1,1,1));
|
||||
material->setDiffuseFactor(vec4(0,0,0,1));
|
||||
material->setSpecularFactor(vec4(0,0,0,1));
|
||||
material->setShininess(1);
|
||||
// 1024 == > 1<<9
|
||||
// 2048 == > 1<<10
|
||||
// 4096 == > 1<<11
|
||||
int32_t size = 1<<11;
|
||||
//material->setTexture0(""); //"
|
||||
material->setTexture0Magic(ivec2(size,size));
|
||||
out->addMaterial("basics", material);
|
||||
//material->setImageSize(ivec2(size,size));
|
||||
egami::Image* myImage = material->get();
|
||||
if (myImage == nullptr) {
|
||||
return out;
|
||||
}
|
||||
myImage->clear(etk::color::black);
|
||||
ivec2 tmpPos;
|
||||
for (int32_t iii=0; iii<6000; iii++) {
|
||||
tmpPos.setValue(etk::tool::frand(0,size), etk::tool::frand(0,size)) ;
|
||||
myImage->set(tmpPos, etk::color::white);
|
||||
}
|
||||
material->flush();
|
||||
// basis on cube :
|
||||
out->createViewBox("basics", 1000/* distance */);
|
||||
// generate the VBO
|
||||
out->generateVBO();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// TODO : Assert When a dynamic object is sponed inside a static object
|
||||
// loke:
|
||||
// o-------o
|
||||
// | |
|
||||
// o--------| X |--------o
|
||||
// | | | |
|
||||
// | o-------o |
|
||||
// | |
|
||||
// | X |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// o-------------------------o
|
||||
|
||||
|
||||
|
||||
void appl::Windows::init() {
|
||||
ewol::widget::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");
|
||||
|
||||
ememory::SharedPtr<ege::physics::Engine> tmpPhysics = ememory::dynamicPointerCast<ege::physics::Engine>(m_env->getEngine("physics"));
|
||||
if (tmpPhysics != nullptr) {
|
||||
tmpPhysics->setGravity(vec3(0.0, 0.0, -9.81)); // generic earth gravity
|
||||
}
|
||||
|
||||
// Create basic Camera
|
||||
m_camera = ememory::makeShared<ege::camera::View>();
|
||||
m_env->addCamera("basic", m_camera);
|
||||
m_cameraControler.setCamera(m_camera);
|
||||
|
||||
ememory::SharedPtr<ege::widget::Scene> tmpWidget = ege::widget::Scene::create();
|
||||
if (tmpWidget == nullptr) {
|
||||
APPL_CRITICAL("Can not allocate widget ==> display might be in error");
|
||||
} else {
|
||||
tmpWidget->setEnv(m_env);
|
||||
tmpWidget->propertyExpand.set(bvec2(true,true));
|
||||
tmpWidget->propertyFill.set(bvec2(true,true));
|
||||
tmpWidget->setCamera("basic");
|
||||
setSubWidget(tmpWidget);
|
||||
}
|
||||
|
||||
ememory::SharedPtr<ege::resource::Mesh> myMesh;
|
||||
// Create an external box: (no physics)
|
||||
myMesh = createViewBoxStar();
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = 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);
|
||||
entity->addComponent(componentPosition);
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->addComponent(componentRender);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
// create basic gird: (no physics)
|
||||
myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = 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);
|
||||
entity->addComponent(componentPosition);
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->addComponent(componentRender);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
|
||||
// create cubes (surface)
|
||||
myMesh = ege::resource::Mesh::createCube(vec3(50,50,10), "basics", etk::color::green);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = ememory::makeShared<ege::Entity>(m_env);
|
||||
// add all component:
|
||||
// 1st Position component:
|
||||
etk::Transform3D transform(vec3(0,0,-10.01), etk::Quaternion::identity());
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->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(200.01,200.01,10.01));
|
||||
componentPhysics->addShape(physic);
|
||||
// The entity can not move
|
||||
componentPhysics->setType(ege::physics::Component::type::bodyStatic);
|
||||
componentPhysics->generate();
|
||||
entity->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
|
||||
// create cubes that will move...
|
||||
myMesh = ege::resource::Mesh::createCube(vec3(5,5,5), "basics", etk::color::yellow);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = ememory::makeShared<ege::Entity>(m_env);
|
||||
// add all component:
|
||||
// 1st Position component:
|
||||
etk::Transform3D transform(vec3(0,0,10), etk::Quaternion::identity());
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->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(5.01,5.01,5.01));
|
||||
physic->setMass(300000);
|
||||
componentPhysics->setType(ege::physics::Component::type::bodyDynamic);
|
||||
componentPhysics->addShape(physic);
|
||||
componentPhysics->generate();
|
||||
entity->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
m_entity = entity;
|
||||
}
|
||||
m_env->propertyStatus.set(ege::gameStart);
|
||||
}
|
||||
|
||||
bool appl::Windows::onEventEntry(const ewol::event::Entry& _event) {
|
||||
if (m_cameraControler.onEventEntry(_event) == true) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool appl::Windows::onEventInput(const ewol::event::Input& _event) {
|
||||
if (m_cameraControler.onEventInput(_event, relativePosition(_event.getPos())) == true) {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
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::orange);
|
||||
if (myMesh != nullptr) {
|
||||
ememory::SharedPtr<ege::Entity> entity = ememory::makeShared<ege::Entity>(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);
|
||||
//entity->addComponent(componentPosition);
|
||||
// 2nd something to diplay:
|
||||
ememory::SharedPtr<ege::render::Component> componentRender = ememory::makeShared<ege::render::Component>(myMesh);
|
||||
entity->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(1.01,1.01,1.01));
|
||||
physic->setMass(1000);
|
||||
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()*100);
|
||||
entity->addComponent(componentPhysics);
|
||||
// add it ..
|
||||
m_env->addEntity(entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
35
sample/TorqueApply/appl/Windows.hpp
Normal file
35
sample/TorqueApply/appl/Windows.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ewol/widget/Windows.hpp>
|
||||
#include <ege/Environement.hpp>
|
||||
#include <ege/camera/View.hpp>
|
||||
#include <ege/camera/ControlBase.hpp>
|
||||
#include <ewol/resource/Colored3DObject.hpp>
|
||||
|
||||
namespace appl {
|
||||
class Windows : public ewol::widget::Windows {
|
||||
private:
|
||||
ememory::SharedPtr<ege::Environement> m_env;
|
||||
ememory::SharedPtr<ege::camera::View> m_camera;
|
||||
ememory::SharedPtr<ege::Entity> m_entity;
|
||||
ege::camera::ControlBase m_cameraControler;
|
||||
protected:
|
||||
Windows();
|
||||
void init() override;
|
||||
public:
|
||||
DECLARE_FACTORY(Windows);
|
||||
virtual ~Windows() { };
|
||||
private:
|
||||
// need this to forward if to the camera controler ...
|
||||
bool onEventEntry(const ewol::event::Entry& _event) override;
|
||||
bool onEventInput(const ewol::event::Input& _event) override;
|
||||
};
|
||||
}
|
||||
|
15
sample/TorqueApply/appl/debug.cpp
Normal file
15
sample/TorqueApply/appl/debug.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
|
||||
int32_t appl::getLogId() {
|
||||
static int32_t g_val = elog::registerInstance("GP-spaceShip");
|
||||
return g_val;
|
||||
}
|
40
sample/TorqueApply/appl/debug.hpp
Normal file
40
sample/TorqueApply/appl/debug.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <elog/log.hpp>
|
||||
|
||||
namespace appl {
|
||||
int32_t getLogId();
|
||||
}
|
||||
#define APPL_BASE(info,data) ELOG_BASE(appl::getLogId(),info,data)
|
||||
|
||||
#define APPL_PRINT(data) APPL_BASE(-1, data)
|
||||
#define APPL_CRITICAL(data) APPL_BASE(1, data)
|
||||
#define APPL_ERROR(data) APPL_BASE(2, data)
|
||||
#define APPL_WARNING(data) APPL_BASE(3, data)
|
||||
#ifdef DEBUG
|
||||
#define APPL_INFO(data) APPL_BASE(4, data)
|
||||
#define APPL_DEBUG(data) APPL_BASE(5, data)
|
||||
#define APPL_VERBOSE(data) APPL_BASE(6, data)
|
||||
#define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)
|
||||
#else
|
||||
#define APPL_INFO(data) do { } while(false)
|
||||
#define APPL_DEBUG(data) do { } while(false)
|
||||
#define APPL_VERBOSE(data) do { } while(false)
|
||||
#define APPL_TODO(data) do { } while(false)
|
||||
#endif
|
||||
|
||||
#define APPL_ASSERT(cond,data) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
APPL_CRITICAL(data); \
|
||||
assert(!#cond); \
|
||||
} \
|
||||
} while (0)
|
||||
|
68
sample/TorqueApply/appl/main.cpp
Normal file
68
sample/TorqueApply/appl/main.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
|
||||
#include <appl/debug.hpp>
|
||||
#include <appl/Windows.hpp>
|
||||
#include <ewol/object/Object.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <ewol/context/Context.hpp>
|
||||
|
||||
|
||||
class MainApplication : public ewol::context::Application {
|
||||
public:
|
||||
void onCreate(ewol::Context& _context) override {
|
||||
APPL_INFO(" == > CREATE ... " << PROJECT_NAME << " v" << APPL_VERSION << " (START) [" << gale::getBoardType() << "] (" << gale::getCompilationMode() << ") (BEGIN)");
|
||||
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
|
||||
std::string tmpppp = _context.getCmd().get(iii);
|
||||
if ( tmpppp == "-h"
|
||||
|| tmpppp == "--help") {
|
||||
APPL_INFO(" -h/--help display this help" );
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
// TODO : Remove this : Move if in the windows properties
|
||||
_context.setSize(vec2(800, 600));
|
||||
|
||||
// select internal data for font ...
|
||||
_context.getFontDefault().setUseExternal(true);
|
||||
_context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19);
|
||||
|
||||
ememory::SharedPtr<ewol::widget::Windows> basicWindows = appl::Windows::create();
|
||||
// create the specific windows
|
||||
_context.setWindows(basicWindows);
|
||||
APPL_INFO("==> CREATE ... " PROJECT_NAME " (END)");
|
||||
}
|
||||
|
||||
void onStart(ewol::Context& _context) override {
|
||||
APPL_INFO("==> START ... " PROJECT_NAME " (BEGIN)");
|
||||
// nothing to do ...
|
||||
APPL_INFO("==> START ... " PROJECT_NAME " (END)");
|
||||
}
|
||||
void onStop(ewol::Context& _context) override {
|
||||
APPL_INFO("==> STOP ... " PROJECT_NAME " (START)");
|
||||
// nothing to do ...
|
||||
APPL_INFO("==> STOP ... " PROJECT_NAME " (END)");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
// second possibility
|
||||
return ewol::run(new MainApplication(), _argc, _argv);
|
||||
}
|
||||
|
||||
|
9
sample/TorqueApply/appl/main.hpp
Normal file
9
sample/TorqueApply/appl/main.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2010, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
58
sample/TorqueApply/lutin_ege-sample-torque-apply.py
Normal file
58
sample/TorqueApply/lutin_ege-sample-torque-apply.py
Normal file
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
def get_type():
|
||||
return "BINARY"
|
||||
|
||||
def get_sub_type():
|
||||
return "SAMPLE"
|
||||
|
||||
def get_name():
|
||||
return "ege-sample-torque-apply"
|
||||
|
||||
def get_desc():
|
||||
return "ege sample : Torque Apply"
|
||||
|
||||
def get_licence():
|
||||
return "MPL-2"
|
||||
|
||||
def get_compagny_type():
|
||||
return "com"
|
||||
|
||||
def get_compagny_name():
|
||||
return "atria-soft"
|
||||
|
||||
def get_maintainer():
|
||||
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
|
||||
|
||||
def get_version():
|
||||
return [0,1]
|
||||
|
||||
def configure(target, my_module):
|
||||
my_module.add_extra_flags()
|
||||
|
||||
my_module.add_src_file([
|
||||
'appl/debug.cpp',
|
||||
'appl/main.cpp',
|
||||
'appl/Windows.cpp'
|
||||
])
|
||||
|
||||
my_module.add_depend('ege')
|
||||
|
||||
my_module.add_path(".")
|
||||
|
||||
my_module.copy_path("data/*")
|
||||
|
||||
my_module.add_flag('c++', [
|
||||
"-DPROJECT_NAME=\"\\\"" + my_module.get_name() + "\\\"\"",
|
||||
"-DAPPL_VERSION=\"\\\"" + tools.version_to_string(get_version()) + "\\\"\""
|
||||
])
|
||||
|
||||
# set the package properties :
|
||||
my_module.set_pkg("SECTION", ["Game"])
|
||||
my_module.set_pkg("PRIORITY", "optional")
|
||||
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user