Rotating a Vector2

Minor issues with the Ogre API that can be trivial to fix
User avatar
Mikachu
Gnoll
Posts: 603
Joined: Thu Jul 28, 2005 4:11 pm
Location: Nice, France
x 35

Rotating a Vector2

Post by Mikachu »

Hi,

For a project of mine, I implemented t :) hat function :

Code: Select all

// Rotates a Vector2 by a given oriented angle
	static inline Ogre::Vector2 rotateVector2(const Ogre::Vector2& in, Ogre::Radian angle)
	{
		return Ogre::Vector2(in.x* Ogre::Math::Cos(angle) - in.y * Ogre::Math::Sin(angle),
			in.x * Ogre::Math::Sin(angle) + in.y * Ogre::Math::Cos(angle));
	}
It just rotates a given Vector2 by an angle, just like a Quaternion does on a Vector3...
I think it could be made a member function of Vector2.

I'll post a patch for this if I get the time :)
OgreProcedural - Procedural Geometry for Ogre3D
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: Rotating a Vector2

Post by cyrfer »

Patch!
Too bad there is no 2x2 matrix class.

If the 2x2 support existed, you could just say:
Vector2 vPrime = R2x2 * v;

Here is how you can use a 3x3 (already works):
Vector3 vPrime3 = Rz * Vector3(v.x, v.y,0.0);
Vector2 vPrime( vPrime3.x, vPrime3.y );
User avatar
Mikachu
Gnoll
Posts: 603
Joined: Thu Jul 28, 2005 4:11 pm
Location: Nice, France
x 35

Re: Rotating a Vector2

Post by Mikachu »

OgreProcedural - Procedural Geometry for Ogre3D