Compare commits

...

20 Commits

Author SHA1 Message Date
Recep Aslantas
3a141b7cc8 extend unions for struct api 2022-01-06 18:12:46 +03:00
Recep Aslantas
5cd1a4ab44 add missing ivec types 2022-01-06 18:01:35 +03:00
Recep Aslantas
897f2afd88 Merge pull request #234 from madebr/sse3_header
Header containing sse3 intrinsics is pmmintrin.h
2021-12-31 17:51:30 +03:00
Anonymous Maarten
68e3a072e8 Header containing sse3 intrinsics is pmmintrin.h 2021-12-29 08:48:55 +01:00
Recep Aslantas
282ea84dc0 Merge pull request #231 from omar-polo/master
set PACKAGE_VERSION so it gets substituted in cglm.pc.in by cmake
2021-11-22 11:20:20 +03:00
Omar Polo
2d5506d15d set PACKAGE_VERSION so it gets substituted in cglm.pc.in by cmake
otherwise it ends up being an empty string and the installed pc has a
bogus line:

	Version:
2021-11-21 21:04:59 +01:00
Recep Aslantas
87f561fb06 Merge pull request #229 from mxi/vec2-ext-complex
Add complex routines to `vec2-ext`
2021-11-10 10:09:09 +03:00
Maxim Kasyanenko
522b18bda9 Add tests 2021-11-08 17:53:39 -08:00
Maxim Kasyanenko
b7178749ee Forgot to add the dynamic implementation file itself 2021-11-08 17:53:27 -08:00
Maxim Kasyanenko
98c708281f Syntax errors 2021-11-08 17:52:47 -08:00
Maxim Kasyanenko
896ba0a0f9 Add dynamic/struct versions of routines 2021-11-08 17:52:31 -08:00
Maxim Kasyanenko
4603816330 Forgot return type 2021-11-08 17:09:28 -08:00
Maxim Kasyanenko
9f5cc3a745 Implement a few complex routines 2021-11-08 16:28:55 -08:00
Recep Aslantas
bde653b607 Update CMakeLists.txt 2021-10-28 19:10:19 +03:00
Recep Aslantas
ede72ca412 Merge pull request #225 from podsvirov/fix-win32-shared
win: fix shared library name and destination
2021-10-17 18:09:18 +03:00
Konstantin Podsvirov
8e784e762f win: fix shared library name and destination 2021-10-10 12:02:44 +03:00
Recep Aslantas
82d1050c63 update GLM_FLT_EPSILON to use 1e-5 instead of 1e-6 2021-10-06 21:08:55 +03:00
Recep Aslantas
0631598d08 now working on v0.8.5 2021-08-18 05:03:59 +03:00
Recep Aslantas
34e5704fe8 bump version to v0.8.4 2021-08-18 04:47:11 +03:00
Recep Aslantas
672523e5af Merge pull request #219 from recp/project_zo
extend glm_project() to support ZERO_TO_ONE
2021-08-16 16:55:19 +03:00
16 changed files with 263 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8.2) cmake_minimum_required(VERSION 3.8.2)
project(cglm VERSION 0.8.3 LANGUAGES C) project(cglm VERSION 0.8.5 LANGUAGES C)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED YES) set(CMAKE_C_STANDARD_REQUIRED YES)
@@ -47,7 +47,10 @@ include(GNUInstallDirs)
set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
if(NOT CPack_CMake_INCLUDED)
include(CPack)
endif()
# Target Start # Target Start
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
@@ -97,6 +100,12 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}) SOVERSION ${PROJECT_VERSION_MAJOR})
if(WIN32)
# Because SOVERSION has no effect to file naming on Windows
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_NAME ${PROJECT_NAME}-${PROJECT_VERSION_MAJOR})
endif()
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PUBLIC PUBLIC
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
@@ -122,7 +131,7 @@ install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN ".*" EXCLUDE) PATTERN ".*" EXCLUDE)
@@ -143,6 +152,7 @@ set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
set(PACKAGE_VERSION "${PROJECT_VERSION}")
configure_file(${CMAKE_CURRENT_LIST_DIR}/cglm.pc.in ${CMAKE_BINARY_DIR}/cglm.pc @ONLY) configure_file(${CMAKE_CURRENT_LIST_DIR}/cglm.pc.in ${CMAKE_BINARY_DIR}/cglm.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/cglm.pc install(FILES ${CMAKE_BINARY_DIR}/cglm.pc

View File

@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
# Description # Description
s.name = "cglm" s.name = "cglm"
s.version = "0.8.2" s.version = "0.8.4"
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.8.3], [info@recp.me]) AC_INIT([cglm], [0.8.5], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests]) AM_INIT_AUTOMAKE([-Wall -Werror 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

@@ -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.8.3' version = u'0.8.5'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'0.8.3' release = u'0.8.5'
# 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

@@ -149,6 +149,18 @@ CGLM_EXPORT
void void
glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest); glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_complex_div(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_complex_conjugate(vec2 a, vec2 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -44,7 +44,7 @@
#ifndef CGLM_USE_DEFAULT_EPSILON #ifndef CGLM_USE_DEFAULT_EPSILON
# ifndef GLM_FLT_EPSILON # ifndef GLM_FLT_EPSILON
# define GLM_FLT_EPSILON 1e-6 # define GLM_FLT_EPSILON 1e-5
# endif # endif
#else #else
# define GLM_FLT_EPSILON FLT_EPSILON # define GLM_FLT_EPSILON FLT_EPSILON

View File

@@ -34,7 +34,7 @@
#endif #endif
#if defined(__SSE3__) #if defined(__SSE3__)
# include <x86intrin.h> # include <pmmintrin.h>
# ifndef CGLM_SIMD_x86 # ifndef CGLM_SIMD_x86
# define CGLM_SIMD_x86 # define CGLM_SIMD_x86
# endif # endif

View File

@@ -195,4 +195,45 @@ glms_vec2_sqrt(vec2s v) {
return r; return r;
} }
/*!
* @brief treat vectors as complex numbers and multiply them as such.
*
* @param[in] a left number
* @param[in] b right number
* @param[out] dest destination number
*/
CGLM_INLINE
vec2s
glms_vec2_complex_mul(vec2s a, vec2s b, vec2s dest) {
glm_vec2_complex_mul(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief treat vectors as complex numbers and divide them as such.
*
* @param[in] a left number (numerator)
* @param[in] b right number (denominator)
* @param[out] dest destination number
*/
CGLM_INLINE
vec2s
glms_vec2_complex_div(vec2s a, vec2s b, vec2s dest) {
glm_vec2_complex_div(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief treat the vector as a complex number and conjugate it as such.
*
* @param[in] a the number
* @param[out] dest destination number
*/
CGLM_INLINE
vec2s
glms_vec2_complex_conjugate(vec2s a, vec2s dest) {
glm_vec2_complex_conjugate(a.raw, dest.raw);
return dest;
}
#endif /* cglms_vec2s_ext_h */ #endif /* cglms_vec2s_ext_h */

View File

@@ -47,6 +47,21 @@ typedef union vec2s {
float x; float x;
float y; float y;
}; };
struct {
float r;
float i;
};
struct {
float u;
float v;
};
struct {
float s;
float t;
};
#endif #endif
} vec2s; } vec2s;
@@ -58,9 +73,40 @@ typedef union vec3s {
float y; float y;
float z; float z;
}; };
struct {
float r;
float g;
float b;
};
#endif #endif
} vec3s; } vec3s;
typedef union ivec2s {
ivec2 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
};
struct {
int r;
int i;
};
struct {
int u;
int v;
};
struct {
int s;
int t;
};
#endif
} ivec2s;
typedef union ivec3s { typedef union ivec3s {
ivec3 raw; ivec3 raw;
#if CGLM_USE_ANONYMOUS_STRUCT #if CGLM_USE_ANONYMOUS_STRUCT
@@ -69,9 +115,34 @@ typedef union ivec3s {
int y; int y;
int z; int z;
}; };
struct {
int r;
int g;
int b;
};
#endif #endif
} ivec3s; } ivec3s;
typedef union ivec4s {
ivec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
int z;
int w;
};
struct {
int r;
int g;
int b;
int a;
};
#endif
} ivec4s;
typedef union CGLM_ALIGN_IF(16) vec4s { typedef union CGLM_ALIGN_IF(16) vec4s {
vec4 raw; vec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT #if CGLM_USE_ANONYMOUS_STRUCT
@@ -81,6 +152,13 @@ typedef union CGLM_ALIGN_IF(16) vec4s {
float z; float z;
float w; float w;
}; };
struct {
float r;
float g;
float b;
float a;
};
#endif #endif
} vec4s; } vec4s;

