Compare commits

..

10 Commits

Author SHA1 Message Date
Recep Aslantas
bf4c5b4e26 dont use I macro defined in standard 2024-03-31 13:24:50 +03:00
Recep Aslantas
f388df7f3e fix typos 2024-03-31 04:40:42 +03:00
Recep Aslantas
4c872238d9 dont use I macro defined in standard 2024-03-31 04:22:42 +03:00
Recep Aslantas
edfb5e3984 docs: alignment 2024-03-29 08:42:07 +03:00
Recep Aslantas
4d43241a69 docs: add note to enable config where may not work is some environments 2024-03-29 08:21:14 +03:00
Recep Aslantas
1337e9cdfb docs: ray sphere docs improvements 2024-03-29 08:10:56 +03:00
Recep Aslantas
9df36ce005 docs: ray sphere docs improvements 2024-03-29 08:05:10 +03:00
Recep Aslantas
55521ecd61 Merge pull request #402 from nitrix/fix/struct-api-ray-at
Struct API glms_ray_at incorrect dir param.
2024-03-29 07:55:28 +03:00
Recep Aslantas
829b7dddce now working on v0.9.4 2024-03-29 07:53:48 +03:00
Alex Belanger
2fced7181a Struct API glms_ray_at incorrect dir param. 2024-03-28 14:22:39 -04:00
29 changed files with 190 additions and 180 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.8.2) cmake_minimum_required(VERSION 3.8.2)
project(cglm project(cglm
VERSION 0.9.3 VERSION 0.9.4
HOMEPAGE_URL https://github.com/recp/cglm HOMEPAGE_URL https://github.com/recp/cglm
DESCRIPTION "OpenGL Mathematics (glm) for C" DESCRIPTION "OpenGL Mathematics (glm) for C"
LANGUAGES C LANGUAGES C

View File

@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
# Description # Description
s.name = "cglm" s.name = "cglm"
s.version = "0.9.2" s.version = "0.9.3"
s.summary = "📽 Highly Optimized Graphics Math (glm) for C" s.summary = "📽 Highly Optimized Graphics Math (glm) for C"
s.description = <<-DESC s.description = <<-DESC
cglm is math library for graphics programming for C. See the documentation or README for all features. cglm is math library for graphics programming for C. See the documentation or README for all features.

View File

@@ -7,7 +7,7 @@
#***************************************************************************** #*****************************************************************************
AC_PREREQ([2.69]) 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]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects serial-tests])
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am. # Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.

View File

@@ -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_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 - **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: Detailed documentation for Struct API:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'0.9.2' version = u'0.9.4'
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@@ -5,35 +5,33 @@
A few options are provided via macros. 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 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 - vec3: 8 bytes
vec4: 16 byte - vec4: 16 bytes
mat4: 16 byte - mat4: 16 bytes (32 on AVX)
versor: 16 byte - versor: 16 bytes
By starting **v0.4.5** cglm provides an option to disable alignment requirement. 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.
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.
**VERY VERY IMPORTANT:** If you use cglm in multiple projects and **NOTE:❗️** If you're using **cglm** across multiple interdependent projects:
those projects are depends on each other, then
| *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 - **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.
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**.
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] Clipspace Option[s]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -36,9 +36,11 @@ Functions documentation
ray sphere intersection 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 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: 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 - 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 specific range (for example, tmin < t1, t2 < tmax) to determine if the
intersections are within a desired segment of the ray intersections are within a desired segment of the ray

View File

@@ -397,16 +397,16 @@ Functions documentation
| *[in]* **src** pointer to an array of floats | *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector | *[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 Reflection vector using an incident ray and a surface normal
Parameters: Parameters:
| *[in]* **I** incident vector | *[in]* **v** incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector | *[in]* **n** *❗️ normalized ❗️* normal vector
| *[out]* **dest** destination: reflection result | *[out]* **dest** destination: reflection result
.. c:function:: bool 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)
Computes refraction vector for an incident vector and a surface normal. Computes refraction vector for an incident vector and a surface normal.
@@ -415,8 +415,8 @@ Functions documentation
Otherwise, computes refraction vector, stores it in dest, and returns true. Otherwise, computes refraction vector, stores it in dest, and returns true.
Parameters: Parameters:
| *[in]* **I** *❗️ normalized ❗️* incident vector | *[in]* **v** *❗️ normalized ❗️* incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector | *[in]* **n** *❗️ normalized ❗️* normal vector
| *[in]* **eta** ratio of indices of refraction (incident/transmitted) | *[in]* **eta** ratio of indices of refraction (incident/transmitted)
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise | *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise

