mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Initial implementation of struct type vec4s
This commit is contained in:
20
include/cglm/cglms.h
Normal file
20
include/cglm/cglms.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef cglm_structs_h
|
||||||
|
#define cglm_structs_h
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "cglm.h"
|
||||||
|
#include "structs/vec4.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* cglm_structs_h */
|
||||||
114
include/cglm/structs/vec4-ext.h
Normal file
114
include/cglm/structs/vec4-ext.h
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef cglm_vec4s_ext_h
|
||||||
|
#define cglm_vec4s_ext_h
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "vec3-ext.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
vec4s
|
||||||
|
glms_vec4_broadcast(float val, vec4 d)
|
||||||
|
{
|
||||||
|
vec4s r;
|
||||||
|
glm_vec4_broadcast(val, r.raw);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_eq(vec4s v, float val)
|
||||||
|
{
|
||||||
|
return glm_vec4_eq(v.raw, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_eq_eps(vec4 v, float val)
|
||||||
|
{
|
||||||
|
return glm_vec4_eq_eps(v.raw, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_eq_all(vec4s v)
|
||||||
|
{
|
||||||
|
return glm_vec4_eq_all(v.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_eqv(vec4s a, vec4s b)
|
||||||
|
{
|
||||||
|
return glm_vec4_eqv(a.raw, b.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_eqv_eps(vec4s a, vec4s b)
|
||||||
|
{
|
||||||
|
return glm_vec4_eqv_eps(a.raw, b.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glms_vec4_max(vec4s v)
|
||||||
|
{
|
||||||
|
return glm_vec4_max(v.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
float
|
||||||
|
glms_vec4_min(vec4s v)
|
||||||
|
{
|
||||||
|
return glm_vec4_min(v.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_isnan(vec4s v)
|
||||||
|
{
|
||||||
|
return glm_vec4_isnan(v.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_isinf(vec4s v)
|
||||||
|
{
|
||||||
|
return glm_vec4_isinf(v.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
bool
|
||||||
|
glms_vec4_isvalid(vec4s v)
|
||||||
|
{
|
||||||
|
return glm_vec4_isvalid(v.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
vec4s
|
||||||
|
glms_vec4_sign(vec4s v)
|
||||||
|
{
|
||||||
|
vec4s r;
|
||||||
|
glm_vec4_sign(v.raw, r.raw);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
CGLM_INLINE
|
||||||
|
vec4s
|
||||||
|
glms_vec4_sqrt(vec4s v)
|
||||||
|
{
|
||||||
|
vec4s r;
|
||||||
|
glm_vec4_sqrt(v.raw, r.raw);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* cglm_vec4s_ext_h */
|
||||||
@@ -8,9 +8,11 @@
|
|||||||
#ifndef cglm_vec4s_h
|
#ifndef cglm_vec4s_h
|
||||||
#define cglm_vec4s_h
|
#define cglm_vec4s_h
|
||||||
|
|
||||||
#include "common.h"
|
#ifdef __cplusplus
|
||||||
#include "vec4-ext.h"
|
extern "C" {
|
||||||
#include "util.h"
|
#endif
|
||||||
|
|
||||||
|
#include "../cglm.h"
|
||||||
|
|
||||||
#define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f}
|
#define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f}
|
||||||
#define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f}
|
#define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f}
|
||||||
@@ -92,7 +94,7 @@ vec4s
|
|||||||
glms_vec4_adds(vec4s v, float s)
|
glms_vec4_adds(vec4s v, float s)
|
||||||
{
|
{
|
||||||
vec4s r;
|
vec4s r;
|
||||||
glm_vec4_adds(v.raw s, r.raw);
|
glm_vec4_adds(v.raw, s, r.raw);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +228,7 @@ vec4s
|
|||||||
glms_vec4_inv(vec4s v)
|
glms_vec4_inv(vec4s v)
|
||||||
{
|
{
|
||||||
glm_vec4_inv(v.raw);
|
glm_vec4_inv(v.raw);
|
||||||
return r;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
@@ -279,4 +281,7 @@ glms_vec4_lerp(vec4s from, vec4s to, float t)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif /* cglm_vec4s_h */
|
#endif /* cglm_vec4s_h */
|
||||||
|
|||||||
@@ -47,17 +47,7 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4];
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// struct types
|
// struct types
|
||||||
typedef union CGLM_ALIGN_IF(8) vec2s {
|
typedef union CGLM_ALIGN_IF(16) vec3s {
|
||||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
|
||||||
struct {
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
vec2 raw;
|
|
||||||
} vec2s;
|
|
||||||
|
|
||||||
typedef union CGLM_ALIGN_IF(8) vec3s {
|
|
||||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||||
struct {
|
struct {
|
||||||
float x;
|
float x;
|
||||||
@@ -68,17 +58,6 @@ typedef union CGLM_ALIGN_IF(8) vec3s {
|
|||||||
vec3 raw;
|
vec3 raw;
|
||||||
} vec3s;
|
} vec3s;
|
||||||
|
|
||||||
typedef union CGLM_ALIGN_IF(8) ivec3s {
|
|
||||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
|
||||||
struct {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int z;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
ivec3 raw;
|
|
||||||
} ivec3s;
|
|
||||||
|
|
||||||
typedef union CGLM_ALIGN_IF(16) vec4s {
|
typedef union CGLM_ALIGN_IF(16) vec4s {
|
||||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ test_rand_vec4(vec4 dest) {
|
|||||||
dest[3] = drand48();
|
dest[3] = drand48();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec4s
|
||||||
|
test_rand_vec4s()
|
||||||
|
{
|
||||||
|
vec4s r;
|
||||||
|
test_rand_vec4(r.raw);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
test_rand(void) {
|
test_rand(void) {
|
||||||
srand((unsigned int)time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
@@ -127,6 +135,12 @@ test_assert_vec4_eq(vec4 v1, vec4 v2) {
|
|||||||
assert_true(fabsf(v1[3] - v2[3]) <= 0.000009);
|
assert_true(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_assert_vec4s_eq(vec4s v1, vec4s v2)
|
||||||
|
{
|
||||||
|
test_assert_vec4_eq(v1.raw, v2.raw);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_assert_quat_eq_abs(versor v1, versor v2) {
|
test_assert_quat_eq_abs(versor v1, versor v2) {
|
||||||
assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */
|
assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <cglm/cglm.h>
|
#include <cglm/cglm.h>
|
||||||
|
#include <cglm/cglms.h>
|
||||||
#include <cglm/call.h>
|
#include <cglm/call.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -46,6 +47,9 @@ test_assert_vec3_eq(vec3 v1, vec3 v2);
|
|||||||
void
|
void
|
||||||
test_assert_vec4_eq(vec4 v1, vec4 v2);
|
test_assert_vec4_eq(vec4 v1, vec4 v2);
|
||||||
|
|
||||||
|
void
|
||||||
|
test_assert_vec4s_eq(vec4s v1, vec4s v2);
|
||||||
|
|
||||||
void
|
void
|
||||||
test_assert_quat_eq(versor v1, versor v2);
|
test_assert_quat_eq(versor v1, versor v2);
|
||||||
|
|
||||||
@@ -56,7 +60,10 @@ void
|
|||||||
test_rand_vec3(vec3 dest);
|
test_rand_vec3(vec3 dest);
|
||||||
|
|
||||||
void
|
void
|
||||||
test_rand_vec4(vec4 dest) ;
|
test_rand_vec4(vec4 dest);
|
||||||
|
|
||||||
|
vec4s
|
||||||
|
test_rand_vec4s();
|
||||||
|
|
||||||
float
|
float
|
||||||
test_rand(void);
|
test_rand(void);
|
||||||
|
|||||||
@@ -44,9 +44,11 @@ test_quat(void **state) {
|
|||||||
test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */
|
test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */
|
||||||
|
|
||||||
/* 4. test SSE mul and raw mul */
|
/* 4. test SSE mul and raw mul */
|
||||||
|
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||||
test_quat_mul_raw(inQuat, outQuat, q3);
|
test_quat_mul_raw(inQuat, outQuat, q3);
|
||||||
glm_quat_mul_sse2(inQuat, outQuat, q4);
|
glm_quat_mul_sse2(inQuat, outQuat, q4);
|
||||||
test_assert_quat_eq(q3, q4);
|
test_assert_quat_eq(q3, q4);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 5. test lookat */
|
/* 5. test lookat */
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ test_vec4_clamp(vec4 v, float minVal, float maxVal) {
|
|||||||
void
|
void
|
||||||
test_vec4(void **state) {
|
test_vec4(void **state) {
|
||||||
vec4 v, v1, v2, v3, v4;
|
vec4 v, v1, v2, v3, v4;
|
||||||
|
vec4s vs1, vs2, vs3, vs4;
|
||||||
int i;
|
int i;
|
||||||
float d1, d2;
|
float d1, d2;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < 1000; i++) {
|
for (i = 0; i < 1000; i++) {
|
||||||
/* 1. test SSE/SIMD dot product */
|
/* 1. test SSE/SIMD dot product */
|
||||||
test_rand_vec4(v);
|
test_rand_vec4(v);
|
||||||
@@ -175,4 +175,12 @@ test_vec4(void **state) {
|
|||||||
assert_true(v3[1] >= 0.0999 && v3[1] <= 0.80001);
|
assert_true(v3[1] >= 0.0999 && v3[1] <= 0.80001);
|
||||||
assert_true(v3[2] >= 0.0999 && v3[2] <= 0.80001);
|
assert_true(v3[2] >= 0.0999 && v3[2] <= 0.80001);
|
||||||
assert_true(v3[3] >= 0.0999 && v3[3] <= 0.80001);
|
assert_true(v3[3] >= 0.0999 && v3[3] <= 0.80001);
|
||||||
|
|
||||||
|
/* structs */
|
||||||
|
vs1 = test_rand_vec4s();
|
||||||
|
vs2 = test_rand_vec4s();
|
||||||
|
|
||||||
|
vs3 = glms_vec4_add(vs1, vs2);
|
||||||
|
vs4 = glms_vec4_maxv(vs1, vs3);
|
||||||
|
test_assert_vec4s_eq(vs3, vs4);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user