Browse files

Implement kmMat4ExtractPlane, reduce the cmake minimum version. Fix a…

… warning
  • Loading branch information...
1 parent adce7b4 commit 9d9cd8b9c9671666e9371b5022572db95df7fe0c @Kazade committed Jan 14, 2011
View
4 kazmath/include/kazmath/mat4.h
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct kmVec3;
struct kmMat3;
struct kmQuaternion;
+struct kmPlane;
/*
A 4x4 matrix
@@ -83,7 +84,8 @@ kmMat4* const kmMat4OrthographicProjection(kmMat4* pOut, kmScalar left, kmScalar
kmMat4* const kmMat4LookAt(kmMat4* pOut, const struct kmVec3* pEye, const struct kmVec3* pCenter, const struct kmVec3* pUp);
kmMat4* const kmMat4RotationAxisAngle(kmMat4* pOut, const struct kmVec3* axis, kmScalar radians);
-struct kmMat3* const kmMat4ExtractRotation(struct kmMat3* pOut, const kmMat4* pIn);
+struct kmMat3* const kmMat4ExtractRotation(struct kmMat3* pOut, const kmMat4* pIn);
+struct kmPlane* const kmMat4ExtractPlane(struct kmPlane* pOut, const kmMat4* pIn, const kmEnum plane);
struct kmVec3* const kmMat4RotationToAxisAngle(struct kmVec3* pAxis, kmScalar* radians, const kmMat4* pIn);
#ifdef __cplusplus
}
View
9 kazmath/include/kazmath/plane.h
@@ -26,9 +26,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PLANE_H_INCLUDED
#define PLANE_H_INCLUDED
+#define KM_PLANE_LEFT 0
+#define KM_PLANE_RIGHT 1
+#define KM_PLANE_BOTTOM 2
+#define KM_PLANE_TOP 3
+#define KM_PLANE_NEAR 4
+#define KM_PLANE_FAR 5
+
#include "utility.h"
struct kmVec3;
+struct kmVec4;
+struct kmMat4;
typedef struct kmPlane {
kmScalar a, b, c, d;
View
4 kazmath/include/kazmath/utility.h
@@ -32,6 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define kmScalar float
#endif
+#ifndef kmEnum
+#define kmEnum unsigned int
+#endif
+
#ifndef KM_FALSE
#define KM_FALSE 0
#endif
View
57 kazmath/src/mat4.c
@@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "kazmath/mat4.h"
#include "kazmath/mat3.h"
#include "kazmath/quaternion.h"
+#include "kazmath/plane.h"
/**
* Fills a kmMat4 structure with the values from a 16
@@ -719,3 +720,59 @@ kmMat4* const kmMat4RotationTranslation(kmMat4* pOut, const kmMat3* rotation, co
return pOut;
}
+
+kmPlane* const kmMat4ExtractPlane(kmPlane* pOut, const kmMat4* pIn, const kmEnum plane)
+{
+ float t = 1.0f;
+
+ switch(plane) {
+ case KM_PLANE_RIGHT:
+ pOut->a = pIn->mat[3] - pIn->mat[0];
+ pOut->b = pIn->mat[7] - pIn->mat[4];
+ pOut->c = pIn->mat[11] - pIn->mat[8];
+ pOut->d = pIn->mat[15] - pIn->mat[12];
+ break;
+ case KM_PLANE_LEFT:
+ pOut->a = pIn->mat[3] + pIn->mat[0];
+ pOut->b = pIn->mat[7] + pIn->mat[4];
+ pOut->c = pIn->mat[11] + pIn->mat[8];
+ pOut->d = pIn->mat[15] + pIn->mat[12];
+ break;
+ case KM_PLANE_BOTTOM:
+ pOut->a = pIn->mat[3] + pIn->mat[1];
+ pOut->b = pIn->mat[7] + pIn->mat[5];
+ pOut->c = pIn->mat[11] + pIn->mat[9];
+ pOut->d = pIn->mat[15] + pIn->mat[13];
+ break;
+ case KM_PLANE_TOP:
+ pOut->a = pIn->mat[3] - pIn->mat[1];
+ pOut->b = pIn->mat[7] - pIn->mat[5];
+ pOut->c = pIn->mat[11] - pIn->mat[9];
+ pOut->d = pIn->mat[15] - pIn->mat[13];
+ break;
+ case KM_PLANE_FAR:
+ pOut->a = pIn->mat[3] - pIn->mat[2];
+ pOut->b = pIn->mat[7] - pIn->mat[6];
+ pOut->c = pIn->mat[11] - pIn->mat[10];
+ pOut->d = pIn->mat[15] - pIn->mat[14];
+ break;
+ case KM_PLANE_NEAR:
+ pOut->a = pIn->mat[3] + pIn->mat[2];
+ pOut->b = pIn->mat[7] + pIn->mat[6];
+ pOut->c = pIn->mat[11] + pIn->mat[10];
+ pOut->d = pIn->mat[15] + pIn->mat[14];
+ break;
+ default:
+ assert(0 && "Invalid plane index");
+ }
+
+ t = sqrtf(pOut->a * pOut->a +
+ pOut->b * pOut->b +
+ pOut->c * pOut->c);
+ pOut->a /= t;
+ pOut->b /= t;
+ pOut->c /= t;
+ pOut->d /= t;
+
+ return pOut;
+}
View
2 kazmathxx/CMakeLists.txt
@@ -1,2 +1,2 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.6)
ADD_SUBDIRECTORY(src)

0 comments on commit 9d9cd8b

Please sign in to comment.