mirror of
https://github.com/recp/cglm.git
synced 2025-10-03 08:41:55 +00:00
move extracting planes to camera header
* since it related to view frustum / camera it should be in thie header or separate header called frustum.h * update LICENSE to add authors of algorithm
This commit is contained in:
6
LICENSE
6
LICENSE
@@ -52,3 +52,9 @@ LICENSE:
|
|||||||
|
|
||||||
Computing Euler angles from a rotation matrix (euler.pdf)
|
Computing Euler angles from a rotation matrix (euler.pdf)
|
||||||
Gregory G. Slabaugh
|
Gregory G. Slabaugh
|
||||||
|
|
||||||
|
4. Extracting Planes
|
||||||
|
Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
|
||||||
|
Authors:
|
||||||
|
Gil Gribb (ggribb@ravensoft.com)
|
||||||
|
Klaus Hartmann (k_hartmann@osnabrueck.netsurf.de)
|
||||||
|
@@ -48,6 +48,10 @@ glmc_lookat(vec3 eye,
|
|||||||
vec3 up,
|
vec3 up,
|
||||||
mat4 dest);
|
mat4 dest);
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_extract_planes(mat4 m, vec4 dest[6]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -17,10 +17,6 @@ CGLM_EXPORT
|
|||||||
void
|
void
|
||||||
glmc_plane_normalize(vec4 plane);
|
glmc_plane_normalize(vec4 plane);
|
||||||
|
|
||||||
CGLM_EXPORT
|
|
||||||
void
|
|
||||||
glmc_plane_extract(mat4 projView, vec4 dest[6]);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -50,12 +50,14 @@
|
|||||||
float * __restrict farVal);
|
float * __restrict farVal);
|
||||||
CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float * __restrict farVal);
|
CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float * __restrict farVal);
|
||||||
CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *__restrict nearVal);
|
CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *__restrict nearVal);
|
||||||
|
CGLM_INLINE void glm_extract_planes(mat4 m, vec4 dest[6]);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef cglm_vcam_h
|
#ifndef cglm_vcam_h
|
||||||
#define cglm_vcam_h
|
#define cglm_vcam_h
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "plane.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief set up perspective peprojection matrix
|
* @brief set up perspective peprojection matrix
|
||||||
@@ -422,4 +424,45 @@ void
|
|||||||
glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) {
|
glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) {
|
||||||
*nearVal = proj[3][2] / (proj[2][2] - 1);
|
*nearVal = proj[3][2] / (proj[2][2] - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief extracts view frustum planes
|
||||||
|
*
|
||||||
|
* planes' space:
|
||||||
|
* 1- if m = proj: View Space
|
||||||
|
* 2- if m = projView: World Space
|
||||||
|
* 3- if m = MVP: Object Space
|
||||||
|
*
|
||||||
|
* You probably want to extract planes in world space so use projView as m
|
||||||
|
* Computing projView:
|
||||||
|
* glm_mat4_mul(proj, view, projView);
|
||||||
|
*
|
||||||
|
* Exracted planes order: [left, right, bottom, top, near, far]
|
||||||
|
*
|
||||||
|
* @param[in] m matrix (see brief)
|
||||||
|
* @param[out] dest exracted view frustum planes (see brief)
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_extract_planes(mat4 m, vec4 dest[6]) {
|
||||||
|
mat4 t;
|
||||||
|
|
||||||
|
glm_mat4_transpose_to(m, t);
|
||||||
|
|
||||||
|
glm_vec4_add(t[3], t[0], dest[0]); /* left */
|
||||||
|
glm_vec4_sub(t[3], t[0], dest[1]); /* right */
|
||||||
|
glm_vec4_add(t[3], t[1], dest[2]); /* bottom */
|
||||||
|
glm_vec4_sub(t[3], t[1], dest[3]); /* top */
|
||||||
|
glm_vec4_add(t[3], t[2], dest[4]); /* near */
|
||||||
|
glm_vec4_sub(t[3], t[2], dest[5]); /* far */
|
||||||
|
|
||||||
|
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_vcam_h */
|
#endif /* cglm_vcam_h */
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "mat4.h"
|
#include "mat4.h"
|
||||||
#include "vec4.h"
|
#include "vec4.h"
|
||||||
|
#include "vec3.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Plane equation: Ax + By + Cz + D = 0;
|
Plane equation: Ax + By + Cz + D = 0;
|
||||||
@@ -21,7 +22,6 @@
|
|||||||
/*
|
/*
|
||||||
Functions:
|
Functions:
|
||||||
CGLM_INLINE void glm_plane_normalize(vec4 plane);
|
CGLM_INLINE void glm_plane_normalize(vec4 plane);
|
||||||
CGLM_INLINE void glm_plane_extract(mat4 projView, vec4 dest[6]);
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -35,36 +35,4 @@ glm_plane_normalize(vec4 plane) {
|
|||||||
glm_vec4_scale(plane, 1.0f / glm_vec_norm(plane), 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 */
|
#endif /* cglm_plane_h */
|
||||||
|
@@ -66,3 +66,9 @@ glmc_lookat(vec3 eye,
|
|||||||
mat4 dest) {
|
mat4 dest) {
|
||||||
glm_lookat(eye, center, up, dest);
|
glm_lookat(eye, center, up, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_extract_planes(mat4 m, vec4 dest[6]) {
|
||||||
|
glm_extract_planes(m, dest);
|
||||||
|
}
|
||||||
|
@@ -13,9 +13,3 @@ void
|
|||||||
glmc_plane_normalize(vec4 plane) {
|
glmc_plane_normalize(vec4 plane) {
|
||||||
glm_plane_normalize(plane);
|
glm_plane_normalize(plane);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
|
||||||
void
|
|
||||||
glmc_plane_extract(mat4 projView, vec4 dest[6]) {
|
|
||||||
glm_plane_extract(projView, dest);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user