View File

@@ -42,9 +42,12 @@
#define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \ #define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \
((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type))) ((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type)))
typedef int ivec2[2];
typedef int ivec3[3];
typedef int ivec4[4];
typedef float vec2[2]; typedef float vec2[2];
typedef float vec3[3]; typedef float vec3[3];
typedef int ivec3[3];
typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef CGLM_ALIGN_IF(16) float vec4[4];
typedef vec4 versor; /* |x, y, z, w| -> w is the last */ typedef vec4 versor; /* |x, y, z, w| -> w is the last */
typedef vec3 mat3[3]; typedef vec3 mat3[3];

View File

@@ -20,6 +20,9 @@
CGLM_INLINE bool glm_vec2_isvalid(vec2 v); CGLM_INLINE bool glm_vec2_isvalid(vec2 v);
CGLM_INLINE void glm_vec2_sign(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_sign(vec2 v, vec2 dest);
CGLM_INLINE void glm_vec2_sqrt(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_sqrt(vec2 v, vec2 dest);
CGLM_INLINE void glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_complex_conjugate(vec2 a, vec2 dest)
*/ */
#ifndef cglm_vec2_ext_h #ifndef cglm_vec2_ext_h
@@ -186,4 +189,53 @@ glm_vec2_sqrt(vec2 v, vec2 dest) {
dest[1] = sqrtf(v[1]); dest[1] = sqrtf(v[1]);
} }
/*!
* @brief treat vectors as complex numbers and multiply them as such.
*
* @param[in] a left number
* @param[in] b right number
* @param[out] dest destination number
*/
CGLM_INLINE
void
glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) {
float tr, ti;
tr = a[0] * b[0] - a[1] * b[1];
ti = a[0] * b[1] + a[1] * b[0];
dest[0] = tr;
dest[1] = ti;
}
/*!
* @brief treat vectors as complex numbers and divide them as such.
*
* @param[in] a left number (numerator)
* @param[in] b right number (denominator)
* @param[out] dest destination number
*/
CGLM_INLINE
void
glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest) {
float tr, ti;
float const ibnorm2 = 1.0f / (b[0] * b[0] + b[1] * b[1]);
tr = ibnorm2 * (a[0] * b[0] + a[1] * b[1]);
ti = ibnorm2 * (a[1] * b[0] - a[0] * b[1]);
dest[0] = tr;
dest[1] = ti;
}
/*!
* @brief treat the vector as a complex number and conjugate it as such.
*
* @param[in] a the number
* @param[out] dest destination number
*/
CGLM_INLINE
void
glm_vec2_complex_conjugate(vec2 a, vec2 dest) {
dest[0] = a[0];
dest[1] = -a[1];
}
#endif /* cglm_vec2_ext_h */ #endif /* cglm_vec2_ext_h */

