|
Motive Animation System
An open source project by
FPL.
|
Represent an angle in radians, uniquely in the range (-pi, pi]. More...
#include <angle.h>
Represent an angle in radians, uniquely in the range (-pi, pi].
We include pi in the range, but exclude -pi, because pi and -pi are equivalent mod 2pi.
Equivalence is key to this class. We want only one representation of every equivalent angle. For example, 0 and 2pi are both represented as 0, internally. This unique representation allows for comparison and precise arithmetic.
All operators keep the angle values in the valid range.
Quaternions are great for three dimensional rotations, but for many applications you only have two dimensional rotations. Instead of the four floats and heavy operations required by quaternions, an angle can represent the rotation in one float and reasonably light operations. Angles are easier to do trigonometry on. Also, they're conceptually simpler.
Public Member Functions | |
| Angle (float angle) | |
| Angle | Abs () const |
| Returns the absolute value of an angle. | |
| Angle & | operator= (const Angle &rhs) |
| Angle & | operator+= (const Angle &rhs) |
Add rhs and ensure result is in the range (-pi,pi]. | |
| Angle & | operator-= (const Angle &rhs) |
Subtract rhs and ensure result is in the range (-pi,pi]. | |
| Angle & | operator*= (const float rhs) |
Multiply rhs and ensure result is in the normalized range (-pi,pi]. | |
| Angle & | operator/= (const float rhs) |
Divide rhs and ensure result is in the normalized range (-pi,pi]. | |
| Angle | operator- () const |
| Negate the angle and ensure result is in the normalized range (-pi,pi]. | |
| float | ToRadians () const |
| Return the angle value in radians. Value is in the range (-pi,pi]. | |
| float | ToDegrees () const |
| Return the angle value in degrees. Value is in the range (-180,180]. | |
| mathfu::vec3 | ToVectorSystem (const AngleToVectorSystem system) const |
| mathfu::vec3 | ToXYVector () const |
| mathfu::vec2 | ToXYVector2f () const |
| mathfu::vec3 | ToXZVector () const |
| mathfu::vec3 | ToYZVector () const |
| mathfu::vec3 | ToYXVector () const |
| mathfu::vec2 | ToYXVector2f () const |
| mathfu::vec3 | ToZXVector () const |
| mathfu::vec3 | ToZYVector () const |
| mathfu::mat3 | ToRotationMatrix (const AngleToVectorSystem system) const |
| mathfu::mat3 | ToXYRotationMatrix () const |
Returns a matrix that rotates about the Z axis angle radians. | |
| mathfu::mat3 | ToXZRotationMatrix () const |
Returns a matrix that rotates about the Y axis angle radians. | |
| mathfu::mat3 | ToYZRotationMatrix () const |
Returns a matrix that rotates about the X axis angle radians. | |
| mathfu::mat3 | ToYXRotationMatrix () const |
Returns a matrix that rotates about the Z axis -angle radians. | |
| mathfu::mat3 | ToZXRotationMatrix () const |
Returns a matrix that rotates about the Y axis -angle radians. | |
| mathfu::mat3 | ToZYRotationMatrix () const |
Returns a matrix that rotates about the X axis -angle radians. | |
| bool | IsValid () const |
| Angle | Clamp (const Angle ¢er, const Angle &max_diff) const |
Static Public Member Functions | |
| static float | WrapAngle (float angle) |
| static Angle | FromWithinThreePi (const float angle) |
| static Angle | FromRadians (const float radians) |
Create from radians, which is converted to the range (-pi, pi]. | |
| static Angle | FromDegrees (const float degrees) |
Create from degrees, which is converted to the range (-pi, pi]. | |
| static Angle | FromVectorSystem (const mathfu::vec3 &v, const AngleToVectorSystem system) |
| static Angle | FromXYVector (const mathfu::vec3 &v) |
| static Angle | FromXZVector (const mathfu::vec3 &v) |
| static Angle | FromYZVector (const mathfu::vec3 &v) |
| static Angle | FromYXVector (const mathfu::vec3 &v) |
| static Angle | FromZXVector (const mathfu::vec3 &v) |
| static Angle | FromZYVector (const mathfu::vec3 &v) |
| static bool | IsAngleInRange (const float angle) |
Friends | |
| bool | operator== (const Angle &a, const Angle &b) |
| bool | operator< (const Angle &a, const Angle &b) |
| bool | operator<= (const Angle &a, const Angle &b) |
|
inlineexplicit |
Create from angle, which is already in the valid range (-pi,pi]. If your angle is outside that range, construct the Angle with the slower FromRadians function to automatically wrap it.
| angle | radians in the range (-pi,pi] – i.e. exclusive of -pi but inclusive of +pi. |
Clamps the angle to the range [center - max_diff, center + max_diff]. max_diff must be in the range [0~pi].
|
inlinestatic |
Returns a point on the unit circle corresponding to a sweep of angle across the specified vector system.
|
inlinestatic |
Create from angle, in radians, which is in the range (-3pi,3pi]. This function is significantly faster than WrapAngle since it avoids division. It's also more precise for the same reason. The range may seem strange at first glance; it's a consequence of the implementation. Just know that any two sums of normalized angles will still be in the range (-3pi,3pi].
|
inlinestatic |
Create from the x,y coordinates of a vector, using the system described in ToXYVector().
|
inlinestatic |
Create from the x,z coordinates of a vector, using the system described in ToXZVector().
|
inlinestatic |
Create from the y,x coordinates of a vector, using the system described in ToYXVector().
|
inlinestatic |
Create from the y,z coordinates of a vector, using the system described in ToYZVector().
|
inlinestatic |
Create from the z,x coordinates of a vector, using the system described in ToZXVector().
|
inlinestatic |
Create from the z,y coordinates of a vector, using the system described in ToZYVector().
|
inlinestatic |
Return true if 'angle' is within the valid range (-pi,pi], that is, the range inclusive of +pi but exclusive of -pi.
|
inline |
Check internal consistency. If class is functioning correctly, should always return true.
|
inline |
Returns a point on the unit circle corresponding to a sweep of angle across the specified vector system.
|
inline |
Returns a point on the unit circle corresponding to a sweep of angle across the specified vector system.
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the x-axis towards the y-axis. 0 ==> ( 1, 0, 0) pi/2 ==> ( 0, 1, 0) pi ==> (-1, 0, 0) 3pi/2 ==> ( 0, -1, 0)
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the x-axis towards the y-axis. 0 ==> ( 1, 0 ) pi/2 ==> ( 0, 1 ) pi ==> (-1, 0 ) 3pi/2 ==> ( 0, -1 )
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the x-axis towards the z-axis. 0 ==> ( 1, 0, 0) pi/2 ==> ( 0, 0, 1) pi ==> (-1, 0, 0) 3pi/2 ==> ( 0, 0, -1)
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the y-axis towards the x-axis. 0 ==> ( 0, 1, 0) pi/2 ==> ( 1, 0, 0) pi ==> ( 0, -1, 0) 3pi/2 ==> (-1, 0, 0)
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the y-axis towards the x-axis. 0 ==> ( 0, 1 ) pi/2 ==> ( 1, 0 ) pi ==> ( 0, -1 ) 3pi/2 ==> (-1, 0 )
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the y-axis towards the z-axis. 0 ==> (0, 1, 0) pi/2 ==> (0, 0, 1) pi ==> (0, -1, 0) 3pi/2 ==> (0, 0, -1)
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the z-axis towards the x-axis. 0 ==> ( 0, 0, 1) pi/2 ==> ( 1, 0, 0) pi ==> ( 0, 0, -1) 3pi/2 ==> (-1, 0, 0)
|
inline |
Returns a point on unit circle corresponding to a sweep of angle degrees from the z-axis towards the y-axis. 0 ==> (0, 0, 1) pi/2 ==> (0, 1, 0) pi ==> (0, 0, -1) 3pi/2 ==> (0, -1, 0)
|
inlinestatic |
Wraps an angle to the range (-pi, pi]. This function is slow because it has a division. When possible, use FromWithinThreePi instead.