diff --git a/lutinParseSubFolders.txt b/lutinParseSubFolders.txt index eeba3f4..eb333b6 100644 --- a/lutinParseSubFolders.txt +++ b/lutinParseSubFolders.txt @@ -13,4 +13,5 @@ sample/Particle sample/RayTest sample/Script sample/StereoVision +sample/TorqueApply sample/LowPoly \ No newline at end of file diff --git a/sample/TorqueApply/README.md b/sample/TorqueApply/README.md new file mode 100644 index 0000000..0aff0eb --- /dev/null +++ b/sample/TorqueApply/README.md @@ -0,0 +1 @@ +Apply Torque on an object (check of the physics) \ No newline at end of file diff --git a/sample/TorqueApply/appl/Windows.cpp b/sample/TorqueApply/appl/Windows.cpp new file mode 100644 index 0000000..689fcf1 --- /dev/null +++ b/sample/TorqueApply/appl/Windows.cpp @@ -0,0 +1,249 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license MPL v2.0 (see license file) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +appl::Windows::Windows() { + addObjectType("appl::Windows"); + propertyTitle.setDirectCheck("example ege : Collision"); +} + + +static ememory::SharedPtr createViewBoxStar() { + ememory::SharedPtr out = ege::resource::Mesh::create("viewBoxStar", "DATA:texturedNoMaterial.prog"); + if (out == nullptr) { + return out; + } + ememory::SharedPtr material = ememory::makeShared(); + // 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 tmpPhysics = ememory::dynamicPointerCast(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(); + m_env->addCamera("basic", m_camera); + m_cameraControler.setCamera(m_camera); + + ememory::SharedPtr 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 myMesh; + // Create an external box: (no physics) + myMesh = createViewBoxStar(); + if (myMesh != nullptr) { + ememory::SharedPtr entity = ememory::makeShared(m_env); + // 1st Position component: + etk::Transform3D transform(vec3(0,0,0), etk::Quaternion::identity()); + ememory::SharedPtr componentPosition = ememory::makeShared(transform); + entity->addComponent(componentPosition); + // 2nd something to diplay: + ememory::SharedPtr componentRender = ememory::makeShared(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 entity = ememory::makeShared(m_env); + // 1st Position component: + etk::Transform3D transform(vec3(0,0,0), etk::Quaternion::identity()); + ememory::SharedPtr componentPosition = ememory::makeShared(transform); + entity->addComponent(componentPosition); + // 2nd something to diplay: + ememory::SharedPtr componentRender = ememory::makeShared(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 entity = ememory::makeShared(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 componentRender = ememory::makeShared(myMesh); + entity->addComponent(componentRender); + // 3rd some physic: + ememory::SharedPtr componentPhysics = ememory::makeShared(m_env, transform); + ememory::SharedPtr physic = ememory::makeShared(); + 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 entity = ememory::makeShared(m_env); + // add all component: + // 1st Position component: + etk::Transform3D transform(vec3(0,0,10), etk::Quaternion::identity()); + // 2nd something to diplay: + ememory::SharedPtr componentRender = ememory::makeShared(myMesh); + entity->addComponent(componentRender); + // 3rd some physic: + ememory::SharedPtr componentPhysics = ememory::makeShared(m_env, transform); + ememory::SharedPtr physic = ememory::makeShared(); + 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 myMesh; + myMesh = ege::resource::Mesh::createCube(1, "basics", etk::color::orange); + if (myMesh != nullptr) { + ememory::SharedPtr entity = ememory::makeShared(m_env); + // add all component: + // 1st Position component: + etk::Transform3D transform(ray.getOrigin(), etk::Quaternion::identity()); + //ememory::SharedPtr componentPosition = ememory::makeShared(transform); + //entity->addComponent(componentPosition); + // 2nd something to diplay: + ememory::SharedPtr componentRender = ememory::makeShared(myMesh); + entity->addComponent(componentRender); + // 3rd some physic: + ememory::SharedPtr componentPhysics = ememory::makeShared(m_env, transform); + ememory::SharedPtr physic = ememory::makeShared(); + 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; +} + + diff --git a/sample/TorqueApply/appl/Windows.hpp b/sample/TorqueApply/appl/Windows.hpp new file mode 100644 index 0000000..bcaa058 --- /dev/null +++ b/sample/TorqueApply/appl/Windows.hpp @@ -0,0 +1,35 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include +#include +#include +#include +#include + +namespace appl { + class Windows : public ewol::widget::Windows { + private: + ememory::SharedPtr m_env; + ememory::SharedPtr m_camera; + ememory::SharedPtr 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; + }; +} + diff --git a/sample/TorqueApply/appl/debug.cpp b/sample/TorqueApply/appl/debug.cpp new file mode 100644 index 0000000..4f5780b --- /dev/null +++ b/sample/TorqueApply/appl/debug.cpp @@ -0,0 +1,15 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license MPL v2.0 (see license file) + */ + + +#include + +int32_t appl::getLogId() { + static int32_t g_val = elog::registerInstance("GP-spaceShip"); + return g_val; +} diff --git a/sample/TorqueApply/appl/debug.hpp b/sample/TorqueApply/appl/debug.hpp new file mode 100644 index 0000000..4c40487 --- /dev/null +++ b/sample/TorqueApply/appl/debug.hpp @@ -0,0 +1,40 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license MPL v2.0 (see license file) + */ +#pragma once + +#include + +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) + diff --git a/sample/TorqueApply/appl/main.cpp b/sample/TorqueApply/appl/main.cpp new file mode 100644 index 0000000..cf31945 --- /dev/null +++ b/sample/TorqueApply/appl/main.cpp @@ -0,0 +1,68 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license MPL v2.0 (see license file) + */ + + +#include +#include +#include + +#include +#include +#include +#include +#include + + +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 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); +} + + diff --git a/sample/TorqueApply/appl/main.hpp b/sample/TorqueApply/appl/main.hpp new file mode 100644 index 0000000..91c03bf --- /dev/null +++ b/sample/TorqueApply/appl/main.hpp @@ -0,0 +1,9 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license MPL v2.0 (see license file) + */ +#pragma once + diff --git a/sample/TorqueApply/lutin_ege-sample-torque-apply.py b/sample/TorqueApply/lutin_ege-sample-torque-apply.py new file mode 100644 index 0000000..9da478b --- /dev/null +++ b/sample/TorqueApply/lutin_ege-sample-torque-apply.py @@ -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 "] + +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 +