summaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-01 22:59:22 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-01 22:59:22 +0200
commitd9c5a439d09211ec210195709d275596c6c3c9ba (patch)
treeb536721f8ac5f42649345eeb836259bbf6a887e3 /src/math
parent9bd4ec03b272e7925b11c3efc2bd8460894ea589 (diff)
downloadcolobot-d9c5a439d09211ec210195709d275596c6c3c9ba.tar.gz
colobot-d9c5a439d09211ec210195709d275596c6c3c9ba.tar.bz2
colobot-d9c5a439d09211ec210195709d275596c6c3c9ba.zip
CGLDevice implementation
- extended Gfx::CDevice interface - written OpenGL implementation in Gfx::CGLDevice - rewrote color and light module - added Gfx::VertexCol - added array casts to Math::Vector, Math::Matrix and Gfx::Color
Diffstat (limited to 'src/math')
-rw-r--r--src/math/geometry.h18
-rw-r--r--src/math/matrix.h6
-rw-r--r--src/math/point.h6
-rw-r--r--src/math/vector.h6
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
{