Commit 7babf477 authored by hybrid's avatar hybrid

Add new angles calculation method suggested by Yoran.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2861 dfc29bdd-3216-0410-991c-e03cc46cb475
parent cac36415
...@@ -277,23 +277,47 @@ namespace core ...@@ -277,23 +277,47 @@ namespace core
angle.Y = (T)(atan2(X, Z) * (T) RADTODEG64); angle.Y = (T)(atan2(X, Z) * (T) RADTODEG64);
if (angle.Y < 0.0f) if (angle.Y < 0)
angle.Y += 360.0f; angle.Y += 360;
if (angle.Y >= 360.0f) if (angle.Y >= 360)
angle.Y -= 360.0f; angle.Y -= 360;
const T z1 = core::squareroot(X*X + Z*Z); const T z1 = core::squareroot(X*X + Z*Z);
angle.X = (T)(atan2(z1, (T)Y) * (T) RADTODEG64 - (T) 90.0); angle.X = (T)(atan2((f64)z1, (f64)Y) * RADTODEG64 - 90.0);
if (angle.X < (T) 0.0) if (angle.X < 0)
angle.X += (T) 360.0; angle.X += 360;
if (angle.X >= (T) 360.0) if (angle.X >= 360)
angle.X -= (T) 360.0; angle.X -= 360;
return angle; return angle;
} }
//! Get the spherical coordinate angles
/** This returns Euler degrees for the point represented by
this vector. The calculation assumes the pole at (0,1,0) and
returns the angles in X and Y.
*/
vector3d<T> getSphericalCoordinateAngles()
{
vector3d<T> angle;
const T length=getLength();
if (length)
{
if (X!=0)
{
angle.Y = (T)(atan2(Z,X) * RADTODEG64);
}
else if (Z<0)
angle.Y=180;
angle.X = (T)(acos(Y / length) * RADTODEG);
}
return angle;
}
//! Builds a direction vector from (this) rotation vector. //! Builds a direction vector from (this) rotation vector.
/** This vector is assumed to be a rotation vector composed of 3 Euler angle rotations, in degrees. /** This vector is assumed to be a rotation vector composed of 3 Euler angle rotations, in degrees.
The implementation performs the same calculations as using a matrix to do the rotation. The implementation performs the same calculations as using a matrix to do the rotation.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment