I''ve got big problems with my cyl to ray test, I found this text that described how to do it:
quote:
** Cylinder vs ray/line segment **
Graphics Gems IV had an algorithm for this. Basically you find a vector
that is perpendicular to both the axis and the ray. Then you take a vector
from the endpoint of the cylinder to a point on the ray. You then project
this vector onto your perpendicular vector, and compare that length against
the radius.
...
So I have a line (vLine), a startpoint for the cylinder (vCylBase) and a endpoint (vCylTop).
To get a perpendicular vector, I took the crossproduct (think that''s the way to do it)
cVector vVector1 = vLine[1] - vLine[0];
cVector vVector2 = vCylTop - vCylBase;
cVector vCrossNormal = Normalize(Cross(vVector1, vVector2));
Then I get a vector from a point in the cylinder to a point on the ray, and project it to the perpendicular vector (using dot product, as with the crossproduct earlier I''m not sure this is right)
cVector vV1 = vLine[1]- vCylBase;
float t = Dot(vCrossNormal, vV1);
cVector vV2 = vCrossNormal * t;
If I had done this correctly, i could have tested the distance from vV2 and the cylinder.. but I get crazy results only from this.. Could someone help me correct my code?
-Lord Maz-