Raycasting to find static shapes and triggers
by janet kim · in Torque Game Engine · 04/13/2005 (9:21 am) · 18 replies
Does anyone know why some static objects will not be found by the typical typeMasks like ShapeBaseObjectType? I've been working on a script using
www.garagegames.com/mg/forums/result.thread.php?qt=15719, etc.
and I can always find the objects and interiors that I place in the scene. However, I just
imported a new dts model and it cannot be found. Is there any reason why something
like this might happen?
Also, I'm trying to use typeMask TriggerObjectType to find triggers, but this is also failing
miserably. Am I completely off base with using this to detect a trigger in the line of sight
of the player?
www.garagegames.com/mg/forums/result.thread.php?qt=15719, etc.
and I can always find the objects and interiors that I place in the scene. However, I just
imported a new dts model and it cannot be found. Is there any reason why something
like this might happen?
Also, I'm trying to use typeMask TriggerObjectType to find triggers, but this is also failing
miserably. Am I completely off base with using this to detect a trigger in the line of sight
of the player?
#2
04/13/2005 (9:35 am)
I actually put every mask that I could find (see below), but I still can't find the triggers or new imported shape. Is the hidden attribute something set in the 3dsmax to dts plugin?function serverCmdPopDialogToggle(%client)
{
%player = %client.player;
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, 400);
%startPoint = %player.getEyeTransform();
%endPoint = VectorAdd(%startPoint,%vec);
%searchMasks = $TypeMasks::ShapeBaseObjectType |
$TypeMasks::StaticObjectType |
$TypeMasks::StaticRenderedObjectType |
$TypeMasks::StaticShapeObjectType |
$TypeMasks::StaticTSObjectType |
$TypeMasks::CameraObjectType |
$TypeMasks::CorpseObjectType |
$TypeMasks::DamagableItemObjectType |
$TypeMasks::DebrisObjectType|
$TypeMasks::EnvironmentObjectType |
$TypeMasks::ExplosionObjectType |
$TypeMasks::ForceFieldObjectType |
$TypeMasks::GameBaseObjectType |
$TypeMasks::GoalObjectType |
$TypeMasks::GuiControlObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::ItemObjectType |
$TypeMasks::MarkerObjectType |
$TypeMasks::PhysicalZoneObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::ProjectileObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::TriggerObjectType |
$TypeMasks::VehicleBlockerObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::WaterObjectType;
//cast ray
%object = ContainerRayCast(%startPoint, %endPoint, %searchMasks, %player);
if (%object) echo(">object found>>" @ %object);
else echo(">object NOT found!!");
%x = getWord(%object,1);
echo(">>x = " @ %x);
if ( %x > 27 ) {
%dialog = 1;
} else {//if (%x <= 25 ) {
%dialog = 2;
}
popDialogToggle(%client, %dialog);
}
#3
04/13/2005 (1:44 pm)
I've been scouring the forums and resources for any helpful nuggest of information, but I'm simply not getting anywhere. Does anyone have any idea or can direct me to some resource I might be missing? Any help would be tremendously appreciated!!
#4
Tip: If you want to use all masks simply pass -1 as the mask argument instead of ORing the named masks.
PS - I may not have been entirely clear. By static shape I meant TSStatic, not staticShape, but in either case you'll need to have a collision mesh for the ray to strike. Note that for the purpose of mesh to mesh collisions, TSStatic uses a simple bounding box. "Why then doesn't a TSStatic also work automatically for rayCasts?" My guess is in order to give you, the developer, options. You may not want a bunch of TSStatics clutering your rayCasts, thus you would use meshes w/o collision meshes. Sometimes, you may want a TSStatic to block/catch a cast ray....
PPS - You can easily demonstrate this to yourself by loading the Racing mod and dropping the body of the jeep and a tire (both as 'Static Shapes', not Shapes), then try to do a ray cast. You'll be able to cast the body (chassis), but not the tire as the body is designed w/ a collision-1 mesh and the tire is not.
Hall Of Worlds, LLC
EdM|EGTGE
04/13/2005 (2:14 pm)
@Janet - For the containerRayCast() to work, the shape in question must have a collision mesh (even for static shapes). So, the first thing I'd do is check my model for collision mesh(es) (collision-1 ..). You can use the Show Tool Pro to do this. Simply load the DTS shape and click the CM button (at top). Tip: If you want to use all masks simply pass -1 as the mask argument instead of ORing the named masks.
PS - I may not have been entirely clear. By static shape I meant TSStatic, not staticShape, but in either case you'll need to have a collision mesh for the ray to strike. Note that for the purpose of mesh to mesh collisions, TSStatic uses a simple bounding box. "Why then doesn't a TSStatic also work automatically for rayCasts?" My guess is in order to give you, the developer, options. You may not want a bunch of TSStatics clutering your rayCasts, thus you would use meshes w/o collision meshes. Sometimes, you may want a TSStatic to block/catch a cast ray....
PPS - You can easily demonstrate this to yourself by loading the Racing mod and dropping the body of the jeep and a tire (both as 'Static Shapes', not Shapes), then try to do a ray cast. You'll be able to cast the body (chassis), but not the tire as the body is designed w/ a collision-1 mesh and the tire is not.
EdM|EGTGE
#5
So that must be why the triggerObjectType mask is not working as well? Is there some other appropriate ray-casting function that I can use? I can see that there are several castRay() methods.
I'm checking out ShowTool right now...
04/13/2005 (2:53 pm)
@edward - thanks for responding!!!So that must be why the triggerObjectType mask is not working as well? Is there some other appropriate ray-casting function that I can use? I can see that there are several castRay() methods.
I'm checking out ShowTool right now...
#6
BTW, Good questions and thanks for asking.
Hall Of Worlds, LLC
EdM|EGTGE
04/13/2005 (2:56 pm)
@Janet - I'm not is a place where I can investigate the trigger object vs. rayCast but I'll do so later and post my findings. BTW, Good questions and thanks for asking.
EdM|EGTGE
#7
Thanks for the information! Wow - the model definitely does not have a collision mesh. Unfortunately I'm not the artistic type - is there any good doc where I can try to figure out how to create one?
BTW - I love your Hall Of Worlds resources!
04/13/2005 (3:08 pm)
@Edward -Thanks for the information! Wow - the model definitely does not have a collision mesh. Unfortunately I'm not the artistic type - is there any good doc where I can try to figure out how to create one?
BTW - I love your Hall Of Worlds resources!
#8
1) Triggers don't support castray's
2) Triggers are server-side only so a client-side scripts can't view them
If you want to fix this you need to make the following changes:
in game/trigger.h line 89 add:
in game/trigger.cc line 134 add:
04/13/2005 (3:12 pm)
Couple of problems with using a ContainerRayCast against triggers:1) Triggers don't support castray's
2) Triggers are server-side only so a client-side scripts can't view them
If you want to fix this you need to make the following changes:
in game/trigger.h line 89 add:
bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
in game/trigger.cc line 134 add:
bool Trigger::castRay(const Point3F &start, const Point3F &end, RayInfo* info)
{
// Collide against bounding box.
F32 st,et,fst = 0,fet = 1;
F32 *bmin = &mObjBox.min.x;
F32 *bmax = &mObjBox.max.x;
F32 const *si = &start.x;
F32 const *ei = &end.x;
for (int i = 0; i < 3; i++) {
if (*si < *ei) {
if (*si > *bmax || *ei < *bmin)
return false;
F32 di = *ei - *si;
st = (*si < *bmin)? (*bmin - *si) / di: 0;
et = (*ei > *bmax)? (*bmax - *si) / di: 1;
}
else {
if (*ei > *bmax || *si < *bmin)
return false;
F32 di = *ei - *si;
st = (*si > *bmax)? (*bmax - *si) / di: 0;
et = (*ei < *bmin)? (*bmin - *si) / di: 1;
}
if (st > fst) fst = st;
if (et < fet) fet = et;
if (fet < fst)
return false;
bmin++; bmax++;
si++; ei++;
}
info->normal = start - end;
info->normal.normalizeSafe();
getTransform().mulV( info->normal );
info->t = fst;
info->object = this;
info->point.interpolate(start,end,fst);
info->material = 0;
return true;
}
#9
04/13/2005 (3:15 pm)
Thanks - I'll try this right away!
#10
Unfortunately, the only way you'll be able to add those meshes (AFAIK) is to use a modelling tool like MS3D, 3DS Max, Lightwave, Gamespace, Blender, ... you get the idea.
You'll need to acquire the source file for the shape in question, add a simple box around the shape and label it 'collision-1'. Re-export, and violla! You can of course make more complex shapes for a collision mesh, but that is learning for another day.
@Matt
Thanks for answering the triggers question! And a solution too. Great stuff.
Hall Of Worlds, LLC
EdM|EGTGE
04/13/2005 (3:18 pm)
@JanetUnfortunately, the only way you'll be able to add those meshes (AFAIK) is to use a modelling tool like MS3D, 3DS Max, Lightwave, Gamespace, Blender, ... you get the idea.
You'll need to acquire the source file for the shape in question, add a simple box around the shape and label it 'collision-1'. Re-export, and violla! You can of course make more complex shapes for a collision mesh, but that is learning for another day.
@Matt
Thanks for answering the triggers question! And a solution too. Great stuff.
EdM|EGTGE
#11
04/13/2005 (3:29 pm)
I just checked these changes into HEAD btw.
#12
Good deal, I'll be sure to describe this properly in the guide. Did you include a console method in that check in? No need to reply, I'll check when I get home. :)
Hall Of Worlds, LLC
EdM|EGTGE
04/13/2005 (3:30 pm)
@MattGood deal, I'll be sure to describe this properly in the guide. Did you include a console method in that check in? No need to reply, I'll check when I get home. :)
EdM|EGTGE
#13
04/13/2005 (3:47 pm)
No new console method but it will be accessible with ContainerRayCast now.
#14
@Janet - Ignore my comments above about adding console methods. Will erase so folks reading in future won't take wrong path...
Hall Of Worlds, LLC
EdM|EGTGE
04/13/2005 (3:58 pm)
@Matt - Ah, but of course. I don't have the source code in front of me, but I should have made that connection.@Janet - Ignore my comments above about adding console methods. Will erase so folks reading in future won't take wrong path...
EdM|EGTGE
#15
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7335?
04/14/2005 (8:04 am)
@Matthew - the code is working out wonderfully! The only strange thing is that upon entering the app, the trigger boundary boxes appear. When I go into any of the world editors, they then disappear. Is this a normal thing? I also implemented objection selection from:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7335?
#16
Change #: 461
Committed by:
Date: 2005/04/13 22:22:05
Description:
Added castray to triggers and set the netflags to ghost them to clients (useful for some client-side gui effects)
Modified Files:
torque/engine/game/trigger.cc (2.2)
torque/engine/game/trigger.h (2.2)
04/15/2005 (8:05 am)
It appears that raycasting to triggers was added to the current head:Change #: 461
Committed by:
Date: 2005/04/13 22:22:05
Description:
Added castray to triggers and set the netflags to ghost them to clients (useful for some client-side gui effects)
Modified Files:
torque/engine/game/trigger.cc (2.2)
torque/engine/game/trigger.h (2.2)
#17
08/18/2005 (6:48 am)
I think that this change makes it so your mounted weapon gets pushed back when entering the trigger. ie. Has the same effect on weapons as when you press up against an interior.
#18
I thought it possibly may have been our project but I confirmed the same happens with a clean version of the SDK with the above code added. Your weapons either won't appear or only see the tip because the trigger seems to have a collision effect on it. It ends up screwing up your aiming when zooming as well.
09/02/2005 (7:47 am)
Bump I thought it possibly may have been our project but I confirmed the same happens with a clean version of the SDK with the above code added. Your weapons either won't appear or only see the tip because the trigger seems to have a collision effect on it. It ends up screwing up your aiming when zooming as well.
Torque Owner Chris Labombard
Premium Preferred