mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-28 08:49:30 +00:00
Updated Lua and citro3D, Added a type check in ctr.thread.pool
This commit is contained in:
parent
d3ea68f3d7
commit
2725dce383
81 changed files with 1467 additions and 801 deletions
|
|
@ -21,7 +21,7 @@ VERSION := $(CITRO3D_MAJOR).$(CITRO3D_MINOR).$(CITRO3D_PATCH)
|
|||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := $(notdir $(CURDIR))
|
||||
TARGET := citro3d
|
||||
BUILD := build
|
||||
SOURCES := source \
|
||||
source/maths
|
||||
|
|
|
|||
|
|
@ -283,12 +283,6 @@ static inline void Mtx_Copy(C3D_Mtx* out, const C3D_Mtx* in)
|
|||
*out = *in;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Identity matrix
|
||||
* @param[out] out Matrix to fill
|
||||
*/
|
||||
void Mtx_Identity(C3D_Mtx* out);
|
||||
|
||||
/**
|
||||
* @brief Multiply two matrices
|
||||
* @param[out] out Output matrix
|
||||
|
|
@ -489,6 +483,62 @@ void Mtx_PerspStereoTilt(C3D_Mtx* mtx, float fovy, float aspect, float near, flo
|
|||
* @param[in] isLeftHanded If true, output matrix is left-handed. If false, output matrix is right-handed.
|
||||
*/
|
||||
void Mtx_LookAt(C3D_Mtx* out, C3D_FVec cameraPosition, C3D_FVec cameraTarget, C3D_FVec cameraUpVector, bool isLeftHanded);
|
||||
|
||||
/**
|
||||
*@brief Transposes the matrix. Row => Column, and vice versa.
|
||||
*@param[in,out] out Output matrix.
|
||||
*/
|
||||
void Mtx_Transpose(C3D_Mtx* out);
|
||||
|
||||
/**
|
||||
* @brief Creates a matrix with the diagonal using the given parameters.
|
||||
* @param[out] out Output matrix.
|
||||
* @param[in] x The X component.
|
||||
* @param[in] y The Y component.
|
||||
* @param[in] z The Z component.
|
||||
* @param[in] w The W component.
|
||||
*/
|
||||
static inline void Mtx_Diagonal(C3D_Mtx* out, float x, float y, float z, float w)
|
||||
{
|
||||
Mtx_Zeros(out);
|
||||
out->r[0].x = x;
|
||||
out->r[1].y = y;
|
||||
out->r[2].z = z;
|
||||
out->r[3].w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Identity matrix
|
||||
* @param[out] out Matrix to fill
|
||||
*/
|
||||
static inline void Mtx_Identity(C3D_Mtx* out)
|
||||
{
|
||||
Mtx_Diagonal(out, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix addition
|
||||
* @param[out] out Output matrix.
|
||||
* @param[in] lhs Left matrix.
|
||||
* @param[in] rhs Right matrix.
|
||||
*/
|
||||
static inline void Mtx_Add(C3D_Mtx* out, const C3D_Mtx* lhs, const C3D_Mtx* rhs)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
out->m[i] = lhs->m[i] + rhs->m[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Matrix subtraction
|
||||
* @param[out] out Output matrix.
|
||||
* @param[in] lhs Left matrix.
|
||||
* @param[in] rhs Right matrix.
|
||||
*/
|
||||
static inline void Mtx_Subtract(C3D_Mtx* out, const C3D_Mtx* lhs, const C3D_Mtx* rhs)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
out->m[i] = lhs->m[i] - rhs->m[i];
|
||||
}
|
||||
///@}
|
||||
|
||||
///@name Quaternion Math
|
||||
|
|
@ -621,6 +671,14 @@ C3D_FQuat Quat_RotateZ(C3D_FQuat q, float r, bool bRightSide);
|
|||
*/
|
||||
void Mtx_FromQuat(C3D_Mtx* m, C3D_FQuat q);
|
||||
|
||||
/**
|
||||
* @brief Get Quaternion equivalent to 4x4 matrix
|
||||
* @note If the matrix is orthogonal or special orthogonal, where determinant(matrix) = +1.0f, then the matrix can be converted.
|
||||
* @param[in] m Input Matrix
|
||||
* @return Generated Quaternion
|
||||
*/
|
||||
C3D_FQuat Quat_FromMtx(const C3D_Mtx* m);
|
||||
|
||||
/**
|
||||
* @brief Identity Quaternion
|
||||
* @return Identity Quaternion
|
||||
|
|
@ -668,4 +726,31 @@ static inline C3D_FVec FVec3_CrossQuat(C3D_FVec v, C3D_FQuat q)
|
|||
// v×q = q^-1×v
|
||||
return Quat_CrossFVec3(Quat_Inverse(q), v);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converting Pitch, Yaw, and Roll to Quaternion equivalent
|
||||
* @param[in] pitch The pitch angle in radians.
|
||||
* @param[in] yaw The yaw angle in radians.
|
||||
* @param[in] roll The roll angle in radians.
|
||||
* @return C3D_FQuat The Quaternion equivalent with the pitch, yaw, and roll orientations applied.
|
||||
*/
|
||||
C3D_FQuat Quat_FromPitchYawRoll(float pitch, float yaw, float roll, bool bRightSide);
|
||||
|
||||
/**
|
||||
* @brief Quaternion Look At
|
||||
* @param[in] source C3D_FVec Starting position. Origin of rotation.
|
||||
* @param[in] target C3D_FVec Target position to orient towards.
|
||||
* @param[in] forwardVector C3D_FVec The Up vector.
|
||||
* @param[in] upVector C3D_FVec The Up vector.
|
||||
* @return Quaternion rotation.
|
||||
*/
|
||||
C3D_FQuat Quat_LookAt(C3D_FVec source, C3D_FVec target, C3D_FVec forwardVector, C3D_FVec upVector);
|
||||
|
||||
/**
|
||||
* @brief Quaternion, created from a given axis and angle in radians.
|
||||
* @param[in] axis C3D_FVec The axis to rotate around at.
|
||||
* @param[in] angle float The angle to rotate. Unit: Radians
|
||||
* @return Quaternion rotation based on the axis and angle. Axis doesn't have to be orthogonal.
|
||||
*/
|
||||
C3D_FQuat Quat_FromAxisAngle(C3D_FVec axis, float angle);
|
||||
///@}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
#include <c3d/maths.h>
|
||||
|
||||
void Mtx_Identity(C3D_Mtx* out)
|
||||
{
|
||||
// http://www.wolframalpha.com/input/?i={{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}
|
||||
int i;
|
||||
for (i = 0; i < 16; ++i)
|
||||
out->m[i] = 0.0f;
|
||||
out->r[0].x = out->r[1].y = out->r[2].z = out->r[3].w = 1.0f;
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
#include <unistd.h>
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "vshader_shbin.h"
|
||||
|
||||
|
|
@ -840,6 +841,104 @@ void ortho_test()
|
|||
C3D_RenderTargetDelete(tex);
|
||||
}
|
||||
|
||||
void transpose_test()
|
||||
{
|
||||
consoleClear();
|
||||
C3D_Mtx modelView, check;
|
||||
|
||||
Mtx_Identity(&modelView);
|
||||
Mtx_Translate(&modelView, ((float)(rand() % 100)) + 5.0f, ((float)(rand() % 100)) + 5.0f, ((float)(rand() % 100)) + 5.0f, true);
|
||||
Mtx_RotateX(&modelView, (float)(rand() % 180) * (acos(-1)/180.0f), true);
|
||||
Mtx_RotateY(&modelView, (float)(rand() % 180) * (acos(-1)/180.0f), true);
|
||||
Mtx_RotateZ(&modelView, (float)(rand() % 180) * (acos(-1)/180.0f), true);
|
||||
Mtx_Copy(&check, &modelView);
|
||||
|
||||
std::printf("Random Translation:\n");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
std::printf("%2.2f ", modelView.m[i]);
|
||||
if (i % 4 == 3)
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
Mtx_Transpose(&modelView);
|
||||
|
||||
std::printf("Random Translation Transposed:\n");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
std::printf("%2.2f ", modelView.m[i]);
|
||||
if (i % 4 == 3)
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
Mtx_Transpose(&modelView);
|
||||
|
||||
std::printf("Rand-Trans Transposed Transposed:\n");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
std::printf("%2.2f ", modelView.m[i]);
|
||||
if (i % 4 == 3)
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
bool transposeFailCheck = false;
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
if (modelView.m[i] != check.m[i])
|
||||
{
|
||||
transposeFailCheck = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool transInvFailCheck = false;
|
||||
Mtx_Inverse(&modelView);
|
||||
Mtx_Transpose(&modelView);
|
||||
Mtx_Transpose(&check);
|
||||
Mtx_Inverse(&check);
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
if (fabsf(modelView.m[i] - check.m[i]) > 0.001f)
|
||||
{
|
||||
std::printf("%f != %f\n", modelView.m[i], check.m[i]);
|
||||
transInvFailCheck = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::printf("Transposed Inverse of RandMatrix:\n");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
std::printf("%2.2f ", modelView.m[i]);
|
||||
if (i % 4 == 3)
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
std::printf("Inverse Transposed of RandMatrix:\n");
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
std::printf("%2.2f ", check.m[i]);
|
||||
if (i % 4 == 3)
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
std::printf("\n");
|
||||
std::printf("Transpose(Transpose(A)) = A? %s\n", (transposeFailCheck ? "False" : "True"));
|
||||
std::printf("Inv(Trans(A))=Trans(Inv(A))? %s\n", (transInvFailCheck ? "False" : "True"));
|
||||
|
||||
while(aptMainLoop())
|
||||
{
|
||||
gspWaitForVBlank();
|
||||
|
||||
hidScanInput();
|
||||
u32 down = hidKeysDown();
|
||||
if(down & (KEY_START|KEY_SELECT))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
|
|
@ -854,6 +953,7 @@ test_t tests[] =
|
|||
{ "Mtx_Persp", persp_test, },
|
||||
{ "Mtx_PerspStereo", stereo_test, },
|
||||
{ "Mtx_Ortho", ortho_test, },
|
||||
{ "Mtx_Transpose", transpose_test, },
|
||||
};
|
||||
|
||||
const size_t num_tests = sizeof(tests)/sizeof(tests[0]);
|
||||
|
|
|
|||
|
|
@ -737,6 +737,31 @@ check_matrix(generator_t &gen, distribution_t &dist)
|
|||
|
||||
assert(Mtx_MultiplyFVecH(&m, FVec3_New(v.x, v.y, v.z)) == glm::mat4x3(g)*v);
|
||||
}
|
||||
|
||||
// check matrix transpose
|
||||
{
|
||||
C3D_Mtx m;
|
||||
glm::mat4 check;
|
||||
|
||||
randomMatrix(m, gen, dist);
|
||||
|
||||
//Reducing rounding errors, and copying the values over to the check matrix.
|
||||
for(size_t i = 0; i < 16; ++i)
|
||||
{
|
||||
m.m[i] = static_cast<int>(m.m[i]);
|
||||
}
|
||||
|
||||
check = loadMatrix(m);
|
||||
|
||||
Mtx_Transpose(&m);
|
||||
Mtx_Transpose(&m);
|
||||
assert(m == glm::transpose(glm::transpose(check)));
|
||||
|
||||
//Comparing inverse(transpose(m)) == transpose(inverse(m))
|
||||
Mtx_Transpose(&m);
|
||||
Mtx_Inverse(&m);
|
||||
assert(m == glm::transpose(glm::inverse(check)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue