Remove redundant vertex, matrix and quaternion code

This commit is contained in:
Gustaf Alhäll 2025-09-05 22:14:03 +02:00 committed by Anonimus
parent bfc55ed016
commit d0ab031a71
20 changed files with 239 additions and 525 deletions

View file

@ -26,7 +26,6 @@ hu_stuff.c
i_time.c
y_inter.c
st_stuff.c
matrix.c
m_aatree.c
m_anigif.c
m_argv.c
@ -66,7 +65,6 @@ p_slopes.c
p_sweep.cpp
p_test.cpp
p_deepcopy.cpp
quaternion.c
tables.c
r_bsp.cpp
r_data.c
@ -90,7 +88,6 @@ r_debug.cpp
r_debug_parser.cpp
screen.c
taglist.c
vector3d.c
v_video.c
s_sound.c
sounds.c

View file

@ -79,7 +79,7 @@ typedef struct mesh_s
typedef struct tag_s
{
char name[64];
// oldmatrix_t transform;
// matrix_t transform;
} tag_t;
#define MODEL_INTERPOLATION_FLAG "+i"

View file

@ -2362,17 +2362,32 @@ static int slope_get(lua_State *L)
lua_pushboolean(L, 1);
return 1;
case slope_o: // o
LUA_PushUserdata(L, &slope->o, META_VECTOR3);
{
vector3_t *vec = lua_newuserdata(L, sizeof(vector3_t));
luaL_getmetatable(L, META_VECTOR3);
lua_setmetatable(L, -2);
FV3_Load(vec, slope->o.x, slope->o.y, slope->o.z);
return 1;
}
case slope_d: // d
LUA_PushUserdata(L, &slope->d, META_VECTOR2);
{
vector2_t *vec = lua_newuserdata(L, sizeof(vector2_t));
luaL_getmetatable(L, META_VECTOR2);
lua_setmetatable(L, -2);
FV2_Load(vec, slope->d.x, slope->d.y);
return 1;
}
case slope_zdelta: // zdelta
lua_pushfixed(L, slope->zdelta);
return 1;
case slope_normal: // normal
LUA_PushUserdata(L, &slope->normal, META_VECTOR3);
{
vector3_t *vec = lua_newuserdata(L, sizeof(vector3_t));
luaL_getmetatable(L, META_VECTOR3);
lua_setmetatable(L, -2);
FV3_Load(vec, slope->normal.x, slope->normal.y, slope->normal.z);
return 1;
}
case slope_zangle: // zangle
lua_pushangle(L, slope->zangle);
return 1;

View file

@ -9,8 +9,7 @@
/// \file lua_matrixlib.c
/// \brief matrix library for Lua scripting
#include "matrix.h"
#include "vector3d.h"
#include "m_fixed.h"
#include "lua_script.h"
#include "lua_libs.h"
@ -62,7 +61,7 @@ static matrix_t *NewMatrix(lua_State *L)
static int matrix_new(lua_State *L)
{
Matrix_SetIdentity(NewMatrix(L));
FM_LoadIdentity(NewMatrix(L));
return 1;
}
@ -70,7 +69,7 @@ static int matrix_translation(lua_State *L)
{
vector3_t translation;
GetVectorOrXYZ(L, 1, &translation);
Matrix_SetTranslation(NewMatrix(L), translation.x, translation.y, translation.z);
FM_Translate(NewMatrix(L), translation.x, translation.y, translation.z);
return 1;
}
@ -78,7 +77,7 @@ static int matrix_scaling(lua_State *L)
{
vector3_t scaling;
GetVectorOrXYZ(L, 1, &scaling);
Matrix_SetScaling(NewMatrix(L), scaling.x, scaling.y, scaling.z);
FM_Scale(NewMatrix(L), scaling.x, scaling.y, scaling.z);
return 1;
}
@ -110,7 +109,7 @@ static const char *const matrixfield_opt[] = {
static int matrix_clone(lua_State *L)
{
matrix_t *mat = luaL_checkudata(L, 1, META_MATRIX);
Matrix_Copy(NewMatrix(L), mat);
memcpy(NewMatrix(L), mat, sizeof(matrix_t));
return 1;
}
@ -125,7 +124,7 @@ static int matrix_getvalue(lua_State *L)
if (col < 1 || col > 4)
return luaL_error(L, "matrix column %d out of range (1 - 4)", col);
lua_pushfixed(L, mat->matrix[row - 1][col - 1]);
lua_pushfixed(L, mat->m[(col - 1) * 4 + row - 1]);
return 1;
}
@ -141,7 +140,7 @@ static int matrix_setvalue(lua_State *L)
if (col < 1 || col > 4)
return luaL_error(L, "matrix column %d out of range (1 - 4)", col);
mat->matrix[row - 1][col - 1] = value;
mat->m[(col - 1) * 4 + row - 1] = value;
return 0;
}
@ -154,8 +153,8 @@ static int matrix_mulXYZ(lua_State *L)
vector3_t vec;
vector3_t result;
Vector3D_Set(&vec, x, y, z);
Matrix_MulVector(&result, mat, &vec);
FV3_Load(&vec, x, y, z);
FM_MultMatrixVec3(mat, &vec, &result);
lua_pushfixed(L, result.x);
lua_pushfixed(L, result.y);
@ -195,12 +194,12 @@ static int matrix_mul(lua_State *L)
luaL_getmetatable(L, META_VECTOR3);
lua_setmetatable(L, -2);
Matrix_MulVector(result, mat1, vec2);
FM_MultMatrixVec3(mat1, vec2, result);
}
else
{
matrix_t *mat2 = luaL_checkudata(L, 2, META_MATRIX);
Matrix_Mul(NewMatrix(L), mat1, mat2);
FM_MultMatrixEx(mat1, mat2, NewMatrix(L));
}
return 1;

View file

