RayCaster question

Dutchie

27-02-2008 20:13:41

is it possible to do a raycast from a point to another point, instead of from a point giving it a direction and than a distance?

This will help me very much, or do you have a script that converts 2 positions to a direction and distance?

Thanks,

Dutchie

Caphalor

27-02-2008 21:12:36

I hope that this is correct:

Ogre::Vector3 Diff = Target - Origin;
Ogre::Vector3 Direction = Diff.normalisedCopy();
float distance = Diff.length();

nullsquared

28-02-2008 00:45:05

I hope that this is correct:

Ogre::Vector3 Diff = Target - Origin;
Ogre::Vector3 Direction = Diff.normalisedCopy();
float distance = Diff.length();

Yup. You can optimize it a bit, though:

Ogre::Vector3 dir = target - origin;
Ogre::Real dist = dir.normalise();

This way you only do one sqrt, instead of doing it one time for the normalise and another for the length (normalise returns the previous length).

Dutchie

28-02-2008 08:00:54

thanks, i will try that...