About Store Forum Documentation Contact



Post Reply 
how to rotate/move a object
Author Message
wARmAcH1n3 Offline
Member

Post: #1
how to rotate/move a object
i create a object dynamicly like in the tutorial 10 - Dynamically Created Objects.cpp

Code:
Game::ObjParamsPtr obj_B;

bool Init()
{

...

   // set world
   {
      Game::World.init();

      // set object classess, do not use enum's because we don't know them yet, they will be loaded depending on the DataPath
      Game::World.setObjType(Statics       , Game::ObjType(L"OBJ_STATIC"      ));
      Game::World.setObjType(Kinematics    , Game::ObjType(L"OBJ_KINEMATIC"   ));
      Game::World.setObjType(Items         , Game::ObjType(L"OBJ_ITEM"        ));
      Game::World.setObjType(Doors         , Game::ObjType(L"OBJ_DOOR"        ));
      Game::World.setObjType(Chrs          , Game::ObjType(L"OBJ_CHR"         ));
      Game::World.setObjType(Players       , Game::ObjType(L"OBJ_PLAYER"      ));
      Game::World.setObjType(ObjLightPoints, Game::ObjType(L"OBJ_LIGHT_POINT" ));
      Game::World.setObjType(ObjLightCones , Game::ObjType(L"OBJ_LIGHT_CONE"  ));
      Game::World.setObjType(ObjParticless , Game::ObjType(L"OBJ_PARTICLES"   ));
      Game::World.setObjType(Destructibles , Game::ObjType(L"OBJ_DESTRUCTIBLE"));
      Game::World.setObjType(Animatables   , Game::ObjType(L"OBJ_ANIMATABLE"  ));

      Game::World.New(L"World/world01.world");
   }

     obj_B=Game::Objs.ptrRequire("obj/item/misc/barrel/0.obj"); // get barrel object parameters
     Game::World.objCreate(*obj_B, Matrix(obj_B->scale(), Vec(16,8,16)));            // create new object at (16,8,16) position and give objects default scaling
    
   return true;
}

if i look at the ObjParamsPtr obj_B i don't find a function to rotate or move this object. only if i go over _data

Code:
obj._data->matrixFinal(Vec(16,8,16));

i get the error that _data is private member
(This post was last modified: 08-16-2012 11:48 PM by wARmAcH1n3.)
08-16-2012 11:47 PM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #2
RE: how to rotate/move a object
Something like this might work

Code:
Game::ObjParamsPtr obj_B;
      obj_B=Game::Objs.ptrRequire("obj/item/misc/barrel/0.obj");
      Game::ObjParams actualObject= *obj_B;
      actualObject.matrix.pos.set(Flt x, Flt y, flt Z);
      actualObject.matrix.rotate(Vec Axis, flt Angle);

There is probably an elegant way to do what you want.
08-17-2012 05:21 AM
Find all posts by this user Quote this message in a reply
wARmAcH1n3 Offline
Member

Post: #3
RE: how to rotate/move a object
thx i got it compile but the set function and the other functions like scale doesnt work, whatever i try the barrel just spawns and dont react the settings

i tried
obj->matrix.pos.set(2,2,2);
too, but same no reaction

i dont get it why it doesnt work
Code:
Bool Update()
{
       if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1f, 100, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   Game::World.update(Cam.at);

   if(Kb.bp(KB_SPACE)) // on space
   {
      Game::ObjParamsPtr obj=Game::Objs.ptrRequire("obj/item/misc/barrel/0.obj"); // get barrel object parameters
      Game::World.objCreate(*obj, Matrix(obj->scale(), Vec(16,8,16)));            // create new object at (16,8,16) position and give objects default scaling
      Game::ObjParams actualObject= *obj;
      actualObject.matrix.pos.set(2,2,2);
      actualObject.scale(true,3);
   }
   return true;
}



i tried it with a
static Game::ObjParamsPtr obj;
but still doesnt work

Code:
Bool Update()
{
    static Game::ObjParamsPtr obj;

       if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1f, 100, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   Game::World.update(Cam.at);

   if(Kb.bp(KB_SPACE)) // on space
   {
      obj=Game::Objs.ptrRequire("obj/item/misc/barrel/0.obj"); // get barrel object parameters
      Game::World.objCreate(*obj, Matrix(obj->scale(), Vec(16,8,16)));            // create new object at (16,8,16) position and give objects default scaling
   }
   if(Kb.bp(KB_LEFT)) // on space
   {
         Game::ObjParams actualObject= *obj;
      actualObject.matrix.pos.set(2,2,2);
      actualObject.scale(true,3);
   }


   return true;
}
(This post was last modified: 08-17-2012 09:34 PM by wARmAcH1n3.)
08-17-2012 09:29 PM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #4
RE: how to rotate/move a object
Try this instead

Code:
Game::ObjParamsPtr obj_B;
      obj_B=Game::Objs.ptrRequire("obj/item/misc/barrel/0.obj");
      Game::ObjParams objectparams= *obj_B;
Game::Obj barrelObj;
barrelObj.create(objectparams);
barrelObj.matrix(Matrix().setPosDir(Vec position,Vec direction, Vec upDirection));

Where you replace Vec position,Vec direction, Vec upDirection with how you want the object oriented.
08-18-2012 01:26 AM
Find all posts by this user Quote this message in a reply
wARmAcH1n3 Offline
Member

Post: #5
RE: how to rotate/move a object
the creating of barrelObj causes an compiler error
Game::Obj barrelObj;

--\source\main.cpp(112) : error C2259: 'EE::Game::Obj' : cannot instantiate abstract class
due to following members:
'void EE::Game::Obj::create(EE::Game::ObjParams &)' : is abstract
c:\program files (x86)\microsoft visual studio 9.0\vc\include\esenthelengine\game\object.h(14) : see declaration of 'EE::Game::Obj::create'
'void EE::Game::Obj::pos(const EE::Vec &)' : is abstract




but never mind, i switched the engine, thx anyway
08-18-2012 01:28 PM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #6
RE: how to rotate/move a object
Hmm ya that makes sense.

Instead of Game::Obj change it to Game::Kinematic

Put this where you declare stuff
Code:
Game::ObjParamsPtr obj_B;
Game::ObjParams objectparams;
Game::Kinematic  barrelObj;

Put this where you create stuff
Code:
obj_B=Game::Objs.ptrRequire("obj/item/misc/barrel/0.obj");
   objectparams= *obj_B;
barrelObj.create(objectparams);

Put this wherever you update stuff
Code:
barrelObj.matrix(Vec position,Vec direction, Vec upDirection));
make sure to pass Vec upDirection as upDirection.normalize()

Then put
Code:
barrelObj.drawPrepare();
Where you prepare drawing

Put
Code:
barrelObj.drawBlend();
Where you draw things (assuming you are using blended mode), if not change it.

I just tested this and it works on my machine.

There may be an easier way to do this, but I can't think of it. If you want to have multiple barrels you would need to put them in a memory container and add/remove them. Like Memc<Game::Kinematic> barrels; Then do like REPA(barrels)barrels[i].draw; In your draw function etc.

Maybe why you were not seeing things earlier was that you were just creating the object but not drawing it to the screen.
(This post was last modified: 08-19-2012 01:38 AM by Fex.)
08-19-2012 01:33 AM
Find all posts by this user Quote this message in a reply
Post Reply