View File

@@ -516,26 +516,26 @@ Functions documentation
| *[in]* **src** pointer to an array of floats | *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector | *[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 A vector pointing in the same direction as another
Parameters: Parameters:
| *[in]* **N** vector to orient | *[in]* **n** vector to orient
| *[in]* **I** incident vector | *[in]* **v** incident vector
| *[in]* **Nref** reference vector | *[in]* **nref** reference vector
| *[out]* **dest** destination: oriented vector, pointing away from the surface. | *[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 Reflection vector using an incident ray and a surface normal
Parameters: Parameters:
| *[in]* **I** incident vector | *[in]* **v** incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector | *[in]* **n** *❗️ normalized ❗️* normal vector
| *[out]* **dest** destination: reflection result | *[out]* **dest** destination: reflection result
.. c:function:: bool 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)
Computes refraction vector for an incident vector and a surface normal. Computes refraction vector for an incident vector and a surface normal.
@@ -545,8 +545,8 @@ Functions documentation
Otherwise, computes refraction vector, stores it in dest, and returns true. Otherwise, computes refraction vector, stores it in dest, and returns true.
Parameters: Parameters:
| *[in]* **I** *❗️ normalized ❗️* incident vector | *[in]* **v** *❗️ normalized ❗️* incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector | *[in]* **n** *❗️ normalized ❗️* normal vector
| *[in]* **eta** ratio of indices of refraction (incident/transmitted) | *[in]* **eta** ratio of indices of refraction (incident/transmitted)
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise | *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise

View File

@@ -427,16 +427,16 @@ Functions documentation
| *[in]* **src** pointer to an array of floats | *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: bool 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 Reflection vector using an incident ray and a surface normal
Parameters: Parameters:
| *[in]* **I** incident vector | *[in]* **v** incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector | *[in]* **n** *❗️ normalized ❗️* normal vector
| *[out]* **dest** destination: reflection result | *[out]* **dest** destination: reflection result
.. c:function:: bool 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)
computes refraction vector for an incident vector and a surface normal. computes refraction vector for an incident vector and a surface normal.
@@ -449,8 +449,8 @@ Functions documentation
the 'w' component should manually adjust 'dest' after calling this function. the 'w' component should manually adjust 'dest' after calling this function.
Parameters: Parameters:
| *[in]* **I** *❗️ normalized ❗️* incident vector | *[in]* **v** *❗️ normalized ❗️* incident vector
| *[in]* **N** *❗️ normalized ❗️* normal vector | *[in]* **n** *❗️ normalized ❗️* normal vector
| *[in]* **eta** ratio of indices of refraction (incident/transmitted) | *[in]* **eta** ratio of indices of refraction (incident/transmitted)
| *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise | *[out]* **dest** refraction vector if refraction occurs; zero vector otherwise

View File

