exracting planes

This commit is contained in:
Recep Aslantas
2017-12-30 12:18:32 +03:00
parent 3f616ce6a3
commit c98340d9d2
6 changed files with 121 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ https://github.com/g-truc/glm
- euler angles / yaw-pitch-roll to matrix
- extract euler angles
- inline or pre-compiled function call
- extract view frustum planes
<hr />

View File

@@ -20,6 +20,7 @@ extern "C" {
#include "call/cam.h"
#include "call/quat.h"
#include "call/euler.h"
#include "call/plane.h"
#include "call/io.h"
#ifdef __cplusplus

27
include/cglm/call/plane.h Normal file
View File

@@ -0,0 +1,27 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_plane_h
#define cglmc_plane_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_plane_normalize(vec4 plane);
CGLM_EXPORT
void
glmc_plane_extract(mat4 projView, vec4 dest[6]);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_plane_h */

View File

@@ -17,6 +17,7 @@
#include "cam.h"
#include "quat.h"
#include "euler.h"
#include "plane.h"
#include "util.h"
#include "io.h"

70
include/cglm/plane.h Normal file
View File

@@ -0,0 +1,70 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_plane_h
#define cglm_plane_h
#include "common.h"
#include "mat4.h"
#include "vec4.h"
/*
Plane equation: Ax + By + Cz + D = 0;
It stored in vec4 as [A, B, C, D]. (A, B, C) is normal and D is distance
*/
/*
Functions:
CGLM_INLINE void glm_plane_normalize(vec4 plane);
CGLM_INLINE void glm_plane_extract(mat4 projView, vec4 dest[6]);
*/
/*!
* @brief normalizes a plane
*
* @param[in, out] plane pnale to normalize
*/
CGLM_INLINE
void
glm_plane_normalize(vec4 plane) {
glm_vec4_scale(plane, 1.0f / glm_vec_norm(plane), plane);
}
/*!
* @brief extracts view frustum planes
*
* computing projView: glm_mat4_mul(proj, view, projView);
*
* exracted planes order: [left, right, bottom, top, near, far]
*
* @param[in] projView source
* @param[out] dest exracted view frustum planes (see brief)
*/
CGLM_INLINE
void
glm_plane_extract(mat4 projView, vec4 dest[6]) {
mat4 m;
glm_mat4_transpose_to(projView, m);
glm_vec4_add(m[3], m[0], dest[0]);
glm_vec4_sub(m[3], m[0], dest[1]);
glm_vec4_add(m[3], m[1], dest[2]);
glm_vec4_sub(m[3], m[1], dest[3]);
glm_vec4_add(m[3], m[2], dest[4]);
glm_vec4_sub(m[3], m[2], dest[5]);
glm_plane_normalize(dest[0]);
glm_plane_normalize(dest[1]);
glm_plane_normalize(dest[2]);
glm_plane_normalize(dest[3]);
glm_plane_normalize(dest[4]);
glm_plane_normalize(dest[5]);
}
#endif /* cglm_plane_h */

21
src/plane.c Normal file
View File

@@ -0,0 +1,21 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#include "../include/cglm/cglm.h"
#include "../include/cglm/call.h"
CGLM_EXPORT
void
glmc_plane_normalize(vec4 plane) {
glm_plane_normalize(plane);
}
CGLM_EXPORT
void
glmc_plane_extract(mat4 projView, vec4 dest[6]) {
glm_plane_extract(projView, dest);
}