diff options
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/geometry.h | 18 | ||||
-rw-r--r-- | src/math/matrix.h | 6 | ||||
-rw-r--r-- | src/math/point.h | 6 | ||||
-rw-r--r-- | src/math/vector.h | 6 |
4 files changed, 36 insertions, 0 deletions
diff --git a/src/math/geometry.h b/src/math/geometry.h index 2f937e5..d5960b8 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -305,6 +305,24 @@ inline void LoadProjectionMatrix(Matrix &mat, float fov = 1.570795f, float aspec /* (3,4) */ mat.m[14] = -q * nearPlane; } +//! Loads an othogonal projection matrix +/** \a left,right coordinates for left and right vertical clipping planes + \a bottom,top coordinates for bottom and top horizontal clipping planes + \a zNear,zFar distance to nearer and farther depth clipping planes */ +inline void LoadOrthoProjectionMatrix(Matrix &mat, float left, float right, float bottom, float top, + float zNear = -1.0f, float zFar = 1.0f) +{ + mat.LoadIdentity(); + + /* (1,1) */ mat.m[0 ] = 2.0f / (right - left); + /* (2,2) */ mat.m[5 ] = 2.0f / (top - bottom); + /* (3,3) */ mat.m[10] = -2.0f / (zFar - zNear); + + /* (1,4) */ mat.m[12] = - (right + left) / (right - left); + /* (2,4) */ mat.m[12] = - (top + bottom) / (top - bottom); + /* (3,4) */ mat.m[14] = - (zFar + zNear) / (zFar - zNear); +} + //! Loads a translation matrix from given vector /** \a trans vector of translation*/ inline void LoadTranslationMatrix(Matrix &mat, const Vector &trans) diff --git a/src/math/matrix.h b/src/math/matrix.h index 9b29f46..0315a33 100644 --- a/src/math/matrix.h +++ b/src/math/matrix.h @@ -118,6 +118,12 @@ struct Matrix /* (4,4) */ m[15] = 1.0f; } + //! Returns the struct cast to \c float* array; use with care! + inline float* Array() + { + return (float*)this; + } + //! Transposes the matrix inline void Transpose() { diff --git a/src/math/point.h b/src/math/point.h index 84be190..d6768c8 100644 --- a/src/math/point.h +++ b/src/math/point.h @@ -67,6 +67,12 @@ struct Point x = y = 0.0f; } + //! Returns the struct cast to \c float* array; use with care! + inline float* Array() + { + return (float*)this; + } + //! Returns the distance from (0,0) to the point (x,y) inline float Length() { diff --git a/src/math/vector.h b/src/math/vector.h index 3c756f2..baba6bb 100644 --- a/src/math/vector.h +++ b/src/math/vector.h @@ -72,6 +72,12 @@ struct Vector x = y = z = 0.0f; } + //! Returns the struct cast to \c float* array; use with care! + inline float* Array() + { + return (float*)this; + } + //! Returns the vector length inline float Length() const { |