CastRay and radar/sonar
by Dennis Saarela · in Torque Game Engine · 06/11/2004 (3:41 pm) · 2 replies
Hi!
I have implemented the radar resource from Matt "CaptFallout" Webster and modified it a bit because in the end it will be used as a sonar. But I want to use LOS test to see if the object will show up on the radar/sonar.
This code is in onRender on the gui control (client side)
I would like to do some kind of LOS test. I found castRay but does it work like above? It never returns true... :( And ow do I test if the object that was hit is the same as the one I try to hit?
I have implemented the radar resource from Matt "CaptFallout" Webster and modified it a bit because in the end it will be used as a sonar. But I want to use LOS test to see if the object will show up on the radar/sonar.
This code is in onRender on the gui control (client side)
for (SimSetIterator itr(conn); *itr; ++itr) {
// Make sure that the object is a shapebase object
if ((*itr)->getType() & ShapeBaseObjectType) {
ShapeBase* shape = static_cast<ShapeBase*>(*itr);
// Make sure that the object isn't the client
if (shape != control && shape->getShapeName()) {
// Make sure the shapebase object is a player (or Vehicle)
if (shape->getType() & VehicleObjectType) {
Point3F newCoord;
// Get coords of player object
newCoord = shape->getPosition();
// Find distance from point A (player object) to point B (client's player)
VectorF shapeDir = newCoord - cObjPos;
// Test to see if player object in range (deal with squared objects in cheap way to use non-negative value)
F32 shapeDist = shapeDir.lenSquared();
if (shapeDist == 0 || shapeDist > (mRadius * mRadius))
continue;
// LOS
// cObjPos = control Object position, newCoord = target object pos
if(control->castRay(cObjPos, newCoord, &sonarBeam)) {
// Some kind of control...
// Like if(sonarBeam.object == shape)
}I would like to do some kind of LOS test. I found castRay but does it work like above? It never returns true... :( And ow do I test if the object that was hit is the same as the one I try to hit?
Associate Kyle Carter