@ -9,13 +9,13 @@
/// \file lua_quaternionlib.c
/// \brief quaternion library for Lua scripting
#include "quaternion.h"
#include "m_fixed.h"
#include "lua_script.h"
#include "lua_libs.h"
static quaternion_t *NewQuaternion(lua_State *L)
static vector4_t *NewQuaternion(lua_State *L)
{
quaternion_t *quat = lua_newuserdata(L, sizeof(*quat));
vector4_t *quat = lua_newuserdata(L, sizeof(*quat));
luaL_getmetatable(L, META_QUATERNION);
lua_setmetatable(L, -2);
return quat;
@ -27,7 +27,11 @@ static quaternion_t *NewQuaternion(lua_State *L)
static int quaternion_new(lua_State *L)
{
Quaternion_SetIdentity(NewQuaternion(L));
vector4_t *q = NewQuaternion(L);
q->x = 0;
q->y = 0;
q->z = 0;
q->a = FRACUNIT;
return 1;
}
@ -35,7 +39,19 @@ static int quaternion_fromAxisRotation(lua_State *L)
{
vector3_t *axis = luaL_checkudata(L, 1, META_VECTOR3);
fixed_t angle = luaL_checkfixed(L, 2);
Quaternion_SetAxisRotation(NewQuaternion(L), axis, angle);
fixed_t cosangle = FINECOSINE(((angle / 2) >> ANGLETOFINESHIFT) & FINEMASK);
fixed_t sinangle = FINESINE(((angle / 2) >> ANGLETOFINESHIFT) & FINEMASK);
vector3_t normaxis;
FV3_NormalizeEx(axis, &normaxis);
FV4_Load(NewQuaternion(L),
FixedMul(normaxis.x, sinangle),
FixedMul(normaxis.y, sinangle),
FixedMul(normaxis.z, sinangle),
cosangle
);
return 1;
}
@ -51,20 +67,47 @@ static luaL_Reg quaternion[] = {
static int quaternion_clone(lua_State *L)
{
quaternion_t *quat = luaL_checkudata(L, 1, META_QUATERNION);
Quaternion_Copy(NewQuaternion(L), quat);
vector4_t *quat = luaL_checkudata(L, 1, META_QUATERNION);
FV4_Copy(NewQuaternion(L), quat);
return 1;
}
static int quaternion_toMatrix(lua_State *L)
static int vector4_toMatrix(lua_State *L)
{
quaternion_t *quat = luaL_checkudata(L, 1, META_QUATERNION);
vector4_t *quat = luaL_checkudata(L, 1, META_QUATERNION);
matrix_t *mat = lua_newuserdata(L, sizeof(*mat));
luaL_getmetatable(L, META_MATRIX);
lua_setmetatable(L, -2);
Quaternion_ToMatrix(mat, quat);
fixed_t x = quat->x, y = quat->y, z = quat->z, w = quat->a;
fixed_t xx2 = 2 * FixedMul(x, x);
fixed_t xy2 = 2 * FixedMul(x, y);
fixed_t xz2 = 2 * FixedMul(x, z);
fixed_t xw2 = 2 * FixedMul(x, w);
fixed_t yy2 = 2 * FixedMul(y, y);
fixed_t yz2 = 2 * FixedMul(y, z);
fixed_t yw2 = 2 * FixedMul(y, w);
fixed_t zz2 = 2 * FixedMul(z, z);
fixed_t zw2 = 2 * FixedMul(z, w);
FM_LoadIdentity(mat);
mat->m[0 + 0*4] = FRACUNIT - yy2 - zz2;
mat->m[0 + 1*4] = xy2 - zw2;
mat->m[0 + 2*4] = xz2 + yw2;
mat->m[1 + 0*4] = xy2 + zw2;
mat->m[1 + 1*4] = FRACUNIT - xx2 - zz2;
mat->m[1 + 2*4] = yz2 - xw2;
mat->m[2 + 0*4] = xz2 - yw2;
mat->m[2 + 1*4] = yz2 + xw2;
mat->m[2 + 2*4] = FRACUNIT - xx2 - yy2;
mat->m[3 + 3*4] = FRACUNIT;
return 1;
}
@ -88,18 +131,18 @@ static const char *const quaternionfield_opt[] = {
static int quaternion_get(lua_State *L)
{
quaternion_t *quat = luaL_checkudata(L, 1, META_QUATERNION);
vector4_t *quat = luaL_checkudata(L, 1, META_QUATERNION);
enum quaternionfield_e field = luaL_checkoption(L, 2, quaternionfield_opt[0], quaternionfield_opt);
switch(field)
{
case quaternionfield_clone: lua_pushcfunction(L, quaternion_clone); return 1;
case quaternionfield_toMatrix: lua_pushcfunction(L, quaternion_toMatrix); return 1;
case quaternionfield_toMatrix: lua_pushcfunction(L, vector4_toMatrix); return 1;
case quaternionfield_x: lua_pushfixed(L, quat->x); return 1;
case quaternionfield_y: lua_pushfixed(L, quat->y); return 1;
case quaternionfield_z: lua_pushfixed(L, quat->z); return 1;
case quaternionfield_w: lua_pushfixed(L, quat->w); return 1;
case quaternionfield_w: lua_pushfixed(L, quat->a); return 1;
default: break;
}
@ -113,9 +156,9 @@ static int quaternion_get(lua_State *L)
static int quaternion_mul(lua_State *L)
{
quaternion_t *quat1 = luaL_checkudata(L, 1, META_QUATERNION);
quaternion_t *quat2 = luaL_checkudata(L, 2, META_QUATERNION);
Quaternion_Mul(NewQuaternion(L), quat1, quat2);
vector4_t *quat1 = luaL_checkudata(L, 1, META_QUATERNION);
vector4_t *quat2 = luaL_checkudata(L, 2, META_QUATERNION);
FV4_MulEx(quat1, quat2, NewQuaternion(L));
return 1;
}

View file

@ -9,7 +9,7 @@
/// \file lua_vectorlib.c
/// \brief vector library for Lua scripting
#include "vector3d.h"
#include "m_fixed.h"
#include "lua_script.h"
#include "lua_libs.h"
@ -44,7 +44,7 @@ static const char *const vectorfield_opt[] = {
static int vector2d_get(lua_State *L)
{
vector2_t *vec = *((vector2_t **)luaL_checkudata(L, 1, META_VECTOR2));
vector2_t *vec = luaL_checkudata(L, 1, META_VECTOR2);
enum vectorfield_e field = luaL_checkoption(L, 2, vectorfield_opt[0], vectorfield_opt);
switch(field)
@ -79,7 +79,7 @@ static int vector3d_new(lua_State *L)
fixed_t y = luaL_checkfixed(L, 2);
fixed_t z = luaL_optfixed(L, 3, 0);
Vector3D_Set(NewVector3(L), x, y, z);
FV3_Load(NewVector3(L), x, y, z);
return 1;
}
@ -95,14 +95,14 @@ static luaL_Reg vector3d[] = {
static int vector3d_clone(lua_State *L)
{
vector3_t *vec = luaL_checkudata(L, 1, META_VECTOR3);
Vector3D_Copy(NewVector3(L), vec);
FV3_Copy(NewVector3(L), vec);
return 1;
}
static int vector3d_opposite(lua_State *L)
{
vector3_t *vec = luaL_checkudata(L, 1, META_VECTOR3);
Vector3D_Opposite(NewVector3(L), vec);
FV3_NegateEx(vec, NewVector3(L));
return 1;
}
@ -114,6 +114,7 @@ static int vector3d_get(lua_State *L)
if (!vec)
return luaL_error(L, "accessed vector3_t doesn't exist anymore.");
vector3_t unit = { 0, 0, 0 };
switch(field)
{
case vectorfield_clone: lua_pushcfunction(L, vector3d_clone); return 1;
@ -122,8 +123,8 @@ static int vector3d_get(lua_State *L)
case vectorfield_x: lua_pushfixed(L, vec->x); return 1;
case vectorfield_y: lua_pushfixed(L, vec->y); return 1;
case vectorfield_z: lua_pushfixed(L, vec->z); return 1;
case vectorfield_length: lua_pushfixed(L, Vector3D_Length(vec)); return 1;
case vectorfield_normalized: Vector3D_Normalize(NewVector3(L), vec); return 1;
case vectorfield_length: lua_pushfixed(L, FV3_Distance(&unit, vec)); return 1;
case vectorfield_normalized: FV3_NormalizeEx(vec, NewVector3(L)); return 1;
default: break;
}
@ -139,27 +140,28 @@ static int vector3d_eq(lua_State *L)
{
vector3_t *vec1 = luaL_checkudata(L, 1, META_VECTOR3);
vector3_t *vec2 = luaL_checkudata(L, 2, META_VECTOR3);
lua_pushboolean(L, Vector3D_Equal(vec1, vec2));
lua_pushboolean(L, FV3_Equal(vec1, vec2));
return 1;
}
static int vector3d_op(
lua_State *L,
vector3_t *(*opvector)(vector3_t*, vector3_t*, vector3_t*),
vector3_t *(*opfixed)(vector3_t*, vector3_t*, fixed_t)
vector3_t *(*opvector)(const vector3_t*, const vector3_t*, vector3_t*)
)
{
if (lua_isnumber(L, 1) && (opfixed == Vector3D_AddFixed || opfixed == Vector3D_MulFixed))
if (lua_isnumber(L, 1) && (opvector == FV3_AddEx || opvector == FV3_MulEx))
{
fixed_t n1 = lua_tofixed(L, 1);
vector3_t vec1 = { n1, n1, n1 };
vector3_t *vec2 = luaL_checkudata(L, 2, META_VECTOR3);
opfixed(NewVector3(L), vec2, n1);
opvector(NewVector3(L), vec2, &vec1);
}
else if (lua_isnumber(L, 2))
{
vector3_t *vec1 = luaL_checkudata(L, 1, META_VECTOR3);
fixed_t n2 = lua_tofixed(L, 2);
opfixed(NewVector3(L), vec1, n2);
vector3_t vec2 = { n2, n2, n2 };
opvector(NewVector3(L), vec1, &vec2);
}
else
{
@ -173,28 +175,28 @@ static int vector3d_op(
static int vector3d_add(lua_State *L)
{
return vector3d_op(L, Vector3D_Add, Vector3D_AddFixed);
return vector3d_op(L, FV3_AddEx);
}
static int vector3d_sub(lua_State *L)
{
return vector3d_op(L, Vector3D_Sub, Vector3D_SubFixed);
return vector3d_op(L, FV3_SubEx);
}
static int vector3d_mul(lua_State *L)
{
return vector3d_op(L, Vector3D_Mul, Vector3D_MulFixed);
return vector3d_op(L, FV3_MulEx);
}
static int vector3d_div(lua_State *L)
{
return vector3d_op(L, Vector3D_Div, Vector3D_DivFixed);
return vector3d_op(L, FV3_DivideEx);
}
static int vector3d_unm(lua_State *L)
{
vector3_t *vec = luaL_checkudata(L, 1, META_VECTOR3);
Vector3D_Opposite(NewVector3(L), vec);
FV3_NegateEx(vec, NewVector3(L));
return 1;
}

View file

@ -287,32 +287,65 @@ vector3_t *FV3_Sub(vector3_t *a_i, const vector3_t *a_c)
return FV3_SubEx(a_i, a_c, a_i);
}
vector3_t *FV3_MulEx(const vector3_t *a_i, fixed_t a_c, vector3_t *a_o)
vector4_t *FV4_Sub(vector4_t *a_i, const vector4_t *a_c)
{
a_o->x = FixedMul(a_i->x, a_c);
a_o->y = FixedMul(a_i->y, a_c);
a_o->z = FixedMul(a_i->z, a_c);
return FV4_SubEx(a_i, a_c, a_i);
}
vector3_t *FV3_MulEx(const vector3_t *a_i, const vector3_t *a_c, vector3_t *a_o)
{
a_o->x = FixedMul(a_i->x, a_c->x);
a_o->y = FixedMul(a_i->y, a_c->y);
a_o->z = FixedMul(a_i->z, a_c->z);
return a_o;
}
vector3_t *FV3_Mul(vector3_t *a_i, fixed_t a_c)
vector4_t *FV4_MulEx(const vector4_t *a_i, const vector4_t *a_c, vector4_t *a_o)
{
a_o->x = FixedMul(a_i->x, a_c->x);
a_o->y = FixedMul(a_i->y, a_c->y);
a_o->z = FixedMul(a_i->z, a_c->z);
a_o->a = FixedMul(a_i->a, a_c->a);
return a_o;
}
vector3_t *FV3_Mul(vector3_t *a_i, const vector3_t *a_c)
{
return FV3_MulEx(a_i, a_c, a_i);
}
vector3_t *FV3_DivideEx(const vector3_t *a_i, fixed_t a_c, vector3_t *a_o)
vector4_t *FV4_Mul(vector4_t *a_i, const vector4_t *a_c)
{
a_o->x = FixedDiv(a_i->x, a_c);
a_o->y = FixedDiv(a_i->y, a_c);
a_o->z = FixedDiv(a_i->z, a_c);
return FV4_MulEx(a_i, a_c, a_i);
}
vector3_t *FV3_DivideEx(const vector3_t *a_i, const vector3_t *a_c, vector3_t *a_o)
{
a_o->x = FixedDiv(a_i->x, a_c->x);
a_o->y = FixedDiv(a_i->y, a_c->y);
a_o->z = FixedDiv(a_i->z, a_c->z);
return a_o;
}
vector3_t *FV3_Divide(vector3_t *a_i, fixed_t a_c)
vector4_t *FV4_DivideEx(const vector4_t *a_i, const vector4_t *a_c, vector4_t *a_o)
{
a_o->x = FixedDiv(a_i->x, a_c->x);
a_o->y = FixedDiv(a_i->y, a_c->y);
a_o->z = FixedDiv(a_i->z, a_c->z);
a_o->a = FixedDiv(a_i->a, a_c->a);
return a_o;
}
vector3_t *FV3_Divide(vector3_t *a_i, const vector3_t *a_c)
{
return FV3_DivideEx(a_i, a_c, a_i);
}
vector4_t *FV4_Divide(vector4_t *a_i, const vector4_t *a_c)
{
return FV4_DivideEx(a_i, a_c, a_i);
}
// Vector Complex Math
vector3_t *FV3_Midpoint(const vector3_t *a_1, const vector3_t *a_2, vector3_t *a_o)
{
@ -424,8 +457,9 @@ vector3_t *FV3_ClosestPointOnLine(const vector3_t *Line, const vector3_t *p, vec
return FV3_Copy(out, &Line[1]);
}
// Return the point between <20>Line[0]<5D> and <20>Line[1]<5D>
FV3_Mul(&V, t);
// Return the point between "Line[0]" and "Line[1]"
vector3_t T = { t, t, t };
FV3_Mul(&V, &T);
return FV3_AddEx(&Line[0], &V, out);
}
@ -440,7 +474,8 @@ void FV3_ClosestPointOnVector(const vector3_t *dir, const vector3_t *p, vector3_
fixed_t t = FV3_Dot(dir, p);
// Return the point on the line closest
FV3_MulEx(dir, t, out);
vector3_t T = { t, t, t };
FV3_MulEx(dir, &T, out);
return;
}
@ -725,10 +760,10 @@ boolean FV3_PointInsideBox(const vector3_t *point, const vector3_t *box)
//
// Loads the identity matrix into a matrix
//
void FM_LoadIdentity(oldmatrix_t* matrix)
void FM_LoadIdentity(matrix_t* matrix)
{
#define M(row,col) matrix->m[col * 4 + row]
memset(matrix, 0x00, sizeof(oldmatrix_t));
memset(matrix, 0x00, sizeof(matrix_t));
M(0, 0) = FRACUNIT;
M(1, 1) = FRACUNIT;
@ -743,7 +778,7 @@ void FM_LoadIdentity(oldmatrix_t* matrix)
// Creates a matrix that can be used for
// adjusting the position of an object
//
void FM_CreateObjectMatrix(oldmatrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius)
void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius)
{
vector3_t upcross;
vector3_t upvec;
@ -782,7 +817,7 @@ void FM_CreateObjectMatrix(oldmatrix_t *matrix, fixed_t x, fixed_t y, fixed_t z,
//
// Multiplies a vector by the specified matrix
//
const vector3_t *FM_MultMatrixVec3(const oldmatrix_t *matrix, const vector3_t *vec, vector3_t *out)
const vector3_t *FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t *out)
{
#define M(row,col) matrix->m[col * 4 + row]
out->x = FixedMul(vec->x, M(0, 0))
@ -803,7 +838,7 @@ const vector3_t *FM_MultMatrixVec3(const oldmatrix_t *matrix, const vector3_t *v
return out;
}
const vector4_t *FM_MultMatrixVec4(const oldmatrix_t *matrix, const vector4_t *vec, vector4_t *out)
const vector4_t *FM_MultMatrixVec4(const matrix_t *matrix, const vector4_t *vec, vector4_t *out)
{
#define M(row,col) matrix->m[col * 4 + row]
out->x = FixedMul(vec->x, M(0, 0))
@ -835,13 +870,12 @@ const vector4_t *FM_MultMatrixVec4(const oldmatrix_t *matrix, const vector4_t *v
//
// Multiples one matrix into another
//
void FM_MultMatrix(oldmatrix_t *dest, const oldmatrix_t *multme)
void FM_MultMatrixEx(const matrix_t *m1, const matrix_t *m2, matrix_t *dest)
{
oldmatrix_t result;
UINT8 i, j;
#define M(row,col) multme->m[col * 4 + row]
#define D(row,col) dest->m[col * 4 + row]
#define R(row,col) result.m[col * 4 + row]
#define M(row,col) m1->m[col * 4 + row]
#define D(row,col) m2->m[col * 4 + row]
#define R(row,col) dest->m[col * 4 + row]
for (i = 0; i < 4; i++)
{
@ -849,24 +883,27 @@ void FM_MultMatrix(oldmatrix_t *dest, const oldmatrix_t *multme)
R(i, j) = FixedMul(D(i, 0), M(0, j)) + FixedMul(D(i, 1), M(1, j)) + FixedMul(D(i, 2), M(2, j)) + FixedMul(D(i, 3), M(3, j));
}
M_Memcpy(dest, &result, sizeof(oldmatrix_t));
#undef R
#undef D
#undef M
}
void FM_MultMatrix(matrix_t *dest, const matrix_t *multme)
{
FM_MultMatrixEx(dest, multme, dest);
}
//
// Translate
//
// Translates a matrix
//
void FM_Translate(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
{
oldmatrix_t trans;
matrix_t trans;
#define M(row,col) trans.m[col * 4 + row]
memset(&trans, 0x00, sizeof(oldmatrix_t));
memset(&trans, 0x00, sizeof(matrix_t));
M(0, 0) = M(1, 1) = M(2, 2) = M(3, 3) = FRACUNIT;
M(0, 3) = x;
@ -882,12 +919,12 @@ void FM_Translate(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
//
// Scales a matrix
//
void FM_Scale(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z)
{
oldmatrix_t scale;
matrix_t scale;
#define M(row,col) scale.m[col * 4 + row]
memset(&scale, 0x00, sizeof(oldmatrix_t));
memset(&scale, 0x00, sizeof(matrix_t));
M(3, 3) = FRACUNIT;
M(0, 0) = x;

View file

@ -299,10 +299,10 @@ vector3_t *FV3_AddEx(const vector3_t *a_i, const vector3_t *a_c, vector3_t *a_o)
vector3_t *FV3_Add(vector3_t *a_i, const vector3_t *a_c);
vector3_t *FV3_SubEx(const vector3_t *a_i, const vector3_t *a_c, vector3_t *a_o);
vector3_t *FV3_Sub(vector3_t *a_i, const vector3_t *a_c);
vector3_t *FV3_MulEx(const vector3_t *a_i, fixed_t a_c, vector3_t *a_o);
vector3_t *FV3_Mul(vector3_t *a_i, fixed_t a_c);
vector3_t *FV3_DivideEx(const vector3_t *a_i, fixed_t a_c, vector3_t *a_o);
vector3_t *FV3_Divide(vector3_t *a_i, fixed_t a_c);
vector3_t *FV3_MulEx(const vector3_t *a_i, const vector3_t *a_c, vector3_t *a_o);
vector3_t *FV3_Mul(vector3_t *a_i, const vector3_t *a_c);
vector3_t *FV3_DivideEx(const vector3_t *a_i, const vector3_t *a_c, vector3_t *a_o);
vector3_t *FV3_Divide(vector3_t *a_i, const vector3_t *a_c);
vector3_t *FV3_Midpoint(const vector3_t *a_1, const vector3_t *a_2, vector3_t *a_o);
fixed_t FV3_Distance(const vector3_t *p1, const vector3_t *p2);
fixed_t FV3_Magnitude(const vector3_t *a_normal);
@ -327,18 +327,45 @@ vector3_t *FV3_IntersectionPoint(const vector3_t *vNormal, const vector3_t *vLin
UINT8 FV3_PointOnLineSide(const vector3_t *point, const vector3_t *line);
boolean FV3_PointInsideBox(const vector3_t *point, const vector3_t *box);
struct oldmatrix_t
typedef struct
{
fixed_t x, y, z, a;
} vector4_t;
vector4_t *FV4_Load(vector4_t *vec, fixed_t x, fixed_t y, fixed_t z, fixed_t a);
vector4_t *FV4_UnLoad(vector4_t *vec, fixed_t *x, fixed_t *y, fixed_t *z, fixed_t *a);
vector4_t *FV4_Copy(vector4_t *a_o, const vector4_t *a_i);
vector4_t *FV4_AddEx(const vector4_t *a_i, const vector4_t *a_c, vector4_t *a_o);
vector4_t *FV4_Add(vector4_t *a_i, const vector4_t *a_c);
vector4_t *FV4_SubEx(const vector4_t *a_i, const vector4_t *a_c, vector4_t *a_o);
vector4_t *FV4_Sub(vector4_t *a_i, const vector4_t *a_c);
vector4_t *FV4_MulEx(const vector4_t *a_i, const vector4_t *a_c, vector4_t *a_o);
vector4_t *FV4_Mul(vector4_t *a_i, const vector4_t *a_c);
vector4_t *FV4_DivideEx(const vector4_t *a_i, const vector4_t *a_c, vector4_t *a_o);
vector4_t *FV4_Divide(vector4_t *a_i, const vector4_t *a_c);
vector4_t *FV4_Midpoint(const vector4_t *a_1, const vector4_t *a_2, vector4_t *a_o);
fixed_t FV4_Distance(const vector4_t *p1, const vector4_t *p2);
fixed_t FV4_Magnitude(const vector4_t *a_normal);
fixed_t FV4_NormalizeEx(const vector4_t *a_normal, vector4_t *a_o);
fixed_t FV4_Normalize(vector4_t *a_normal);
vector4_t *FV4_NegateEx(const vector4_t *a_1, vector4_t *a_o);
vector4_t *FV4_Negate(vector4_t *a_1);
boolean FV4_Equal(const vector4_t *a_1, const vector4_t *a_2);
fixed_t FV4_Dot(const vector4_t *a_1, const vector4_t *a_2);
typedef struct
{
fixed_t m[16];
};
} matrix_t;
void FM_LoadIdentity(oldmatrix_t* matrix);
void FM_CreateObjectMatrix(oldmatrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius);
const vector3_t *FM_MultMatrixVec3(const oldmatrix_t *matrix, const vector3_t *vec, vector3_t *out);
const vector4_t *FM_MultMatrixVec4(const oldmatrix_t *matrix, const vector4_t *vec, vector4_t *out);
void FM_MultMatrix(oldmatrix_t *dest, const oldmatrix_t *multme);
void FM_Translate(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z);
void FM_Scale(oldmatrix_t *dest, fixed_t x, fixed_t y, fixed_t z);
void FM_LoadIdentity(matrix_t* matrix);
void FM_CreateObjectMatrix(matrix_t *matrix, fixed_t x, fixed_t y, fixed_t z, fixed_t anglex, fixed_t angley, fixed_t anglez, fixed_t upx, fixed_t upy, fixed_t upz, fixed_t radius);
const vector3_t *FM_MultMatrixVec3(const matrix_t *matrix, const vector3_t *vec, vector3_t *out);
const vector4_t *FM_MultMatrixVec4(const matrix_t *matrix, const vector4_t *vec, vector4_t *out);
void FM_MultMatrix(matrix_t *dest, const matrix_t *multme);
void FM_MultMatrixEx(const matrix_t *m1, const matrix_t *m2, matrix_t *dest);
void FM_Translate(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z);
void FM_Scale(matrix_t *dest, fixed_t x, fixed_t y, fixed_t z);
#ifdef __cplusplus
} // extern "C"

View file

@ -1,72 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by LJ Sonic
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file matrix.c
/// \brief Fixed-point 3D vector
#include <string.h>
#include "matrix.h"
static matrix_t identitymatrix = {{
{FRACUNIT, 0, 0, 0},
{0, FRACUNIT, 0, 0},
{0, 0, FRACUNIT, 0},
{0, 0, 0, FRACUNIT},
}};
matrix_t *Matrix_SetIdentity(matrix_t *mat)
{
return memcpy(mat, identitymatrix.matrix, sizeof(*mat));
}
matrix_t *Matrix_SetTranslation(matrix_t *mat, fixed_t x, fixed_t y, fixed_t z)
{
Matrix_SetIdentity(mat);
mat->matrix[0][3] = x;
mat->matrix[1][3] = y;
mat->matrix[2][3] = z;
return mat;
}
matrix_t *Matrix_SetScaling(matrix_t *mat, fixed_t x, fixed_t y, fixed_t z)
{
Matrix_SetIdentity(mat);
mat->matrix[0][0] = x;
mat->matrix[1][1] = y;
mat->matrix[2][2] = z;
return mat;
}
matrix_t *Matrix_Copy(matrix_t *out, matrix_t *in)
{
return memcpy(out, in, sizeof(*out));
}
matrix_t *Matrix_Mul(matrix_t *out, matrix_t *a, matrix_t *b)
{
for (size_t r = 0; r < 4; r++)
for (size_t c = 0; c < 4; c++)
for (size_t i = 0; i < 4; i++)
out->matrix[r][c] += FixedMul(a->matrix[r][i], b->matrix[i][c]);
return out;
}
vector3_t *Matrix_MulVector(vector3_t *out, matrix_t *a, vector3_t *b)
{
out->x = FixedMul(a->matrix[0][0], b->x) + FixedMul(a->matrix[0][1], b->y) + FixedMul(a->matrix[0][2], b->z) + a->matrix[0][3];
out->y = FixedMul(a->matrix[1][0], b->x) + FixedMul(a->matrix[1][1], b->y) + FixedMul(a->matrix[1][2], b->z) + a->matrix[1][3];
out->z = FixedMul(a->matrix[2][0], b->x) + FixedMul(a->matrix[2][1], b->y) + FixedMul(a->matrix[2][2], b->z) + a->matrix[2][3];
return out;
}

View file

@ -1,30 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by LJ Sonic
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file matrix.c
/// \brief Fixed-point 4x4 matrix
#ifndef __MATRIX__
#define __MATRIX__
#include "m_fixed.h"
#include "vector3d.h"
typedef struct
{
fixed_t matrix[4][4];
} matrix_t;
matrix_t *Matrix_SetIdentity(matrix_t *mat);
matrix_t *Matrix_SetTranslation(matrix_t *mat, fixed_t x, fixed_t y, fixed_t z);
matrix_t *Matrix_SetScaling(matrix_t *mat, fixed_t x, fixed_t y, fixed_t z);
matrix_t *Matrix_Copy(matrix_t *out, matrix_t *in);
matrix_t *Matrix_Mul(matrix_t *out, matrix_t *a, matrix_t *b);
vector3_t *Matrix_MulVector(vector3_t *out, matrix_t *a, vector3_t *b);
#endif

View file

@ -78,8 +78,9 @@ void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *Line, vector3_t
FV3_SubEx(p, v1, &c);
d = R_PointToDist2(0, v2->z, R_PointToDist2(v2->x, v2->y, v1->x, v1->y), v1->z);
vector3_t vd = { d, d, d };
FV3_Copy(&n, &V);
FV3_Divide(&n, d);
FV3_Divide(&n, &vd);
t = FV3_Dot(&n, &c);
@ -95,7 +96,8 @@ void P_ClosestPointOnLine3D(const vector3_t *p, const vector3_t *Line, vector3_t
return;
}
FV3_Mul(&n, t);
vector3_t tv = { t, t, t };
FV3_Mul(&n, &tv);
FV3_AddEx(v1, &n, result);
return;

View file

@ -167,9 +167,10 @@ void P_ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector
max(max(abs(vec2.x), abs(vec2.y)), abs(vec2.z))
) >> 5; // shifting right by 5 is good enough.
vector3_t vm = { m, m, m };
FV3_Cross(
FV3_Divide(&vec1, m),
FV3_Divide(&vec2, m),
FV3_Divide(&vec1, &vm),
FV3_Divide(&vec2, &vm),
&slope->normal
);
@ -180,7 +181,10 @@ void P_ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector
if (slope->normal.z < 0)
m = -m;
FV3_Divide(&slope->normal, m);
vm.x = m;
vm.y = m;
vm.z = m;
FV3_Divide(&slope->normal, &vm);
// Get direction vector
m = FixedHypot(slope->normal.x, slope->normal.y);

View file

@ -1,120 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by LJ Sonic
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file quaternion.c
/// \brief Fixed-point 3D vector
#include <string.h>
#include "quaternion.h"
#include "vector3d.h"
#include "matrix.h"
#include "r_main.h" // R_PointToDist2
quaternion_t *Quaternion_Set(quaternion_t *quat, fixed_t x, fixed_t y, fixed_t z, fixed_t w)
{
quat->x = x;
quat->y = y;
quat->z = z;
quat->w = w;
return quat;
}
quaternion_t *Quaternion_SetIdentity(quaternion_t *quat)
{
return Quaternion_Set(quat, 0, 0, 0, FRACUNIT);
}
quaternion_t *Quaternion_SetAxisRotation(quaternion_t *quat, vector3_t *axis, fixed_t angle)
{
fixed_t cosangle = FINECOSINE(((angle / 2) >> ANGLETOFINESHIFT) & FINEMASK);
fixed_t sinangle = FINESINE(((angle / 2) >> ANGLETOFINESHIFT) & FINEMASK);
vector3_t normaxis;
Vector3D_Normalize(&normaxis, axis);
return Quaternion_Set(quat,
FixedMul(normaxis.x, sinangle),
FixedMul(normaxis.y, sinangle),
FixedMul(normaxis.z, sinangle),
cosangle
);
}
quaternion_t *Quaternion_Copy(quaternion_t *out, quaternion_t *in)
{
return memcpy(out, in, sizeof(*out));
}
matrix_t *Quaternion_ToMatrix(matrix_t *mat, const quaternion_t *quat)
{
fixed_t x = quat->x, y = quat->y, z = quat->z, w = quat->w;
fixed_t xx2 = 2 * FixedMul(x, x);
fixed_t xy2 = 2 * FixedMul(x, y);
fixed_t xz2 = 2 * FixedMul(x, z);
fixed_t xw2 = 2 * FixedMul(x, w);
fixed_t yy2 = 2 * FixedMul(y, y);
fixed_t yz2 = 2 * FixedMul(y, z);
fixed_t yw2 = 2 * FixedMul(y, w);
fixed_t zz2 = 2 * FixedMul(z, z);
fixed_t zw2 = 2 * FixedMul(z, w);
Matrix_SetIdentity(mat);
mat->matrix[0][0] = FRACUNIT - yy2 - zz2;
mat->matrix[0][1] = xy2 - zw2;
mat->matrix[0][2] = xz2 + yw2;
mat->matrix[1][0] = xy2 + zw2;
mat->matrix[1][1] = FRACUNIT - xx2 - zz2;
mat->matrix[1][2] = yz2 - xw2;
mat->matrix[2][0] = xz2 - yw2;
mat->matrix[2][1] = yz2 + xw2;
mat->matrix[2][2] = FRACUNIT - xx2 - yy2;
mat->matrix[3][3] = FRACUNIT;
return mat;
}
quaternion_t *Quaternion_Normalize(quaternion_t *out, quaternion_t *in)
{
fixed_t sqlen =
FixedMul(in->x, in->x) +
FixedMul(in->y, in->y) +
FixedMul(in->z, in->z) +
FixedMul(in->w, in->w);
if (sqlen < FRACUNIT / 1024)
return Quaternion_Set(out, in->x, in->y, in->z, in->w);
fixed_t len = R_PointToDist2(0, 0, R_PointToDist2(0, 0, R_PointToDist2(0, 0, in->x, in->y), in->z), in->w);
return Quaternion_Set(out,
FixedDiv(in->x, len),
FixedDiv(in->y, len),
FixedDiv(in->z, len),
FixedDiv(in->w, len)
);
}
quaternion_t *Quaternion_Mul(quaternion_t *out, quaternion_t *a, quaternion_t *b)
{
fixed_t ax = a->x, ay = a->y, az = a->z, aw = a->w;
fixed_t bx = b->x, by = b->y, bz = b->z, bw = b->w;
return Quaternion_Normalize(out, Quaternion_Set(out,
FixedMul(aw, bx) + FixedMul(ax, bw) + FixedMul(ay, bz) - FixedMul(az, by),
FixedMul(aw, by) - FixedMul(ax, bz) + FixedMul(ay, bw) + FixedMul(az, bx),
FixedMul(aw, bz) + FixedMul(ax, by) - FixedMul(ay, bx) + FixedMul(az, bw),
FixedMul(aw, bw) - FixedMul(ax, bx) - FixedMul(ay, by) - FixedMul(az, bz)
));
}

View file

@ -1,31 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by LJ Sonic
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file quaternion.c
/// \brief Fixed-point quaternion
#ifndef __QUATERNION__
#define __QUATERNION__
#include "m_fixed.h"
#include "matrix.h"
typedef struct
{
fixed_t x, y, z, w;
} quaternion_t;
quaternion_t *Quaternion_Set(quaternion_t *quat, fixed_t x, fixed_t y, fixed_t z, fixed_t w);
quaternion_t *Quaternion_SetIdentity(quaternion_t *quat);
quaternion_t *Quaternion_SetAxisRotation(quaternion_t *quat, vector3_t *axis, fixed_t angle);
quaternion_t *Quaternion_Copy(quaternion_t *out, quaternion_t *in);
matrix_t *Quaternion_ToMatrix(matrix_t *mat, const quaternion_t *quat);
quaternion_t *Quaternion_Normalize(quaternion_t *out, quaternion_t *in);
quaternion_t *Quaternion_Mul(quaternion_t *out, quaternion_t *a, quaternion_t *b);
#endif

View file

@ -130,7 +130,8 @@ static vector2_t *R_LerpVector2(const vector2_t *from, const vector2_t *to, fixe
static vector3_t *R_LerpVector3(const vector3_t *from, const vector3_t *to, fixed_t frac, vector3_t *out)
{
FV3_SubEx(to, from, out);
FV3_MulEx(out, frac, out);
vector3_t vfrac = { frac, frac, frac };
FV3_MulEx(out, &vfrac, out);
FV3_AddEx(from, out, out);
return out;
}

View file

@ -435,7 +435,7 @@ void FV3_Rotate(vector3_t *rotVec, const vector3_t *axisVec, const angle_t angle
}
#define M(row,col) dest->m[row * 4 + col]
oldmatrix_t *FM_Rotate(oldmatrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z)
matrix_t *FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z)
{
const fixed_t sinA = FINESINE(angle>>ANGLETOFINESHIFT);
const fixed_t cosA = FINECOSINE(angle>>ANGLETOFINESHIFT);
@ -491,7 +491,7 @@ oldmatrix_t *FM_Rotate(oldmatrix_t *dest, angle_t angle, fixed_t x, fixed_t y, f
}
oldmatrix_t *FM_RotateX(oldmatrix_t *dest, angle_t rad)
matrix_t *FM_RotateX(matrix_t *dest, angle_t rad)
{
const angle_t fa = rad>>ANGLETOFINESHIFT;
const fixed_t cosrad = FINECOSINE(fa), sinrad = FINESINE(fa);
@ -516,7 +516,7 @@ oldmatrix_t *FM_RotateX(oldmatrix_t *dest, angle_t rad)
return dest;
}
oldmatrix_t *FM_RotateY(oldmatrix_t *dest, angle_t rad)
matrix_t *FM_RotateY(matrix_t *dest, angle_t rad)
{
const angle_t fa = rad>>ANGLETOFINESHIFT;
const fixed_t cosrad = FINECOSINE(fa), sinrad = FINESINE(fa);
@ -541,7 +541,7 @@ oldmatrix_t *FM_RotateY(oldmatrix_t *dest, angle_t rad)
return dest;
}
oldmatrix_t *FM_RotateZ(oldmatrix_t *dest, angle_t rad)
matrix_t *FM_RotateZ(matrix_t *dest, angle_t rad)
{
const angle_t fa = rad>>ANGLETOFINESHIFT;
const fixed_t cosrad = FINECOSINE(fa), sinrad = FINESINE(fa);

View file

@ -126,10 +126,10 @@ boolean FV3_InsidePolygon(const vector3_t *vIntersection, const vector3_t *Poly,
boolean FV3_IntersectedPolygon(const vector3_t *vPoly, const vector3_t *vLine, const INT32 vertexCount, vector3_t *collisionPoint);
void FV3_Rotate(vector3_t *rotVec, const vector3_t *axisVec, const angle_t angle);
/// Fixed Point Matrix functions
oldmatrix_t *FM_Rotate(oldmatrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z);
oldmatrix_t *FM_RotateX(oldmatrix_t *dest, angle_t rad);
oldmatrix_t *FM_RotateY(oldmatrix_t *dest, angle_t rad);
oldmatrix_t *FM_RotateZ(oldmatrix_t *dest, angle_t rad);
matrix_t *FM_Rotate(matrix_t *dest, angle_t angle, fixed_t x, fixed_t y, fixed_t z);
matrix_t *FM_RotateX(matrix_t *dest, angle_t rad);
matrix_t *FM_RotateY(matrix_t *dest, angle_t rad);
matrix_t *FM_RotateZ(matrix_t *dest, angle_t rad);
// The table values in tables.c are calculated with this many fractional bits.
#define FINE_FRACBITS 16

View file

@ -228,7 +228,7 @@ TYPEDEF (mdllistitem_t);
// m_fixed.h
TYPEDEF (vector2_t);
TYPEDEF (vector3_t);
TYPEDEF (oldmatrix_t);
TYPEDEF (matrix_t);
// m_perfstats.h
TYPEDEF (ps_hookinfo_t);

View file

@ -1,126 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by LJ Sonic
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file vector3d.c
/// \brief Fixed-point 3D vector
#include <string.h>
#include "vector3d.h"
#include "r_main.h" // R_PointToDist2
vector3_t *Vector3D_Set(vector3_t *vec, fixed_t x, fixed_t y, fixed_t z)
{
vec->x = x;
vec->y = y;
vec->z = z;
return vec;
}
vector3_t *Vector3D_Copy(vector3_t *out, vector3_t *in)
{
return memcpy(out, in, sizeof(*out));
}
fixed_t Vector3D_Length(vector3_t *vec)
{
return R_PointToDist2(0, 0, R_PointToDist2(0, 0, vec->x, vec->y), vec->z);
}
vector3_t *Vector3D_Opposite(vector3_t *out, vector3_t *in)
{
return Vector3D_Set(out, -in->x, -in->y, -in->z);
}
vector3_t *Vector3D_Normalize(vector3_t *out, vector3_t *in)
{
fixed_t len = Vector3D_Length(in);
if (len == 0)
return Vector3D_Set(out, in->x, in->y, in->z);
else
return Vector3D_Set(out, FixedDiv(in->x, len), FixedDiv(in->y, len), FixedDiv(in->z, len));
}
boolean Vector3D_Equal(vector3_t *a, vector3_t *b)
{
return (a->x == b->x && a->y == b->y && a->z == b->z);
}
vector3_t *Vector3D_Add(vector3_t *out, vector3_t *a, vector3_t *b)
{
out->x = a->x + b->x;
out->y = a->y + b->y;
out->z = a->z + b->z;
return out;
}
vector3_t *Vector3D_Sub(vector3_t *out, vector3_t *a, vector3_t *b)
{
out->x = a->x - b->x;
out->y = a->y - b->y;
out->z = a->z - b->z;
return out;
}
vector3_t *Vector3D_Mul(vector3_t *out, vector3_t *a, vector3_t *b)
{
out->x = FixedMul(a->x, b->x);
out->y = FixedMul(a->y, b->y);
out->z = FixedMul(a->z, b->z);
return out;
}
vector3_t *Vector3D_Div(vector3_t *out, vector3_t *a, vector3_t *b)
{
out->x = FixedDiv(a->x, b->x);
out->y = FixedDiv(a->y, b->y);
out->z = FixedDiv(a->z, b->z);
return out;
}
vector3_t *Vector3D_AddFixed(vector3_t *out, vector3_t *a, fixed_t b)
{
out->x = a->x + b;
out->y = a->y + b;
out->z = a->z + b;
return out;
}
vector3_t *Vector3D_SubFixed(vector3_t *out, vector3_t *a, fixed_t b)
{
out->x = a->x - b;
out->y = a->y - b;
out->z = a->z - b;
return out;
}
vector3_t *Vector3D_MulFixed(vector3_t *out, vector3_t *a, fixed_t b)
{
out->x = FixedMul(a->x, b);
out->y = FixedMul(a->y, b);
out->z = FixedMul(a->z, b);
return out;
}
vector3_t *Vector3D_DivFixed(vector3_t *out, vector3_t *a, fixed_t b)
{
out->x = FixedDiv(a->x, b);
out->y = FixedDiv(a->y, b);
out->z = FixedDiv(a->z, b);
return out;
}

View file

@ -1,34 +0,0 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2025 by LJ Sonic
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file vector3d.c
/// \brief Fixed-point 3D vector
#ifndef __VECTOR3D__
#define __VECTOR3D__
#include "m_fixed.h"
vector3_t *Vector3D_Set(vector3_t *vec, fixed_t x, fixed_t y, fixed_t z);
vector3_t *Vector3D_Copy(vector3_t *out, vector3_t *in);
fixed_t Vector3D_Length(vector3_t *vec);
vector3_t *Vector3D_Opposite(vector3_t *out, vector3_t *in);
vector3_t *Vector3D_Normalize(vector3_t *out, vector3_t *in);
boolean Vector3D_Equal(vector3_t *a, vector3_t *b);
vector3_t *Vector3D_Add(vector3_t *out, vector3_t *a, vector3_t *b);
vector3_t *Vector3D_Sub(vector3_t *out, vector3_t *a, vector3_t *b);
vector3_t *Vector3D_Mul(vector3_t *out, vector3_t *a, vector3_t *b);
vector3_t *Vector3D_Div(vector3_t *out, vector3_t *a, vector3_t *b);
vector3_t *Vector3D_AddFixed(vector3_t *out, vector3_t *a, fixed_t b);
vector3_t *Vector3D_SubFixed(vector3_t *out, vector3_t *a, fixed_t b);
vector3_t *Vector3D_MulFixed(vector3_t *out, vector3_t *a, fixed_t b);
vector3_t *Vector3D_DivFixed(vector3_t *out, vector3_t *a, fixed_t b);
#endif