From 16793fe43598a7edf6a7c7bf128bd772a04d73a6 Mon Sep 17 00:00:00 2001 From: AKindyakov Date: Mon, 23 Sep 2013 01:18:19 +0400 Subject: [PATCH] remake mechanism of transporting 3d objects --- .../include/heliumPreparedSceneObjects.h | 31 ++++---- .../include/heliumSceneObjects.h | 20 +++++- .../src/heliumPreparedSceneObjects.cpp | 70 ++++++++++--------- .../src/heliumSceneObjects.cpp | 62 +++++++++++++--- tests/sceneWorldDevelop/src/main.cpp | 2 +- tests/sceneWorldDevelop/src/proGameObject.cpp | 23 +++--- 6 files changed, 138 insertions(+), 70 deletions(-) diff --git a/modules/heliumSceneObjects/include/heliumPreparedSceneObjects.h b/modules/heliumSceneObjects/include/heliumPreparedSceneObjects.h index 97641f1..2535d98 100644 --- a/modules/heliumSceneObjects/include/heliumPreparedSceneObjects.h +++ b/modules/heliumSceneObjects/include/heliumPreparedSceneObjects.h @@ -15,6 +15,7 @@ typedef enum { PREPARED_3D_UNKNOWN = 0, + PREPARED_3D_HELIUM_556_BULLET_BOX = 1, PREPARED_3D_LAST } HeliumPreparedSceneObjects; @@ -36,23 +37,22 @@ struct HeliumTestBox : public PackagedSceneObject { ~HeliumTestBox() {} }; +struct Helium556BulletBox : public PackagedSceneObject { + Helium556BulletBox( double pos_x, double pos_y, double pos_z, double size ); +}; + class HeliumSceneArchitecktHand : public SceneObject { public: - HeliumSceneArchitecktHand( PackagedSceneObject*); - HeliumSceneArchitecktHand( HeliumPreparedSceneObjects ); - ~HeliumSceneArchitecktHand(); - - void lifeStep(); /** - * @brief - */ - void mouseCursor(); + * @brief Create null hand and if click - > object will be picked up from the scene + */ + HeliumSceneArchitecktHand(IHeliumObjectsWorld::ObjectsIdType id=0); - /** - * @brief - */ - void mouseClick( int button, bool upDown ); + + ~HeliumSceneArchitecktHand(); + + void lifeStep(); /** * @brief @@ -65,15 +65,14 @@ class HeliumSceneArchitecktHand : public SceneObject { void mouseDoubleClick(); private: - PackagedSceneObject* creatingObject; + IHeliumObjectsWorld::ObjectsIdType creatingObject; }; class HeliumSceneArchitecktHandPack : public PackagedSceneObject { public: - HeliumSceneArchitecktHandPack(); - HeliumSceneArchitecktHandPack( PackagedSceneObject* ); - HeliumSceneArchitecktHandPack( HeliumPreparedSceneObjects ); + + HeliumSceneArchitecktHandPack( IHeliumObjectsWorld::ObjectsIdType id=0); ~HeliumSceneArchitecktHandPack(); }; diff --git a/modules/heliumSceneObjects/include/heliumSceneObjects.h b/modules/heliumSceneObjects/include/heliumSceneObjects.h index f6cdaed..2954648 100644 --- a/modules/heliumSceneObjects/include/heliumSceneObjects.h +++ b/modules/heliumSceneObjects/include/heliumSceneObjects.h @@ -199,11 +199,21 @@ class SceneObjectsWorld : public IHeliumObjectsWorld { */ Polycode::RayTestResult rayTest(Polycode::Vector2); + /** + * + */ + IHeliumObjectsWorld::ObjectsIdType getObjectIdByEntity(Polycode::SceneEntity* entity)const; + /** * @brief add id of object to queue of mouse point click */ void addObjectToMousePointQueue(IHeliumObjectsWorld::ObjectsIdType); + /** + * @brief warp object to point, if it exist of course + */ + void warpTo(IHeliumObjectsWorld::ObjectsIdType, Polycode::Vector3, bool resetRotation=true); + protected: Polycode::PhysicsScene* engineScene; Polycode::Vector2 horisontalVectorMove; @@ -219,12 +229,20 @@ class SceneObjectsWorld : public IHeliumObjectsWorld { std::set< IHeliumObjectsWorld::ObjectsIdType > queueToMousePoint; std::list< IHeliumObjectsWorld::ObjectsIdType > delayedSignOutObjects; - + +private: /** * @return True - if the queue in mot empty, otherwise False */ bool checkQueueToMousePointClick( int button, bool upDown, Polycode::Vector2 mouse ); void checkDelayedSignOutObject(); + + /** + * @param + */ + void addPackagedToEngineScene( PackagedSceneObject* obj ); + + void engineSceneWarpTo( Polycode::SceneEntity* obj, Polycode::Vector3 point, bool resetRotation ); }; /** diff --git a/modules/heliumSceneObjects/src/heliumPreparedSceneObjects.cpp b/modules/heliumSceneObjects/src/heliumPreparedSceneObjects.cpp index 6bee5bb..ed9ad37 100644 --- a/modules/heliumSceneObjects/src/heliumPreparedSceneObjects.cpp +++ b/modules/heliumSceneObjects/src/heliumPreparedSceneObjects.cpp @@ -65,65 +65,67 @@ HeliumTestBox::HeliumTestBox( double size_x, double size_y, double size_z, mass = 0.5; } -HeliumSceneArchitecktHand::HeliumSceneArchitecktHand( PackagedSceneObject* pack ) - : SceneObject(pack->getModel()->Clone()), - creatingObject(pack) {} -// : SceneObject( new P::ScenePrimitive( P::ScenePrimitive::TYPE_BOX,1,1,1 )), -// creatingObject(pack) {} - -HeliumSceneArchitecktHand::HeliumSceneArchitecktHand( HeliumPreparedSceneObjects id) - : SceneObject(NULL), - creatingObject(NULL) { +Helium556BulletBox::Helium556BulletBox(double pos_x, double pos_y, double pos_z, double size ) +{ + P::ScenePrimitive* box = new P::ScenePrimitive( P::ScenePrimitive::TYPE_BOX, + size*5, size*3, size*3 ); + + box->loadTexture(g_helium_resource_path + "/556bullet_box.png"); + box->setPosition(pos_x, pos_z, pos_y); + heliumObject = new SceneObject(box); + alife = 1; + entityType = POLY_ENTITY_PHYSICAL; + shapeType = P::PhysicsSceneEntity::SHAPE_BOX; + mass = size; } +HeliumSceneArchitecktHand::HeliumSceneArchitecktHand(IHeliumObjectsWorld::ObjectsIdType id) + : SceneObject(new P::ScenePrimitive(P::ScenePrimitive::TYPE_SPHERE, 0.25, 5, 5 )), + creatingObject(id) {} + HeliumSceneArchitecktHand::~HeliumSceneArchitecktHand() { } void HeliumSceneArchitecktHand::lifeStep() { - std::cout << "HeliumSceneArchitecktHand::lifeStep()\n"; HeliumGameCore* gm = HeliumGlobal::getCurrentGame(); Polycode::Vector2 mouse = gm->getEngineCorePt()->getInput()->getMousePosition(); Polycode::RayTestResult rayRez = gm->getSceneWorldPt()->rayTest(mouse); - rayRez.position.y += model->bBox.y/2; - model->setPosition(rayRez.position); - std::cout << rayRez.position.x << ' ' << rayRez.position.y << ' ' << rayRez.position.z << '\n'; -} - -void HeliumSceneArchitecktHand::mouseCursor() { -} -void HeliumSceneArchitecktHand::mouseClick( int button, bool upDown ) { - std::cout << "HeliumSceneArchitecktHand::mouseClick()\n"; + gm->getSceneWorldPt()->warpTo(creatingObject, rayRez.position); + // rayRez.position.y += model->bBox.y/2; + model->setPosition(rayRez.position); + std::cout << rayRez.position.x << ' ' + << rayRez.position.y << ' ' + << rayRez.position.z << '\n'; } void HeliumSceneArchitecktHand::mousePoint( int button, bool upDown, Polycode::Vector2 mouse ) { std::cout << "HeliumSceneArchitecktHand::mousePoint()\n"; - creatingObject->getModel()->setPosition(model->getPosition()); - HeliumGlobal::getCurrentGame()->getSceneWorldPt()->addObject( creatingObject ); - delete creatingObject; - creatingObject = NULL; - HeliumGlobal::getCurrentGame()->getSceneWorldPt()->delayedSignOut( this->getId() ); + + if( creatingObject ) { + creatingObject = 0; + //HeliumGlobal::getCurrentGame()->getSceneWorldPt()->delayedSignOut( this->getId() ); + } + else { + HeliumGameCore* gm = HeliumGlobal::getCurrentGame(); + Polycode::Vector2 mouse = gm->getEngineCorePt()->getInput()->getMousePosition(); + Polycode::RayTestResult rayRez = gm->getSceneWorldPt()->rayTest(mouse); + creatingObject = gm->getSceneWorldPt()->getObjectIdByEntity(rayRez.entity); + } } void HeliumSceneArchitecktHand::mouseDoubleClick() { } -HeliumSceneArchitecktHandPack::HeliumSceneArchitecktHandPack() { - std::cout << "here ->\n"; - heliumObject = new HeliumSceneArchitecktHand( new HeliumTestBox( 2, 2, 2, 0, 5, 0) ); - std::cout << "\t-> and here\n"; +HeliumSceneArchitecktHandPack::HeliumSceneArchitecktHandPack( + IHeliumObjectsWorld::ObjectsIdType id) { + heliumObject = new HeliumSceneArchitecktHand(id); alife = 1; entityType = POLY_ENTITY_IMMATERIAL; shapeType = P::PhysicsSceneEntity::SHAPE_BOX; addToMousePointQueue = true; } -HeliumSceneArchitecktHandPack::HeliumSceneArchitecktHandPack( PackagedSceneObject* ) { -} - -HeliumSceneArchitecktHandPack::HeliumSceneArchitecktHandPack( HeliumPreparedSceneObjects ) { -} - HeliumSceneArchitecktHandPack::~HeliumSceneArchitecktHandPack() { } diff --git a/modules/heliumSceneObjects/src/heliumSceneObjects.cpp b/modules/heliumSceneObjects/src/heliumSceneObjects.cpp index 80033c0..692ba07 100644 --- a/modules/heliumSceneObjects/src/heliumSceneObjects.cpp +++ b/modules/heliumSceneObjects/src/heliumSceneObjects.cpp @@ -68,6 +68,11 @@ P::RayTestResult SceneObjectsWorld::rayTest(P::Vector2 mouse) { return engineScene->getFirstEntityInRay(engineScene->getDefaultCamera()->getPosition(), dir * 100); } +IHeliumObjectsWorld::ObjectsIdType +SceneObjectsWorld::getObjectIdByEntity(P::SceneEntity* entity)const { + return reinterpret_cast(entity); +} + void SceneObjectsWorld::addObjectToMousePointQueue(IHeliumObjectsWorld::ObjectsIdType id) { if ( id != 0 ) { queueToMousePoint.insert(id); @@ -112,27 +117,33 @@ bool SceneObjectsWorld::mouseClick( int button, bool upDown, P::Vector2 mouse ) return false; } -IHeliumObjectsWorld::ObjectsIdType -SceneObjectsWorld::addObject( PackagedSceneObject* obj ) { - switch ( obj->getEntityType() ) { +void SceneObjectsWorld::addPackagedToEngineScene( PackagedSceneObject* obj ) { + if( obj->getModel() ) { + switch ( obj->getEntityType() ) { case PackagedSceneObject::POLY_ENTITY_IMMATERIAL: engineScene->addChild(obj->getModel()); break; - + case PackagedSceneObject::POLY_ENTITY_COLLISION_ONLY: engineScene->addCollisionChild( obj->getModel(), obj->getShapeType() ); break; - + case PackagedSceneObject::POLY_ENTITY_PHYSICAL: engineScene->addPhysicsChild( obj->getModel(), obj->getShapeType(), obj->getMass(), obj->getFriction(), obj->getRestitution() ); break; + default: throw "Addition secene child without idetificator"; - break; - } + } + } +} + +IHeliumObjectsWorld::ObjectsIdType SceneObjectsWorld::addObject( PackagedSceneObject* obj ) { + + addPackagedToEngineScene(obj); if ( obj->isAlife() != 0 ) { alifeObjects.insert(obj->getAlifePair()); @@ -143,7 +154,12 @@ SceneObjectsWorld::addObject( PackagedSceneObject* obj ) { if ( obj->getToMousePointQueue() ) { addObjectToMousePointQueue(obj->getId()); } - return obj->getId(); + + IHeliumObjectsWorld::ObjectsIdType id = obj->getId(); + delete obj; + obj = NULL; + + return id; } void SceneObjectsWorld::setPause(bool set) { @@ -197,6 +213,36 @@ void SceneObjectsWorld::cameraHorizonMovingDirection(Polycode::Vector2 dir) { horisontalVectorMove.y = spaceMove.z; } +void SceneObjectsWorld::warpTo( IHeliumObjectsWorld::ObjectsIdType id, Polycode::Vector3 point, bool resetRotation) { + P::SceneEntity* pObj = NULL; + + ObjectIterator it = objects.find(id); + if ( it != objects.end() ) { + pObj = reinterpret_cast(id); + } + else { + AlifeIterator ait = alifeObjects.find(id); + if (ait != alifeObjects.end() ) { + pObj = reinterpret_cast(id); + } + } + engineSceneWarpTo(pObj, point, resetRotation); +} + +void SceneObjectsWorld::engineSceneWarpTo( P::SceneEntity* obj, Polycode::Vector3 point, bool resetRotation ) { + if( obj ) { + P::PhysicsSceneEntity *physicsEntity = engineScene->getPhysicsEntityBySceneEntity(obj); + + if(physicsEntity) { + physicsEntity->rigidBody->setActivationState(DISABLE_DEACTIVATION); + physicsEntity->warpTo(point, resetRotation); + } + else { + obj->setPosition(point); + } + } +} + PackagedSceneObject::PackagedSceneObject() : heliumObject(NULL), alife(0), mass(0), friction(1), diff --git a/tests/sceneWorldDevelop/src/main.cpp b/tests/sceneWorldDevelop/src/main.cpp index 6aa6809..68aac7f 100644 --- a/tests/sceneWorldDevelop/src/main.cpp +++ b/tests/sceneWorldDevelop/src/main.cpp @@ -28,7 +28,7 @@ APP_MAIN_FINCTION enableDebugTools(); using namespace Polycode; PolycodeView* view = new POLYCODE_VIEW_CREATOR("key test"); - Core* core = new POLYCODE_CORE(view, 640, 480, false, false, 0, 0, 90); + Core* core = new POLYCODE_CORE(view, 1024, 768, false, false, 0, 0, 90); ProGameObject* game = new ProGameObject( core ); diff --git a/tests/sceneWorldDevelop/src/proGameObject.cpp b/tests/sceneWorldDevelop/src/proGameObject.cpp index 571e94b..393db38 100644 --- a/tests/sceneWorldDevelop/src/proGameObject.cpp +++ b/tests/sceneWorldDevelop/src/proGameObject.cpp @@ -56,20 +56,23 @@ ProGameObject::ProGameObject( P::Core* _core ) keyboardInput->addEventHandler( P::KEY_w, new XCameraMove()); keyboardInput->addEventHandler( P::KEY_s, new XNegativeCameraMove()); - HeliumTestFloor floor( 20.0, 20.0 ); - this->getSceneWorldPt()->addObject( &floor ); + HeliumTestFloor* floor = new HeliumTestFloor( 20.0, 20.0 ); + this->getSceneWorldPt()->addObject( floor ); - HeliumTestBarrel barrel( 1, 3, 0, 0, 6 ); - this->getSceneWorldPt()->addObject( &barrel ); + HeliumTestBarrel* barrel = new HeliumTestBarrel( 1, 3, 0, 0, 6 ); + this->getSceneWorldPt()->addObject( barrel ); - HeliumTestBox box( 2, 2, 2, 2, 2, 5); - this->getSceneWorldPt()->addObject( &box ); + HeliumTestBox* box = new HeliumTestBox( 2, 2, 2, 2, 2, 5); + this->getSceneWorldPt()->addObject( box ); - HeliumExitScreenButton exitBt(this); - this->getScreenWorldPt()->addObject( &exitBt ); + HeliumExitScreenButton* exitBt = new HeliumExitScreenButton(this); + this->getScreenWorldPt()->addObject( exitBt ); - HeliumSceneArchitecktHandPack hand; - this->getSceneWorldPt()->addObject( &hand ); + Helium556BulletBox* buletBox = new Helium556BulletBox(-2, -2, 5, 1); + this->getSceneWorldPt()->addObject( buletBox ); + + HeliumSceneArchitecktHandPack* hand = new HeliumSceneArchitecktHandPack(); + this->getSceneWorldPt()->addObject( hand ); } ProGameObject::~ProGameObject(){