@@ -199,11 +199,11 @@ glmc_vec2_make(const float * __restrict src, vec2 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest); glmc_vec2_reflect(vec2 v, vec2 n, vec2 dest);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest); glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -336,15 +336,15 @@ glmc_vec3_make(const float * __restrict src, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void 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 CGLM_EXPORT
void void
glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest); glmc_vec3_reflect(vec3 v, vec3 n, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest); glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -313,11 +313,11 @@ glmc_vec4_make(const float * __restrict src, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest); glmc_vec4_reflect(vec4 v, vec4 n, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest); glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -82,9 +82,11 @@ glm_ray_triangle(vec3 origin,
/*! /*!
* @brief ray sphere intersection * @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 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: 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 * - 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 * specific range (for example, tmin < t1, t2 < tmax) to determine if the
* intersections are within a desired segment of the ray * 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] s sphere [center.x, center.y, center.z, radii]
* @param[in] t1 near point1 (closer to origin) * @param[in] t1 near point1 (closer to origin)
* @param[in] t2 far point2 (farther from origin) * @param[in] t2 far point2 (farther from origin)
*
* @returns whether there is intersection
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
@@ -105,7 +109,6 @@ glm_ray_sphere(vec3 origin,
vec3 dp; vec3 dp;
float r2, ddp, dpp, dscr, q, tmp, _t1, _t2; float r2, ddp, dpp, dscr, q, tmp, _t1, _t2;
/* ensure dir is normalized */
glm_vec3_sub(s, origin, dp); glm_vec3_sub(s, origin, dp);
ddp = glm_vec3_dot(dir, dp); ddp = glm_vec3_dot(dir, dp);

View File

@@ -40,9 +40,11 @@ glms_ray_(triangle)(vec3s origin,
/*! /*!
* @brief ray sphere intersection * @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 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: 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 * - 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 * specific range (for example, tmin < t1, t2 < tmax) to determine if the
* intersections are within a desired segment of the ray * 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] s sphere [center.x, center.y, center.z, radii]
* @param[in] t1 near point1 (closer to origin) * @param[in] t1 near point1 (closer to origin)
* @param[in] t2 far point2 (farther from origin) * @param[in] t2 far point2 (farther from origin)
*
* @returns whether there is intersection
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
@@ -75,7 +79,7 @@ CGLM_INLINE
vec3s vec3s
glms_ray_(at)(vec3s orig, vec3s dir, float t) { glms_ray_(at)(vec3s orig, vec3s dir, float t) {
vec3s r; vec3s r;
glm_ray_at(orig.raw, orig.raw, t, r.raw); glm_ray_at(orig.raw, dir.raw, t, r.raw);
return r; return r;
} }

View File

@@ -54,8 +54,8 @@
CGLM_INLINE vec2s glms_vec2_clamp(vec2s v, float minVal, float maxVal) 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_lerp(vec2s from, vec2s to, float t)
CGLM_INLINE vec2s glms_vec2_make(float * restrict src) CGLM_INLINE vec2s glms_vec2_make(float * restrict src)
CGLM_INLINE vec2s glms_vec2_reflect(vec2s I, vec2s N) CGLM_INLINE vec2s glms_vec2_reflect(vec2s v, vec2s n)
CGLM_INLINE bool glms_vec2_refract(vec2s I, vec2s N, float eta, vec2s *dest) CGLM_INLINE bool glms_vec2_refract(vec2s v, vec2s n, float eta, vec2s *dest)
*/ */
#ifndef cglms_vec2s_h #ifndef cglms_vec2s_h
@@ -702,9 +702,9 @@ glms_vec2_(make)(const float * __restrict src) {
*/ */
CGLM_INLINE CGLM_INLINE
vec2s vec2s
glms_vec2_(reflect)(vec2s I, vec2s N) { glms_vec2_(reflect)(vec2s v, vec2s n) {
vec2s dest; vec2s dest;
glm_vec2_reflect(I.raw, N.raw, dest.raw); glm_vec2_reflect(v.raw, n.raw, dest.raw);
return dest; return dest;
} }
@@ -715,8 +715,8 @@ glms_vec2_(reflect)(vec2s I, vec2s N) {
* occurs (angle too great given eta), dest is set to zero and returns false. * 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. * Otherwise, computes refraction vector, stores it in dest, and returns true.
* *
* @param[in] I normalized incident vector * @param[in] v normalized incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[in] eta ratio of indices of refraction (incident/transmitted) * @param[in] eta ratio of indices of refraction (incident/transmitted)
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
* *
@@ -724,8 +724,8 @@ glms_vec2_(reflect)(vec2s I, vec2s N) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glms_vec2_(refract)(vec2s I, vec2s N, float eta, vec2s * __restrict dest) { glms_vec2_(refract)(vec2s v, vec2s n, float eta, vec2s * __restrict dest) {
return glm_vec2_refract(I.raw, N.raw, eta, dest->raw); return glm_vec2_refract(v.raw, n.raw, eta, dest->raw);
} }
#endif /* cglms_vec2s_h */ #endif /* cglms_vec2s_h */

View File

@@ -76,9 +76,9 @@
CGLM_INLINE vec3s glms_vec3_smoothinterpc(vec3s from, vec3s to, float t); 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_swizzle(vec3s v, int mask);
CGLM_INLINE vec3s glms_vec3_make(float * restrict src); 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_faceforward(vec3s n, vec3s v, vec3s nref);
CGLM_INLINE vec3s glms_vec3_reflect(vec3s I, vec3s N); CGLM_INLINE vec3s glms_vec3_reflect(vec3s v, vec3s n);
CGLM_INLINE bool glms_vec3_refract(vec3s I, vec3s N, float eta, vec3s *dest) CGLM_INLINE bool glms_vec3_refract(vec3s v, vec3s n, float eta, vec3s *dest)
Convenient: Convenient:
CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b); 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 * orients a vector to point away from a surface as defined by its normal
* *
* @param[in] N vector to orient. * @param[in] n vector to orient.
* @param[in] I incident vector * @param[in] v incident vector
* @param[in] Nref reference vector * @param[in] nref reference vector
* @returns oriented vector, pointing away from the surface. * @returns oriented vector, pointing away from the surface.
*/ */
CGLM_INLINE CGLM_INLINE
vec3s vec3s
glms_vec3_(faceforward)(vec3s N, vec3s I, vec3s Nref) { glms_vec3_(faceforward)(vec3s n, vec3s v, vec3s nref) {
vec3s dest; 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; return dest;
} }
@@ -1113,9 +1113,9 @@ glms_vec3_(faceforward)(vec3s N, vec3s I, vec3s Nref) {
*/ */
CGLM_INLINE CGLM_INLINE
vec3s vec3s
glms_vec3_(reflect)(vec3s I, vec3s N) { glms_vec3_(reflect)(vec3s v, vec3s n) {
vec3s dest; vec3s dest;
glm_vec3_reflect(I.raw, N.raw, dest.raw); glm_vec3_reflect(v.raw, n.raw, dest.raw);
return dest; return dest;
} }
@@ -1126,8 +1126,8 @@ glms_vec3_(reflect)(vec3s I, vec3s N) {
* occurs (angle too great given eta), dest is set to zero and returns false. * 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. * Otherwise, computes refraction vector, stores it in dest, and returns true.
* *
* @param[in] I normalized incident vector * @param[in] v normalized incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[in] eta ratio of indices of refraction (incident/transmitted) * @param[in] eta ratio of indices of refraction (incident/transmitted)
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
* *
@@ -1135,8 +1135,8 @@ glms_vec3_(reflect)(vec3s I, vec3s N) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glms_vec3_(refract)(vec3s I, vec3s N, float eta, vec3s * __restrict dest) { glms_vec3_(refract)(vec3s v, vec3s n, float eta, vec3s * __restrict dest) {
return glm_vec3_refract(I.raw, N.raw, eta, dest->raw); return glm_vec3_refract(v.raw, n.raw, eta, dest->raw);
} }
#endif /* cglms_vec3s_h */ #endif /* cglms_vec3s_h */

View File

@@ -67,8 +67,8 @@
CGLM_INLINE vec4s glms_vec4_cubic(float s); CGLM_INLINE vec4s glms_vec4_cubic(float s);
CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask); CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
CGLM_INLINE vec4s glms_vec4_make(float * restrict src); CGLM_INLINE vec4s glms_vec4_make(float * restrict src);
CGLM_INLINE vec4s glms_vec4_reflect(vec4s I, vec4s N); CGLM_INLINE vec4s glms_vec4_reflect(vec4s v, vec4s n);
CGLM_INLINE bool glms_vec4_refract(vec4s I, vec4s N, float eta, vec4s *dest) CGLM_INLINE bool glms_vec4_refract(vec4s v, vec4s n, float eta, vec4s *dest)
*/ */
#ifndef cglms_vec4s_h #ifndef cglms_vec4s_h
@@ -932,15 +932,15 @@ glms_vec4_(make)(const float * __restrict src) {
/*! /*!
* @brief reflection vector using an incident ray and a surface normal * @brief reflection vector using an incident ray and a surface normal
* *
* @param[in] I incident vector * @param[in] v incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @returns reflection result * @returns reflection result
*/ */
CGLM_INLINE CGLM_INLINE
vec4s vec4s
glms_vec4_(reflect)(vec4s I, vec4s N) { glms_vec4_(reflect)(vec4s v, vec4s n) {
vec4s dest; vec4s dest;
glm_vec4_reflect(I.raw, N.raw, dest.raw); glm_vec4_reflect(v.raw, n.raw, dest.raw);
return dest; return dest;
} }
@@ -955,8 +955,8 @@ glms_vec4_(reflect)(vec4s I, vec4s N) {
* incident vector 'I' in the output 'dest', users requiring the preservation of * incident vector 'I' in the output 'dest', users requiring the preservation of
* the 'w' component should manually adjust 'dest' after calling this function. * the 'w' component should manually adjust 'dest' after calling this function.
* *
* @param[in] I normalized incident vector * @param[in] v normalized incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[in] eta ratio of indices of refraction (incident/transmitted) * @param[in] eta ratio of indices of refraction (incident/transmitted)
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
* *
@@ -964,8 +964,8 @@ glms_vec4_(reflect)(vec4s I, vec4s N) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glms_vec4_(refract)(vec4s I, vec4s N, float eta, vec4s * __restrict dest) { glms_vec4_(refract)(vec4s v, vec4s n, float eta, vec4s * __restrict dest) {
return glm_vec4_refract(I.raw, N.raw, eta, dest->raw); return glm_vec4_refract(v.raw, n.raw, eta, dest->raw);
} }
#endif /* cglms_vec4s_h */ #endif /* cglms_vec4s_h */

View File

@@ -55,8 +55,8 @@
CGLM_INLINE void glm_vec2_clamp(vec2 v, float minVal, float maxVal) 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_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_make(float * restrict src, vec2 dest)
CGLM_INLINE void glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) CGLM_INLINE void glm_vec2_reflect(vec2 v, vec2 n, vec2 dest)
CGLM_INLINE void glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) CGLM_INLINE void glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest)
*/ */
#ifndef cglm_vec2_h #ifndef cglm_vec2_h
@@ -716,16 +716,16 @@ glm_vec2_make(const float * __restrict src, vec2 dest) {
/*! /*!
* @brief reflection vector using an incident ray and a surface normal * @brief reflection vector using an incident ray and a surface normal
* *
* @param[in] I incident vector * @param[in] v incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[out] dest destination vector for the reflection result * @param[out] dest destination vector for the reflection result
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) { glm_vec2_reflect(vec2 v, vec2 n, vec2 dest) {
vec2 temp; vec2 temp;
glm_vec2_scale(N, 2.0f * glm_vec2_dot(I, N), temp); glm_vec2_scale(n, 2.0f * glm_vec2_dot(v, n), temp);
glm_vec2_sub(I, temp, dest); glm_vec2_sub(v, temp, dest);
} }
/*! /*!
@@ -735,8 +735,8 @@ glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) {
* occurs (angle too great given eta), dest is set to zero and returns false. * 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. * Otherwise, computes refraction vector, stores it in dest, and returns true.
* *
* @param[in] I normalized incident vector * @param[in] v normalized incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[in] eta ratio of indices of refraction (incident/transmitted) * @param[in] eta ratio of indices of refraction (incident/transmitted)
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
* *
@@ -744,10 +744,10 @@ glm_vec2_reflect(vec2 I, vec2 N, vec2 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) { glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
float ndi, eni, k; float ndi, eni, k;
ndi = glm_vec2_dot(N, I); ndi = glm_vec2_dot(n, v);
eni = eta * ndi; eni = eta * ndi;
k = 1.0f + eta * eta - eni * eni; k = 1.0f + eta * eta - eni * eni;
@@ -756,8 +756,8 @@ glm_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) {
return false; return false;
} }
glm_vec2_scale(I, eta, dest); glm_vec2_scale(v, eta, dest);
glm_vec2_mulsubs(N, eni + sqrtf(k), dest); glm_vec2_mulsubs(n, eni + sqrtf(k), dest);
return true; return true;
} }

View File

@@ -80,9 +80,9 @@
CGLM_INLINE void glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest); 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_swizzle(vec3 v, int mask, vec3 dest);
CGLM_INLINE void glm_vec3_make(float * restrict src, 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_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest);
CGLM_INLINE void glm_vec3_reflect(vec3 I, vec3 N, vec3 dest); CGLM_INLINE void glm_vec3_reflect(vec3 v, vec3 n, vec3 dest);
CGLM_INLINE void glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest); CGLM_INLINE void glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
Convenient: Convenient:
CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d);
@@ -1210,36 +1210,36 @@ glm_vec3_make(const float * __restrict src, vec3 dest) {
* *
* orients a vector to point away from a surface as defined by its normal * orients a vector to point away from a surface as defined by its normal
* *
* @param[in] N vector to orient * @param[in] n vector to orient
* @param[in] I incident vector * @param[in] v incident vector
* @param[in] Nref reference vector * @param[in] nref reference vector
* @param[out] dest oriented vector, pointing away from the surface * @param[out] dest oriented vector, pointing away from the surface
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest) { glm_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest) {
if (glm_vec3_dot(I, Nref) < 0.0f) { if (glm_vec3_dot(v, nref) < 0.0f) {
/* N is facing away from I */ /* N is facing away from I */
glm_vec3_copy(N, dest); glm_vec3_copy(n, dest);
} else { } else {
/* N is facing towards I, negate it */ /* 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 * @brief reflection vector using an incident ray and a surface normal
* *
* @param[in] I incident vector * @param[in] v incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[out] dest reflection result * @param[out] dest reflection result
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_reflect(vec3 I, vec3 N, vec3 dest) { glm_vec3_reflect(vec3 v, vec3 n, vec3 dest) {
vec3 temp; vec3 temp;
glm_vec3_scale(N, 2.0f * glm_vec3_dot(I, N), temp); glm_vec3_scale(n, 2.0f * glm_vec3_dot(v, n), temp);
glm_vec3_sub(I, temp, dest); glm_vec3_sub(v, temp, dest);
} }
/*! /*!
@@ -1249,8 +1249,8 @@ glm_vec3_reflect(vec3 I, vec3 N, vec3 dest) {
* occurs (angle too great given eta), dest is set to zero and returns false. * 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. * Otherwise, computes refraction vector, stores it in dest, and returns true.
* *
* @param[in] I normalized incident vector * @param[in] v normalized incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[in] eta ratio of indices of refraction (incident/transmitted) * @param[in] eta ratio of indices of refraction (incident/transmitted)
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
* *
@@ -1258,10 +1258,10 @@ glm_vec3_reflect(vec3 I, vec3 N, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) { glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
float ndi, eni, k; float ndi, eni, k;
ndi = glm_vec3_dot(N, I); ndi = glm_vec3_dot(n, v);
eni = eta * ndi; eni = eta * ndi;
k = 1.0f + eta * eta - eni * eni; k = 1.0f + eta * eta - eni * eni;
@@ -1270,8 +1270,8 @@ glm_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) {
return false; return false;
} }
glm_vec3_scale(I, eta, dest); glm_vec3_scale(v, eta, dest);
glm_vec3_mulsubs(N, eni + sqrtf(k), dest); glm_vec3_mulsubs(n, eni + sqrtf(k), dest);
return true; return true;
} }

View File

@@ -65,8 +65,8 @@
CGLM_INLINE void glm_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest); 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_swizzle(vec4 v, int mask, vec4 dest);
CGLM_INLINE void glm_vec4_make(float * restrict src, 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_reflect(vec4 v, vec4 n, vec4 dest);
CGLM_INLINE void glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest); CGLM_INLINE void glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
DEPRECATED: DEPRECATED:
glm_vec4_dup glm_vec4_dup
@@ -1309,20 +1309,20 @@ glm_vec4_make(const float * __restrict src, vec4 dest) {
/*! /*!
* @brief reflection vector using an incident ray and a surface normal * @brief reflection vector using an incident ray and a surface normal
* *
* @param[in] I incident vector * @param[in] v incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[out] dest destination vector for the reflection result * @param[out] dest destination vector for the reflection result
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) { glm_vec4_reflect(vec4 v, vec4 n, vec4 dest) {
vec4 temp; vec4 temp;
/* TODO: direct simd touch */ /* TODO: direct simd touch */
glm_vec4_scale(N, 2.0f * glm_vec4_dot(I, N), temp); glm_vec4_scale(n, 2.0f * glm_vec4_dot(v, n), temp);
glm_vec4_sub(I, temp, dest); glm_vec4_sub(v, temp, dest);
dest[3] = I[3]; dest[3] = v[3];
} }
/*! /*!
@@ -1336,8 +1336,8 @@ glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) {
* incident vector 'I' in the output 'dest', users requiring the preservation of * incident vector 'I' in the output 'dest', users requiring the preservation of
* the 'w' component should manually adjust 'dest' after calling this function. * the 'w' component should manually adjust 'dest' after calling this function.
* *
* @param[in] I normalized incident vector * @param[in] v normalized incident vector
* @param[in] N normalized normal vector * @param[in] n normalized normal vector
* @param[in] eta ratio of indices of refraction (incident/transmitted) * @param[in] eta ratio of indices of refraction (incident/transmitted)
* @param[out] dest refraction vector if refraction occurs; zero vector otherwise * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
* *
@@ -1345,10 +1345,10 @@ glm_vec4_reflect(vec4 I, vec4 N, vec4 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) { glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
float ndi, eni, k; float ndi, eni, k;
ndi = glm_vec4_dot(N, I); ndi = glm_vec4_dot(n, v);
eni = eta * ndi; eni = eta * ndi;
k = 1.0f + eta * eta - eni * eni; k = 1.0f + eta * eta - eni * eni;
@@ -1357,8 +1357,8 @@ glm_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) {
return false; return false;
} }
glm_vec4_scale(I, eta, dest); glm_vec4_scale(v, eta, dest);
glm_vec4_mulsubs(N, eni + sqrtf(k), dest); glm_vec4_mulsubs(n, eni + sqrtf(k), dest);
return true; return true;
} }

View File

@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 9 #define CGLM_VERSION_MINOR 9
#define CGLM_VERSION_PATCH 3 #define CGLM_VERSION_PATCH 4
#endif /* cglm_version_h */ #endif /* cglm_version_h */

View File

@@ -1,5 +1,5 @@
project('cglm', 'c', project('cglm', 'c',
version : '0.9.3', version : '0.9.4',
license : 'mit', license : 'mit',
default_options : [ default_options : [
'c_std=c11', 'c_std=c11',

View File

@@ -305,12 +305,12 @@ glmc_vec2_make(const float * __restrict src, vec2 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec2_reflect(vec2 I, vec2 N, vec2 dest) { glmc_vec2_reflect(vec2 v, vec2 n, vec2 dest) {
glm_vec2_reflect(I, N, dest); glm_vec2_reflect(v, n, dest);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec2_refract(vec2 I, vec2 N, float eta, vec2 dest) { glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
return glm_vec2_refract(I, N, eta, dest); return glm_vec2_refract(v, n, eta, dest);
} }

View File

@@ -462,18 +462,18 @@ glmc_vec3_make(const float * __restrict src, vec3 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec3_faceforward(vec3 N, vec3 I, vec3 Nref, vec3 dest) { glmc_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest) {
glm_vec3_faceforward(N, I, Nref, dest); glm_vec3_faceforward(n, v, nref, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec3_reflect(vec3 I, vec3 N, vec3 dest) { glmc_vec3_reflect(vec3 v, vec3 n, vec3 dest) {
glm_vec3_reflect(I, N, dest); glm_vec3_reflect(v, n, dest);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec3_refract(vec3 I, vec3 N, float eta, vec3 dest) { glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
return glm_vec3_refract(I, N, eta, dest); return glm_vec3_refract(v, n, eta, dest);
} }

View File

@@ -426,12 +426,12 @@ glmc_vec4_make(const float * __restrict src, vec4 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_reflect(vec4 I, vec4 N, vec4 dest) { glmc_vec4_reflect(vec4 v, vec4 n, vec4 dest) {
glm_vec4_reflect(I, N, dest); glm_vec4_reflect(v, n, dest);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec4_refract(vec4 I, vec4 N, float eta, vec4 dest) { glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
return glm_vec4_refract(I, N, eta, dest); return glm_vec4_refract(v, n, eta, dest);
} }

View File

@@ -781,7 +781,7 @@ TEST_IMPL(GLM_PREFIX, vec2_reflect) {
} }
TEST_IMPL(GLM_PREFIX, vec2_refract) { TEST_IMPL(GLM_PREFIX, vec2_refract) {
vec2 I = {sqrtf(0.5f), -sqrtf(0.5f)}; /* Incoming vector at 45 degrees to normal */ vec2 v = {sqrtf(0.5f), -sqrtf(0.5f)}; /* Incoming vector at 45 degrees to normal */
vec2 N = {0.0f, 1.0f}; /* Surface normal */ vec2 N = {0.0f, 1.0f}; /* Surface normal */
vec2 dest; vec2 dest;
float eta; float eta;
@@ -789,7 +789,7 @@ TEST_IMPL(GLM_PREFIX, vec2_refract) {
/* Water to Air (eta = 1.33/1.0) */ /* Water to Air (eta = 1.33/1.0) */
eta = 1.33f / 1.0f; eta = 1.33f / 1.0f;
r = 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] // 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)) { if (!(dest[0] == 0.0f && dest[1] == 0.0f)) {
ASSERT(dest[1] < -sqrtf(0.5f)); // Refracted ray bends away from the normal ASSERT(dest[1] < -sqrtf(0.5f)); // Refracted ray bends away from the normal
@@ -801,17 +801,17 @@ TEST_IMPL(GLM_PREFIX, vec2_refract) {
/* Air to Glass (eta = 1.0 / 1.5) */ /* Air to Glass (eta = 1.0 / 1.5) */
eta = 1.0f / 1.5f; eta = 1.0f / 1.5f;
r = 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 ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal
/* Glass to Water (eta = 1.5 / 1.33) */ /* Glass to Water (eta = 1.5 / 1.33) */
eta = 1.5f / 1.33f; eta = 1.5f / 1.33f;
r = 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 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) */ /* Diamond to Air (eta = 2.42 / 1.0) */
eta = 2.42f / 1.0f; eta = 2.42f / 1.0f;
r = GLM(vec2_refract)(I, N, eta, dest); r = GLM(vec2_refract)(v, N, eta, dest);
if (!(dest[0] == 0.0f && dest[1] == 0.0f)) { if (!(dest[0] == 0.0f && dest[1] == 0.0f)) {
/* High potential for total internal reflection, but if it occurs, expect significant bending */ /* High potential for total internal reflection, but if it occurs, expect significant bending */
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));

View File

@@ -1843,11 +1843,11 @@ TEST_IMPL(GLM_PREFIX, vec3_make) {
TEST_IMPL(GLM_PREFIX, vec3_faceforward) { TEST_IMPL(GLM_PREFIX, vec3_faceforward) {
vec3 N = {0.0f, 1.0f, 0.0f}; 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 Nref = {0.0f, -1.0f, 0.0f};
vec3 dest; vec3 dest;
GLM(vec3_faceforward)(N, I, Nref, dest); GLM(vec3_faceforward)(N, v, Nref, dest);
ASSERT(dest[0] == 0.0f ASSERT(dest[0] == 0.0f
&& dest[1] == -1.0f && dest[1] == -1.0f
&& dest[2] == 0.0f); /* Expect N flipped */ && dest[2] == 0.0f); /* Expect N flipped */
@@ -1886,7 +1886,7 @@ TEST_IMPL(GLM_PREFIX, vec3_reflect) {
} }
TEST_IMPL(GLM_PREFIX, vec3_refract) { TEST_IMPL(GLM_PREFIX, vec3_refract) {
vec3 I = {sqrtf(0.5f), -sqrtf(0.5f), 0.0f}; /* Incoming vector at 45 degrees to normal */ 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 N = {0.0f, 1.0f, 0.0f}; /* Surface normal */
vec3 dest; vec3 dest;
float eta; float eta;
@@ -1894,7 +1894,7 @@ TEST_IMPL(GLM_PREFIX, vec3_refract) {
/* Water to Air (eta = 1.33/1.0) */ /* Water to Air (eta = 1.33/1.0) */
eta = 1.33f / 1.0f; eta = 1.33f / 1.0f;
r = 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)) { if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f)) {
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));
ASSERT(r == true); ASSERT(r == true);
@@ -1905,21 +1905,21 @@ TEST_IMPL(GLM_PREFIX, vec3_refract) {
/* Air to Glass (eta = 1.0 / 1.5) */ /* Air to Glass (eta = 1.0 / 1.5) */
eta = 1.0f / 1.5f; eta = 1.0f / 1.5f;
r = GLM(vec3_refract)(I, N, eta, dest); r = GLM(vec3_refract)(v, N, eta, dest);
/* Expect bending towards the normal */ /* Expect bending towards the normal */
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));
/* Glass to Water (eta = 1.5 / 1.33) */ /* Glass to Water (eta = 1.5 / 1.33) */
eta = 1.5f / 1.33f; eta = 1.5f / 1.33f;
r = 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 */ /* Expect bending towards the normal, less bending than air to glass */
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));
/* Diamond to Air (eta = 2.42 / 1.0) */ /* Diamond to Air (eta = 2.42 / 1.0) */
eta = 2.42f / 1.0f; eta = 2.42f / 1.0f;
r = 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)) { 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 */ /* High potential for total internal reflection, but if it occurs, expect significant bending */
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));

View File

@@ -1571,7 +1571,7 @@ TEST_IMPL(GLM_PREFIX, vec4_reflect) {
} }
TEST_IMPL(GLM_PREFIX, vec4_refract) { TEST_IMPL(GLM_PREFIX, vec4_refract) {
vec4 I = {sqrtf(0.5f), -sqrtf(0.5f), 0.0f, 0.0f}; /* Incoming vector */ 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 N = {0.0f, 1.0f, 0.0f, 0.0f}; /* Surface normal */
vec4 dest; vec4 dest;
float eta; float eta;
@@ -1579,7 +1579,7 @@ TEST_IMPL(GLM_PREFIX, vec4_refract) {
/* Water to Air (eta = 1.33/1.0) */ /* Water to Air (eta = 1.33/1.0) */
eta = 1.33f / 1.0f; eta = 1.33f / 1.0f;
r = 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)) { if (!(dest[0] == 0.0f && dest[1] == 0.0f && dest[2] == 0.0f && dest[3] == 0.0f)) {
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));
ASSERT(r == true); ASSERT(r == true);
@@ -1590,17 +1590,17 @@ TEST_IMPL(GLM_PREFIX, vec4_refract) {
/* Air to Glass (eta = 1.0 / 1.5) */ /* Air to Glass (eta = 1.0 / 1.5) */
eta = 1.0f / 1.5f; eta = 1.0f / 1.5f;
r = 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 ASSERT(dest[1] < -sqrtf(0.5f)); // Expect bending towards the normal
/* Glass to Water (eta = 1.5 / 1.33) */ /* Glass to Water (eta = 1.5 / 1.33) */
eta = 1.5f / 1.33f; eta = 1.5f / 1.33f;
r = 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 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) */ /* Diamond to Air (eta = 2.42 / 1.0) */
eta = 2.42f / 1.0f; eta = 2.42f / 1.0f;
r = 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)) { 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 */ /* High potential for total internal reflection, but if it occurs, expect significant bending */
ASSERT(dest[1] < -sqrtf(0.5f)); ASSERT(dest[1] < -sqrtf(0.5f));