# End Source File\r
# Begin Source File\r
\r
-SOURCE=.\matrix3x4.c\r
-# End Source File\r
-# Begin Source File\r
-\r
-SOURCE=.\matrix4x4.c\r
+SOURCE=.\matrixlib.c\r
# End Source File\r
# Begin Source File\r
\r
#if you want no CD audio
CD=cd_null.o
-OBJECTS= builddate.o $(CD) $(SND) chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o r_sky.o gl_rmain.o gl_rsurf.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_explosion.o sbar.o sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o r_clip.o ui.o portals.o sys_shared.o cl_light.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o cgame.o filematch.o collision.o cl_collision.o matrix4x4.o matrix3x4.o
+OBJECTS= builddate.o $(CD) $(SND) chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o r_sky.o gl_rmain.o gl_rsurf.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_explosion.o sbar.o sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o r_clip.o ui.o portals.o sys_shared.o cl_light.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o cgame.o filematch.o collision.o cl_collision.o matrixlib.o
#K6/athlon optimizations
CPUOPTIMIZATIONS=-march=k6
-OBJECTS= builddate.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o r_sky.o gl_rmain.o gl_rsurf.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o r_clip.o ui.o portals.o sys_shared.o cl_light.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o cgame.o filematch.o collision.o cl_collision.o matrix4x4.o matrix3x4.o
+OBJECTS= builddate.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o r_sky.o gl_rmain.o gl_rsurf.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o r_clip.o ui.o portals.o sys_shared.o cl_light.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o cgame.o filematch.o collision.o cl_collision.o matrixlib.o
#K6/athlon optimizations
#CPUOPTIMIZATIONS=-march=k6
+++ /dev/null
-
-#include "matrix3x4.h"
-#include <math.h>
-
-void Matrix3x4_Copy (matrix3x4_t *out, matrix3x4_t *in)
-{
- *out = *in;
-}
-
-void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2)
-{
- out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[0][1] * in2->m[1][0] + in1->m[0][2] * in2->m[2][0];
- out->m[0][1] = in1->m[0][0] * in2->m[0][1] + in1->m[0][1] * in2->m[1][1] + in1->m[0][2] * in2->m[2][1];
- out->m[0][2] = in1->m[0][0] * in2->m[0][2] + in1->m[0][1] * in2->m[1][2] + in1->m[0][2] * in2->m[2][2];
- out->m[0][3] = in1->m[0][0] * in2->m[0][3] + in1->m[0][1] * in2->m[1][3] + in1->m[0][2] * in2->m[2][3] + in1->m[0][3];
- out->m[1][0] = in1->m[1][0] * in2->m[0][0] + in1->m[1][1] * in2->m[1][0] + in1->m[1][2] * in2->m[2][0];
- out->m[1][1] = in1->m[1][0] * in2->m[0][1] + in1->m[1][1] * in2->m[1][1] + in1->m[1][2] * in2->m[2][1];
- out->m[1][2] = in1->m[1][0] * in2->m[0][2] + in1->m[1][1] * in2->m[1][2] + in1->m[1][2] * in2->m[2][2];
- out->m[1][3] = in1->m[1][0] * in2->m[0][3] + in1->m[1][1] * in2->m[1][3] + in1->m[1][2] * in2->m[2][3] + in1->m[1][3];
- out->m[2][0] = in1->m[2][0] * in2->m[0][0] + in1->m[2][1] * in2->m[1][0] + in1->m[2][2] * in2->m[2][0];
- out->m[2][1] = in1->m[2][0] * in2->m[0][1] + in1->m[2][1] * in2->m[1][1] + in1->m[2][2] * in2->m[2][1];
- out->m[2][2] = in1->m[2][0] * in2->m[0][2] + in1->m[2][1] * in2->m[1][2] + in1->m[2][2] * in2->m[2][2];
- out->m[2][3] = in1->m[2][0] * in2->m[0][3] + in1->m[2][1] * in2->m[1][3] + in1->m[2][2] * in2->m[2][3] + in1->m[2][3];
-}
-
-void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1)
-{
- out->m[0][0] = in1->m[0][0];
- out->m[0][1] = in1->m[1][0];
- out->m[0][2] = in1->m[2][0];
- out->m[0][3] = 0.0f;
- out->m[1][0] = in1->m[0][1];
- out->m[1][1] = in1->m[1][1];
- out->m[1][2] = in1->m[2][1];
- out->m[1][3] = 0.0f;
- out->m[2][0] = in1->m[0][2];
- out->m[2][1] = in1->m[1][2];
- out->m[2][2] = in1->m[2][2];
- out->m[2][3] = 0.0f;
-}
-
-void Matrix3x4_CreateIdentity (matrix3x4_t *out)
-{
- out->m[0][0]=1.0f;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=0.0f;
- out->m[1][0]=0.0f;
- out->m[1][1]=1.0f;
- out->m[1][2]=0.0f;
- out->m[1][3]=0.0f;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=1.0f;
- out->m[2][3]=0.0f;
-}
-
-void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z)
-{
- out->m[0][0]=1.0f;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=x;
- out->m[1][0]=0.0f;
- out->m[1][1]=1.0f;
- out->m[1][2]=0.0f;
- out->m[1][3]=y;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=1.0f;
- out->m[2][3]=z;
-}
-
-void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z)
-{
- float len, c, s;
-
- len = x*x+y*y+z*z;
- if (len != 0.0f)
- len = 1.0f / sqrt(len);
- x *= len;
- y *= len;
- z *= len;
-
- angle *= M_PI / 180.0;
- c = cos(angle);
- s = sin(angle);
-
- out->m[0][0]=x * x + c * (1 - x * x);
- out->m[0][1]=x * y * (1 - c) + z * s;
- out->m[0][2]=z * x * (1 - c) - y * s;
- out->m[0][3]=0.0f;
- out->m[1][0]=x * y * (1 - c) - z * s;
- out->m[1][1]=y * y + c * (1 - y * y);
- out->m[1][2]=y * z * (1 - c) + x * s;
- out->m[1][3]=0.0f;
- out->m[2][0]=z * x * (1 - c) + y * s;
- out->m[2][1]=y * z * (1 - c) - x * s;
- out->m[2][2]=z * z + c * (1 - z * z);
- out->m[2][3]=0.0f;
-}
-
-void Matrix3x4_CreateScale (matrix3x4_t *out, float x)
-{
- out->m[0][0]=x;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=0.0f;
- out->m[1][0]=0.0f;
- out->m[1][1]=x;
- out->m[1][2]=0.0f;
- out->m[1][3]=0.0f;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=x;
- out->m[2][3]=0.0f;
-}
-
-void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z)
-{
- out->m[0][0]=x;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=0.0f;
- out->m[1][0]=0.0f;
- out->m[1][1]=y;
- out->m[1][2]=0.0f;
- out->m[1][3]=0.0f;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=z;
- out->m[2][3]=0.0f;
-}
-
-void Matrix3x4_ToVectors(const matrix3x4_t *in, vec3_t vx, vec3_t vy, vec3_t vz, vec3_t t)
-{
- vx[0] = in->m[0][0];
- vx[1] = in->m[1][0];
- vx[2] = in->m[2][0];
- vy[0] = in->m[0][1];
- vy[1] = in->m[1][1];
- vy[2] = in->m[2][1];
- vz[0] = in->m[0][2];
- vz[1] = in->m[1][2];
- vz[2] = in->m[2][2];
- t[0] = in->m[0][3];
- t[1] = in->m[1][3];
- t[2] = in->m[2][3];
-}
-
-void Matrix3x4_FromVectors(matrix3x4_t *out, const vec3_t vx, const vec3_t vy, const vec3_t vz, const vec3_t t)
-{
- out->m[0][0] = vx[0];
- out->m[0][1] = vy[0];
- out->m[0][2] = vz[0];
- out->m[0][3] = t[0];
- out->m[1][0] = vx[1];
- out->m[1][1] = vy[1];
- out->m[1][2] = vz[1];
- out->m[1][3] = t[1];
- out->m[2][0] = vx[2];
- out->m[2][1] = vy[2];
- out->m[2][2] = vz[2];
- out->m[2][3] = t[2];
-}
-
-void Matrix3x4_Transform (const matrix3x4_t *in, const vec3_t v, vec3_t out)
-{
- out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
- out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
- out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
-}
-
-void Matrix3x4_Untransform (const matrix3x4_t *in, const vec3_t v, vec3_t out)
-{
- vec3_t t;
- t[0] = v[0] - in->m[0][3];
- t[1] = v[1] - in->m[1][3];
- t[2] = v[2] - in->m[2][3];
- out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
- out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
- out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
-}
-
-// FIXME: optimize
-void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
-{
- matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
- Matrix3x4_CreateTranslate(&temp, x, y, z);
- Matrix3x4_Concat(out, &base, &temp);
-}
-
-// FIXME: optimize
-void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z)
-{
- matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
- Matrix3x4_CreateRotate(&temp, angle, x, y, z);
- Matrix3x4_Concat(out, &base, &temp);
-}
-
-// FIXME: optimize
-void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
-{
- matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
- Matrix3x4_CreateScale(&temp, x);
- Matrix3x4_Concat(out, &base, &temp);
-}
-
-// FIXME: optimize
-void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z)
-{
- matrix3x4_t base, temp;
- Matrix3x4_Copy(out, &base);
- Matrix3x4_CreateScale3(&temp, x, y, z);
- Matrix3x4_Concat(out, &base, &temp);
-}
-
+++ /dev/null
-
-#ifndef MATRIX3X4_H
-#define MATRIX3X4_H
-
-// to get the vec3_t type
-#include "mathlib.h"
-
-typedef struct matrix3x4_s
-{
- float m[3][4];
-}
-matrix3x4_t;
-
-void Matrix3x4_Copy (matrix3x4_t *out, matrix3x4_t *in);
-void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2);
-void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1);
-
-void Matrix3x4_CreateIdentity (matrix3x4_t *out);
-void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z);
-void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z);
-void Matrix3x4_CreateScale (matrix3x4_t *out, float x);
-void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z);
-
-void Matrix3x4_ToVectors(const matrix3x4_t *in, vec3_t vx, vec3_t vy, vec3_t vz, vec3_t t);
-void Matrix3x4_FromVectors(matrix3x4_t *out, const vec3_t vx, const vec3_t vy, const vec3_t vz, const vec3_t t);
-
-void Matrix3x4_Transform (const matrix3x4_t *in, const vec3_t v, vec3_t out);
-void Matrix3x4_Untransform (const matrix3x4_t *in, const vec3_t v, vec3_t out);
-
-void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z);
-void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z);
-void Matrix3x4_ConcatScale (matrix3x4_t *out, float x);
-void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z);
-
-#endif
+++ /dev/null
-
-#include "matrix4x4.h"
-#include <math.h>
-
-void Matrix4x4_Copy (matrix4x4_t *out, matrix4x4_t *in)
-{
- *out = *in;
-}
-
-void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
-{
- out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[0][1] * in2->m[1][0] + in1->m[0][2] * in2->m[2][0] + in1->m[0][3] * in2->m[3][0];
- out->m[0][1] = in1->m[0][0] * in2->m[0][1] + in1->m[0][1] * in2->m[1][1] + in1->m[0][2] * in2->m[2][1] + in1->m[0][3] * in2->m[3][1];
- out->m[0][2] = in1->m[0][0] * in2->m[0][2] + in1->m[0][1] * in2->m[1][2] + in1->m[0][2] * in2->m[2][2] + in1->m[0][3] * in2->m[3][2];
- out->m[0][3] = in1->m[0][0] * in2->m[0][3] + in1->m[0][1] * in2->m[1][3] + in1->m[0][2] * in2->m[2][3] + in1->m[0][3] * in2->m[3][3];
- out->m[1][0] = in1->m[1][0] * in2->m[0][0] + in1->m[1][1] * in2->m[1][0] + in1->m[1][2] * in2->m[2][0] + in1->m[1][3] * in2->m[3][0];
- out->m[1][1] = in1->m[1][0] * in2->m[0][1] + in1->m[1][1] * in2->m[1][1] + in1->m[1][2] * in2->m[2][1] + in1->m[1][3] * in2->m[3][1];
- out->m[1][2] = in1->m[1][0] * in2->m[0][2] + in1->m[1][1] * in2->m[1][2] + in1->m[1][2] * in2->m[2][2] + in1->m[1][3] * in2->m[3][2];
- out->m[1][3] = in1->m[1][0] * in2->m[0][3] + in1->m[1][1] * in2->m[1][3] + in1->m[1][2] * in2->m[2][3] + in1->m[1][3] * in2->m[3][3];
- out->m[2][0] = in1->m[2][0] * in2->m[0][0] + in1->m[2][1] * in2->m[1][0] + in1->m[2][2] * in2->m[2][0] + in1->m[2][3] * in2->m[3][0];
- out->m[2][1] = in1->m[2][0] * in2->m[0][1] + in1->m[2][1] * in2->m[1][1] + in1->m[2][2] * in2->m[2][1] + in1->m[2][3] * in2->m[3][1];
- out->m[2][2] = in1->m[2][0] * in2->m[0][2] + in1->m[2][1] * in2->m[1][2] + in1->m[2][2] * in2->m[2][2] + in1->m[2][3] * in2->m[3][2];
- out->m[2][3] = in1->m[2][0] * in2->m[0][3] + in1->m[2][1] * in2->m[1][3] + in1->m[2][2] * in2->m[2][3] + in1->m[2][3] * in2->m[3][3];
- out->m[3][0] = in1->m[3][0] * in2->m[0][0] + in1->m[3][1] * in2->m[1][0] + in1->m[3][2] * in2->m[2][0] + in1->m[3][3] * in2->m[3][0];
- out->m[3][1] = in1->m[3][0] * in2->m[0][1] + in1->m[3][1] * in2->m[1][1] + in1->m[3][2] * in2->m[2][1] + in1->m[3][3] * in2->m[3][1];
- out->m[3][2] = in1->m[3][0] * in2->m[0][2] + in1->m[3][1] * in2->m[1][2] + in1->m[3][2] * in2->m[2][2] + in1->m[3][3] * in2->m[3][2];
- out->m[3][3] = in1->m[3][0] * in2->m[0][3] + in1->m[3][1] * in2->m[1][3] + in1->m[3][2] * in2->m[2][3] + in1->m[3][3] * in2->m[3][3];
-}
-
-void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1)
-{
- out->m[0][0] = in1->m[0][0];
- out->m[0][1] = in1->m[1][0];
- out->m[0][2] = in1->m[2][0];
- out->m[0][3] = in1->m[3][0];
- out->m[1][0] = in1->m[0][1];
- out->m[1][1] = in1->m[1][1];
- out->m[1][2] = in1->m[2][1];
- out->m[1][3] = in1->m[3][1];
- out->m[2][0] = in1->m[0][2];
- out->m[2][1] = in1->m[1][2];
- out->m[2][2] = in1->m[2][2];
- out->m[2][3] = in1->m[3][2];
- out->m[3][0] = in1->m[0][3];
- out->m[3][1] = in1->m[1][3];
- out->m[3][2] = in1->m[2][3];
- out->m[3][3] = in1->m[3][3];
-}
-
-void Matrix4x4_CreateIdentity (matrix4x4_t *out)
-{
- out->m[0][0]=1.0f;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=0.0f;
- out->m[1][0]=0.0f;
- out->m[1][1]=1.0f;
- out->m[1][2]=0.0f;
- out->m[1][3]=0.0f;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=1.0f;
- out->m[2][3]=0.0f;
- out->m[3][0]=0.0f;
- out->m[3][1]=0.0f;
- out->m[3][2]=0.0f;
- out->m[3][3]=1.0f;
-}
-
-void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z)
-{
- out->m[0][0]=1.0f;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=x;
- out->m[1][0]=0.0f;
- out->m[1][1]=1.0f;
- out->m[1][2]=0.0f;
- out->m[1][3]=y;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=1.0f;
- out->m[2][3]=z;
- out->m[3][0]=0.0f;
- out->m[3][1]=0.0f;
- out->m[3][2]=0.0f;
- out->m[3][3]=1.0f;
-}
-
-void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z)
-{
- float len, c, s;
-
- len = x*x+y*y+z*z;
- if (len != 0.0f)
- len = 1.0f / sqrt(len);
- x *= len;
- y *= len;
- z *= len;
-
- angle *= M_PI / 180.0;
- c = cos(angle);
- s = sin(angle);
-
- out->m[0][0]=x * x + c * (1 - x * x);
- out->m[0][1]=x * y * (1 - c) + z * s;
- out->m[0][2]=z * x * (1 - c) - y * s;
- out->m[0][3]=0.0f;
- out->m[1][0]=x * y * (1 - c) - z * s;
- out->m[1][1]=y * y + c * (1 - y * y);
- out->m[1][2]=y * z * (1 - c) + x * s;
- out->m[1][3]=0.0f;
- out->m[2][0]=z * x * (1 - c) + y * s;
- out->m[2][1]=y * z * (1 - c) - x * s;
- out->m[2][2]=z * z + c * (1 - z * z);
- out->m[2][3]=0.0f;
- out->m[3][0]=0.0f;
- out->m[3][1]=0.0f;
- out->m[3][2]=0.0f;
- out->m[3][3]=1.0f;
-}
-
-void Matrix4x4_CreateScale (matrix4x4_t *out, float x)
-{
- out->m[0][0]=x;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=0.0f;
- out->m[1][0]=0.0f;
- out->m[1][1]=x;
- out->m[1][2]=0.0f;
- out->m[1][3]=0.0f;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=x;
- out->m[2][3]=0.0f;
- out->m[3][0]=0.0f;
- out->m[3][1]=0.0f;
- out->m[3][2]=0.0f;
- out->m[3][3]=1.0f;
-}
-
-void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z)
-{
- out->m[0][0]=x;
- out->m[0][1]=0.0f;
- out->m[0][2]=0.0f;
- out->m[0][3]=0.0f;
- out->m[1][0]=0.0f;
- out->m[1][1]=y;
- out->m[1][2]=0.0f;
- out->m[1][3]=0.0f;
- out->m[2][0]=0.0f;
- out->m[2][1]=0.0f;
- out->m[2][2]=z;
- out->m[2][3]=0.0f;
- out->m[3][0]=0.0f;
- out->m[3][1]=0.0f;
- out->m[3][2]=0.0f;
- out->m[3][3]=1.0f;
-}
-
-void Matrix4x4_ToVectors(const matrix4x4_t *in, vec3_t vx, vec3_t vy, vec3_t vz, vec3_t t)
-{
- vx[0] = in->m[0][0];
- vx[1] = in->m[1][0];
- vx[2] = in->m[2][0];
- vy[0] = in->m[0][1];
- vy[1] = in->m[1][1];
- vy[2] = in->m[2][1];
- vz[0] = in->m[0][2];
- vz[1] = in->m[1][2];
- vz[2] = in->m[2][2];
- t[0] = in->m[0][3];
- t[1] = in->m[1][3];
- t[2] = in->m[2][3];
-}
-
-void Matrix4x4_ToVectors4(const matrix4x4_t *in, vec4_t vx, vec4_t vy, vec4_t vz, vec4_t t)
-{
- vx[0] = in->m[0][0];
- vx[1] = in->m[1][0];
- vx[2] = in->m[2][0];
- vx[3] = in->m[3][0];
- vy[0] = in->m[0][1];
- vy[1] = in->m[1][1];
- vy[2] = in->m[2][1];
- vy[3] = in->m[3][1];
- vz[0] = in->m[0][2];
- vz[1] = in->m[1][2];
- vz[2] = in->m[2][2];
- vz[3] = in->m[3][2];
- t[0] = in->m[0][3];
- t[1] = in->m[1][3];
- t[2] = in->m[2][3];
- t[3] = in->m[3][3];
-}
-
-void Matrix4x4_FromVectors(matrix4x4_t *out, const vec3_t vx, const vec3_t vy, const vec3_t vz, const vec3_t t)
-{
- out->m[0][0] = vx[0];
- out->m[0][1] = vy[0];
- out->m[0][2] = vz[0];
- out->m[0][3] = t[0];
- out->m[1][0] = vx[1];
- out->m[1][1] = vy[1];
- out->m[1][2] = vz[1];
- out->m[1][3] = t[1];
- out->m[2][0] = vx[2];
- out->m[2][1] = vy[2];
- out->m[2][2] = vz[2];
- out->m[2][3] = t[2];
- out->m[3][0] = 0.0f;
- out->m[3][1] = 0.0f;
- out->m[3][2] = 0.0f;
- out->m[3][3] = 1.0f;
-}
-
-void Matrix4x4_FromVectors4(matrix4x4_t *out, const vec4_t vx, const vec4_t vy, const vec4_t vz, const vec4_t t)
-{
- out->m[0][0] = vx[0];
- out->m[0][1] = vy[0];
- out->m[0][2] = vz[0];
- out->m[0][3] = t[0];
- out->m[1][0] = vx[1];
- out->m[1][1] = vy[1];
- out->m[1][2] = vz[1];
- out->m[1][3] = t[1];
- out->m[2][0] = vx[2];
- out->m[2][1] = vy[2];
- out->m[2][2] = vz[2];
- out->m[2][3] = t[2];
- out->m[3][0] = vx[3];
- out->m[3][1] = vy[3];
- out->m[3][2] = vz[3];
- out->m[3][3] = t[3];
-}
-
-void Matrix4x4_Transform (const matrix4x4_t *in, const vec3_t v, vec3_t out)
-{
- out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
- out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
- out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
-}
-
-void Matrix4x4_Transform4 (const matrix4x4_t *in, const vec4_t v, vec4_t out)
-{
- out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + v[3] * in->m[0][3];
- out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + v[3] * in->m[1][3];
- out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + v[3] * in->m[2][3];
- out[3] = v[0] * in->m[3][0] + v[1] * in->m[3][1] + v[2] * in->m[3][2] + v[3] * in->m[3][3];
-}
-
-void Matrix4x4_Untransform (const matrix4x4_t *in, const vec3_t v, vec3_t out)
-{
- vec3_t t;
- t[0] = v[0] - in->m[0][3];
- t[1] = v[1] - in->m[1][3];
- t[2] = v[2] - in->m[2][3];
- out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
- out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
- out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
-}
-
-void Matrix4x4_Untransform4 (const matrix4x4_t *in, const vec4_t v, vec4_t out)
-{
- vec3_t t;
- t[0] = v[0] - in->m[0][3];
- t[1] = v[1] - in->m[1][3];
- t[2] = v[2] - in->m[2][3];
- t[3] = v[3] - in->m[3][3];
- out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0] + t[3] * in->m[3][0];
- out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1] + t[3] * in->m[3][1];
- out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2] + t[3] * in->m[3][2];
- out[3] = t[0] * in->m[0][3] + t[1] * in->m[1][3] + t[2] * in->m[2][3] + t[3] * in->m[3][3];
-}
-
-// FIXME: optimize
-void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
-{
- matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
- Matrix4x4_CreateTranslate(&temp, x, y, z);
- Matrix4x4_Concat(out, &base, &temp);
-}
-
-// FIXME: optimize
-void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
-{
- matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
- Matrix4x4_CreateRotate(&temp, angle, x, y, z);
- Matrix4x4_Concat(out, &base, &temp);
-}
-
-// FIXME: optimize
-void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
-{
- matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
- Matrix4x4_CreateScale(&temp, x);
- Matrix4x4_Concat(out, &base, &temp);
-}
-
-// FIXME: optimize
-void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
-{
- matrix4x4_t base, temp;
- Matrix4x4_Copy(out, &base);
- Matrix4x4_CreateScale3(&temp, x, y, z);
- Matrix4x4_Concat(out, &base, &temp);
-}
-
+++ /dev/null
-
-#ifndef MATRIX4X4_H
-#define MATRIX4X4_H
-
-// to get the vec3_t and vec4_t types
-#include "mathlib.h"
-
-typedef struct matrix4x4_s
-{
- float m[4][4];
-}
-matrix4x4_t;
-
-void Matrix4x4_Copy (matrix4x4_t *out, matrix4x4_t *in);
-void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2);
-void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1);
-
-void Matrix4x4_CreateIdentity (matrix4x4_t *out);
-void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z);
-void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z);
-void Matrix4x4_CreateScale (matrix4x4_t *out, float x);
-void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z);
-
-void Matrix4x4_ToVectors(const matrix4x4_t *in, vec3_t vx, vec3_t vy, vec3_t vz, vec3_t t);
-void Matrix4x4_ToVectors4(const matrix4x4_t *in, vec4_t vx, vec4_t vy, vec4_t vz, vec4_t t);
-void Matrix4x4_FromVectors(matrix4x4_t *out, const vec3_t vx, const vec3_t vy, const vec3_t vz, const vec3_t t);
-void Matrix4x4_FromVectors4(matrix4x4_t *out, const vec4_t vx, const vec4_t vy, const vec4_t vz, const vec4_t t);
-
-void Matrix4x4_Transform (const matrix4x4_t *in, const vec3_t v, vec3_t out);
-void Matrix4x4_Transform4 (const matrix4x4_t *in, const vec4_t v, vec4_t out);
-void Matrix4x4_Untransform (const matrix4x4_t *in, const vec3_t v, vec3_t out);
-void Matrix4x4_Untransform4 (const matrix4x4_t *in, const vec4_t v, vec4_t out);
-
-void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z);
-void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z);
-void Matrix4x4_ConcatScale (matrix4x4_t *out, float x);
-void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
-
-#endif
--- /dev/null
+
+#include "matrixlib.h"
+#include <math.h>
+
+void Matrix4x4_Copy (matrix4x4_t *out, matrix4x4_t *in)
+{
+ *out = *in;
+}
+
+void Matrix4x4_CopyRotateOnly (matrix4x4_t *out, matrix4x4_t *in)
+{
+ out->m[0][0] = in->m[0][0];
+ out->m[0][1] = in->m[0][1];
+ out->m[0][2] = in->m[0][2];
+ out->m[0][3] = 0.0f;
+ out->m[1][0] = in->m[1][0];
+ out->m[1][1] = in->m[1][1];
+ out->m[1][2] = in->m[1][2];
+ out->m[1][3] = 0.0f;
+ out->m[2][0] = in->m[2][0];
+ out->m[2][1] = in->m[2][1];
+ out->m[2][2] = in->m[2][2];
+ out->m[2][3] = 0.0f;
+ out->m[3][0] = 0.0f;
+ out->m[3][1] = 0.0f;
+ out->m[3][2] = 0.0f;
+ out->m[3][3] = 1.0f;
+}
+
+void Matrix4x4_CopyTranslateOnly (matrix4x4_t *out, matrix4x4_t *in)
+{
+ out->m[0][0] = 0.0f;
+ out->m[0][1] = 0.0f;
+ out->m[0][2] = 0.0f;
+ out->m[0][3] = in->m[0][3];
+ out->m[1][0] = 0.0f;
+ out->m[1][1] = 0.0f;
+ out->m[1][2] = 0.0f;
+ out->m[1][3] = in->m[0][3];
+ out->m[2][0] = 0.0f;
+ out->m[2][1] = 0.0f;
+ out->m[2][2] = 0.0f;
+ out->m[2][3] = in->m[0][3];
+ out->m[3][0] = 0.0f;
+ out->m[3][1] = 0.0f;
+ out->m[3][2] = 0.0f;
+ out->m[3][3] = 1.0f;
+}
+
+void Matrix4x4_FromMatrix3x4 (matrix4x4_t *out, matrix3x4_t *in)
+{
+ out->m[0][0] = in->m[0][0];
+ out->m[0][1] = in->m[0][1];
+ out->m[0][2] = in->m[0][2];
+ out->m[0][3] = in->m[0][3];
+ out->m[1][0] = in->m[1][0];
+ out->m[1][1] = in->m[1][1];
+ out->m[1][2] = in->m[1][2];
+ out->m[1][3] = in->m[1][3];
+ out->m[2][0] = in->m[2][0];
+ out->m[2][1] = in->m[2][1];
+ out->m[2][2] = in->m[2][2];
+ out->m[2][3] = in->m[2][3];
+ out->m[3][0] = 0.0f;
+ out->m[3][1] = 0.0f;
+ out->m[3][2] = 0.0f;
+ out->m[3][3] = 1.0f;
+}
+
+void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
+{
+ out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[0][1] * in2->m[1][0] + in1->m[0][2] * in2->m[2][0] + in1->m[0][3] * in2->m[3][0];
+ out->m[0][1] = in1->m[0][0] * in2->m[0][1] + in1->m[0][1] * in2->m[1][1] + in1->m[0][2] * in2->m[2][1] + in1->m[0][3] * in2->m[3][1];
+ out->m[0][2] = in1->m[0][0] * in2->m[0][2] + in1->m[0][1] * in2->m[1][2] + in1->m[0][2] * in2->m[2][2] + in1->m[0][3] * in2->m[3][2];
+ out->m[0][3] = in1->m[0][0] * in2->m[0][3] + in1->m[0][1] * in2->m[1][3] + in1->m[0][2] * in2->m[2][3] + in1->m[0][3] * in2->m[3][3];
+ out->m[1][0] = in1->m[1][0] * in2->m[0][0] + in1->m[1][1] * in2->m[1][0] + in1->m[1][2] * in2->m[2][0] + in1->m[1][3] * in2->m[3][0];
+ out->m[1][1] = in1->m[1][0] * in2->m[0][1] + in1->m[1][1] * in2->m[1][1] + in1->m[1][2] * in2->m[2][1] + in1->m[1][3] * in2->m[3][1];
+ out->m[1][2] = in1->m[1][0] * in2->m[0][2] + in1->m[1][1] * in2->m[1][2] + in1->m[1][2] * in2->m[2][2] + in1->m[1][3] * in2->m[3][2];
+ out->m[1][3] = in1->m[1][0] * in2->m[0][3] + in1->m[1][1] * in2->m[1][3] + in1->m[1][2] * in2->m[2][3] + in1->m[1][3] * in2->m[3][3];
+ out->m[2][0] = in1->m[2][0] * in2->m[0][0] + in1->m[2][1] * in2->m[1][0] + in1->m[2][2] * in2->m[2][0] + in1->m[2][3] * in2->m[3][0];
+ out->m[2][1] = in1->m[2][0] * in2->m[0][1] + in1->m[2][1] * in2->m[1][1] + in1->m[2][2] * in2->m[2][1] + in1->m[2][3] * in2->m[3][1];
+ out->m[2][2] = in1->m[2][0] * in2->m[0][2] + in1->m[2][1] * in2->m[1][2] + in1->m[2][2] * in2->m[2][2] + in1->m[2][3] * in2->m[3][2];
+ out->m[2][3] = in1->m[2][0] * in2->m[0][3] + in1->m[2][1] * in2->m[1][3] + in1->m[2][2] * in2->m[2][3] + in1->m[2][3] * in2->m[3][3];
+ out->m[3][0] = in1->m[3][0] * in2->m[0][0] + in1->m[3][1] * in2->m[1][0] + in1->m[3][2] * in2->m[2][0] + in1->m[3][3] * in2->m[3][0];
+ out->m[3][1] = in1->m[3][0] * in2->m[0][1] + in1->m[3][1] * in2->m[1][1] + in1->m[3][2] * in2->m[2][1] + in1->m[3][3] * in2->m[3][1];
+ out->m[3][2] = in1->m[3][0] * in2->m[0][2] + in1->m[3][1] * in2->m[1][2] + in1->m[3][2] * in2->m[2][2] + in1->m[3][3] * in2->m[3][2];
+ out->m[3][3] = in1->m[3][0] * in2->m[0][3] + in1->m[3][1] * in2->m[1][3] + in1->m[3][2] * in2->m[2][3] + in1->m[3][3] * in2->m[3][3];
+}
+
+void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1)
+{
+ float scale;
+ scale = 3.0 / (in1->m[0][0] * in1->m[0][0]
+ + in1->m[0][1] * in1->m[0][1]
+ + in1->m[0][2] * in1->m[0][2]
+ + in1->m[1][0] * in1->m[1][0]
+ + in1->m[1][1] * in1->m[1][1]
+ + in1->m[1][2] * in1->m[1][2]
+ + in1->m[2][0] * in1->m[2][0]
+ + in1->m[2][1] * in1->m[2][1]
+ + in1->m[2][2] * in1->m[2][2]);
+ out->m[0][0] = in1->m[0][0] * scale;
+ out->m[0][1] = in1->m[1][0] * scale;
+ out->m[0][2] = in1->m[2][0] * scale;
+ out->m[0][3] = in1->m[3][0];
+ out->m[1][0] = in1->m[0][1] * scale;
+ out->m[1][1] = in1->m[1][1] * scale;
+ out->m[1][2] = in1->m[2][1] * scale;
+ out->m[1][3] = in1->m[3][1];
+ out->m[2][0] = in1->m[0][2] * scale;
+ out->m[2][1] = in1->m[1][2] * scale;
+ out->m[2][2] = in1->m[2][2] * scale;
+ out->m[2][3] = in1->m[3][2];
+ out->m[3][0] = in1->m[0][3];
+ out->m[3][1] = in1->m[1][3];
+ out->m[3][2] = in1->m[2][3];
+ out->m[3][3] = in1->m[3][3];
+}
+
+void Matrix4x4_CreateIdentity (matrix4x4_t *out)
+{
+ out->m[0][0]=1.0f;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=1.0f;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=1.0f;
+ out->m[2][3]=0.0f;
+ out->m[3][0]=0.0f;
+ out->m[3][1]=0.0f;
+ out->m[3][2]=0.0f;
+ out->m[3][3]=1.0f;
+}
+
+void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z)
+{
+ out->m[0][0]=1.0f;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=x;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=1.0f;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=y;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=1.0f;
+ out->m[2][3]=z;
+ out->m[3][0]=0.0f;
+ out->m[3][1]=0.0f;
+ out->m[3][2]=0.0f;
+ out->m[3][3]=1.0f;
+}
+
+void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z)
+{
+ float len, c, s;
+
+ len = x*x+y*y+z*z;
+ if (len != 0.0f)
+ len = 1.0f / sqrt(len);
+ x *= len;
+ y *= len;
+ z *= len;
+
+ angle *= M_PI / 180.0;
+ c = cos(angle);
+ s = sin(angle);
+
+ out->m[0][0]=x * x + c * (1 - x * x);
+ out->m[0][1]=x * y * (1 - c) + z * s;
+ out->m[0][2]=z * x * (1 - c) - y * s;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=x * y * (1 - c) - z * s;
+ out->m[1][1]=y * y + c * (1 - y * y);
+ out->m[1][2]=y * z * (1 - c) + x * s;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=z * x * (1 - c) + y * s;
+ out->m[2][1]=y * z * (1 - c) - x * s;
+ out->m[2][2]=z * z + c * (1 - z * z);
+ out->m[2][3]=0.0f;
+ out->m[3][0]=0.0f;
+ out->m[3][1]=0.0f;
+ out->m[3][2]=0.0f;
+ out->m[3][3]=1.0f;
+}
+
+void Matrix4x4_CreateScale (matrix4x4_t *out, float x)
+{
+ out->m[0][0]=x;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=x;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=x;
+ out->m[2][3]=0.0f;
+ out->m[3][0]=0.0f;
+ out->m[3][1]=0.0f;
+ out->m[3][2]=0.0f;
+ out->m[3][3]=1.0f;
+}
+
+void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z)
+{
+ out->m[0][0]=x;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=y;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=z;
+ out->m[2][3]=0.0f;
+ out->m[3][0]=0.0f;
+ out->m[3][1]=0.0f;
+ out->m[3][2]=0.0f;
+ out->m[3][3]=1.0f;
+}
+
+void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
+{
+ vx[0] = in->m[0][0];
+ vx[1] = in->m[1][0];
+ vx[2] = in->m[2][0];
+ vy[0] = in->m[0][1];
+ vy[1] = in->m[1][1];
+ vy[2] = in->m[2][1];
+ vz[0] = in->m[0][2];
+ vz[1] = in->m[1][2];
+ vz[2] = in->m[2][2];
+ t[0] = in->m[0][3];
+ t[1] = in->m[1][3];
+ t[2] = in->m[2][3];
+}
+
+void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
+{
+ out->m[0][0] = vx[0];
+ out->m[0][1] = vy[0];
+ out->m[0][2] = vz[0];
+ out->m[0][3] = t[0];
+ out->m[1][0] = vx[1];
+ out->m[1][1] = vy[1];
+ out->m[1][2] = vz[1];
+ out->m[1][3] = t[1];
+ out->m[2][0] = vx[2];
+ out->m[2][1] = vy[2];
+ out->m[2][2] = vz[2];
+ out->m[2][3] = t[2];
+ out->m[3][0] = 0.0f;
+ out->m[3][1] = 0.0f;
+ out->m[3][2] = 0.0f;
+ out->m[3][3] = 1.0f;
+}
+
+void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3])
+{
+ out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
+ out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
+ out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
+}
+
+void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4])
+{
+ out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + v[3] * in->m[0][3];
+ out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + v[3] * in->m[1][3];
+ out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + v[3] * in->m[2][3];
+ out[3] = v[0] * in->m[3][0] + v[1] * in->m[3][1] + v[2] * in->m[3][2] + v[3] * in->m[3][3];
+}
+
+void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3])
+{
+ float t[3];
+ t[0] = v[0] - in->m[0][3];
+ t[1] = v[1] - in->m[1][3];
+ t[2] = v[2] - in->m[2][3];
+ out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
+ out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
+ out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
+}
+
+// FIXME: optimize
+void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
+{
+ matrix4x4_t base, temp;
+ Matrix4x4_Copy(out, &base);
+ Matrix4x4_CreateTranslate(&temp, x, y, z);
+ Matrix4x4_Concat(out, &base, &temp);
+}
+
+// FIXME: optimize
+void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
+{
+ matrix4x4_t base, temp;
+ Matrix4x4_Copy(out, &base);
+ Matrix4x4_CreateRotate(&temp, angle, x, y, z);
+ Matrix4x4_Concat(out, &base, &temp);
+}
+
+// FIXME: optimize
+void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
+{
+ matrix4x4_t base, temp;
+ Matrix4x4_Copy(out, &base);
+ Matrix4x4_CreateScale(&temp, x);
+ Matrix4x4_Concat(out, &base, &temp);
+}
+
+// FIXME: optimize
+void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
+{
+ matrix4x4_t base, temp;
+ Matrix4x4_Copy(out, &base);
+ Matrix4x4_CreateScale3(&temp, x, y, z);
+ Matrix4x4_Concat(out, &base, &temp);
+}
+
+
+
+
+
+
+
+
+void Matrix3x4_Copy (matrix3x4_t *out, matrix3x4_t *in)
+{
+ *out = *in;
+}
+
+void Matrix3x4_CopyRotateOnly (matrix3x4_t *out, matrix3x4_t *in)
+{
+ out->m[0][0] = in->m[0][0];
+ out->m[0][1] = in->m[0][1];
+ out->m[0][2] = in->m[0][2];
+ out->m[0][3] = 0.0f;
+ out->m[1][0] = in->m[1][0];
+ out->m[1][1] = in->m[1][1];
+ out->m[1][2] = in->m[1][2];
+ out->m[1][3] = 0.0f;
+ out->m[2][0] = in->m[2][0];
+ out->m[2][1] = in->m[2][1];
+ out->m[2][2] = in->m[2][2];
+ out->m[2][3] = 0.0f;
+}
+
+void Matrix3x4_CopyTranslateOnly (matrix3x4_t *out, matrix3x4_t *in)
+{
+ out->m[0][0] = 0.0f;
+ out->m[0][1] = 0.0f;
+ out->m[0][2] = 0.0f;
+ out->m[0][3] = in->m[0][3];
+ out->m[1][0] = 0.0f;
+ out->m[1][1] = 0.0f;
+ out->m[1][2] = 0.0f;
+ out->m[1][3] = in->m[0][3];
+ out->m[2][0] = 0.0f;
+ out->m[2][1] = 0.0f;
+ out->m[2][2] = 0.0f;
+ out->m[2][3] = in->m[0][3];
+}
+
+void Matrix3x4_FromMatrix4x4 (matrix3x4_t *out, matrix4x4_t *in)
+{
+ out->m[0][0] = in->m[0][0];
+ out->m[0][1] = in->m[0][1];
+ out->m[0][2] = in->m[0][2];
+ out->m[0][3] = in->m[0][3];
+ out->m[1][0] = in->m[1][0];
+ out->m[1][1] = in->m[1][1];
+ out->m[1][2] = in->m[1][2];
+ out->m[1][3] = in->m[1][3];
+ out->m[2][0] = in->m[2][0];
+ out->m[2][1] = in->m[2][1];
+ out->m[2][2] = in->m[2][2];
+ out->m[2][3] = in->m[2][3];
+}
+
+void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2)
+{
+ out->m[0][0] = in1->m[0][0] * in2->m[0][0] + in1->m[0][1] * in2->m[1][0] + in1->m[0][2] * in2->m[2][0];
+ out->m[0][1] = in1->m[0][0] * in2->m[0][1] + in1->m[0][1] * in2->m[1][1] + in1->m[0][2] * in2->m[2][1];
+ out->m[0][2] = in1->m[0][0] * in2->m[0][2] + in1->m[0][1] * in2->m[1][2] + in1->m[0][2] * in2->m[2][2];
+ out->m[0][3] = in1->m[0][0] * in2->m[0][3] + in1->m[0][1] * in2->m[1][3] + in1->m[0][2] * in2->m[2][3] + in1->m[0][3];
+ out->m[1][0] = in1->m[1][0] * in2->m[0][0] + in1->m[1][1] * in2->m[1][0] + in1->m[1][2] * in2->m[2][0];
+ out->m[1][1] = in1->m[1][0] * in2->m[0][1] + in1->m[1][1] * in2->m[1][1] + in1->m[1][2] * in2->m[2][1];
+ out->m[1][2] = in1->m[1][0] * in2->m[0][2] + in1->m[1][1] * in2->m[1][2] + in1->m[1][2] * in2->m[2][2];
+ out->m[1][3] = in1->m[1][0] * in2->m[0][3] + in1->m[1][1] * in2->m[1][3] + in1->m[1][2] * in2->m[2][3] + in1->m[1][3];
+ out->m[2][0] = in1->m[2][0] * in2->m[0][0] + in1->m[2][1] * in2->m[1][0] + in1->m[2][2] * in2->m[2][0];
+ out->m[2][1] = in1->m[2][0] * in2->m[0][1] + in1->m[2][1] * in2->m[1][1] + in1->m[2][2] * in2->m[2][1];
+ out->m[2][2] = in1->m[2][0] * in2->m[0][2] + in1->m[2][1] * in2->m[1][2] + in1->m[2][2] * in2->m[2][2];
+ out->m[2][3] = in1->m[2][0] * in2->m[0][3] + in1->m[2][1] * in2->m[1][3] + in1->m[2][2] * in2->m[2][3] + in1->m[2][3];
+}
+
+void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1)
+{
+ float scale;
+ scale = 3.0 / (in1->m[0][0] * in1->m[0][0]
+ + in1->m[0][1] * in1->m[0][1]
+ + in1->m[0][2] * in1->m[0][2]
+ + in1->m[1][0] * in1->m[1][0]
+ + in1->m[1][1] * in1->m[1][1]
+ + in1->m[1][2] * in1->m[1][2]
+ + in1->m[2][0] * in1->m[2][0]
+ + in1->m[2][1] * in1->m[2][1]
+ + in1->m[2][2] * in1->m[2][2]);
+ out->m[0][0] = in1->m[0][0] * scale;
+ out->m[0][1] = in1->m[1][0] * scale;
+ out->m[0][2] = in1->m[2][0] * scale;
+ out->m[0][3] = 0.0f;
+ out->m[1][0] = in1->m[0][1] * scale;
+ out->m[1][1] = in1->m[1][1] * scale;
+ out->m[1][2] = in1->m[2][1] * scale;
+ out->m[1][3] = 0.0f;
+ out->m[2][0] = in1->m[0][2] * scale;
+ out->m[2][1] = in1->m[1][2] * scale;
+ out->m[2][2] = in1->m[2][2] * scale;
+ out->m[2][3] = 0.0f;
+}
+
+void Matrix3x4_CreateIdentity (matrix3x4_t *out)
+{
+ out->m[0][0]=1.0f;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=1.0f;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=1.0f;
+ out->m[2][3]=0.0f;
+}
+
+void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z)
+{
+ out->m[0][0]=1.0f;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=x;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=1.0f;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=y;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=1.0f;
+ out->m[2][3]=z;
+}
+
+void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z)
+{
+ float len, c, s;
+
+ len = x*x+y*y+z*z;
+ if (len != 0.0f)
+ len = 1.0f / sqrt(len);
+ x *= len;
+ y *= len;
+ z *= len;
+
+ angle *= M_PI / 180.0;
+ c = cos(angle);
+ s = sin(angle);
+
+ out->m[0][0]=x * x + c * (1 - x * x);
+ out->m[0][1]=x * y * (1 - c) + z * s;
+ out->m[0][2]=z * x * (1 - c) - y * s;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=x * y * (1 - c) - z * s;
+ out->m[1][1]=y * y + c * (1 - y * y);
+ out->m[1][2]=y * z * (1 - c) + x * s;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=z * x * (1 - c) + y * s;
+ out->m[2][1]=y * z * (1 - c) - x * s;
+ out->m[2][2]=z * z + c * (1 - z * z);
+ out->m[2][3]=0.0f;
+}
+
+void Matrix3x4_CreateScale (matrix3x4_t *out, float x)
+{
+ out->m[0][0]=x;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=x;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=x;
+ out->m[2][3]=0.0f;
+}
+
+void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z)
+{
+ out->m[0][0]=x;
+ out->m[0][1]=0.0f;
+ out->m[0][2]=0.0f;
+ out->m[0][3]=0.0f;
+ out->m[1][0]=0.0f;
+ out->m[1][1]=y;
+ out->m[1][2]=0.0f;
+ out->m[1][3]=0.0f;
+ out->m[2][0]=0.0f;
+ out->m[2][1]=0.0f;
+ out->m[2][2]=z;
+ out->m[2][3]=0.0f;
+}
+
+void Matrix3x4_ToVectors(const matrix3x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
+{
+ vx[0] = in->m[0][0];
+ vx[1] = in->m[1][0];
+ vx[2] = in->m[2][0];
+ vy[0] = in->m[0][1];
+ vy[1] = in->m[1][1];
+ vy[2] = in->m[2][1];
+ vz[0] = in->m[0][2];
+ vz[1] = in->m[1][2];
+ vz[2] = in->m[2][2];
+ t[0] = in->m[0][3];
+ t[1] = in->m[1][3];
+ t[2] = in->m[2][3];
+}
+
+void Matrix3x4_FromVectors(matrix3x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
+{
+ out->m[0][0] = vx[0];
+ out->m[0][1] = vy[0];
+ out->m[0][2] = vz[0];
+ out->m[0][3] = t[0];
+ out->m[1][0] = vx[1];
+ out->m[1][1] = vy[1];
+ out->m[1][2] = vz[1];
+ out->m[1][3] = t[1];
+ out->m[2][0] = vx[2];
+ out->m[2][1] = vy[2];
+ out->m[2][2] = vz[2];
+ out->m[2][3] = t[2];
+}
+
+void Matrix3x4_Transform (const matrix3x4_t *in, const float v[3], float out[3])
+{
+ out[0] = v[0] * in->m[0][0] + v[1] * in->m[0][1] + v[2] * in->m[0][2] + in->m[0][3];
+ out[1] = v[0] * in->m[1][0] + v[1] * in->m[1][1] + v[2] * in->m[1][2] + in->m[1][3];
+ out[2] = v[0] * in->m[2][0] + v[1] * in->m[2][1] + v[2] * in->m[2][2] + in->m[2][3];
+}
+
+void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3])
+{
+ float t[3];
+ t[0] = v[0] - in->m[0][3];
+ t[1] = v[1] - in->m[1][3];
+ t[2] = v[2] - in->m[2][3];
+ out[0] = t[0] * in->m[0][0] + t[1] * in->m[1][0] + t[2] * in->m[2][0];
+ out[1] = t[0] * in->m[0][1] + t[1] * in->m[1][1] + t[2] * in->m[2][1];
+ out[2] = t[0] * in->m[0][2] + t[1] * in->m[1][2] + t[2] * in->m[2][2];
+}
+
+// FIXME: optimize
+void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z)
+{
+ matrix3x4_t base, temp;
+ Matrix3x4_Copy(out, &base);
+ Matrix3x4_CreateTranslate(&temp, x, y, z);
+ Matrix3x4_Concat(out, &base, &temp);
+}
+
+// FIXME: optimize
+void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z)
+{
+ matrix3x4_t base, temp;
+ Matrix3x4_Copy(out, &base);
+ Matrix3x4_CreateRotate(&temp, angle, x, y, z);
+ Matrix3x4_Concat(out, &base, &temp);
+}
+
+// FIXME: optimize
+void Matrix3x4_ConcatScale (matrix3x4_t *out, float x)
+{
+ matrix3x4_t base, temp;
+ Matrix3x4_Copy(out, &base);
+ Matrix3x4_CreateScale(&temp, x);
+ Matrix3x4_Concat(out, &base, &temp);
+}
+
+// FIXME: optimize
+void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z)
+{
+ matrix3x4_t base, temp;
+ Matrix3x4_Copy(out, &base);
+ Matrix3x4_CreateScale3(&temp, x, y, z);
+ Matrix3x4_Concat(out, &base, &temp);
+}
--- /dev/null
+
+#ifndef MATRIXLIB_H
+#define MATRIXLIB_H
+
+typedef struct matrix4x4_s
+{
+ float m[4][4];
+}
+matrix4x4_t;
+
+typedef struct matrix3x4_s
+{
+ float m[3][4];
+}
+matrix3x4_t;
+
+// functions for manipulating 4x4 matrices
+
+// copy a matrix4x4
+void Matrix4x4_Copy (matrix4x4_t *out, matrix4x4_t *in);
+// copy only the rotation portion of a matrix4x4
+void Matrix4x4_CopyRotateOnly (matrix4x4_t *out, matrix4x4_t *in);
+// copy only the translate portion of a matrix4x4
+void Matrix4x4_CopyTranslateOnly (matrix4x4_t *out, matrix4x4_t *in);
+// make a matrix4x4 from a matrix3x4
+void Matrix4x4_FromMatrix3x4 (matrix4x4_t *out, matrix3x4_t *in);
+// multiply two matrix4x4 together, combining their transformations
+// (warning: order matters - Concat(a, b, c) != Concat(a, c, b))
+void Matrix4x4_Concat (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2);
+// swaps the rows and columns of the matrix4x4 and attempts to undo uniform
+// scaling (Scale, not Scale3), resulting in a matrix that will do the opposite
+// (warning: this only inverts rotation, uniform scaling and translation,
+// do not use with shearing, Scale3, or other complex matrices)
+void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1);
+
+// creates an identity matrix
+// (a matrix which does nothing)
+void Matrix4x4_CreateIdentity (matrix4x4_t *out);
+// creates a translate matrix
+// (moves vectors)
+void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z);
+// creates a rotate matrix
+// (rotates vectors)
+void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z);
+// creates a scaling matrix
+// (expands or contracts vectors)
+// (warning: this is not reversed by Transpose)
+void Matrix4x4_CreateScale (matrix4x4_t *out, float x);
+// creates a squishing matrix
+// (expands or contracts vectors differently in different axis)
+// (warning: this is not reversed by Transpose)
+// (warning: do not apply this kind of matrix to direction vectors)
+void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z);
+
+// converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate
+void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]);
+// creates a matrix4x4 from a set of 3D vectors for axial directions, and translate
+void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
+
+// transforms a 3D vector through a matrix4x4
+void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3]);
+// transforms a 4D vector through a matrix4x4
+// (warning: if you don't know why you would need this, you don't need it)
+// (warning: the 4th component of the vector should be 1.0)
+void Matrix4x4_Transform4 (const matrix4x4_t *in, const float v[4], float out[4]);
+// reverse transforms a 3D vector through a matrix4x4, at least for *simple*
+// cases (rotation and translation *ONLY*), this attempts to undo the results
+// of Transform
+void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3]);
+
+// ease of use functions
+// immediately applies a Translate to the matrix
+void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z);
+// immediately applies a Rotate to the matrix
+void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z);
+// immediately applies a Scale to the matrix
+void Matrix4x4_ConcatScale (matrix4x4_t *out, float x);
+// immediately applies a Scale3 to the matrix
+void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
+
+
+
+// functions for manipulating 3x4 matrices
+
+// copy a matrix3x4
+void Matrix3x4_Copy (matrix3x4_t *out, matrix3x4_t *in);
+// copy only the rotation portion of a matrix3x4
+void Matrix3x4_CopyRotateOnly (matrix3x4_t *out, matrix3x4_t *in);
+// copy only the translate portion of a matrix3x4
+void Matrix3x4_CopyTranslateOnly (matrix3x4_t *out, matrix3x4_t *in);
+// make a matrix3x4 from a matrix4x4
+void Matrix3x4_FromMatrix4x4 (matrix3x4_t *out, matrix4x4_t *in);
+// multiply two matrix3x4 together, combining their transformations
+// (warning: order matters - Concat(a, b, c) != Concat(a, c, b))
+void Matrix3x4_Concat (matrix3x4_t *out, const matrix3x4_t *in1, const matrix3x4_t *in2);
+// swaps the rows and columns of the rotation portion of the matrix, and
+// attempts to undo uniform scaling (Scale, not Scale3), resulting in a
+// matrix that will do the opposite
+// (warning: this only inverts rotation and uniform scaling, do not use with
+// translation, shearing, Scale3 or other complex matrices)
+void Matrix3x4_Transpose3x3 (matrix3x4_t *out, const matrix3x4_t *in1);
+
+// creates an identity matrix
+// (a matrix which does nothing)
+void Matrix3x4_CreateIdentity (matrix3x4_t *out);
+// creates a translate matrix
+// (moves vectors)
+void Matrix3x4_CreateTranslate (matrix3x4_t *out, float x, float y, float z);
+// creates a rotate matrix
+// (rotates vectors)
+void Matrix3x4_CreateRotate (matrix3x4_t *out, float angle, float x, float y, float z);
+// creates a scaling matrix
+// (expands or contracts vectors)
+// (warning: this is not reversed by Transpose)
+void Matrix3x4_CreateScale (matrix3x4_t *out, float x);
+// creates a squishing matrix
+// (expands or contracts vectors differently in different axis)
+// (warning: this is not reversed by Transpose)
+// (warning: do not apply this kind of matrix to direction vectors)
+void Matrix3x4_CreateScale3 (matrix3x4_t *out, float x, float y, float z);
+
+// converts a matrix3x4 to a set of 3D vectors for the 3 axial directions, and the translate
+void Matrix3x4_ToVectors(const matrix3x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]);
+// creates a matrix3x4 from a set of 3D vectors for axial directions, and translate
+void Matrix3x4_FromVectors(matrix3x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
+
+// transforms a 3D vector through a matrix3x4
+void Matrix3x4_Transform (const matrix3x4_t *in, const float v[3], float out[3]);
+// reverse transforms a 3D vector through a matrix3x4, at least for *simple*
+// cases (rotation and translation *ONLY*), this attempts to undo the results
+// of Transform
+void Matrix3x4_SimpleUntransform (const matrix3x4_t *in, const float v[3], float out[3]);
+
+// ease of use functions
+// immediately applies a Translate to the matrix
+void Matrix3x4_ConcatTranslate (matrix3x4_t *out, float x, float y, float z);
+// immediately applies a Rotate to the matrix
+void Matrix3x4_ConcatRotate (matrix3x4_t *out, float angle, float x, float y, float z);
+// immediately applies a Scale to the matrix
+void Matrix3x4_ConcatScale (matrix3x4_t *out, float x);
+// immediately applies a Scale3 to the matrix
+void Matrix3x4_ConcatScale3 (matrix3x4_t *out, float x, float y, float z);
+
+#endif