raycast intersection point

Zoulz

05-05-2008 20:12:17

Hello!
How would I go about getting the exact point of intersection from my BasicRayCast? I'd like a position vector where the intersection occured. This is so I can position my character on the "ground".

Maybe there is some simple math way of doing this? I'm not that good with math.. :cry:

Any help would be appreciated. Thanks!

Chris Thornton

06-05-2008 02:03:56

I think you need to make a vector that represents the direction of your ray, then just figure out how far along that vector you need to travel to get your intersection point. I think this pseudocode should work


Vector3 startPoint
Vector3 endPoint

Vector3 direction = endPoint - startPoint;
Real dist = direction.length();
direction.normalize();

BasicRayCast ray(mWorld, startPoint, endPoint);
dist = dist * ray.getFirstHit().mDistance;

direction = direction * dist;

Vector3 intersection = startPoint + direction;