About Store Forum Documentation Contact



Post Reply 
grabbing dynamically created objects
Author Message
andrake Offline
Member

Post: #1
grabbing dynamically created objects
Greetings!
in tutorial there is 2 different tutorial for
1) dynamically created objects..
Code:
Game.ObjParamsPtr obj=UID(3288625716, 1272016745, 1410615726, 2673274168);
Game.World.objCreate(*obj, Matrix(61, Vec(17.0, 10.0, -17.0)) );

2) grab phys objects
when
Code:
Actor ground, // ground
          obj   ; // object
obj .create(Box(0.3                     )   ); // create object


but how to grab dynamically created object if i don't have dynamically created actor? how to get actor when i create object via Game.World.objCreate?
01-17-2014 07:16 PM
Find all posts by this user Quote this message in a reply
candam Offline
Member

Post: #2
RE: grabbing dynamically created objects
By saving them into the container like that
Game.ObjMemx<Game.obj> Objects;
I hope it could help
01-17-2014 07:41 PM
Find all posts by this user Quote this message in a reply
andrake Offline
Member

Post: #3
RE: grabbing dynamically created objects
but how to get actor from obj?
01-17-2014 07:55 PM
Find all posts by this user Quote this message in a reply
candam Offline
Member

Post: #4
RE: grabbing dynamically created objects
If I get you right you can get it this way " Items[c].actor "
c is the element number in the container
Items[c].actor.addForce(Vec(1,0, 0) * 40.0); an example .
(This post was last modified: 01-17-2014 08:13 PM by candam.)
01-17-2014 08:02 PM
Find all posts by this user Quote this message in a reply
andrake Offline
Member

Post: #5
RE: grabbing dynamically created objects
the task is get actor that under cursor, but using phys_hit.user or phys_hit.obj i can get only user data or obj.
i see for that oly one way - user data. but from user data i cant get actor. and for what actor i put user data if i do not know what actor or obj was created by Game.World.objCreate(*obj, Matrix(61, Vec(17.0, 10.0, -17.0)) );

i was try to put actor pointer as user data for every dynamically created object, but there was problem to convert Ptr to EE:Actor

also i try to use number Item.Elm() as user data...but this is not constant parameter and can be changed at runtime.
there is only way to store for every dynamically created obj unique ID as user data and when i need to get actor under cursor : get user data of obj under cursor and search the same id in Items.Elm collection using Item[i].actor.user() ?
(This post was last modified: 01-18-2014 07:05 PM by andrake.)
01-18-2014 06:56 PM
Find all posts by this user Quote this message in a reply
para Offline
Member

Post: #6
RE: grabbing dynamically created objects
Here's how I went about getting an actor from a ray cast..

Code:
PhysHit phys_hit;
Actor  *hit_actor=null;

if(Physics.ray(start, end-start, &phys_hit)) // 1. obtain 'collision' info
{
   if(phys_hit.obj)
   {
      switch( phys_hit.obj.type() ) // 2. get obj's class type
      {
         case OBJ_ITEM: // 3. cast obj pointer to correct type...
            hit_actor = &CAST( Game::Item, phys_hit.obj ).actor; // 4. ...and get actor
            break;
         case OBJ_PROP:
            hit_actor = &CAST( Prop, phys_hit.obj ).actor;
            break;
         case OBJ_CHR:
            hit_actor = &CAST( Game::Chr, phys_hit.obj ).ctrl.actor;
            break;              
         default:
            hit_actor = null;
      }
      if( hit_actor &&  hit_actor.is() )  
        // 5. DO grab/addForce/etc stuff ...
   }
}
01-19-2014 02:04 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply