mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
sphere and aabb
This commit is contained in:
@@ -45,3 +45,4 @@ Follow the :doc:`build` documentation for this
|
|||||||
util
|
util
|
||||||
io
|
io
|
||||||
call
|
call
|
||||||
|
sphere
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ Functions:
|
|||||||
#. :c:func:`glm_aabb_size`
|
#. :c:func:`glm_aabb_size`
|
||||||
#. :c:func:`glm_aabb_radius`
|
#. :c:func:`glm_aabb_radius`
|
||||||
#. :c:func:`glm_aabb_center`
|
#. :c:func:`glm_aabb_center`
|
||||||
|
#. :c:func:`glm_aabb_aabb`
|
||||||
|
#. :c:func:`glm_aabb_sphere`
|
||||||
|
#. :c:func:`glm_aabb_point`
|
||||||
|
#. :c:func:`glm_aabb_contains`
|
||||||
|
|
||||||
Functions documentation
|
Functions documentation
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -139,4 +143,39 @@ Functions documentation
|
|||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
| *[in]* **box** bounding box
|
| *[in]* **box** bounding box
|
||||||
| *[out]* **box** center of bounding box
|
| *[out]* **dest** center of bounding box
|
||||||
|
|
||||||
|
.. c:function:: bool glm_aabb_aabb(vec3 box[2], vec3 other[2])
|
||||||
|
|
||||||
|
| check if two AABB intersects
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **box** bounding box
|
||||||
|
| *[out]* **other** other bounding box
|
||||||
|
|
||||||
|
.. c:function:: bool glm_aabb_sphere(vec3 box[2], vec4 s)
|
||||||
|
|
||||||
|
| check if AABB intersects with sphere
|
||||||
|
|
||||||
|
| https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
|
||||||
|
| Solid Box - Solid Sphere test.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **box** solid bounding box
|
||||||
|
| *[out]* **s** solid sphere
|
||||||
|
|
||||||
|
.. c:function:: bool glm_aabb_point(vec3 box[2], vec3 point)
|
||||||
|
|
||||||
|
| check if point is inside of AABB
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **box** bounding box
|
||||||
|
| *[out]* **point** point
|
||||||
|
|
||||||
|
.. c:function:: bool glm_aabb_contains(vec3 box[2], vec3 other[2])
|
||||||
|
|
||||||
|
| check if AABB contains other AABB
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **box** bounding box
|
||||||
|
| *[out]* **other** other bounding box
|
||||||
|
|||||||
65
docs/source/sphere.rst
Normal file
65
docs/source/sphere.rst
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
.. default-domain:: C
|
||||||
|
|
||||||
|
Sphere
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
Header: cglm/sphere.h
|
||||||
|
|
||||||
|
**Definition of sphere:**
|
||||||
|
|
||||||
|
Sphere Representation in cglm is *vec4*: **[center.x, center.y, center.z, radii]**
|
||||||
|
|
||||||
|
You can call any vec3 function by pasing sphere. Because first three elements
|
||||||
|
defines center of sphere.
|
||||||
|
|
||||||
|
Table of contents (click to go):
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Functions:
|
||||||
|
|
||||||
|
1. :c:func:`glm_sphere_radii`
|
||||||
|
#. :c:func:`glm_sphere_transform`
|
||||||
|
#. :c:func:`glm_sphere_merge`
|
||||||
|
#. :c:func:`glm_sphere_sphere`
|
||||||
|
|
||||||
|
Functions documentation
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. c:function:: float glm_sphere_radii(vec4 s)
|
||||||
|
|
||||||
|
| helper for getting sphere radius
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **s** sphere
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
returns radii
|
||||||
|
|
||||||
|
.. c:function:: void glm_sphere_transform(vec4 s, mat4 m, vec4 dest)
|
||||||
|
|
||||||
|
| apply transform to sphere, it is just wrapper for glm_mat4_mulv3
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **s** sphere
|
||||||
|
| *[in]* **m** transform matrix
|
||||||
|
| *[out]* **dest** transformed sphere
|
||||||
|
|
||||||
|
.. c:function:: void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest)
|
||||||
|
|
||||||
|
| merges two spheres and creates a new one
|
||||||
|
|
||||||
|
two sphere must be in same space, for instance if one in world space then
|
||||||
|
the other must be in world space too, not in local space.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **s1** sphere 1
|
||||||
|
| *[in]* **s2** sphere 2
|
||||||
|
| *[out]* **dest** merged/extended sphere
|
||||||
|
|
||||||
|
.. c:function:: bool glm_sphere_sphere(vec4 s1, vec4 s2)
|
||||||
|
|
||||||
|
| check if two sphere intersects
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in]* **s1** sphere
|
||||||
|
| *[in]* **s2** other sphere
|
||||||
@@ -25,6 +25,7 @@ extern "C" {
|
|||||||
#include "call/box.h"
|
#include "call/box.h"
|
||||||
#include "call/io.h"
|
#include "call/io.h"
|
||||||
#include "call/project.h"
|
#include "call/project.h"
|
||||||
|
#include "call/sphere.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
32
include/cglm/call/sphere.h
Normal file
32
include/cglm/call/sphere.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef cglmc_sphere_h
|
||||||
|
#define cglmc_sphere_h
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../cglm.h"
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
float
|
||||||
|
glmc_sphere_radii(vec4 s);
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_sphere_transform(vec4 s, mat4 m, vec4 dest);
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest);
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
bool
|
||||||
|
glmc_sphere_sphere(vec4 s1, vec4 s2);
|
||||||
|
|
||||||
|
#endif /* cglmc_sphere_h */
|
||||||
@@ -18,6 +18,26 @@
|
|||||||
any function
|
any function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief helper for getting sphere radius
|
||||||
|
*
|
||||||
|
* @param[in] s sphere
|
||||||
|
*
|
||||||
|
* @return returns radii
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glm_sphere_radii(vec4 s) {
|
||||||
|
return s[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3
|
||||||
|
*
|
||||||
|
* @param[in] s sphere
|
||||||
|
* @param[in] m transform matrix
|
||||||
|
* @param[out] dest transformed sphere
|
||||||
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_sphere_transform(vec4 s, mat4 m, vec4 dest) {
|
glm_sphere_transform(vec4 s, mat4 m, vec4 dest) {
|
||||||
@@ -25,6 +45,16 @@ glm_sphere_transform(vec4 s, mat4 m, vec4 dest) {
|
|||||||
dest[3] = s[3];
|
dest[3] = s[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief merges two spheres and creates a new one
|
||||||
|
*
|
||||||
|
* two sphere must be in same space, for instance if one in world space then
|
||||||
|
* the other must be in world space too, not in local space.
|
||||||
|
*
|
||||||
|
* @param[in] s1 sphere 1
|
||||||
|
* @param[in] s2 sphere 2
|
||||||
|
* @param[out] dest merged/extended sphere
|
||||||
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
void
|
void
|
||||||
glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
|
glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
|
||||||
@@ -33,8 +63,23 @@ glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
|
|||||||
dist = glm_vec_distance(s1, s2);
|
dist = glm_vec_distance(s1, s2);
|
||||||
radii = dist + s1[3] + s2[3];
|
radii = dist + s1[3] + s2[3];
|
||||||
|
|
||||||
|
radii = glm_max(radii, s1[3]);
|
||||||
|
radii = glm_max(radii, s2[3]);
|
||||||
|
|
||||||
glm_vec_center(s1, s2, dest);
|
glm_vec_center(s1, s2, dest);
|
||||||
dest[3] = radii;
|
dest[3] = radii;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief check if two sphere intersects
|
||||||
|
*
|
||||||
|
* @param[in] s1 sphere
|
||||||
|
* @param[in] s2 other sphere
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glm_sphere_sphere(vec4 s1, vec4 s2) {
|
||||||
|
return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* cglm_sphere_h */
|
#endif /* cglm_sphere_h */
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ cglm_HEADERS = include/cglm/version.h \
|
|||||||
include/cglm/frustum.h \
|
include/cglm/frustum.h \
|
||||||
include/cglm/box.h \
|
include/cglm/box.h \
|
||||||
include/cglm/color.h \
|
include/cglm/color.h \
|
||||||
include/cglm/project.h
|
include/cglm/project.h \
|
||||||
|
include/cglm/sphere.h
|
||||||
|
|
||||||
cglm_calldir=$(includedir)/cglm/call
|
cglm_calldir=$(includedir)/cglm/call
|
||||||
cglm_call_HEADERS = include/cglm/call/mat4.h \
|
cglm_call_HEADERS = include/cglm/call/mat4.h \
|
||||||
@@ -70,7 +71,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \
|
|||||||
include/cglm/call/plane.h \
|
include/cglm/call/plane.h \
|
||||||
include/cglm/call/frustum.h \
|
include/cglm/call/frustum.h \
|
||||||
include/cglm/call/box.h \
|
include/cglm/call/box.h \
|
||||||
include/cglm/call/project.h
|
include/cglm/call/project.h \
|
||||||
|
include/cglm/call/sphere.h
|
||||||
|
|
||||||
cglm_simddir=$(includedir)/cglm/simd
|
cglm_simddir=$(includedir)/cglm/simd
|
||||||
cglm_simd_HEADERS = include/cglm/simd/intrin.h
|
cglm_simd_HEADERS = include/cglm/simd/intrin.h
|
||||||
@@ -101,7 +103,8 @@ libcglm_la_SOURCES=\
|
|||||||
src/plane.c \
|
src/plane.c \
|
||||||
src/frustum.c \
|
src/frustum.c \
|
||||||
src/box.c \
|
src/box.c \
|
||||||
src/project.c
|
src/project.c \
|
||||||
|
src/sphere.c
|
||||||
|
|
||||||
test_tests_SOURCES=\
|
test_tests_SOURCES=\
|
||||||
test/src/test_common.c \
|
test/src/test_common.c \
|
||||||
|
|||||||
33
src/sphere.c
Normal file
33
src/sphere.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
float
|
||||||
|
glmc_sphere_radii(vec4 s) {
|
||||||
|
return glm_sphere_radii(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_sphere_transform(vec4 s, mat4 m, vec4 dest) {
|
||||||
|
glm_sphere_transform(s, m, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
|
||||||
|
glm_sphere_merge(s1, s2, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
bool
|
||||||
|
glmc_sphere_sphere(vec4 s1, vec4 s2) {
|
||||||
|
return glm_sphere_sphere(s1, s2);
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
<ClCompile Include="..\src\plane.c" />
|
<ClCompile Include="..\src\plane.c" />
|
||||||
<ClCompile Include="..\src\project.c" />
|
<ClCompile Include="..\src\project.c" />
|
||||||
<ClCompile Include="..\src\quat.c" />
|
<ClCompile Include="..\src\quat.c" />
|
||||||
|
<ClCompile Include="..\src\sphere.c" />
|
||||||
<ClCompile Include="..\src\vec3.c" />
|
<ClCompile Include="..\src\vec3.c" />
|
||||||
<ClCompile Include="..\src\vec4.c" />
|
<ClCompile Include="..\src\vec4.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -50,6 +51,7 @@
|
|||||||
<ClInclude Include="..\include\cglm\call\plane.h" />
|
<ClInclude Include="..\include\cglm\call\plane.h" />
|
||||||
<ClInclude Include="..\include\cglm\call\project.h" />
|
<ClInclude Include="..\include\cglm\call\project.h" />
|
||||||
<ClInclude Include="..\include\cglm\call\quat.h" />
|
<ClInclude Include="..\include\cglm\call\quat.h" />
|
||||||
|
<ClInclude Include="..\include\cglm\call\sphere.h" />
|
||||||
<ClInclude Include="..\include\cglm\call\vec3.h" />
|
<ClInclude Include="..\include\cglm\call\vec3.h" />
|
||||||
<ClInclude Include="..\include\cglm\call\vec4.h" />
|
<ClInclude Include="..\include\cglm\call\vec4.h" />
|
||||||
<ClInclude Include="..\include\cglm\cam.h" />
|
<ClInclude Include="..\include\cglm\cam.h" />
|
||||||
@@ -72,6 +74,7 @@
|
|||||||
<ClInclude Include="..\include\cglm\simd\sse2\mat3.h" />
|
<ClInclude Include="..\include\cglm\simd\sse2\mat3.h" />
|
||||||
<ClInclude Include="..\include\cglm\simd\sse2\mat4.h" />
|
<ClInclude Include="..\include\cglm\simd\sse2\mat4.h" />
|
||||||
<ClInclude Include="..\include\cglm\simd\sse2\quat.h" />
|
<ClInclude Include="..\include\cglm\simd\sse2\quat.h" />
|
||||||
|
<ClInclude Include="..\include\cglm\sphere.h" />
|
||||||
<ClInclude Include="..\include\cglm\types.h" />
|
<ClInclude Include="..\include\cglm\types.h" />
|
||||||
<ClInclude Include="..\include\cglm\util.h" />
|
<ClInclude Include="..\include\cglm\util.h" />
|
||||||
<ClInclude Include="..\include\cglm\vec3-ext.h" />
|
<ClInclude Include="..\include\cglm\vec3-ext.h" />
|
||||||
|
|||||||
@@ -78,6 +78,9 @@
|
|||||||
<ClCompile Include="..\src\project.c">
|
<ClCompile Include="..\src\project.c">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\src\sphere.c">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\config.h">
|
<ClInclude Include="..\src\config.h">
|
||||||
@@ -215,5 +218,11 @@
|
|||||||
<ClInclude Include="..\include\cglm\call\project.h">
|
<ClInclude Include="..\include\cglm\call\project.h">
|
||||||
<Filter>include\cglm\call</Filter>
|
<Filter>include\cglm\call</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\include\cglm\call\sphere.h">
|
||||||
|
<Filter>include\cglm\call</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\include\cglm\sphere.h">
|
||||||
|
<Filter>include\cglm</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user