Game Development Community

CastRay in Opposite Direction

by Matt Huston · in Torque Game Engine · 03/05/2008 (8:13 am) · 2 replies

I am trying to create a castRay in the 'opposite' direction of the camera. However when I multiply endPos *= -1000, the castRay still is cast forward from the players eyes. I need the castray to actually go the opposite direction so it checks what is directly behind the player.

// Get control camera info
MatrixF cam;
Point3F camPos;
conn->getControlCameraTransform(0,&cam);
cam.getColumn(3, &camPos);

// Extend the camera vector to create an endpoint for our ray
Point3F endPos;
cam.getColumn(1, &endPos);
endPos *= 1000;
endPos += camPos;

// Collision info. We're going to be running LOS tests and we
// don't want to collide with the control object.
static U32 losMask = TerrainObjectType | InteriorObjectType | ShapeBaseObjectType | StaticShapeObjectType | StaticRenderedObjectType;
control->disableCollision();

RayInfo info;

if (gClientContainer.castRay(camPos, endPos, losMask, &info)) 
...

#1
03/05/2008 (8:46 am)
It'd be better use the camera transform to multiply against a "backward" vector. That way you'll take rotation into account as well (negating the position doesn't). Here's an example:

MatrixF cam;
conn->getControlCameraTransform(0, &cam);
Point3F backward(0.0f, -1000.0f, 0.0f);
cam.mulP(backward);
// backward is now your endPos, use your current camPos as the start point.
#2
03/05/2008 (10:44 am)
Hmm, it still seems to be shooting the ray forward and not backwards.