summaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-22 22:05:12 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-22 22:05:12 +0200
commit8797569d33c4917eb8f8a1dc2341aac7b5815315 (patch)
tree839aca030b0d3ed36cef15b051fbfd4bf8ecb754 /src/math
parent86ea086790a677d6de6a836e7562814d3ba30bd1 (diff)
downloadcolobot-8797569d33c4917eb8f8a1dc2341aac7b5815315.tar.gz
colobot-8797569d33c4917eb8f8a1dc2341aac7b5815315.tar.bz2
colobot-8797569d33c4917eb8f8a1dc2341aac7b5815315.zip
Texture & mouse functions; refactoring & fixes
- cleaned up and added documentation to engine.h - refactored CEngine interface and associated structs - added mouse handling functions in CApplication & CEngine - fixed bugs in projection matrix setting - changed texture loading & handling - added const-values in CDevice & CGLDevice - changed event management in CApplication - other minor changes & bugfixes
Diffstat (limited to 'src/math')
-rw-r--r--src/math/geometry.h20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/math/geometry.h b/src/math/geometry.h
index 8954655..61d1868 100644
--- a/src/math/geometry.h
+++ b/src/math/geometry.h
@@ -284,26 +284,24 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
//! Loads a perspective projection matrix
/** \a fov field of view in radians
- \a aspect aspect ratio (height / width)
+ \a aspect aspect ratio (width / height)
\a nearPlane distance to near cut plane
\a farPlane distance to far cut plane */
-inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = 1.570795f, float aspect = 1.0f,
+inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f, float aspect = 1.0f,
float nearPlane = 1.0f, float farPlane = 1000.0f)
{
assert(fabs(farPlane - nearPlane) >= 0.01f);
assert(fabs(sin(fov / 2)) >= 0.01f);
- float w = aspect * (cosf(fov / 2) / sinf(fov / 2));
- float h = 1.0f * (cosf(fov / 2) / sinf(fov / 2));
- float q = farPlane / (farPlane - nearPlane);
+ float f = cosf(fov / 2.0f) / sinf(fov / 2.0f);
mat.LoadZero();
- /* (1,1) */ mat.m[0 ] = w;
- /* (2,2) */ mat.m[5 ] = h;
- /* (3,3) */ mat.m[10] = q;
- /* (4,3) */ mat.m[11] = 1.0f;
- /* (3,4) */ mat.m[14] = -q * nearPlane;
+ /* (1,1) */ mat.m[0 ] = f / aspect;
+ /* (2,2) */ mat.m[5 ] = f;
+ /* (3,3) */ mat.m[10] = (nearPlane + farPlane) / (nearPlane - farPlane);
+ /* (4,3) */ mat.m[11] = -1.0f;
+ /* (3,4) */ mat.m[14] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
}
//! Loads an othogonal projection matrix
@@ -320,7 +318,7 @@ inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right
/* (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);
+ /* (2,4) */ mat.m[13] = - (top + bottom) / (top - bottom);
/* (3,4) */ mat.m[14] = - (zFar + zNear) / (zFar - zNear);
}