Skip to content

Commit

Permalink
remake mechanism of transporting 3d objects
Browse files Browse the repository at this point in the history
  • Loading branch information
akindyakov committed Sep 22, 2013
1 parent 0c4d489 commit 16793fe
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 70 deletions.
31 changes: 15 additions & 16 deletions modules/heliumSceneObjects/include/heliumPreparedSceneObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

typedef enum {
PREPARED_3D_UNKNOWN = 0,
PREPARED_3D_HELIUM_556_BULLET_BOX = 1,
PREPARED_3D_LAST
} HeliumPreparedSceneObjects;

Expand All @@ -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
Expand All @@ -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();
};
Expand Down
20 changes: 19 additions & 1 deletion modules/heliumSceneObjects/include/heliumSceneObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
};

/**
Expand Down
70 changes: 36 additions & 34 deletions modules/heliumSceneObjects/src/heliumPreparedSceneObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

62 changes: 54 additions & 8 deletions modules/heliumSceneObjects/src/heliumSceneObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHeliumObjectsWorld::ObjectsIdType>(entity);
}

void SceneObjectsWorld::addObjectToMousePointQueue(IHeliumObjectsWorld::ObjectsIdType id) {
if ( id != 0 ) {
queueToMousePoint.insert(id);
Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand Down Expand Up @@ -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<P::SceneEntity*>(id);
}
else {
AlifeIterator ait = alifeObjects.find(id);
if (ait != alifeObjects.end() ) {
pObj = reinterpret_cast<P::SceneEntity*>(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),
Expand Down
2 changes: 1 addition & 1 deletion tests/sceneWorldDevelop/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
23 changes: 13 additions & 10 deletions tests/sceneWorldDevelop/src/proGameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down

0 comments on commit 16793fe

Please sign in to comment.