Skip to content
Browse files

Merge from upstream

  • Loading branch information...
2 parents dd161fd + 9d9cd8b commit c8f74aa824ea6af0aac90cbb17468677e8ef8028 @Kazade committed Jan 17, 2011
Showing with 74 additions and 2 deletions.
  1. +3 −1 include/kazmath/mat4.h
  2. +9 −0 include/kazmath/plane.h
  3. +4 −0 include/kazmath/utility.h
  4. +1 −1 kazmathxx/CMakeLists.txt
  5. +57 −0 src/mat4.c
View
4 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 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 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
2 kazmathxx/CMakeLists.txt
@@ -1,2 +1,2 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.6)
ADD_SUBDIRECTORY(src)
View
57 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;
+}

0 comments on commit c8f74aa

Please sign in to comment.
Something went wrong with that request. Please try again.