mirror of
https://github.com/recp/cglm.git
synced 2025-10-03 16:51:35 +00:00
exracting planes
This commit is contained in:
@@ -50,6 +50,7 @@ https://github.com/g-truc/glm
|
|||||||
- euler angles / yaw-pitch-roll to matrix
|
- euler angles / yaw-pitch-roll to matrix
|
||||||
- extract euler angles
|
- extract euler angles
|
||||||
- inline or pre-compiled function call
|
- inline or pre-compiled function call
|
||||||
|
- extract view frustum planes
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@ extern "C" {
|
|||||||
#include "call/cam.h"
|
#include "call/cam.h"
|
||||||
#include "call/quat.h"
|
#include "call/quat.h"
|
||||||
#include "call/euler.h"
|
#include "call/euler.h"
|
||||||
|
#include "call/plane.h"
|
||||||
#include "call/io.h"
|
#include "call/io.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
27
include/cglm/call/plane.h
Normal file
27
include/cglm/call/plane.h
Normal 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 */
|
@@ -17,6 +17,7 @@
|
|||||||
#include "cam.h"
|
#include "cam.h"
|
||||||
#include "quat.h"
|
#include "quat.h"
|
||||||
#include "euler.h"
|
#include "euler.h"
|
||||||
|
#include "plane.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
|
70
include/cglm/plane.h
Normal file
70
include/cglm/plane.h
Normal 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
21
src/plane.c
Normal 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);
|
||||||
|
}
|
Reference in New Issue
Block a user