Game Development Community

GClientContainer.castRay and result help

by Dan - · in Torque Game Engine · 07/08/2005 (7:23 pm) · 10 replies

For the past couple of days I have been trying to decipher the gClientContainer.castRay and its return rInfo.

I have the following C++ code:
if (gClientContainer.castRay(start, end, 
				//StaticObjectType | 
                                InteriorObjectType | 
				WaterObjectType | 
                                //ShapeBaseObjectType | 
				StaticShapeObjectType | 
                                //ItemObjectType | 
				StaticTSObjectType 
				, &rInfo))
{
 // Found an object
}

Which works fine for finding the object, but I would like to know what object it is. I know the RayInfo rInfo; returns the pos and other wonderful information including SceneObject* object;

So what I want to know is there a way (through the object I assume) to know what the ray found? At the highest level I would like to know if it was an InteriorObjectType vs WaterObjectType. Even more ideal would be to know more information about the object, such as the script assigned name, object number, etc.

Can anyone help or point me towards some help? I feel I am at a point where I am trying too many random things.

#1
07/09/2005 (1:19 am)
Sure... You can either query the object typemask (getType(), I think) and check each flag individually, or you can do a dynamic cast and get it that way... Easy as pie.
#2
07/09/2005 (8:41 am)
Ben,

I thought it would be easy as pie, but sometimes I don't know when to stop 3.1415... :-)

I will take a look at the getType as well as the dynamice cast.

Thanks for giving me a direction.
#3
07/10/2005 (12:29 pm)
For future reference:
if (gClientContainer.castRay(start, end, 
            //StaticObjectType | 
            InteriorObjectType | 
            WaterObjectType | 
            //ShapeBaseObjectType | 
            StaticShapeObjectType | 
            //ItemObjectType | 
            StaticTSObjectType 
            , &rInfo))
{
   S32 maskType = rInfo.object->getTypeMask();
   if(maskType & WaterObjectType)
   {
      // Water object
   }
   elif(maskType & InteriorObjectType)
   {
      // InteriorObjectType object
    }
etc..

I haven't tackled the the name of the object as assigned by the script yet.
#4
07/10/2005 (6:59 pm)
Ok, I have tackled trying to get the name of the object without any luck. I had hoped that just knowing the mask type would be good enough, but it turns out it isn't.

Does anyone know what to do to get the object name or the shape name?

Thanks,
#5
07/10/2005 (7:48 pm)
I think I made some progress, but I am not sure.

I have the following code which taks my rInfo and casts it to a NetObject, which I can then do a get name on it.
if (NetObject* obj = dynamic_cast<NetObject*>(rInfo.object))
{
      Con::printf("shape name %s",obj->getName());

This all passing, but the shape name always comes up as (null).

Any ideas?

Thank you,
#6
07/11/2005 (9:07 am)
The reason you come up with NULL is that the names seem to only exist of the server side. they are not ghosted over apperantly.
#7
07/11/2005 (12:29 pm)
That vaguely rings a bell in my tinny brain!

Thanks. I will look at a different approach. At least I know I am in the correct area of the woods.
#8
07/11/2005 (6:23 pm)
Ok. I have tried several different methods and I am still at a loss on how to get what type of object it really is. I thought maybe I could get its shapeName (or filename) and from that know what type of object it is.

Is all this boiling down to "You shouldn't be doing this on the client side"? I thought about doing the raycast/look up on the server then sending it to the client, but that seemed like a lot of data to sent to one specific client.

Is there an expert who can once again point me in the right direction?

Thank you,
#9
07/11/2005 (7:18 pm)
You aren't going to be able to get the name on the client-side unless you add that to the data that gets persisted down to the clients packUpdate()/unpackUpdate().

If you are looking for the shapeName then you could use something like:

if (ShapeBase*shape= dynamic_cast<ShapeBase*>(obj))
{
   Con::printf("shapeName = %s", shape->getShapeName());
}

Have you looked at getClassName()?

It really isn't clear what you are trying to distinguish between so it is hard to help.
#10
07/12/2005 (4:53 am)
Mathew,

You are 100% correct. I really haven't given much of a clear description of what I was trying to do.

Basically I created a "grid" (think chess or checkers board) object using Melv May's fxRenderObject (Generic Render Object)
which maps out the grid. In the middle of each square of the grid the code performs a castray (on the client side) to see what objects are on the "board". Originally I thought the requirement was that any DTS Shape on the grid should be treated the same, but the team wants to perform special actions depending on what the dts shape is on the grid. As a result I need to know more about the special shape.

Originally I thought I could just get the assigned name, but as you mentioned that isn't possible on the client side without other modifications. Then I thought the client must know what file name it loaded which would give me the detail I need. (As I understand the requirements now the dts file name is unique enough)

Make sense now?

I haven't tried the getShapeName, nor looked at the getClassName(). I did try to map out the different objects.

Thank you for taking a stab in the dark to help me out when I wasn't clear, but needed help.

I will try your suggestions a bit later today.