Setting mTypeMask for raycast from datablock
by Orion Elenzil · in Torque Game Engine · 12/13/2005 (11:59 am) · 9 replies
Let me know if i'm going about this the wrong way.
(I must be because it ain't working yet ;)
Basically i want certain DTS objects in the scene to have a new typeMask for raycasting.
I've added a bool to SceneObject's datablock indicating "clickable".
(I could add it to TSStatic, but i want the same functionality for Player and possibly others)
In SceneObject's onAdd() method,
i check the bool from the datablock and if it's set (which is working correctly), then i do:
mTypeMask |= MyClickableObjectType;
Later, from script, i call ContainerRayCast() with $TypeMasks::MyClickableObjectType in the mask,
but i don't get any hits.
I know that mTypeMask is being set and retained because script reports it correctly.
(That is, %object.getType() & $TypeMasks::MyClickableObjectType is correct.)
If i simply add MyClickableObjectType to the default TSStatic typeMask it works,
but then of course all DTS objects are included in the raycast.
- This wouldn't be so bad but i'm raycasting on MouseMove() and would like to keep the search space as small as possible.
tia,
Orion
(I must be because it ain't working yet ;)
Basically i want certain DTS objects in the scene to have a new typeMask for raycasting.
I've added a bool to SceneObject's datablock indicating "clickable".
(I could add it to TSStatic, but i want the same functionality for Player and possibly others)
In SceneObject's onAdd() method,
i check the bool from the datablock and if it's set (which is working correctly), then i do:
mTypeMask |= MyClickableObjectType;
Later, from script, i call ContainerRayCast() with $TypeMasks::MyClickableObjectType in the mask,
but i don't get any hits.
I know that mTypeMask is being set and retained because script reports it correctly.
(That is, %object.getType() & $TypeMasks::MyClickableObjectType is correct.)
If i simply add MyClickableObjectType to the default TSStatic typeMask it works,
but then of course all DTS objects are included in the raycast.
- This wouldn't be so bad but i'm raycasting on MouseMove() and would like to keep the search space as small as possible.
tia,
Orion
About the author
#2
so i'm implementing it individually in TSStatic (which also doesn't have a datablock, but does kind of fake one)
and in GameBase.
12/13/2005 (2:19 pm)
Yep - GameBase has no datablock,so i'm implementing it individually in TSStatic (which also doesn't have a datablock, but does kind of fake one)
and in GameBase.
#3
12/13/2005 (2:27 pm)
Actually, GameBase is the first class in the hierarchy that has datablocks, but you are correct, SceneObjects do not, and therefore TSStatics do not either (since they inherit from SceneObject, not GameBase).
#5
03/10/2006 (3:12 pm)
Orion, I am very interested in implementing something similar to what you have done. Only, I am having a bit of trouble understanding exactly what you did to get things working. I was wondering if you might be willing to outline the implementation that eventually worked for you in more detail. Thank you.
#6
i only have time to do a sketch, hopefully it'll work for you.
Parts of this come from Stephen Zepp and Clint Brewer.
We wanted to introduce a new typemask which could be used in RayCasts the way PlayerObjectType and InteriorObjectType are.
Suppose the new typemask is "UsableObjectType".
1. in objectTypes.h, in enum SimObjectTypes, add a line like
2. to expose the new type to script, in main.cc, in initGame(), add a line like
3. in the datablock for your special object, add a line line this:
4. in StaticShape.cc, add UsableObjectType to sgAllowedDynamicTypes
5. i think we're getting close.
in fact i think we're there.
you should now be able to do raycasts for objects of type UsableObjectType!
- my originally outlined method was different than this,
and was sound as far as it went, except that as noted above,
i wasn't transmitting the datablock field from server to client.
had i known about the dynamicType field, i would have used that.
i hope you get it working !
03/10/2006 (3:36 pm)
Hi Scott, sure.i only have time to do a sketch, hopefully it'll work for you.
Parts of this come from Stephen Zepp and Clint Brewer.
We wanted to introduce a new typemask which could be used in RayCasts the way PlayerObjectType and InteriorObjectType are.
Suppose the new typemask is "UsableObjectType".
1. in objectTypes.h, in enum SimObjectTypes, add a line like
UsableObjectType = bit(<whatever the next free bit is>)
2. to expose the new type to script, in main.cc, in initGame(), add a line like
Con::setIntVariable("$TypeMasks::UsableObjectType" , UsableObjectType);3. in the datablock for your special object, add a line line this:
dynamicType = $TypeMasks::UsableObjectType;
4. in StaticShape.cc, add UsableObjectType to sgAllowedDynamicTypes
static const U32 sgAllowedDynamicTypes = 0xffffff | UsableObjectType;
5. i think we're getting close.
in fact i think we're there.
you should now be able to do raycasts for objects of type UsableObjectType!
- my originally outlined method was different than this,
and was sound as far as it went, except that as noted above,
i wasn't transmitting the datablock field from server to client.
had i known about the dynamicType field, i would have used that.
i hope you get it working !
#7
I appreciate you taking the time to lay it out so clearly.
:)
03/10/2006 (4:01 pm)
Wow! Thanks Orion! This is just what I needed! Only tested it for a few mins but it seems to work exactly as intended. Good thing for that 'dynamicType' field!I appreciate you taking the time to lay it out so clearly.
:)
#8
03/10/2006 (4:07 pm)
I'm not certain, but I think this would only work for objects that are declared as "Items", since as far as I can tell ItemData is the only datablock that uses the dynamicType field. I think StaticShapeData might as well, but that would only be used for static DTS objects.
#9
to expand it to another branch of the object heirarchy
you'll need to add it to that object type
and include it in the ghosting.
follow the treatment of dynamicTypeField in StaticShapeData.
@scott - glad it seems to be working!
i've gotten so much help from the GG forums that it's nice to be able to contribute back sometimes.
03/10/2006 (4:13 pm)
@ rubes - you're exactly right. this will only work for Items and StaticShapes.to expand it to another branch of the object heirarchy
you'll need to add it to that object type
and include it in the ghosting.
follow the treatment of dynamicTypeField in StaticShapeData.
@scott - glad it seems to be working!
i've gotten so much help from the GG forums that it's nice to be able to contribute back sometimes.
Associate Orion Elenzil
Real Life Plus
more to come...