View File

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

View File

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

View File

@@ -211,3 +211,21 @@ void
glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) { glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) {
glm_vec2_lerp(from, to, t, dest); glm_vec2_lerp(from, to, t, dest);
} }
CGLM_EXPORT
void
glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) {
glm_vec2_complex_mul(a, b, dest);
}
CGLM_EXPORT
void
glmc_vec2_complex_div(vec2 a, vec2 b, vec2 dest) {
glm_vec2_complex_div(a, b, dest);
}
CGLM_EXPORT
void
glmc_vec2_complex_conjugate(vec2 a, vec2 dest) {
glm_vec2_complex_conjugate(a, dest);
}

View File

@@ -594,3 +594,32 @@ TEST_IMPL(GLM_PREFIX, vec2_lerp) {
TEST_SUCCESS TEST_SUCCESS
} }
TEST_IMPL(GLM_PREFIX, vec2_complex_mul) {
vec2 v1 = { 3.0f, 5.0f },
v2 = { 7.0f, 11.0f },
v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) };
GLM(vec2_complex_mul)(v1, v2, v2);
ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ -34, 68 }))
GLM(vec2_complex_mul)(v3, v3, v3);
ASSERTIFY(test_assert_vec2_eq(v3, (vec2){ 0.0f, 1.0f }))
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, vec2_complex_div) {
vec2 v1 = { -34.0f, 68.0f },
v2 = { 3.0f, 5.0f },
v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) },
v4 = { cosf(M_PI/4.0f), -sinf(M_PI/4.0f) };
GLM(vec2_complex_div)(v1, v2, v2);
ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ 7.0f, 11.0f }))
GLM(vec2_complex_div)(v3, v4, v4);
ASSERTIFY(test_assert_vec2_eq(v4, (vec2){ 0.0f, 1.0f }))
TEST_SUCCESS
}

