mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf4c5b4e26 | ||
|
|
f388df7f3e | ||
|
|
4c872238d9 | ||
|
|
edfb5e3984 | ||
|
|
4d43241a69 | ||
|
|
1337e9cdfb | ||
|
|
9df36ce005 | ||
|
|
55521ecd61 | ||
|
|
829b7dddce | ||
|
|
2fced7181a | ||
|
|
1de373a9bd | ||
|
|
6a7d03bafb | ||
|
|
aad5223da0 | ||
|
|
707bff021c |
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.8.2)
|
||||
project(cglm
|
||||
VERSION 0.9.3
|
||||
VERSION 0.9.4
|
||||
HOMEPAGE_URL https://github.com/recp/cglm
|
||||
DESCRIPTION "OpenGL Mathematics (glm) for C"
|
||||
LANGUAGES C
|
||||
|
||||
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
|
||||
|
||||
# Description
|
||||
s.name = "cglm"
|
||||
s.version = "0.9.2"
|
||||
s.version = "0.9.3"
|
||||
s.summary = "📽 Highly Optimized Graphics Math (glm) for C"
|
||||
s.description = <<-DESC
|
||||
cglm is math library for graphics programming for C. See the documentation or README for all features.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#*****************************************************************************
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([cglm], [0.9.3], [info@recp.me])
|
||||
AC_INIT([cglm], [0.9.4], [info@recp.me])
|
||||
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects serial-tests])
|
||||
|
||||
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.
|
||||
|
||||
@@ -91,6 +91,9 @@ To configure the Struct API namespace, you can define the following macros befor
|
||||
- **CGLM_STRUCT_API_NS**: define name space for struct api, DEFAULT is **glms**
|
||||
- **CGLM_STRUCT_API_NAME_SUFFIX**: define name suffix, DEFAULT is **empty** e.g defining it as #define CGLM_STRUCT_API_NAME_SUFFIX s will add s suffix to mat4_mul -> mat4s_mul
|
||||
|
||||
❗️ IMPORTANT ❗️
|
||||
|
||||
It's a good idea to set up your config macros in build settings like CMake, Xcode, or Visual Studio. This is especially important if you're using features like Modules in Xcode, where adding macros directly before the **cglm** headers might not work.
|
||||
|
||||
Detailed documentation for Struct API:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'0.9.2'
|
||||
version = u'0.9.4'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'0.9.2'
|
||||
release = u'0.9.4'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
@@ -5,35 +5,33 @@
|
||||
|
||||
A few options are provided via macros.
|
||||
|
||||
❗️ IMPORTANT ❗️
|
||||
|
||||
It's a good idea to set up your config macros in build settings like CMake, Xcode, or Visual Studio. This is especially important if you're using features like Modules in Xcode, where adding macros directly before the **cglm** headers might not work.
|
||||
|
||||
Alignment Option
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
As default, cglm requires types to be aligned. Alignment requirements:
|
||||
By default, **cglm** requires types to be aligned with specific byte requirements:
|
||||
|
||||
vec3: 8 byte
|
||||
vec4: 16 byte
|
||||
mat4: 16 byte
|
||||
versor: 16 byte
|
||||
- vec3: 8 bytes
|
||||
- vec4: 16 bytes
|
||||
- mat4: 16 bytes (32 on AVX)
|
||||
- versor: 16 bytes
|
||||
|
||||
By starting **v0.4.5** cglm provides an option to disable alignment requirement.
|
||||
To enable this option define **CGLM_ALL_UNALIGNED** macro before all headers.
|
||||
You can define it in Xcode, Visual Studio (or other IDEs) or you can also prefer
|
||||
to define it in build system. If you use pre-compiled versions then you
|
||||
have to compile cglm with **CGLM_ALL_UNALIGNED** macro.
|
||||
Starting with **v0.4.5**, **cglm** offers an option to relax these alignment requirements. To use this option, define the **CGLM_ALL_UNALIGNED** macro before including any headers. This definition can be made within Xcode, Visual Studio, other IDEs, or directly in your build system. If using pre-compiled versions of **cglm**, you'll need to compile them with the **CGLM_ALL_UNALIGNED** macro.
|
||||
|
||||
**VERY VERY IMPORTANT:** If you use cglm in multiple projects and
|
||||
those projects are depends on each other, then
|
||||
**❗️NOTE:❗️** If you're using **cglm** across multiple interdependent projects:
|
||||
|
||||
| *ALWAYS* or *NEVER USE* **CGLM_ALL_UNALIGNED** macro in linked projects
|
||||
- Always or never use the **CGLM_ALL_UNALIGNED** macro in all linked projects to avoid configuration conflicts. A **cglm** header from one project could require alignment, while a header from another might not, leading to **cglm** functions accessing invalid memory locations.
|
||||
|
||||
if you do not know what you are doing. Because a cglm header included
|
||||
via 'project A' may force types to be aligned and another cglm header
|
||||
included via 'project B' may not require alignment. In this case
|
||||
cglm functions will read from and write to **INVALID MEMORY LOCATIONSNs**.
|
||||
- **Key Point:** Maintain the same **cglm** configuration across all your projects. For example, if you activate **CGLM_ALL_UNALIGNED** in one project, ensure it's set in the others too.
|
||||
|
||||
ALWAYS USE SAME CONFIGURATION / OPTION for **cglm** if you have multiple projects.
|
||||
**❗️NOTE:❗️**
|
||||
|
||||
For instance if you set CGLM_ALL_UNALIGNED in a project then set it in other projects too
|
||||
While **CGLM_ALL_UNALIGNED** allows for flexibility in alignment, it doesn't override C's fundamental alignment rules. For example, an array like *vec4* decays to a pointer (float*) in functions, which must adhere to the alignment requirements of a float pointer (4 bytes). This adherence is crucial because **cglm** directly dereferences these pointers instead of copying data, and failing to meet alignment requirements can lead to unpredictable errors, such as crashes.
|
||||
|
||||
You can use `CGLM_ALIGN` and `CGLM_ALIGN_MAT` macros for aligning local variables or struct members. However, when dealing with dynamic memory allocation or custom memory locations, you'll need to ensure alignment requirements are met appropriately for those cases
|
||||
|
||||
Clipspace Option[s]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -36,9 +36,11 @@ Functions documentation
|
||||
|
||||
ray sphere intersection
|
||||
|
||||
returns false if there is no intersection if true:
|
||||
|
||||
- t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin
|
||||
- t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2
|
||||
- t1 < 0, t2 < 0: no intersection ahead of the ray
|
||||
- t1 < 0, t2 < 0: no intersection ahead of the ray ( returns false )
|
||||
- the caller can check if the intersection points (t1 and t2) fall within a
|
||||
specific range (for example, tmin < t1, t2 < tmax) to determine if the
|
||||
intersections are within a desired segment of the ray
|
||||
|
||||
@@ -397,24 +397,28 @@ Functions documentation
|
||||
| *[in]* **src** pointer to an array of floats
|
||||
| *[out]* **dest** destination vector
|
||||
|
||||
.. c:function:: void glm_vec2_reflect(vec2 I, vec2 N, vec2 dest)
|
||||
.. c:function:: void glm_vec2_reflect(vec2 v, vec2 n, vec2 dest)
|
||||
|
||||
Reflection vector using an incident ray and a surface normal
|
||||
|
||||
Parameters:
|
||||
| *[in]* **I** incident vector
|
||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **v** incident vector
|
||||
| *[in]* **n** *❗️ normalized ❗️* normal vector
|
||||
| *[out]* **dest** destination: reflection result
|
||||
|
||||
.. c:function:: void glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest)
|
||||
.. c:function:: bool glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest)
|
||||
|
||||
Refraction vector using entering ray, surface normal and refraction index
|
||||
Computes refraction vector for an incident vector and a surface normal.
|
||||
|
||||
If the angle between the entering ray I and the surface normal N is too
|
||||
great for a given refraction index, the return value is zero
|
||||
Calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
|
||||
Parameters:
|
||||
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **eta** ratio of indices of refraction ( η )
|
||||
| *[out]* **dest** destination: refraction result
|
||||
| *[in]* **v** *❗️ normalized ❗️* incident vector
|
||||
| *[in]* **n** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **eta** ratio of indices of refraction (incident/transmitted)
|
||||
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise
|
||||
|
||||
Returns:
|
||||
returns true if refraction occurs; false if total internal reflection occurs.
|
||||
|
||||
@@ -516,34 +516,39 @@ Functions documentation
|
||||
| *[in]* **src** pointer to an array of floats
|
||||
| *[out]* **dest** destination vector
|
||||
|
||||
.. c:function:: void glm_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest)
|
||||
.. c:function:: void glm_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest)
|
||||
|
||||
A vector pointing in the same direction as another
|
||||
|
||||
Parameters:
|
||||
| *[in]* **N** vector to orient
|
||||
| *[in]* **I** incident vector
|
||||
| *[in]* **Nref** reference vector
|
||||
| *[in]* **n** vector to orient
|
||||
| *[in]* **v** incident vector
|
||||
| *[in]* **nref** reference vector
|
||||
| *[out]* **dest** destination: oriented vector, pointing away from the surface.
|
||||
|
||||
.. c:function:: void glm_vec3_reflect(vec3 I, vec3 N, vec3 dest)
|
||||
.. c:function:: void glm_vec3_reflect(vec3 v, vec3 n, vec3 dest)
|
||||
|
||||
Reflection vector using an incident ray and a surface normal
|
||||
|
||||
Parameters:
|
||||
| *[in]* **I** incident vector
|
||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **v** incident vector
|
||||
| *[in]* **n** *❗️ normalized ❗️* normal vector
|
||||
| *[out]* **dest** destination: reflection result
|
||||
|
||||
.. c:function:: void glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest)
|
||||
.. c:function:: bool glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest)
|
||||
|
||||
Refraction vector using entering ray, surface normal and refraction index
|
||||
|
||||
If the angle between the entering ray I and the surface normal N is too
|
||||
great for a given refraction index, the return value is zero
|
||||
Computes refraction vector for an incident vector and a surface normal.
|
||||
|
||||
Calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
|
||||
Parameters:
|
||||
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **eta** ratio of indices of refraction ( η )
|
||||
| *[out]* **dest** destination: refraction result
|
||||
| *[in]* **v** *❗️ normalized ❗️* incident vector
|
||||
| *[in]* **n** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **eta** ratio of indices of refraction (incident/transmitted)
|
||||
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise
|
||||
|
||||
Returns:
|
||||
returns true if refraction occurs; false if total internal reflection occurs.
|
||||
|
||||
@@ -427,28 +427,32 @@ Functions documentation
|
||||
| *[in]* **src** pointer to an array of floats
|
||||
| *[out]* **dest** destination vector
|
||||
|
||||
.. c:function:: void glm_vec4_reflect(vec4 I, vec4 N, vec4 dest)
|
||||
.. c:function:: bool glm_vec4_reflect(vec4 v, vec4 n, vec4 dest)
|
||||
|
||||
Reflection vector using an incident ray and a surface normal
|
||||
|
||||
Parameters:
|
||||
| *[in]* **I** incident vector
|
||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **v** incident vector
|
||||
| *[in]* **n** *❗️ normalized ❗️* normal vector
|
||||
| *[out]* **dest** destination: reflection result
|
||||
|
||||
.. c:function:: void glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest)
|
||||
.. c:function:: bool glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest)
|
||||
|
||||
Refraction vector using entering ray, surface normal and refraction index
|
||||
computes refraction vector for an incident vector and a surface normal.
|
||||
|
||||
If the angle between the entering ray I and the surface normal N is too
|
||||
great for a given refraction index, the return value is zero
|
||||
Calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
|
||||
this implementation does not explicitly preserve the 'w' component of the
|
||||
This implementation does not explicitly preserve the 'w' component of the
|
||||
incident vector 'I' in the output 'dest', users requiring the preservation of
|
||||
the 'w' component should manually adjust 'dest' after calling this function.
|
||||
|
||||
Parameters:
|
||||
| *[in]* **I** *❗️ normalized ❗️* incident vector
|
||||
| *[in]* **N** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **eta** ratio of indices of refraction ( η )
|
||||
| *[out]* **dest** destination: refraction result
|
||||
| *[in]* **v** *❗️ normalized ❗️* incident vector
|
||||
| *[in]* **n** *❗️ normalized ❗️* normal vector
|
||||
| *[in]* **eta** ratio of indices of refraction (incident/transmitted)
|
||||
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise
|
||||
|
||||
Returns:
|
||||
returns true if refraction occurs; false if total internal reflection occurs.
|
||||
|
||||
@@ -199,11 +199,11 @@ glmc_vec2_make(const float * __restrict src, vec2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest);
|
||||
glmc_vec2_reflect(vec2 v, vec2 n, vec2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest);
|
||||
bool
|
||||
glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -336,15 +336,15 @@ glmc_vec3_make(const float * __restrict src, vec3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest);
|
||||
glmc_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest);
|
||||
glmc_vec3_reflect(vec3 v, vec3 n, vec3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest);
|
||||
bool
|
||||
glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -313,11 +313,11 @@ glmc_vec4_make(const float * __restrict src, vec4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest);
|
||||
glmc_vec4_reflect(vec4 v, vec4 n, vec4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest);
|
||||
bool
|
||||
glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -37,6 +37,14 @@
|
||||
# define CGLM_INLINE static inline __attribute((always_inline))
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define CGLM_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
||||
# define CGLM_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
||||
#else
|
||||
# define CGLM_UNLIKELY(expr) (expr)
|
||||
# define CGLM_LIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
#define GLM_SHUFFLE4(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
|
||||
#define GLM_SHUFFLE3(z, y, x) (((z) << 4) | ((y) << 2) | (x))
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ void
|
||||
glm_plane_normalize(vec4 plane) {
|
||||
float norm;
|
||||
|
||||
if ((norm = glm_vec3_norm(plane)) == 0.0f) {
|
||||
if (CGLM_UNLIKELY((norm = glm_vec3_norm(plane)) < FLT_EPSILON)) {
|
||||
glm_vec4_zero(plane);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,9 +82,11 @@ glm_ray_triangle(vec3 origin,
|
||||
/*!
|
||||
* @brief ray sphere intersection
|
||||
*
|
||||
* returns false if there is no intersection if true:
|
||||
*
|
||||
* - t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin
|
||||
* - t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2
|
||||
* - t1 < 0, t2 < 0: no intersection ahead of the ray
|
||||
* - t1 < 0, t2 < 0: no intersection ahead of the ray ( returns false )
|
||||
* - the caller can check if the intersection points (t1 and t2) fall within a
|
||||
* specific range (for example, tmin < t1, t2 < tmax) to determine if the
|
||||
* intersections are within a desired segment of the ray
|
||||
@@ -94,6 +96,8 @@ glm_ray_triangle(vec3 origin,
|
||||
* @param[in] s sphere [center.x, center.y, center.z, radii]
|
||||
* @param[in] t1 near point1 (closer to origin)
|
||||
* @param[in] t2 far point2 (farther from origin)
|
||||
*
|
||||
* @returns whether there is intersection
|
||||
*/
|
||||
CGLM_INLINE
|
||||
bool
|
||||
@@ -105,7 +109,6 @@ glm_ray_sphere(vec3 origin,
|
||||
vec3 dp;
|
||||
float r2, ddp, dpp, dscr, q, tmp, _t1, _t2;
|
||||
|
||||
/* ensure dir is normalized */
|
||||
glm_vec3_sub(s, origin, dp);
|
||||
|
||||
ddp = glm_vec3_dot(dir, dp);
|
||||
|
||||
@@ -40,9 +40,11 @@ glms_ray_(triangle)(vec3s origin,
|
||||
/*!
|
||||
* @brief ray sphere intersection
|
||||
*
|
||||
* returns false if there is no intersection if true:
|
||||
*
|
||||
* - t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin
|
||||
* - t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2
|
||||
* - t1 < 0, t2 < 0: no intersection ahead of the ray
|
||||
* - t1 < 0, t2 < 0: no intersection ahead of the ray ( returns false )
|
||||
* - the caller can check if the intersection points (t1 and t2) fall within a
|
||||
* specific range (for example, tmin < t1, t2 < tmax) to determine if the
|
||||
* intersections are within a desired segment of the ray
|
||||
@@ -52,6 +54,8 @@ glms_ray_(triangle)(vec3s origin,
|
||||
* @param[in] s sphere [center.x, center.y, center.z, radii]
|
||||
* @param[in] t1 near point1 (closer to origin)
|
||||
* @param[in] t2 far point2 (farther from origin)
|
||||
*
|
||||
* @returns whether there is intersection
|
||||
*/
|
||||
CGLM_INLINE
|
||||
bool
|
||||
@@ -75,7 +79,7 @@ CGLM_INLINE
|
||||
vec3s
|
||||
glms_ray_(at)(vec3s orig, vec3s dir, float t) {
|
||||
vec3s r;
|
||||
glm_ray_at(orig.raw, orig.raw, t, r.raw);
|
||||
glm_ray_at(orig.raw, dir.raw, t, r.raw);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@
|
||||
CGLM_INLINE vec2s glms_vec2_clamp(vec2s v, float minVal, float maxVal)
|
||||
CGLM_INLINE vec2s glms_vec2_lerp(vec2s from, vec2s to, float t)
|
||||
CGLM_INLINE vec2s glms_vec2_make(float * restrict src)
|
||||
CGLM_INLINE vec2s glms_vec2_reflect(vec2s I, vec2s N)
|
||||
CGLM_INLINE vec2s glms_vec2_refract(vec2s I, vec2s N, float eta)
|
||||
CGLM_INLINE vec2s glms_vec2_reflect(vec2s v, vec2s n)
|
||||
CGLM_INLINE bool glms_vec2_refract(vec2s v, vec2s n, float eta, vec2s *dest)
|
||||
*/
|
||||
|
||||
#ifndef cglms_vec2s_h
|
||||
@@ -702,29 +702,30 @@ glms_vec2_(make)(const float * __restrict src) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec2s
|
||||
glms_vec2_(reflect)(vec2s I, vec2s N) {
|
||||
glms_vec2_(reflect)(vec2s v, vec2s n) {
|
||||
vec2s dest;
|
||||
glm_vec2_reflect(I.raw, N.raw, dest.raw);
|
||||
glm_vec2_reflect(v.raw, n.raw, dest.raw);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief refraction vector using entering ray, surface normal and refraction index
|
||||
* @brief computes refraction vector for an incident vector and a surface normal.
|
||||
*
|
||||
* if the angle between the entering ray I and the surface normal N is too great
|
||||
* for a given refraction index, the return value is zero
|
||||
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
* occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
* Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
*
|
||||
* @param[in] I normalized incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction
|
||||
* @param[out] dest refraction result
|
||||
* @param[in] v normalized incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||
*
|
||||
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec2s
|
||||
glms_vec2_(refract)(vec2s I, vec2s N, float eta) {
|
||||
vec2s dest;
|
||||
glm_vec2_refract(I.raw, N.raw, eta, dest.raw);
|
||||
return dest;
|
||||
bool
|
||||
glms_vec2_(refract)(vec2s v, vec2s n, float eta, vec2s * __restrict dest) {
|
||||
return glm_vec2_refract(v.raw, n.raw, eta, dest->raw);
|
||||
}
|
||||
|
||||
#endif /* cglms_vec2s_h */
|
||||
|
||||
@@ -76,9 +76,9 @@
|
||||
CGLM_INLINE vec3s glms_vec3_smoothinterpc(vec3s from, vec3s to, float t);
|
||||
CGLM_INLINE vec3s glms_vec3_swizzle(vec3s v, int mask);
|
||||
CGLM_INLINE vec3s glms_vec3_make(float * restrict src);
|
||||
CGLM_INLINE vec3s glms_vec3_faceforward(vec3s N, vec3s I, vec3s Nref);
|
||||
CGLM_INLINE vec3s glms_vec3_reflect(vec3s I, vec3s N);
|
||||
CGLM_INLINE vec3s glms_vec3_refract(vec3s I, vec3s N, float eta);
|
||||
CGLM_INLINE vec3s glms_vec3_faceforward(vec3s n, vec3s v, vec3s nref);
|
||||
CGLM_INLINE vec3s glms_vec3_reflect(vec3s v, vec3s n);
|
||||
CGLM_INLINE bool glms_vec3_refract(vec3s v, vec3s n, float eta, vec3s *dest)
|
||||
|
||||
Convenient:
|
||||
CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b);
|
||||
@@ -1091,16 +1091,16 @@ glms_vec3_(make)(const float * __restrict src) {
|
||||
*
|
||||
* orients a vector to point away from a surface as defined by its normal
|
||||
*
|
||||
* @param[in] N vector to orient.
|
||||
* @param[in] I incident vector
|
||||
* @param[in] Nref reference vector
|
||||
* @param[in] n vector to orient.
|
||||
* @param[in] v incident vector
|
||||
* @param[in] nref reference vector
|
||||
* @returns oriented vector, pointing away from the surface.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec3s
|
||||
glms_vec3_(faceforward)(vec3s N, vec3s I, vec3s Nref) {
|
||||
glms_vec3_(faceforward)(vec3s n, vec3s v, vec3s nref) {
|
||||
vec3s dest;
|
||||
glm_vec3_faceforward(N.raw, I.raw, Nref.raw, dest.raw);
|
||||
glm_vec3_faceforward(n.raw, v.raw, nref.raw, dest.raw);
|
||||
return dest;
|
||||
}
|
||||
|
||||
@@ -1113,29 +1113,30 @@ glms_vec3_(faceforward)(vec3s N, vec3s I, vec3s Nref) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec3s
|
||||
glms_vec3_(reflect)(vec3s I, vec3s N) {
|
||||
glms_vec3_(reflect)(vec3s v, vec3s n) {
|
||||
vec3s dest;
|
||||
glm_vec3_reflect(I.raw, N.raw, dest.raw);
|
||||
glm_vec3_reflect(v.raw, n.raw, dest.raw);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief refraction vector using entering ray, surface normal and refraction index
|
||||
* @brief computes refraction vector for an incident vector and a surface normal.
|
||||
*
|
||||
* if the angle between the entering ray I and the surface normal N is too great
|
||||
* for a given refraction index, the return value is zero
|
||||
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
* occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
* Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
*
|
||||
* @param[in] I normalized incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction
|
||||
* @returns refraction result
|
||||
* @param[in] v normalized incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||
*
|
||||
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec3s
|
||||
glms_vec3_(refract)(vec3s I, vec3s N, float eta) {
|
||||
vec3s dest;
|
||||
glm_vec3_refract(I.raw, N.raw, eta, dest.raw);
|
||||
return dest;
|
||||
bool
|
||||
glms_vec3_(refract)(vec3s v, vec3s n, float eta, vec3s * __restrict dest) {
|
||||
return glm_vec3_refract(v.raw, n.raw, eta, dest->raw);
|
||||
}
|
||||
|
||||
#endif /* cglms_vec3s_h */
|
||||
|
||||
@@ -67,8 +67,8 @@
|
||||
CGLM_INLINE vec4s glms_vec4_cubic(float s);
|
||||
CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
|
||||
CGLM_INLINE vec4s glms_vec4_make(float * restrict src);
|
||||
CGLM_INLINE vec4s glms_vec4_reflect(vec4s I, vec4s N);
|
||||
CGLM_INLINE vec4s glms_vec4_refract(vec4s I, vec4s N, float eta);
|
||||
CGLM_INLINE vec4s glms_vec4_reflect(vec4s v, vec4s n);
|
||||
CGLM_INLINE bool glms_vec4_refract(vec4s v, vec4s n, float eta, vec4s *dest)
|
||||
*/
|
||||
|
||||
#ifndef cglms_vec4s_h
|
||||
@@ -932,39 +932,40 @@ glms_vec4_(make)(const float * __restrict src) {
|
||||
/*!
|
||||
* @brief reflection vector using an incident ray and a surface normal
|
||||
*
|
||||
* @param[in] I incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] v incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @returns reflection result
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec4s
|
||||
glms_vec4_(reflect)(vec4s I, vec4s N) {
|
||||
glms_vec4_(reflect)(vec4s v, vec4s n) {
|
||||
vec4s dest;
|
||||
glm_vec4_reflect(I.raw, N.raw, dest.raw);
|
||||
glm_vec4_reflect(v.raw, n.raw, dest.raw);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief refraction vector using entering ray, surface normal and refraction index
|
||||
* @brief computes refraction vector for an incident vector and a surface normal.
|
||||
*
|
||||
* if the angle between the entering ray I and the surface normal N is too great
|
||||
* for a given refraction index, the return value is zero
|
||||
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
* occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
* Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
*
|
||||
* this implementation does not explicitly preserve the 'w' component of the
|
||||
* incident vector 'I' in the output 'dest', users requiring the preservation of
|
||||
* the 'w' component should manually adjust 'dest' after calling this function.
|
||||
*
|
||||
* @param[in] I normalized incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction
|
||||
* @returns refraction result
|
||||
* @param[in] v normalized incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||
*
|
||||
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec4s
|
||||
glms_vec4_(refract)(vec4s I, vec4s N, float eta) {
|
||||
vec4s dest;
|
||||
glm_vec4_refract(I.raw, N.raw, eta, dest.raw);
|
||||
return dest;
|
||||
bool
|
||||
glms_vec4_(refract)(vec4s v, vec4s n, float eta, vec4s * __restrict dest) {
|
||||
return glm_vec4_refract(v.raw, n.raw, eta, dest->raw);
|
||||
}
|
||||
|
||||
#endif /* cglms_vec4s_h */
|
||||
|
||||
@@ -55,8 +55,8 @@
|
||||
CGLM_INLINE void glm_vec2_clamp(vec2 v, float minVal, float maxVal)
|
||||
CGLM_INLINE void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_make(float * restrict src, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_reflect(vec2 I, vec2 N, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_reflect(vec2 v, vec2 n, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest)
|
||||
*/
|
||||
|
||||
#ifndef cglm_vec2_h
|
||||
@@ -278,7 +278,7 @@ glm_vec2_scale_as(vec2 v, float s, vec2 dest) {
|
||||
float norm;
|
||||
norm = glm_vec2_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
glm_vec2_zero(dest);
|
||||
return;
|
||||
}
|
||||
@@ -542,7 +542,7 @@ glm_vec2_normalize(vec2 v) {
|
||||
|
||||
norm = glm_vec2_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
v[0] = v[1] = 0.0f;
|
||||
return;
|
||||
}
|
||||
@@ -563,7 +563,7 @@ glm_vec2_normalize_to(vec2 v, vec2 dest) {
|
||||
|
||||
norm = glm_vec2_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
glm_vec2_zero(dest);
|
||||
return;
|
||||
}
|
||||
@@ -716,45 +716,49 @@ glm_vec2_make(const float * __restrict src, vec2 dest) {
|
||||
/*!
|
||||
* @brief reflection vector using an incident ray and a surface normal
|
||||
*
|
||||
* @param[in] I incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] v incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[out] dest destination vector for the reflection result
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) {
|
||||
glm_vec2_reflect(vec2 v, vec2 n, vec2 dest) {
|
||||
vec2 temp;
|
||||
glm_vec2_scale(N, 2.0f * glm_vec2_dot(I, N), temp);
|
||||
glm_vec2_sub(I, temp, dest);
|
||||
glm_vec2_scale(n, 2.0f * glm_vec2_dot(v, n), temp);
|
||||
glm_vec2_sub(v, temp, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief refraction vector using entering ray, surface normal and refraction index
|
||||
* @brief computes refraction vector for an incident vector and a surface normal.
|
||||
*
|
||||
* if the angle between the entering ray I and the surface normal N is too great
|
||||
* for a given refraction index, the return value is zero
|
||||
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
* occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
* Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
*
|
||||
* @param[in] I normalized incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction
|
||||
* @param[out] dest refraction result
|
||||
* @param[in] v normalized incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||
*
|
||||
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
||||
bool
|
||||
glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
|
||||
float ndi, eni, k;
|
||||
|
||||
ndi = glm_vec2_dot(N, I);
|
||||
ndi = glm_vec2_dot(n, v);
|
||||
eni = eta * ndi;
|
||||
k = 1.0f + eta * eta - eni * eni;
|
||||
|
||||
if (k < 0.0f) {
|
||||
glm_vec2_zero(dest);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
glm_vec2_scale(I, eta, dest);
|
||||
glm_vec2_mulsubs(N, eni + sqrtf(k), dest);
|
||||
glm_vec2_scale(v, eta, dest);
|
||||
glm_vec2_mulsubs(n, eni + sqrtf(k), dest);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* cglm_vec2_h */
|
||||
|
||||
@@ -80,9 +80,9 @@
|
||||
CGLM_INLINE void glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_swizzle(vec3 v, int mask, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_make(float * restrict src, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_reflect(vec3 I, vec3 N, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_reflect(vec3 v, vec3 n, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
|
||||
|
||||
Convenient:
|
||||
CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d);
|
||||
@@ -372,7 +372,7 @@ glm_vec3_scale_as(vec3 v, float s, vec3 dest) {
|
||||
float norm;
|
||||
norm = glm_vec3_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
glm_vec3_zero(dest);
|
||||
return;
|
||||
}
|
||||
@@ -651,7 +651,7 @@ glm_vec3_normalize(vec3 v) {
|
||||
|
||||
norm = glm_vec3_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
v[0] = v[1] = v[2] = 0.0f;
|
||||
return;
|
||||
}
|
||||
@@ -672,7 +672,7 @@ glm_vec3_normalize_to(vec3 v, vec3 dest) {
|
||||
|
||||
norm = glm_vec3_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
glm_vec3_zero(dest);
|
||||
return;
|
||||
}
|
||||
@@ -1210,65 +1210,69 @@ glm_vec3_make(const float * __restrict src, vec3 dest) {
|
||||
*
|
||||
* orients a vector to point away from a surface as defined by its normal
|
||||
*
|
||||
* @param[in] N vector to orient
|
||||
* @param[in] I incident vector
|
||||
* @param[in] Nref reference vector
|
||||
* @param[in] n vector to orient
|
||||
* @param[in] v incident vector
|
||||
* @param[in] nref reference vector
|
||||
* @param[out] dest oriented vector, pointing away from the surface
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest) {
|
||||
if (glm_vec3_dot(I, Nref) < 0.0f) {
|
||||
glm_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest) {
|
||||
if (glm_vec3_dot(v, nref) < 0.0f) {
|
||||
/* N is facing away from I */
|
||||
glm_vec3_copy(N, dest);
|
||||
glm_vec3_copy(n, dest);
|
||||
} else {
|
||||
/* N is facing towards I, negate it */
|
||||
glm_vec3_negate_to(N, dest);
|
||||
glm_vec3_negate_to(n, dest);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief reflection vector using an incident ray and a surface normal
|
||||
*
|
||||
* @param[in] I incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] v incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[out] dest reflection result
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec3_reflect(vec3 I, vec3 N, vec3 dest) {
|
||||
glm_vec3_reflect(vec3 v, vec3 n, vec3 dest) {
|
||||
vec3 temp;
|
||||
glm_vec3_scale(N, 2.0f * glm_vec3_dot(I, N), temp);
|
||||
glm_vec3_sub(I, temp, dest);
|
||||
glm_vec3_scale(n, 2.0f * glm_vec3_dot(v, n), temp);
|
||||
glm_vec3_sub(v, temp, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief refraction vector using entering ray, surface normal and refraction index
|
||||
* @brief computes refraction vector for an incident vector and a surface normal.
|
||||
*
|
||||
* if the angle between the entering ray I and the surface normal N is too great
|
||||
* for a given refraction index, the return value is zero
|
||||
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
* occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
* Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
*
|
||||
* @param[in] I normalized incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction
|
||||
* @param[out] dest refraction result
|
||||
* @param[in] v normalized incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||
*
|
||||
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
|
||||
bool
|
||||
glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
|
||||
float ndi, eni, k;
|
||||
|
||||
ndi = glm_vec3_dot(N, I);
|
||||
ndi = glm_vec3_dot(n, v);
|
||||
eni = eta * ndi;
|
||||
k = 1.0f + eta * eta - eni * eni;
|
||||
|
||||
if (k < 0.0f) {
|
||||
glm_vec3_zero(dest);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
glm_vec3_scale(I, eta, dest);
|
||||
glm_vec3_mulsubs(N, eni + sqrtf(k), dest);
|
||||
glm_vec3_scale(v, eta, dest);
|
||||
glm_vec3_mulsubs(n, eni + sqrtf(k), dest);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* cglm_vec3_h */
|
||||
|
||||
@@ -65,8 +65,8 @@
|
||||
CGLM_INLINE void glm_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_swizzle(vec4 v, int mask, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_make(float * restrict src, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_reflect(vec4 I, vec4 N, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_reflect(vec4 v, vec4 n, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
|
||||
|
||||
DEPRECATED:
|
||||
glm_vec4_dup
|
||||
@@ -487,7 +487,7 @@ glm_vec4_scale_as(vec4 v, float s, vec4 dest) {
|
||||
float norm;
|
||||
norm = glm_vec4_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
glm_vec4_zero(dest);
|
||||
return;
|
||||
}
|
||||
@@ -918,7 +918,7 @@ glm_vec4_normalize_to(vec4 v, vec4 dest) {
|
||||
/* dot = _mm_cvtss_f32(xdot); */
|
||||
dot = wasm_f32x4_extract_lane(xdot, 0);
|
||||
|
||||
if (dot == 0.0f) {
|
||||
if (CGLM_UNLIKELY(dot < FLT_EPSILON)) {
|
||||
glmm_store(dest, wasm_f32x4_const_splat(0.f));
|
||||
return;
|
||||
}
|
||||
@@ -932,7 +932,7 @@ glm_vec4_normalize_to(vec4 v, vec4 dest) {
|
||||
xdot = glmm_vdot(x0, x0);
|
||||
dot = _mm_cvtss_f32(xdot);
|
||||
|
||||
if (dot == 0.0f) {
|
||||
if (CGLM_UNLIKELY(dot < FLT_EPSILON)) {
|
||||
glmm_store(dest, _mm_setzero_ps());
|
||||
return;
|
||||
}
|
||||
@@ -943,7 +943,7 @@ glm_vec4_normalize_to(vec4 v, vec4 dest) {
|
||||
|
||||
norm = glm_vec4_norm(v);
|
||||
|
||||
if (norm == 0.0f) {
|
||||
if (CGLM_UNLIKELY(norm < FLT_EPSILON)) {
|
||||
glm_vec4_zero(dest);
|
||||
return;
|
||||
}
|
||||
@@ -1309,53 +1309,57 @@ glm_vec4_make(const float * __restrict src, vec4 dest) {
|
||||
/*!
|
||||
* @brief reflection vector using an incident ray and a surface normal
|
||||
*
|
||||
* @param[in] I incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] v incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[out] dest destination vector for the reflection result
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) {
|
||||
glm_vec4_reflect(vec4 v, vec4 n, vec4 dest) {
|
||||
vec4 temp;
|
||||
|
||||
/* TODO: direct simd touch */
|
||||
glm_vec4_scale(N, 2.0f * glm_vec4_dot(I, N), temp);
|
||||
glm_vec4_sub(I, temp, dest);
|
||||
glm_vec4_scale(n, 2.0f * glm_vec4_dot(v, n), temp);
|
||||
glm_vec4_sub(v, temp, dest);
|
||||
|
||||
dest[3] = I[3];
|
||||
dest[3] = v[3];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief refraction vector using entering ray, surface normal and refraction index
|
||||
* @brief computes refraction vector for an incident vector and a surface normal.
|
||||
*
|
||||
* if the angle between the entering ray I and the surface normal N is too great
|
||||
* for a given refraction index, the return value is zero
|
||||
* calculates the refraction vector based on Snell's law. If total internal reflection
|
||||
* occurs (angle too great given eta), dest is set to zero and returns false.
|
||||
* Otherwise, computes refraction vector, stores it in dest, and returns true.
|
||||
*
|
||||
* this implementation does not explicitly preserve the 'w' component of the
|
||||
* incident vector 'I' in the output 'dest', users requiring the preservation of
|
||||
* the 'w' component should manually adjust 'dest' after calling this function.
|
||||
*
|
||||
* @param[in] I normalized incident vector
|
||||
* @param[in] N normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction
|
||||
* @param[out] dest refraction result
|
||||
* @param[in] v normalized incident vector
|
||||
* @param[in] n normalized normal vector
|
||||
* @param[in] eta ratio of indices of refraction (incident/transmitted)
|
||||
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise
|
||||
*
|
||||
* @returns true if refraction occurs; false if total internal reflection occurs.
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
|
||||
bool
|
||||
glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
|
||||
float ndi, eni, k;
|
||||
|
||||
ndi = glm_vec4_dot(N, I);
|
||||
ndi = glm_vec4_dot(n, v);
|
||||
eni = eta * ndi;
|
||||
k = 1.0f + eta * eta - eni * eni;
|
||||
|
||||
if (k < 0.0f) {
|
||||
glm_vec4_zero(dest);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
glm_vec4_scale(I, eta, dest);
|
||||
glm_vec4_mulsubs(N, eni + sqrtf(k), dest);
|
||||
glm_vec4_scale(v, eta, dest);
|
||||
glm_vec4_mulsubs(n, eni + sqrtf(k), dest);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* cglm_vec4_h */
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
|
||||
#define CGLM_VERSION_MAJOR 0
|
||||
#define CGLM_VERSION_MINOR 9
|
||||
#define CGLM_VERSION_PATCH 3
|
||||
#define CGLM_VERSION_PATCH 4
|
||||
|
||||
#endif /* cglm_version_h */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
project('cglm', 'c',
|
||||
version : '0.9.3',
|
||||
version : '0.9.4',
|
||||
license : 'mit',
|
||||
default_options : [
|
||||
'c_std=c11',
|
||||
|
||||
10
src/vec2.c
10
src/vec2.c
@@ -305,12 +305,12 @@ glmc_vec2_make(const float * __restrict src, vec2 dest) {
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest) {
|
||||
glm_vec2_reflect(I, N, dest);
|
||||
glmc_vec2_reflect(vec2 v, vec2 n, vec2 dest) {
|
||||
glm_vec2_reflect(v, n, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
|
||||
glm_vec2_refract(I, N, eta, dest);
|
||||
bool
|
||||
glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
|
||||
return glm_vec2_refract(v, n, eta, dest);
|
||||
}
|
||||
|
||||
14
src/vec3.c
14
src/vec3.c
@@ -462,18 +462,18 @@ glmc_vec3_make(const float * __restrict src, vec3 dest) {
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest) {
|
||||
glm_vec3_faceforward(N, I, Nref, dest);
|
||||
glmc_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest) {
|
||||
glm_vec3_faceforward(n, v, nref, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest) {
|
||||
glm_vec3_reflect(I, N, dest);
|
||||
glmc_vec3_reflect(vec3 v, vec3 n, vec3 dest) {
|
||||
glm_vec3_reflect(v, n, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
|
||||
glm_vec3_refract(I, N, eta, dest);
|
||||
bool
|
||||
glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
|
||||
return glm_vec3_refract(v, n, eta, dest);
|
||||
}
|
||||
|
||||
10
src/vec4.c
10
src/vec4.c
@@ -426,12 +426,12 @@ glmc_vec4_make(const float * __restrict src, vec4 dest) {
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest) {
|
||||
glm_vec4_reflect(I, N, dest);
|
||||
glmc_vec4_reflect(vec4 v, vec4 n, vec4 dest) {
|
||||
glm_vec4_reflect(v, n, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
|
||||
glm_vec4_refract(I, N, eta, dest);
|
||||
bool
|
||||
glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
|
||||
return glm_vec4_refract(v, n, eta, dest);
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ TEST_IMPL(GLM_PREFIX, vec2_scale_as) {
|
||||
GLM(vec2_scale_as)(v1, s, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
|
||||
@@ -492,7 +492,7 @@ TEST_IMPL(GLM_PREFIX, vec2_normalize) {
|
||||
GLM(vec2_normalize)(v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
|
||||
@@ -519,7 +519,7 @@ TEST_IMPL(GLM_PREFIX, vec2_normalize_to) {
|
||||
GLM(vec2_normalize_to)(v1, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
|
||||
@@ -781,39 +781,44 @@ TEST_IMPL(GLM_PREFIX, vec2_reflect) {
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, vec2_refract) {
|
||||
vec2 I = {sqrtf(0.5f), -sqrtf(0.5f)}; /* Incoming vector at 45 degrees to normal */
|
||||
vec2 N = {0.0f, 1.0f}; /* Surface normal */
|
||||
vec2 dest;
|
||||
vec2 v = {sqrtf(0.5f), -sqrtf(0.5f)}; /* Incoming vector at 45 degrees to normal */
|
||||
vec2 N = {0.0f, 1.0f}; /* Surface normal */
|
||||
vec2 dest;
|
||||
float eta;
|
||||
float r;
|
||||
|
||||
/* Water to Air (eta = 1.33/1.0) */
|
||||
eta = 1.33f / 1.0f;
|
||||
GLM(vec2_refract)(I, N, eta, dest);
|
||||
r = GLM(vec2_refract)(v, N, eta, dest);
|
||||
// In 2D, we expect a similar bending behavior as in 3D, so we check dest[1]
|
||||
if (!(dest[0] == 0.0f && dest[1] == 0.0f)) {
|
||||
ASSERT(dest[1] < -sqrtf(0.5f)); // Refracted ray bends away from the normal
|
||||
ASSERT(r == true);
|
||||
} else {
|
||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection
|
||||
ASSERT(r == false);
|
||||
}
|
||||
|
||||
/* Air to Glass (eta = 1.0 / 1.5) */
|
||||
eta = 1.0f / 1.5f;
|
||||
GLM(vec2_refract)(I, N, eta, dest);
|
||||
r = GLM(vec2_refract)(v, N, eta, dest);
|
||||
ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal
|
||||
|
||||
/* Glass to Water (eta = 1.5 / 1.33) */
|
||||
eta = 1.5f / 1.33f;
|
||||
GLM(vec2_refract)(I, N, eta, dest);
|
||||
r = GLM(vec2_refract)(v, N, eta, dest);
|
||||
ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal, less bending than air to glass
|
||||
|
||||
/* Diamond to Air (eta = 2.42 / 1.0) */
|
||||
eta = 2.42f / 1.0f;
|
||||
GLM(vec2_refract)(I, N, eta, dest);
|
||||
r = GLM(vec2_refract)(v, N, eta, dest);
|
||||
if (!(dest[0] == 0.0f && dest[1] == 0.0f)) {
|
||||
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
ASSERT(r == true);
|
||||
} else {
|
||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f); // Total internal reflection
|
||||
ASSERT(r == false);
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
|
||||
@@ -433,7 +433,7 @@ TEST_IMPL(GLM_PREFIX, vec3_scale_as) {
|
||||
GLM(vec3_scale_as)(v1, s, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -704,7 +704,7 @@ TEST_IMPL(GLM_PREFIX, vec3_normalize) {
|
||||
GLM(vec3_normalize)(v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -733,7 +733,7 @@ TEST_IMPL(GLM_PREFIX, vec3_normalize_to) {
|
||||
GLM(vec3_normalize_to)(v1, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -764,7 +764,7 @@ TEST_IMPL(GLM_PREFIX, normalize) {
|
||||
GLM(vec3_normalize)(v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -795,7 +795,7 @@ TEST_IMPL(GLM_PREFIX, normalize_to) {
|
||||
GLM(vec3_normalize_to)(v1, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -1843,11 +1843,11 @@ TEST_IMPL(GLM_PREFIX, vec3_make) {
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, vec3_faceforward) {
|
||||
vec3 N = {0.0f, 1.0f, 0.0f};
|
||||
vec3 I = {1.0f, -1.0f, 0.0f};
|
||||
vec3 v = {1.0f, -1.0f, 0.0f};
|
||||
vec3 Nref = {0.0f, -1.0f, 0.0f};
|
||||
vec3 dest;
|
||||
|
||||
GLM(vec3_faceforward)(N, I, Nref, dest);
|
||||
GLM(vec3_faceforward)(N, v, Nref, dest);
|
||||
ASSERT(dest[0] == 0.0f
|
||||
&& dest[1] == -1.0f
|
||||
&& dest[2] == 0.0f); /* Expect N flipped */
|
||||
@@ -1886,42 +1886,47 @@ TEST_IMPL(GLM_PREFIX, vec3_reflect) {
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, vec3_refract) {
|
||||
vec3 I = {sqrtf(0.5f), -sqrtf(0.5f), 0.0f}; /* Incoming vector at 45 degrees to normal */
|
||||
vec3 N = {0.0f, 1.0f, 0.0f}; /* Surface normal */
|
||||
vec3 dest;
|
||||
vec3 v = {sqrtf(0.5f), -sqrtf(0.5f), 0.0f}; /* Incoming vector at 45 degrees to normal */
|
||||
vec3 N = {0.0f, 1.0f, 0.0f}; /* Surface normal */
|
||||
vec3 dest;
|
||||
float eta;
|
||||
bool r;
|
||||
|
||||
/* Water to Air (eta = 1.33/1.0) */
|
||||
eta = 1.33f / 1.0f;
|
||||
GLM(vec3_refract)(I, N, eta, dest);
|
||||
r = GLM(vec3_refract)(v, N, eta, dest);
|
||||
if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f)) {
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
ASSERT(r == true);
|
||||
} else {
|
||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f);
|
||||
ASSERT(r == false);
|
||||
}
|
||||
|
||||
/* Air to Glass (eta = 1.0 / 1.5) */
|
||||
eta = 1.0f / 1.5f;
|
||||
GLM(vec3_refract)(I, N, eta, dest);
|
||||
r = GLM(vec3_refract)(v, N, eta, dest);
|
||||
|
||||
/* Expect bending towards the normal */
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
|
||||
/* Glass to Water (eta = 1.5 / 1.33) */
|
||||
eta = 1.5f / 1.33f;
|
||||
GLM(vec3_refract)(I, N, eta, dest);
|
||||
r = GLM(vec3_refract)(v, N, eta, dest);
|
||||
|
||||
/* Expect bending towards the normal, less bending than air to glass */
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
|
||||
/* Diamond to Air (eta = 2.42 / 1.0) */
|
||||
eta = 2.42f / 1.0f;
|
||||
GLM(vec3_refract)(I, N, eta, dest);
|
||||
r = GLM(vec3_refract)(v, N, eta, dest);
|
||||
if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f)) {
|
||||
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
ASSERT(r == true);
|
||||
} else {
|
||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f);
|
||||
ASSERT(r == false);
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
|
||||
@@ -410,7 +410,7 @@ TEST_IMPL(GLM_PREFIX, vec4_scale_as) {
|
||||
GLM(vec4_scale_as)(v1, s, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -701,7 +701,7 @@ TEST_IMPL(GLM_PREFIX, vec4_normalize) {
|
||||
GLM(vec4_normalize)(v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -732,7 +732,7 @@ TEST_IMPL(GLM_PREFIX, vec4_normalize_to) {
|
||||
GLM(vec4_normalize_to)(v1, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||
if (norm == 0.0f) {
|
||||
if (norm < FLT_EPSILON) {
|
||||
ASSERT(test_eq(v1[0], 0.0f))
|
||||
ASSERT(test_eq(v1[1], 0.0f))
|
||||
ASSERT(test_eq(v1[2], 0.0f))
|
||||
@@ -1571,38 +1571,43 @@ TEST_IMPL(GLM_PREFIX, vec4_reflect) {
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, vec4_refract) {
|
||||
vec4 I = {sqrtf(0.5f), -sqrtf(0.5f), 0.0f, 0.0f}; /* Incoming vector */
|
||||
vec4 N = {0.0f, 1.0f, 0.0f, 0.0f}; /* Surface normal */
|
||||
vec4 dest;
|
||||
vec4 v = {sqrtf(0.5f), -sqrtf(0.5f), 0.0f, 0.0f}; /* Incoming vector */
|
||||
vec4 N = {0.0f, 1.0f, 0.0f, 0.0f}; /* Surface normal */
|
||||
vec4 dest;
|
||||
float eta;
|
||||
float r;
|
||||
|
||||
/* Water to Air (eta = 1.33/1.0) */
|
||||
eta = 1.33f / 1.0f;
|
||||
GLM(vec4_refract)(I, N, eta, dest);
|
||||
r = GLM(vec4_refract)(v, N, eta, dest);
|
||||
if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f)) {
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
ASSERT(r == true);
|
||||
} else {
|
||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f);
|
||||
ASSERT(r == false);
|
||||
}
|
||||
|
||||
/* Air to Glass (eta = 1.0 / 1.5) */
|
||||
eta = 1.0f / 1.5f;
|
||||
GLM(vec4_refract)(I, N, eta, dest);
|
||||
r = GLM(vec4_refract)(v, N, eta, dest);
|
||||
ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal
|
||||
|
||||
/* Glass to Water (eta = 1.5 / 1.33) */
|
||||
eta = 1.5f / 1.33f;
|
||||
GLM(vec4_refract)(I, N, eta, dest);
|
||||
r = GLM(vec4_refract)(v, N, eta, dest);
|
||||
ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal, less bending than air to glass
|
||||
|
||||
/* Diamond to Air (eta = 2.42 / 1.0) */
|
||||
eta = 2.42f / 1.0f;
|
||||
GLM(vec4_refract)(I, N, eta, dest);
|
||||
r = GLM(vec4_refract)(v, N, eta, dest);
|
||||
if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f)) {
|
||||
/* High potential for total internal reflection, but if it occurs, expect significant bending */
|
||||
ASSERT(dest[1] < -sqrtf(0.5f));
|
||||
ASSERT(r == true);
|
||||
} else {
|
||||
ASSERT(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f);
|
||||
ASSERT(r == false);
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
|
||||
Reference in New Issue
Block a user