Minor optimisation to Vector3::angleBetween()

Minor issues with the Ogre API that can be trivial to fix
User avatar
Waruck
Goblin
Posts: 210
Joined: Mon Dec 12, 2011 12:52 pm
Location: Germany
x 34

Minor optimisation to Vector3::angleBetween()

Post by Waruck »

Since calculating squareroots is expensive in terms of cpu operations I would change this line of Vector3 (and Vector2)::angleBewteen():
from:

Code: Select all

Real lenProduct = length() * dest.length();
to:

Code: Select all

Real lenProduct = Math::Sqrt(squaredLength() * dest.squaredLength());
This way only one squareroot has to be calculated instead of two.
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80

Re: Minor optimisation to Vector3::angleBetween()

Post by duststorm »

Nice little fix, and good point.
Developer @ MakeHuman.org
User avatar
masterfalcon
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 4270
Joined: Sun Feb 25, 2007 4:56 am
Location: Bloomington, MN
x 126

Re: Minor optimisation to Vector3::angleBetween()

Post by masterfalcon »

Good find. The same change can also be made to Vector2.