CastRay along an axis
by Robert Brower · in General Discussion · 07/23/2004 (9:47 am) · 1 replies
Hello,
I've got a matrix problem I need to solve, but so far I have had no luck. I have a matrix, M. I am obtaining the position, P, and axis A of the matrix as shown below:
MatrixF M;
Point3F P, U, A;
M.mul(getRenderTransform(), mShapeInstance->mNodeTransforms[mDataBlock->cameraNode]);
M.getColumn(1,&A);
M.getColumn(3,&P);
Then I am computing a position, U, 100 units below P like this:
U = P + Point3F(0.0, 0.0, -100.0); // TODO: this isnt't correct, we need to consider axis
Then I am casting a ray from U to P searching for the contact point as shown below:
RayInfo rInfo;
Point3F contactPoint;
if( gClientContainer.castRay( U, P, SomeObjectType, &rInfo) )
{
contactPoint = rInfo.point;
}
The problem is that the position U was calculated without considering the axis A, so when the object in question is rotated along any axis, the contact point is not perfectly accurate because the object mesh is vertically long and the camera node is at the top.
Could anyone assist me in figuring this out?
Thank you,
Robert Brower
I've got a matrix problem I need to solve, but so far I have had no luck. I have a matrix, M. I am obtaining the position, P, and axis A of the matrix as shown below:
MatrixF M;
Point3F P, U, A;
M.mul(getRenderTransform(), mShapeInstance->mNodeTransforms[mDataBlock->cameraNode]);
M.getColumn(1,&A);
M.getColumn(3,&P);
Then I am computing a position, U, 100 units below P like this:
U = P + Point3F(0.0, 0.0, -100.0); // TODO: this isnt't correct, we need to consider axis
Then I am casting a ray from U to P searching for the contact point as shown below:
RayInfo rInfo;
Point3F contactPoint;
if( gClientContainer.castRay( U, P, SomeObjectType, &rInfo) )
{
contactPoint = rInfo.point;
}
The problem is that the position U was calculated without considering the axis A, so when the object in question is rotated along any axis, the contact point is not perfectly accurate because the object mesh is vertically long and the camera node is at the top.
Could anyone assist me in figuring this out?
Thank you,
Robert Brower
Torque Owner Robert Brower
I needed to normalize A:
A.normalize(100);
then to compute U, I needed to subtract A from P:
U = P - A;
Thank you Raverix. Tell Jill I said hello. =)
Robert