About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
Retrieving Actor from PhysHit
Author Message
andargor Offline
Member

Post: #1
Retrieving Actor from PhysHit
I'm trying to select an Actor with the mouse and have the camera center on it, have it be the focus of commands, etc.

I'm using PhysHit and Physics.ray to determine if I clicked on an actor. However, the obj member is null.

actor is defined as private in PhysHit, so I can't access it when doing Physics.ray. I can see it being set properly when debugging.

Code:
//Register click
    if(Ms.b(0)) {
        Vec screen_pos, screen_dir;
        ScreenToPosDir(Ms.pos(), screen_pos, screen_dir);

        // now having world space position and direction we can calculate ray 'start' and 'end' positions
        Vec start=screen_pos, end=screen_pos + screen_dir*D.viewRange();

        // having ray positions we can perform a ray test
        PhysHit phys_hit;
        if(Physics.ray(start,end-start,&phys_hit)) { // if ray hit something
             D.text(0,0.9f,  "Ray has hit an actor");
             D.text(0,0.8f,S+"Actor's group: "            +         phys_hit.group);
             D.text(0,0.7f,S+"Actor's user data (index): "+(UIntPtr)phys_hit.user );

                         // The following is wrong, what to do?
             Actor *act  = CAST(Actor, phys_hit.obj);
             if (act != NULL) {
                selected_obj = act;
             }
        } else {
         D.text(0,0.9f,"Ray hasn't hit anything");
        }
    }
(This post was last modified: 04-24-2011 08:10 PM by andargor.)
04-24-2011 08:09 PM
Find all posts by this user Quote this message in a reply
Mardok Offline
Member

Post: #2
RE: Retrieving Actor from PhysHit
Code:
actor.user(&actor);
Actor *act = reinterpret_cast<Actor*>(physhit.user);
//but it's wrong way

//if you are using CAST and physhit.obj then you should create your own class based on Game::Obj

Code:
STRUCT(YourClass, Game::Obj)
//{
Actor your_actor;
};

YourClass *pObj;

if(Game::Obj *detected = CAST(YourClass, physhit.obj))
pObj = physhit.obj;
pObj->your_actor;
(This post was last modified: 04-24-2011 09:06 PM by Mardok.)
04-24-2011 09:00 PM
Find all posts by this user Quote this message in a reply
andargor Offline
Member

Post: #3
RE: Retrieving Actor from PhysHit
Thanks! I'll try that out.
04-24-2011 10:10 PM
Find all posts by this user Quote this message in a reply
Post Reply