Compare commits
8 Commits
update-glm
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9f21cf7b38 | ||
![]() |
00396e8a99 | ||
![]() |
66a0594e5d | ||
![]() |
e8825650c6 | ||
![]() |
e2992d276f | ||
![]() |
b6d0b7d876 | ||
![]() |
bbe09c4265 | ||
![]() |
a491a8eb79 |
6
Makefile
6
Makefile
@ -9,8 +9,8 @@ endif
|
|||||||
include $(DEVKITARM)/3ds_rules
|
include $(DEVKITARM)/3ds_rules
|
||||||
|
|
||||||
export CITRO3D_MAJOR := 1
|
export CITRO3D_MAJOR := 1
|
||||||
export CITRO3D_MINOR := 6
|
export CITRO3D_MINOR := 7
|
||||||
export CITRO3D_PATCH := 2
|
export CITRO3D_PATCH := 1
|
||||||
|
|
||||||
VERSION := $(CITRO3D_MAJOR).$(CITRO3D_MINOR).$(CITRO3D_PATCH)
|
VERSION := $(CITRO3D_MAJOR).$(CITRO3D_MINOR).$(CITRO3D_PATCH)
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ CFLAGS := -g -Wall -Wno-sizeof-array-div -Werror -mword-relocations \
|
|||||||
-ffunction-sections -fdata-sections \
|
-ffunction-sections -fdata-sections \
|
||||||
$(ARCH) $(BUILD_CFLAGS)
|
$(ARCH) $(BUILD_CFLAGS)
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS -DCITRO3D_BUILD
|
CFLAGS += $(INCLUDE) -D__3DS__ -DCITRO3D_BUILD
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||||
|
|
||||||
|
@ -77,6 +77,14 @@ enum
|
|||||||
void C3D_LightEnvFresnel(C3D_LightEnv* env, GPU_FRESNELSEL selector);
|
void C3D_LightEnvFresnel(C3D_LightEnv* env, GPU_FRESNELSEL selector);
|
||||||
void C3D_LightEnvBumpMode(C3D_LightEnv* env, GPU_BUMPMODE mode);
|
void C3D_LightEnvBumpMode(C3D_LightEnv* env, GPU_BUMPMODE mode);
|
||||||
void C3D_LightEnvBumpSel(C3D_LightEnv* env, int texUnit);
|
void C3D_LightEnvBumpSel(C3D_LightEnv* env, int texUnit);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures whether to use the z component of the normal map.
|
||||||
|
* @param[out] env Pointer to light environment structure.
|
||||||
|
* @param[in] enable false if the z component is reconstructed from the xy components
|
||||||
|
* of the normal map, true if the z component is taken from the normal map.
|
||||||
|
*/
|
||||||
|
void C3D_LightEnvBumpNormalZ(C3D_LightEnv *env, bool enable);
|
||||||
void C3D_LightEnvShadowMode(C3D_LightEnv* env, u32 mode);
|
void C3D_LightEnvShadowMode(C3D_LightEnv* env, u32 mode);
|
||||||
void C3D_LightEnvShadowSel(C3D_LightEnv* env, int texUnit);
|
void C3D_LightEnvShadowSel(C3D_LightEnv* env, int texUnit);
|
||||||
void C3D_LightEnvClampHighlights(C3D_LightEnv* env, bool clamp);
|
void C3D_LightEnvClampHighlights(C3D_LightEnv* env, bool clamp);
|
||||||
|
@ -13,7 +13,12 @@
|
|||||||
* The one true circumference-to-radius ratio.
|
* The one true circumference-to-radius ratio.
|
||||||
* See http://tauday.com/tau-manifesto
|
* See http://tauday.com/tau-manifesto
|
||||||
*/
|
*/
|
||||||
#define M_TAU (2*M_PI)
|
#define M_TAU (6.28318530717958647692528676655900576)
|
||||||
|
|
||||||
|
// Define the legacy circle constant as well
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI (M_TAU/2)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert an angle from revolutions to radians
|
* @brief Convert an angle from revolutions to radians
|
||||||
|
@ -41,7 +41,7 @@ typedef struct
|
|||||||
};
|
};
|
||||||
} C3D_Tex;
|
} C3D_Tex;
|
||||||
|
|
||||||
typedef struct ALIGN(8)
|
typedef struct CTR_ALIGN(8)
|
||||||
{
|
{
|
||||||
u16 width;
|
u16 width;
|
||||||
u16 height;
|
u16 height;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef _3DS
|
#if defined(__3DS__) || defined(_3DS)
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#else
|
#else
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -38,7 +38,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @brief Subtexture
|
/** @brief Subtexture
|
||||||
* @note If top > bottom, the subtexture is rotated 1/4 revolution counter-clockwise
|
* @note If top < bottom, the subtexture is rotated 1/4 revolution counter-clockwise
|
||||||
*/
|
*/
|
||||||
typedef struct Tex3DS_SubTexture
|
typedef struct Tex3DS_SubTexture
|
||||||
{
|
{
|
||||||
|
@ -124,6 +124,18 @@ static inline bool C3Di_TexIs2D(C3D_Tex* tex)
|
|||||||
return !typeIsCube(C3D_TexGetType(tex));
|
return !typeIsCube(C3D_TexGetType(tex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool addrIsVRAM(const void* addr)
|
||||||
|
{
|
||||||
|
u32 vaddr = (u32)addr;
|
||||||
|
return vaddr >= OS_VRAM_VADDR && vaddr < OS_VRAM_VADDR + OS_VRAM_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline vramAllocPos addrGetVRAMBank(const void* addr)
|
||||||
|
{
|
||||||
|
u32 vaddr = (u32)addr;
|
||||||
|
return vaddr < OS_VRAM_VADDR + OS_VRAM_SIZE/2 ? VRAM_ALLOC_A : VRAM_ALLOC_B;
|
||||||
|
}
|
||||||
|
|
||||||
void C3Di_UpdateContext(void);
|
void C3Di_UpdateContext(void);
|
||||||
void C3Di_AttrInfoBind(C3D_AttrInfo* info);
|
void C3Di_AttrInfoBind(C3D_AttrInfo* info);
|
||||||
void C3Di_BufInfoBind(C3D_BufInfo* info);
|
void C3Di_BufInfoBind(C3D_BufInfo* info);
|
||||||
|
@ -250,6 +250,14 @@ void C3D_LightEnvBumpSel(C3D_LightEnv* env, int texUnit)
|
|||||||
env->flags |= C3DF_LightEnv_Dirty;
|
env->flags |= C3DF_LightEnv_Dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void C3D_LightEnvBumpNormalZ(C3D_LightEnv *env, bool usez) {
|
||||||
|
if (usez)
|
||||||
|
env->conf.config[0] |= BIT(30);
|
||||||
|
else
|
||||||
|
env->conf.config[0] &= ~BIT(30);
|
||||||
|
env->flags |= C3DF_LightEnv_Dirty;
|
||||||
|
}
|
||||||
|
|
||||||
void C3D_LightEnvShadowMode(C3D_LightEnv* env, u32 mode)
|
void C3D_LightEnvShadowMode(C3D_LightEnv* env, u32 mode)
|
||||||
{
|
{
|
||||||
mode &= 0xF<<16;
|
mode &= 0xF<<16;
|
||||||
|
@ -284,7 +284,10 @@ C3D_RenderTarget* C3D_RenderTargetCreate(int width, int height, GPU_COLORBUF col
|
|||||||
if (C3D_DEPTHTYPE_OK(depthFmt))
|
if (C3D_DEPTHTYPE_OK(depthFmt))
|
||||||
{
|
{
|
||||||
depthFmtReal = C3D_DEPTHTYPE_VAL(depthFmt);
|
depthFmtReal = C3D_DEPTHTYPE_VAL(depthFmt);
|
||||||
depthBuf = vramAlloc(C3D_CalcDepthBufSize(width,height,depthFmtReal));
|
size_t depthSize = C3D_CalcDepthBufSize(width,height,depthFmtReal);
|
||||||
|
vramAllocPos vramBank = addrGetVRAMBank(colorBuf);
|
||||||
|
depthBuf = vramAllocAt(depthSize, vramBank ^ VRAM_ALLOC_ANY); // Attempt opposite bank first...
|
||||||
|
if (!depthBuf) depthBuf = vramAllocAt(depthSize, vramBank); // ... if that fails, attempt same bank
|
||||||
if (!depthBuf) goto _fail1;
|
if (!depthBuf) goto _fail1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,6 +316,7 @@ _fail0:
|
|||||||
|
|
||||||
C3D_RenderTarget* C3D_RenderTargetCreateFromTex(C3D_Tex* tex, GPU_TEXFACE face, int level, C3D_DEPTHTYPE depthFmt)
|
C3D_RenderTarget* C3D_RenderTargetCreateFromTex(C3D_Tex* tex, GPU_TEXFACE face, int level, C3D_DEPTHTYPE depthFmt)
|
||||||
{
|
{
|
||||||
|
if (!addrIsVRAM(tex->data)) return NULL; // Render targets must be in VRAM
|
||||||
C3D_RenderTarget* target = C3Di_RenderTargetNew();
|
C3D_RenderTarget* target = C3Di_RenderTargetNew();
|
||||||
if (!target) return NULL;
|
if (!target) return NULL;
|
||||||
|
|
||||||
@ -322,7 +326,10 @@ C3D_RenderTarget* C3D_RenderTargetCreateFromTex(C3D_Tex* tex, GPU_TEXFACE face,
|
|||||||
if (C3D_DEPTHTYPE_OK(depthFmt))
|
if (C3D_DEPTHTYPE_OK(depthFmt))
|
||||||
{
|
{
|
||||||
GPU_DEPTHBUF depthFmtReal = C3D_DEPTHTYPE_VAL(depthFmt);
|
GPU_DEPTHBUF depthFmtReal = C3D_DEPTHTYPE_VAL(depthFmt);
|
||||||
void* depthBuf = vramAlloc(C3D_CalcDepthBufSize(fb->width,fb->height,depthFmtReal));
|
size_t depthSize = C3D_CalcDepthBufSize(fb->width,fb->height,depthFmtReal);
|
||||||
|
vramAllocPos vramBank = addrGetVRAMBank(tex->data);
|
||||||
|
void* depthBuf = vramAllocAt(depthSize, vramBank ^ VRAM_ALLOC_ANY); // Attempt opposite bank first...
|
||||||
|
if (!depthBuf) depthBuf = vramAllocAt(depthSize, vramBank); // ... if that fails, attempt same bank
|
||||||
if (!depthBuf)
|
if (!depthBuf)
|
||||||
{
|
{
|
||||||
free(target);
|
free(target);
|
||||||
|
@ -30,12 +30,6 @@ static inline size_t fmtSize(GPU_TEXCOLOR fmt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool addrIsVRAM(const void* addr)
|
|
||||||
{
|
|
||||||
u32 vaddr = (u32)addr;
|
|
||||||
return vaddr >= 0x1F000000 && vaddr < 0x1F600000;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool checkTexSize(u32 size)
|
static inline bool checkTexSize(u32 size)
|
||||||
{
|
{
|
||||||
if (size < 8 || size > 1024)
|
if (size < 8 || size > 1024)
|
||||||
|
@ -47,10 +47,10 @@ ICON :=
|
|||||||
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
|
||||||
|
|
||||||
CFLAGS := -g -Wall -O3 -mword-relocations \
|
CFLAGS := -g -Wall -O3 -mword-relocations \
|
||||||
-fomit-frame-pointer -ffunction-sections \
|
-ffunction-sections \
|
||||||
$(ARCH)
|
$(ARCH)
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
|
CFLAGS += $(INCLUDE) -D__3DS__
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++11
|
CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++11
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ OFILES := $(addprefix build/,$(CXXFILES:.cpp=.o)) \
|
|||||||
DFILES := $(wildcard build/*.d)
|
DFILES := $(wildcard build/*.d)
|
||||||
|
|
||||||
CFLAGS := -Wall -g -pipe -I../../include --coverage
|
CFLAGS := -Wall -g -pipe -I../../include --coverage
|
||||||
CXXFLAGS := $(CFLAGS) $(CPPFLAGS) -std=gnu++11 -DGLM_FORCE_RADIANS -DGLM_FORCE_CTOR_INIT
|
CXXFLAGS := $(CFLAGS) $(CPPFLAGS) -std=gnu++11 -DGLM_FORCE_RADIANS
|
||||||
LDFLAGS := $(ARCH) -pipe -lm --coverage
|
LDFLAGS := $(ARCH) -pipe -lm --coverage
|
||||||
|
|
||||||
.PHONY: all clean lcov
|
.PHONY: all clean lcov
|
||||||
|
222
test/pc/main.cpp
222
test/pc/main.cpp
@ -13,43 +13,41 @@ extern "C" {
|
|||||||
#include <c3d/maths.h>
|
#include <c3d/maths.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
typedef std::default_random_engine generator_t;
|
||||||
{
|
typedef std::uniform_real_distribution<float> distribution_t;
|
||||||
using generator_t = std::default_random_engine;
|
|
||||||
using distribution_t = std::uniform_real_distribution<float>;
|
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
randomMatrix(C3D_Mtx &m, generator_t &g, distribution_t &d)
|
randomMatrix(C3D_Mtx &m, generator_t &g, distribution_t &d)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < 16; ++i)
|
for(size_t i = 0; i < 16; ++i)
|
||||||
m.m[i] = d(g);
|
m.m[i] = d(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline glm::vec3
|
static inline glm::vec3
|
||||||
randomVector3(generator_t &g, distribution_t &d)
|
randomVector3(generator_t &g, distribution_t &d)
|
||||||
{
|
{
|
||||||
return glm::vec3(d(g), d(g), d(g));
|
return glm::vec3(d(g), d(g), d(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline glm::vec4
|
static inline glm::vec4
|
||||||
randomVector4(generator_t &g, distribution_t &d)
|
randomVector4(generator_t &g, distribution_t &d)
|
||||||
{
|
{
|
||||||
return glm::vec4(d(g), d(g), d(g), d(g));
|
return glm::vec4(d(g), d(g), d(g), d(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float
|
static inline float
|
||||||
randomAngle(generator_t &g, distribution_t &d)
|
randomAngle(generator_t &g, distribution_t &d)
|
||||||
{
|
{
|
||||||
return d(g);
|
return d(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline C3D_FQuat
|
static inline C3D_FQuat
|
||||||
randomQuat(generator_t &g, distribution_t &d)
|
randomQuat(generator_t &g, distribution_t &d)
|
||||||
{
|
{
|
||||||
return Quat_New(d(g), d(g), d(g), d(g));
|
return Quat_New(d(g), d(g), d(g), d(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline glm::mat4
|
static inline glm::mat4
|
||||||
loadMatrix(const C3D_Mtx &m)
|
loadMatrix(const C3D_Mtx &m)
|
||||||
{
|
{
|
||||||
return glm::mat4(m.m[ 3], m.m[ 7], m.m[11], m.m[15],
|
return glm::mat4(m.m[ 3], m.m[ 7], m.m[11], m.m[15],
|
||||||
@ -58,13 +56,13 @@ loadMatrix(const C3D_Mtx &m)
|
|||||||
m.m[ 0], m.m[ 4], m.m[ 8], m.m[12]);
|
m.m[ 0], m.m[ 4], m.m[ 8], m.m[12]);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline glm::quat
|
static inline glm::quat
|
||||||
loadQuat(const C3D_FQuat &q)
|
loadQuat(const C3D_FQuat &q)
|
||||||
{
|
{
|
||||||
return glm::quat(q.r, q.i, q.j, q.k);
|
return glm::quat(q.r, q.i, q.j, q.k);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const glm::vec3 &lhs, const C3D_FVec &rhs)
|
operator==(const glm::vec3 &lhs, const C3D_FVec &rhs)
|
||||||
{
|
{
|
||||||
return std::abs(lhs.x - rhs.x) < 0.001f
|
return std::abs(lhs.x - rhs.x) < 0.001f
|
||||||
@ -72,13 +70,13 @@ operator==(const glm::vec3 &lhs, const C3D_FVec &rhs)
|
|||||||
&& std::abs(lhs.z - rhs.z) < 0.001f;
|
&& std::abs(lhs.z - rhs.z) < 0.001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const C3D_FVec &lhs, const glm::vec3 &rhs)
|
operator==(const C3D_FVec &lhs, const glm::vec3 &rhs)
|
||||||
{
|
{
|
||||||
return rhs == lhs;
|
return rhs == lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const glm::vec4 &lhs, const C3D_FVec &rhs)
|
operator==(const glm::vec4 &lhs, const C3D_FVec &rhs)
|
||||||
{
|
{
|
||||||
return std::abs(lhs.x - rhs.x) < 0.001f
|
return std::abs(lhs.x - rhs.x) < 0.001f
|
||||||
@ -87,13 +85,13 @@ operator==(const glm::vec4 &lhs, const C3D_FVec &rhs)
|
|||||||
&& std::abs(lhs.w - rhs.w) < 0.001f;
|
&& std::abs(lhs.w - rhs.w) < 0.001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const C3D_FVec &lhs, const glm::vec4 &rhs)
|
operator==(const C3D_FVec &lhs, const glm::vec4 &rhs)
|
||||||
{
|
{
|
||||||
return rhs == lhs;
|
return rhs == lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const glm::mat4 &lhs, const C3D_Mtx &rhs)
|
operator==(const glm::mat4 &lhs, const C3D_Mtx &rhs)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < 4; ++i)
|
for(size_t i = 0; i < 4; ++i)
|
||||||
@ -108,13 +106,13 @@ operator==(const glm::mat4 &lhs, const C3D_Mtx &rhs)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const C3D_Mtx &lhs, const glm::mat4 &rhs)
|
operator==(const C3D_Mtx &lhs, const glm::mat4 &rhs)
|
||||||
{
|
{
|
||||||
return rhs == lhs;
|
return rhs == lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const glm::quat &lhs, const C3D_FQuat &rhs)
|
operator==(const glm::quat &lhs, const C3D_FQuat &rhs)
|
||||||
{
|
{
|
||||||
return std::abs(lhs.w - rhs.r) < 0.01f
|
return std::abs(lhs.w - rhs.r) < 0.01f
|
||||||
@ -123,13 +121,13 @@ operator==(const glm::quat &lhs, const C3D_FQuat &rhs)
|
|||||||
&& std::abs(lhs.z - rhs.k) < 0.01f;
|
&& std::abs(lhs.z - rhs.k) < 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const C3D_FQuat &lhs, const glm::quat &rhs)
|
operator==(const C3D_FQuat &lhs, const glm::quat &rhs)
|
||||||
{
|
{
|
||||||
return rhs == lhs;
|
return rhs == lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
static inline bool
|
||||||
operator==(const C3D_FQuat &lhs, const C3D_FQuat &rhs)
|
operator==(const C3D_FQuat &lhs, const C3D_FQuat &rhs)
|
||||||
{
|
{
|
||||||
return std::abs(lhs.r - rhs.r) < 0.01f
|
return std::abs(lhs.r - rhs.r) < 0.01f
|
||||||
@ -138,28 +136,28 @@ operator==(const C3D_FQuat &lhs, const C3D_FQuat &rhs)
|
|||||||
&& std::abs(lhs.k - rhs.k) < 0.01f;
|
&& std::abs(lhs.k - rhs.k) < 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
print(const C3D_FVec &v)
|
print(const C3D_FVec &v)
|
||||||
{
|
{
|
||||||
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
||||||
std::printf("% 6.4f % 6.4f % 6.4f % 6.4f\n", v.w, v.x, v.y, v.z);
|
std::printf("% 6.4f % 6.4f % 6.4f % 6.4f\n", v.w, v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
print(const glm::vec3 &v)
|
print(const glm::vec3 &v)
|
||||||
{
|
{
|
||||||
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
||||||
std::printf("% 6.4f % 6.4f % 6.4f\n", v.x, v.y, v.z);
|
std::printf("% 6.4f % 6.4f % 6.4f\n", v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
print(const glm::vec4 &v)
|
print(const glm::vec4 &v)
|
||||||
{
|
{
|
||||||
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
||||||
std::printf("%6.4f % 6.4f % 6.4f % 6.4f\n", v.w, v.x, v.y, v.z);
|
std::printf("%6.4f % 6.4f % 6.4f % 6.4f\n", v.w, v.x, v.y, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
print(const C3D_Mtx &m)
|
print(const C3D_Mtx &m)
|
||||||
{
|
{
|
||||||
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
||||||
@ -173,7 +171,7 @@ print(const C3D_Mtx &m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
print(const glm::mat4 &m)
|
print(const glm::mat4 &m)
|
||||||
{
|
{
|
||||||
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
||||||
@ -187,33 +185,19 @@ print(const glm::mat4 &m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
static inline void
|
||||||
print(const glm::quat &q)
|
print(const glm::quat &q)
|
||||||
{
|
{
|
||||||
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
std::printf("%s:\n", __PRETTY_FUNCTION__);
|
||||||
std::printf("% 6.4f % 6.4f % 6.4f % 6.4f\n", q.w, q.x, q.y, q.z);
|
std::printf("% 6.4f % 6.4f % 6.4f % 6.4f\n", q.w, q.x, q.y, q.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U>
|
static const glm::vec3 x_axis(1.0f, 0.0f, 0.0f);
|
||||||
bool compare(const T &actual, const U &expected)
|
static const glm::vec3 y_axis(0.0f, 1.0f, 0.0f);
|
||||||
{
|
static const glm::vec3 z_axis(0.0f, 0.0f, 1.0f);
|
||||||
if(actual == expected)
|
static const glm::vec3 z_flip(1.0f, 1.0f, -1.0f);
|
||||||
return true;
|
|
||||||
|
|
||||||
std::printf("Expected:\n");
|
static void
|
||||||
print(expected);
|
|
||||||
std::printf("Actual:\n");
|
|
||||||
print(actual);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glm::vec3 x_axis(1.0f, 0.0f, 0.0f);
|
|
||||||
const glm::vec3 y_axis(0.0f, 1.0f, 0.0f);
|
|
||||||
const glm::vec3 z_axis(0.0f, 0.0f, 1.0f);
|
|
||||||
const glm::vec3 z_flip(1.0f, 1.0f, -1.0f);
|
|
||||||
|
|
||||||
void
|
|
||||||
check_matrix(generator_t &gen, distribution_t &dist)
|
check_matrix(generator_t &gen, distribution_t &dist)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -227,7 +211,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
{
|
{
|
||||||
C3D_Mtx m;
|
C3D_Mtx m;
|
||||||
Mtx_Identity(&m);
|
Mtx_Identity(&m);
|
||||||
assert(compare(m, glm::mat4()));
|
assert(m == glm::mat4());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ortho nominal cases
|
// ortho nominal cases
|
||||||
@ -246,12 +230,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// check near clip plane
|
// check near clip plane
|
||||||
v = Mtx_MultiplyFVecH(&m, FVec3_New((r-l)/2.0f, (t-b)/2.0f, -n));
|
v = Mtx_MultiplyFVecH(&m, FVec3_New((r-l)/2.0f, (t-b)/2.0f, -n));
|
||||||
v = FVec4_PerspDivide(v);
|
v = FVec4_PerspDivide(v);
|
||||||
assert(compare(v, FVec4_New(0.0f, 0.0f, -1.0f, 1.0f)));
|
assert(v == FVec4_New(0.0f, 0.0f, -1.0f, 1.0f));
|
||||||
|
|
||||||
// check far clip plane
|
// check far clip plane
|
||||||
v = Mtx_MultiplyFVecH(&m, FVec3_New((r-l)/2.0f, (t-b)/2.0f, -f));
|
v = Mtx_MultiplyFVecH(&m, FVec3_New((r-l)/2.0f, (t-b)/2.0f, -f));
|
||||||
v = FVec4_PerspDivide(v);
|
v = FVec4_PerspDivide(v);
|
||||||
assert(compare(v, FVec4_New(0.0f, 0.0f, 0.0f, 1.0f)));
|
assert(v == FVec4_New(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// perspective nominal cases
|
// perspective nominal cases
|
||||||
@ -268,12 +252,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// check near clip plane
|
// check near clip plane
|
||||||
v = Mtx_MultiplyFVecH(&m, FVec3_New(0.0f, 0.0f, -near));
|
v = Mtx_MultiplyFVecH(&m, FVec3_New(0.0f, 0.0f, -near));
|
||||||
v = FVec4_PerspDivide(v);
|
v = FVec4_PerspDivide(v);
|
||||||
assert(compare(v, FVec4_New(0.0f, 0.0f, -1.0f, 1.0f)));
|
assert(v == FVec4_New(0.0f, 0.0f, -1.0f, 1.0f));
|
||||||
|
|
||||||
// check far clip plane
|
// check far clip plane
|
||||||
v = Mtx_MultiplyFVecH(&m, FVec3_New(0.0f, 0.0f, -far));
|
v = Mtx_MultiplyFVecH(&m, FVec3_New(0.0f, 0.0f, -far));
|
||||||
v = FVec4_PerspDivide(v);
|
v = FVec4_PerspDivide(v);
|
||||||
assert(compare(v, FVec4_New(0.0f, 0.0f, 0.0f, 1.0f)));
|
assert(v == FVec4_New(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_t x = 0; x < 10000; ++x)
|
for(size_t x = 0; x < 10000; ++x)
|
||||||
@ -292,9 +276,9 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
if(Mtx_Inverse(&inv))
|
if(Mtx_Inverse(&inv))
|
||||||
{
|
{
|
||||||
Mtx_Multiply(&id, &m, &inv);
|
Mtx_Multiply(&id, &m, &inv);
|
||||||
assert(compare(id, glm::mat4())); // could still fail due to rounding errors
|
assert(id == glm::mat4()); // could still fail due to rounding errors
|
||||||
Mtx_Multiply(&id, &inv, &m);
|
Mtx_Multiply(&id, &inv, &m);
|
||||||
assert(compare(id, glm::mat4())); // could still fail due to rounding errors
|
assert(id == glm::mat4()); // could still fail due to rounding errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,12 +308,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// RH
|
// RH
|
||||||
Mtx_Persp(&m, fovy, aspect, near, far, false);
|
Mtx_Persp(&m, fovy, aspect, near, far, false);
|
||||||
glm::mat4 g = glm::perspective(fovy, aspect, near, far);
|
glm::mat4 g = glm::perspective(fovy, aspect, near, far);
|
||||||
assert(compare(m, fix_depth*g));
|
assert(m == fix_depth*g);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_Persp(&m, fovy, aspect, near, far, true);
|
Mtx_Persp(&m, fovy, aspect, near, far, true);
|
||||||
g = glm::perspective(fovy, aspect, near, far);
|
g = glm::perspective(fovy, aspect, near, far);
|
||||||
assert(compare(m, fix_depth*glm::scale(g, z_flip)));
|
assert(m == fix_depth*glm::scale(g, z_flip));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check perspective tilt
|
// check perspective tilt
|
||||||
@ -358,12 +342,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// RH
|
// RH
|
||||||
Mtx_PerspTilt(&m, fovy, aspect, near, far, false);
|
Mtx_PerspTilt(&m, fovy, aspect, near, far, false);
|
||||||
glm::mat4 g = glm::perspective(fovx, 1.0f / aspect, near, far);
|
glm::mat4 g = glm::perspective(fovx, 1.0f / aspect, near, far);
|
||||||
assert(compare(m, fix_depth*g*tilt));
|
assert(m == fix_depth*g*tilt);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_PerspTilt(&m, fovy, aspect, near, far, true);
|
Mtx_PerspTilt(&m, fovy, aspect, near, far, true);
|
||||||
g = glm::perspective(fovx, 1.0f / aspect, near, far);
|
g = glm::perspective(fovx, 1.0f / aspect, near, far);
|
||||||
assert(compare(m, fix_depth*glm::scale(g, z_flip)*tilt));
|
assert(m == fix_depth*glm::scale(g, z_flip)*tilt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check perspective stereo
|
// check perspective stereo
|
||||||
@ -410,14 +394,14 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// RH
|
// RH
|
||||||
Mtx_PerspStereo(&left, fovy, aspect, near, far, -iod, focLen, false);
|
Mtx_PerspStereo(&left, fovy, aspect, near, far, -iod, focLen, false);
|
||||||
Mtx_PerspStereo(&right, fovy, aspect, near, far, iod, focLen, false);
|
Mtx_PerspStereo(&right, fovy, aspect, near, far, iod, focLen, false);
|
||||||
assert(compare(left, fix_depth*g*left_eye));
|
assert(left == fix_depth*g*left_eye);
|
||||||
assert(compare(right, fix_depth*g*right_eye));
|
assert(right == fix_depth*g*right_eye);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_PerspStereo(&left, fovy, aspect, near, far, -iod, focLen, true);
|
Mtx_PerspStereo(&left, fovy, aspect, near, far, -iod, focLen, true);
|
||||||
Mtx_PerspStereo(&right, fovy, aspect, near, far, iod, focLen, true);
|
Mtx_PerspStereo(&right, fovy, aspect, near, far, iod, focLen, true);
|
||||||
assert(compare(left, fix_depth*glm::scale(g*left_eye, z_flip)));
|
assert(left == fix_depth*glm::scale(g*left_eye, z_flip));
|
||||||
assert(compare(right, fix_depth*glm::scale(g*right_eye, z_flip)));
|
assert(right == fix_depth*glm::scale(g*right_eye, z_flip));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check perspective stereo tilt
|
// check perspective stereo tilt
|
||||||
@ -464,14 +448,14 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// RH
|
// RH
|
||||||
Mtx_PerspStereoTilt(&left, fovy, aspect, near, far, -iod, focLen, false);
|
Mtx_PerspStereoTilt(&left, fovy, aspect, near, far, -iod, focLen, false);
|
||||||
Mtx_PerspStereoTilt(&right, fovy, aspect, near, far, iod, focLen, false);
|
Mtx_PerspStereoTilt(&right, fovy, aspect, near, far, iod, focLen, false);
|
||||||
assert(compare(left, fix_depth*g*left_eye*tilt));
|
assert(left == fix_depth*g*left_eye*tilt);
|
||||||
assert(compare(right, fix_depth*g*right_eye*tilt));
|
assert(right == fix_depth*g*right_eye*tilt);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_PerspStereoTilt(&left, fovy, aspect, near, far, -iod, focLen, true);
|
Mtx_PerspStereoTilt(&left, fovy, aspect, near, far, -iod, focLen, true);
|
||||||
Mtx_PerspStereoTilt(&right, fovy, aspect, near, far, iod, focLen, true);
|
Mtx_PerspStereoTilt(&right, fovy, aspect, near, far, iod, focLen, true);
|
||||||
assert(compare(left, fix_depth*glm::scale(g*left_eye, z_flip)*tilt));
|
assert(left == fix_depth*glm::scale(g*left_eye, z_flip)*tilt);
|
||||||
assert(compare(right, fix_depth*glm::scale(g*right_eye, z_flip)*tilt));
|
assert(right == fix_depth*glm::scale(g*right_eye, z_flip)*tilt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ortho
|
// check ortho
|
||||||
@ -496,12 +480,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// RH
|
// RH
|
||||||
Mtx_Ortho(&m, l, r, b, t, n, f, false);
|
Mtx_Ortho(&m, l, r, b, t, n, f, false);
|
||||||
glm::mat4 g = glm::ortho(l, r, b, t, n, f);
|
glm::mat4 g = glm::ortho(l, r, b, t, n, f);
|
||||||
assert(compare(m, fix_depth*g));
|
assert(m == fix_depth*g);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_Ortho(&m, l, r, b, t, n, f, true);
|
Mtx_Ortho(&m, l, r, b, t, n, f, true);
|
||||||
g = glm::ortho(l, r, b, t, n, f);
|
g = glm::ortho(l, r, b, t, n, f);
|
||||||
assert(compare(m, fix_depth*glm::scale(g, z_flip)));
|
assert(m == fix_depth*glm::scale(g, z_flip));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ortho tilt
|
// check ortho tilt
|
||||||
@ -526,12 +510,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
// RH
|
// RH
|
||||||
Mtx_OrthoTilt(&m, l, r, b, t, n, f, false);
|
Mtx_OrthoTilt(&m, l, r, b, t, n, f, false);
|
||||||
glm::mat4 g = glm::ortho(l, r, b, t, n, f);
|
glm::mat4 g = glm::ortho(l, r, b, t, n, f);
|
||||||
assert(compare(m, tilt*fix_depth*g));
|
assert(m == tilt*fix_depth*g);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_OrthoTilt(&m, l, r, b, t, n, f, true);
|
Mtx_OrthoTilt(&m, l, r, b, t, n, f, true);
|
||||||
g = glm::ortho(l, r, b, t, n, f);
|
g = glm::ortho(l, r, b, t, n, f);
|
||||||
assert(compare(m, tilt*fix_depth*glm::scale(g, z_flip)));
|
assert(m == tilt*fix_depth*glm::scale(g, z_flip));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check lookAt
|
// check lookAt
|
||||||
@ -556,12 +540,12 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
// RH
|
// RH
|
||||||
Mtx_LookAt(&m, camera, target, up, false);
|
Mtx_LookAt(&m, camera, target, up, false);
|
||||||
assert(compare(m, g));
|
assert(m == g);
|
||||||
|
|
||||||
// LH
|
// LH
|
||||||
Mtx_LookAt(&m, camera, target, up, true);
|
Mtx_LookAt(&m, camera, target, up, true);
|
||||||
// I can't say for certain that this is the correct test
|
// I can't say for certain that this is the correct test
|
||||||
assert(compare(m, glm::scale(glm::mat4(), glm::vec3(-1.0f, 1.0f, -1.0f))*g));
|
assert(m == glm::scale(glm::mat4(), glm::vec3(-1.0f, 1.0f, -1.0f))*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check multiply
|
// check multiply
|
||||||
@ -575,7 +559,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
C3D_Mtx result;
|
C3D_Mtx result;
|
||||||
Mtx_Multiply(&result, &m1, &m2);
|
Mtx_Multiply(&result, &m1, &m2);
|
||||||
assert(compare(result, g1*g2));
|
assert(result == g1*g2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check translate
|
// check translate
|
||||||
@ -587,7 +571,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
Mtx_Translate(&m, v.x, v.y, v.z, true);
|
Mtx_Translate(&m, v.x, v.y, v.z, true);
|
||||||
assert(compare(m, glm::translate(g, v)));
|
assert(m == glm::translate(g, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check translate (reversed)
|
// check translate (reversed)
|
||||||
@ -599,7 +583,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
Mtx_Translate(&m, v.x, v.y, v.z, false);
|
Mtx_Translate(&m, v.x, v.y, v.z, false);
|
||||||
assert(compare(m, glm::translate(glm::mat4(), v)*g));
|
assert(m == glm::translate(glm::mat4(), v)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check scale
|
// check scale
|
||||||
@ -611,7 +595,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
Mtx_Scale(&m, v.x, v.y, v.z);
|
Mtx_Scale(&m, v.x, v.y, v.z);
|
||||||
assert(compare(m, glm::scale(g, v)));
|
assert(m == glm::scale(g, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate
|
// check rotate
|
||||||
@ -625,7 +609,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
Mtx_Rotate(&m, FVec3_New(v.x, v.y, v.z), r, true);
|
Mtx_Rotate(&m, FVec3_New(v.x, v.y, v.z), r, true);
|
||||||
assert(compare(m, glm::rotate(g, r, v)));
|
assert(m == glm::rotate(g, r, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate (reversed)
|
// check rotate (reversed)
|
||||||
@ -639,7 +623,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
Mtx_Rotate(&m, FVec3_New(v.x, v.y, v.z), r, false);
|
Mtx_Rotate(&m, FVec3_New(v.x, v.y, v.z), r, false);
|
||||||
assert(compare(m, glm::rotate(glm::mat4(), r, v)*g));
|
assert(m == glm::rotate(glm::mat4(), r, v)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate X
|
// check rotate X
|
||||||
@ -652,7 +636,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_RotateX(&m, r, true);
|
Mtx_RotateX(&m, r, true);
|
||||||
assert(compare(m, glm::rotate(g, r, x_axis)));
|
assert(m == glm::rotate(g, r, x_axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate X (reversed)
|
// check rotate X (reversed)
|
||||||
@ -665,7 +649,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_RotateX(&m, r, false);
|
Mtx_RotateX(&m, r, false);
|
||||||
assert(compare(m, glm::rotate(glm::mat4(), r, x_axis)*g));
|
assert(m == glm::rotate(glm::mat4(), r, x_axis)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate Y
|
// check rotate Y
|
||||||
@ -678,7 +662,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_RotateY(&m, r, true);
|
Mtx_RotateY(&m, r, true);
|
||||||
assert(compare(m, glm::rotate(g, r, y_axis)));
|
assert(m == glm::rotate(g, r, y_axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate Y (reversed)
|
// check rotate Y (reversed)
|
||||||
@ -691,7 +675,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_RotateY(&m, r, false);
|
Mtx_RotateY(&m, r, false);
|
||||||
assert(compare(m, glm::rotate(glm::mat4(), r, y_axis)*g));
|
assert(m == glm::rotate(glm::mat4(), r, y_axis)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate Z
|
// check rotate Z
|
||||||
@ -704,7 +688,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_RotateZ(&m, r, true);
|
Mtx_RotateZ(&m, r, true);
|
||||||
assert(compare(m, glm::rotate(g, r, z_axis)));
|
assert(m == glm::rotate(g, r, z_axis));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate Z (reversed)
|
// check rotate Z (reversed)
|
||||||
@ -717,7 +701,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_RotateZ(&m, r, false);
|
Mtx_RotateZ(&m, r, false);
|
||||||
assert(compare(m, glm::rotate(glm::mat4(), r, z_axis)*g));
|
assert(m == glm::rotate(glm::mat4(), r, z_axis)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check vec3 multiply
|
// check vec3 multiply
|
||||||
@ -728,7 +712,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
assert(compare(Mtx_MultiplyFVec3(&m, FVec3_New(v.x, v.y, v.z)), glm::mat3x3(g)*v));
|
assert(Mtx_MultiplyFVec3(&m, FVec3_New(v.x, v.y, v.z)) == glm::mat3x3(g)*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check vec4 multiply
|
// check vec4 multiply
|
||||||
@ -739,7 +723,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::mat4 g = loadMatrix(m);
|
glm::mat4 g = loadMatrix(m);
|
||||||
glm::vec4 v = randomVector4(gen, dist);
|
glm::vec4 v = randomVector4(gen, dist);
|
||||||
|
|
||||||
assert(compare(Mtx_MultiplyFVec4(&m, FVec4_New(v.x, v.y, v.z, v.w)), g*v));
|
assert(Mtx_MultiplyFVec4(&m, FVec4_New(v.x, v.y, v.z, v.w)) == g*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check vecH multiply
|
// check vecH multiply
|
||||||
@ -751,7 +735,7 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec4 v = randomVector4(gen, dist);
|
glm::vec4 v = randomVector4(gen, dist);
|
||||||
v.w = 1.0f;
|
v.w = 1.0f;
|
||||||
|
|
||||||
assert(compare(Mtx_MultiplyFVecH(&m, FVec3_New(v.x, v.y, v.z)), glm::mat4x3(g)*v));
|
assert(Mtx_MultiplyFVecH(&m, FVec3_New(v.x, v.y, v.z)) == glm::mat4x3(g)*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check matrix transpose
|
// check matrix transpose
|
||||||
@ -770,9 +754,9 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
check = loadMatrix(m);
|
check = loadMatrix(m);
|
||||||
|
|
||||||
Mtx_Transpose(&m);
|
Mtx_Transpose(&m);
|
||||||
assert(compare(m, glm::transpose(check)));
|
assert(m == glm::transpose(check));
|
||||||
Mtx_Transpose(&m);
|
Mtx_Transpose(&m);
|
||||||
assert(compare(m, check));
|
assert(m == check);
|
||||||
|
|
||||||
//Comparing inverse(transpose(m)) == transpose(inverse(m))
|
//Comparing inverse(transpose(m)) == transpose(inverse(m))
|
||||||
C3D_Mtx m2;
|
C3D_Mtx m2;
|
||||||
@ -780,21 +764,21 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||||||
Mtx_Transpose(&m2);
|
Mtx_Transpose(&m2);
|
||||||
if(Mtx_Inverse(&m2))
|
if(Mtx_Inverse(&m2))
|
||||||
{
|
{
|
||||||
assert(compare(m2, glm::inverse(glm::transpose(check))));
|
assert(m2 == glm::inverse(glm::transpose(check)));
|
||||||
assert(compare(m2, glm::transpose(glm::inverse(check))));
|
assert(m2 == glm::transpose(glm::inverse(check)));
|
||||||
}
|
}
|
||||||
Mtx_Copy(&m2, &m);
|
Mtx_Copy(&m2, &m);
|
||||||
if(Mtx_Inverse(&m2))
|
if(Mtx_Inverse(&m2))
|
||||||
{
|
{
|
||||||
Mtx_Transpose(&m2);
|
Mtx_Transpose(&m2);
|
||||||
assert(compare(m2, glm::inverse(glm::transpose(check))));
|
assert(m2 == glm::inverse(glm::transpose(check)));
|
||||||
assert(compare(m2, glm::transpose(glm::inverse(check))));
|
assert(m2 == glm::transpose(glm::inverse(check)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
check_quaternion(generator_t &gen, distribution_t &dist)
|
check_quaternion(generator_t &gen, distribution_t &dist)
|
||||||
{
|
{
|
||||||
// check identity
|
// check identity
|
||||||
@ -802,7 +786,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
C3D_FQuat q = Quat_Identity();
|
C3D_FQuat q = Quat_Identity();
|
||||||
glm::quat g;
|
glm::quat g;
|
||||||
|
|
||||||
assert(compare(q, g));
|
assert(q == g);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_t x = 0; x < 10000; ++x)
|
for(size_t x = 0; x < 10000; ++x)
|
||||||
@ -812,7 +796,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
C3D_FQuat q = randomQuat(gen, dist);
|
C3D_FQuat q = randomQuat(gen, dist);
|
||||||
glm::quat g = loadQuat(q);
|
glm::quat g = loadQuat(q);
|
||||||
|
|
||||||
assert(compare(Quat_Negate(q), -g));
|
assert(Quat_Negate(q) == -g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check addition
|
// check addition
|
||||||
@ -823,7 +807,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
glm::quat g1 = loadQuat(q1);
|
glm::quat g1 = loadQuat(q1);
|
||||||
glm::quat g2 = loadQuat(q2);
|
glm::quat g2 = loadQuat(q2);
|
||||||
|
|
||||||
assert(compare(Quat_Add(q1, q2), g1+g2));
|
assert(Quat_Add(q1, q2) == g1+g2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check subtraction
|
// check subtraction
|
||||||
@ -834,7 +818,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
glm::quat g1 = loadQuat(q1);
|
glm::quat g1 = loadQuat(q1);
|
||||||
glm::quat g2 = loadQuat(q2);
|
glm::quat g2 = loadQuat(q2);
|
||||||
|
|
||||||
assert(compare(Quat_Subtract(q1, q2), g1 + (-g2)));
|
assert(Quat_Subtract(q1, q2) == g1 + (-g2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check scale
|
// check scale
|
||||||
@ -844,7 +828,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
float f = dist(gen);
|
float f = dist(gen);
|
||||||
|
|
||||||
assert(compare(Quat_Scale(q, f), g*f));
|
assert(Quat_Scale(q, f) == g*f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check normalize
|
// check normalize
|
||||||
@ -852,7 +836,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
C3D_FQuat q = randomQuat(gen, dist);
|
C3D_FQuat q = randomQuat(gen, dist);
|
||||||
glm::quat g = loadQuat(q);
|
glm::quat g = loadQuat(q);
|
||||||
|
|
||||||
assert(compare(Quat_Normalize(q), glm::normalize(g)));
|
assert(Quat_Normalize(q) == glm::normalize(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check dot
|
// check dot
|
||||||
@ -870,7 +854,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
C3D_FQuat q = randomQuat(gen, dist);
|
C3D_FQuat q = randomQuat(gen, dist);
|
||||||
glm::quat g = loadQuat(q);
|
glm::quat g = loadQuat(q);
|
||||||
|
|
||||||
assert(compare(Quat_Conjugate(q), glm::conjugate(g)));
|
assert(Quat_Conjugate(q) == glm::conjugate(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check inverse
|
// check inverse
|
||||||
@ -878,7 +862,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
C3D_FQuat q = randomQuat(gen, dist);
|
C3D_FQuat q = randomQuat(gen, dist);
|
||||||
glm::quat g = loadQuat(q);
|
glm::quat g = loadQuat(q);
|
||||||
|
|
||||||
assert(compare(Quat_Inverse(q), glm::inverse(g)));
|
assert(Quat_Inverse(q) == glm::inverse(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check quaternion multiplication
|
// check quaternion multiplication
|
||||||
@ -888,7 +872,7 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
glm::quat g1 = loadQuat(q1);
|
glm::quat g1 = loadQuat(q1);
|
||||||
glm::quat g2 = loadQuat(q2);
|
glm::quat g2 = loadQuat(q2);
|
||||||
|
|
||||||
assert(compare(Quat_Multiply(q1, q2), g1*g2));
|
assert(Quat_Multiply(q1, q2) == g1*g2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check quat pow()
|
// check quat pow()
|
||||||
@ -898,17 +882,17 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
//glm::quat g = loadQuat(q);
|
//glm::quat g = loadQuat(q);
|
||||||
float r = dist(gen);
|
float r = dist(gen);
|
||||||
|
|
||||||
//assert(compare(Quat_Pow(q, r), glm::pow(g, r)));
|
//assert(Quat_Pow(q, r) == glm::pow(g, r));
|
||||||
|
|
||||||
q = Quat_Normalize(q);
|
q = Quat_Normalize(q);
|
||||||
|
|
||||||
// check trivial cases
|
// check trivial cases
|
||||||
assert(compare(Quat_Pow(q, 1.0f), q));
|
assert(Quat_Pow(q, 1.0f) == q);
|
||||||
assert(compare(Quat_Pow(q, 0.0f), Quat_Identity()));
|
assert(Quat_Pow(q, 0.0f) == Quat_Identity());
|
||||||
assert(compare(Quat_Pow(Quat_Identity(), r), Quat_Identity()));
|
assert(Quat_Pow(Quat_Identity(), r) == Quat_Identity());
|
||||||
|
|
||||||
// validate semantics
|
// validate semantics
|
||||||
assert(compare(Quat_Pow(q, r), Quat_Multiply(Quat_Pow(q, r/2), Quat_Pow(q, r/2))));
|
assert(Quat_Pow(q, r) == Quat_Multiply(Quat_Pow(q, r/2), Quat_Pow(q, r/2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check vector multiplication (cross)
|
// check vector multiplication (cross)
|
||||||
@ -918,8 +902,8 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
|
|
||||||
assert(compare(Quat_CrossFVec3(q, FVec3_New(v.x, v.y, v.z)), glm::cross(g, v)));
|
assert(Quat_CrossFVec3(q, FVec3_New(v.x, v.y, v.z)) == glm::cross(g, v));
|
||||||
assert(compare(FVec3_CrossQuat(FVec3_New(v.x, v.y, v.z), q), glm::cross(v, g)));
|
assert(FVec3_CrossQuat(FVec3_New(v.x, v.y, v.z), q) == glm::cross(v, g));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotation
|
// check rotation
|
||||||
@ -930,8 +914,8 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
glm::vec3 v = randomVector3(gen, dist);
|
glm::vec3 v = randomVector3(gen, dist);
|
||||||
float r = randomAngle(gen, dist);
|
float r = randomAngle(gen, dist);
|
||||||
|
|
||||||
assert(compare(Quat_Rotate(q, FVec3_New(v.x, v.y, v.z), r, false), glm::rotate(g, r, v)));
|
assert(Quat_Rotate(q, FVec3_New(v.x, v.y, v.z), r, false) == glm::rotate(g, r, v));
|
||||||
assert(compare(Quat_Rotate(q, FVec3_New(v.x, v.y, v.z), r, true), glm::rotate(glm::quat(), r, v)*g));
|
assert(Quat_Rotate(q, FVec3_New(v.x, v.y, v.z), r, true) == glm::rotate(glm::quat(), r, v)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate X
|
// check rotate X
|
||||||
@ -941,8 +925,8 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
float r = randomAngle(gen, dist);
|
float r = randomAngle(gen, dist);
|
||||||
|
|
||||||
assert(compare(Quat_RotateX(q, r, false), glm::rotate(g, r, x_axis)));
|
assert(Quat_RotateX(q, r, false) == glm::rotate(g, r, x_axis));
|
||||||
assert(compare(Quat_RotateX(q, r, true), glm::rotate(glm::quat(), r, x_axis)*g));
|
assert(Quat_RotateX(q, r, true) == glm::rotate(glm::quat(), r, x_axis)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate Y
|
// check rotate Y
|
||||||
@ -952,8 +936,8 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
float r = randomAngle(gen, dist);
|
float r = randomAngle(gen, dist);
|
||||||
|
|
||||||
assert(compare(Quat_RotateY(q, r, false), glm::rotate(g, r, y_axis)));
|
assert(Quat_RotateY(q, r, false) == glm::rotate(g, r, y_axis));
|
||||||
assert(compare(Quat_RotateY(q, r, true), glm::rotate(glm::quat(), r, y_axis)*g));
|
assert(Quat_RotateY(q, r, true) == glm::rotate(glm::quat(), r, y_axis)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check rotate Z
|
// check rotate Z
|
||||||
@ -963,8 +947,8 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
float r = randomAngle(gen, dist);
|
float r = randomAngle(gen, dist);
|
||||||
|
|
||||||
assert(compare(Quat_RotateZ(q, r, false), glm::rotate(g, r, z_axis)));
|
assert(Quat_RotateZ(q, r, false) == glm::rotate(g, r, z_axis));
|
||||||
assert(compare(Quat_RotateZ(q, r, true), glm::rotate(glm::quat(), r, z_axis)*g));
|
assert(Quat_RotateZ(q, r, true) == glm::rotate(glm::quat(), r, z_axis)*g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check conversion to matrix
|
// check conversion to matrix
|
||||||
@ -974,12 +958,10 @@ check_quaternion(generator_t &gen, distribution_t &dist)
|
|||||||
|
|
||||||
C3D_Mtx m;
|
C3D_Mtx m;
|
||||||
Mtx_FromQuat(&m, q);
|
Mtx_FromQuat(&m, q);
|
||||||
assert(compare(m, glm::mat4_cast(g)));
|
assert(m == glm::mat4_cast(g));
|
||||||
|
|
||||||
C3D_FQuat q2 = Quat_FromMtx(&m);
|
C3D_FQuat q2 = Quat_FromMtx(&m);
|
||||||
if(!(q2 == q || q2 == FVec4_Negate(q)))
|
assert(q2 == q || q2 == FVec4_Negate(q));
|
||||||
assert(compare(q2, q));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user