View File

@@ -382,6 +382,8 @@ TEST_DECLARE(glm_vec2_maxv)
TEST_DECLARE(glm_vec2_minv) TEST_DECLARE(glm_vec2_minv)
TEST_DECLARE(glm_vec2_clamp) TEST_DECLARE(glm_vec2_clamp)
TEST_DECLARE(glm_vec2_lerp) TEST_DECLARE(glm_vec2_lerp)
TEST_DECLARE(glm_vec2_complex_mul)
TEST_DECLARE(glm_vec2_complex_div)
TEST_DECLARE(glmc_vec2) TEST_DECLARE(glmc_vec2)
@@ -418,6 +420,8 @@ TEST_DECLARE(glmc_vec2_maxv)
TEST_DECLARE(glmc_vec2_minv) TEST_DECLARE(glmc_vec2_minv)
TEST_DECLARE(glmc_vec2_clamp) TEST_DECLARE(glmc_vec2_clamp)
TEST_DECLARE(glmc_vec2_lerp) TEST_DECLARE(glmc_vec2_lerp)
TEST_DECLARE(glmc_vec2_complex_mul)
TEST_DECLARE(glmc_vec2_complex_div)
/* vec3 */ /* vec3 */
TEST_DECLARE(MACRO_GLM_VEC3_ONE_INIT) TEST_DECLARE(MACRO_GLM_VEC3_ONE_INIT)
@@ -1112,6 +1116,8 @@ TEST_LIST {
TEST_ENTRY(glm_vec2_minv) TEST_ENTRY(glm_vec2_minv)
TEST_ENTRY(glm_vec2_clamp) TEST_ENTRY(glm_vec2_clamp)
TEST_ENTRY(glm_vec2_lerp) TEST_ENTRY(glm_vec2_lerp)
TEST_ENTRY(glm_vec2_complex_mul)
TEST_ENTRY(glm_vec2_complex_div)
TEST_ENTRY(glmc_vec2) TEST_ENTRY(glmc_vec2)
TEST_ENTRY(glmc_vec2_copy) TEST_ENTRY(glmc_vec2_copy)
@@ -1147,6 +1153,8 @@ TEST_LIST {
TEST_ENTRY(glmc_vec2_minv) TEST_ENTRY(glmc_vec2_minv)
TEST_ENTRY(glmc_vec2_clamp) TEST_ENTRY(glmc_vec2_clamp)
TEST_ENTRY(glmc_vec2_lerp) TEST_ENTRY(glmc_vec2_lerp)
TEST_ENTRY(glmc_vec2_complex_mul)
TEST_ENTRY(glmc_vec2_complex_div)
/* vec3 */ /* vec3 */
/* Macros */ /* Macros */