UFO: Alien Invasion
Loading...
Searching...
No Matches
r_matrix.h
Go to the documentation of this file.
1/*
2 * Copyright(c) 2010 DarkPlaces.
3 * Copyright(c) 2010 Quake2World.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or(at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#pragma once
22
23/*#define MATRIX4x4_OPENGLORIENTATION */
24
25typedef struct matrix4x4_s
26{
27 float m[4][4];
29
30extern const matrix4x4_t identitymatrix;
31
32/* functions for manipulating 4x4 matrices */
33
34/* copy a matrix4x4 */
35void Matrix4x4_Copy (matrix4x4_t* out, const matrix4x4_t* in);
36/* copy only the rotation portion of a matrix4x4 */
38/* copy only the translate portion of a matrix4x4 */
40/* multiply two matrix4x4 together, combining their transformations
41 * (warning: order matters - Concat(a, b, c) != Concat(a, c, b)) */
42void Matrix4x4_Concat (matrix4x4_t* out, const matrix4x4_t* in1, const matrix4x4_t* in2);
43/* swaps the rows and columns of the matrix
44 * (is this useful for anything?) */
45void Matrix4x4_Transpose (matrix4x4_t* out, const matrix4x4_t* in1);
46/* creates a matrix that does the opposite of the matrix provided
47 * this is a full matrix inverter, it should be able to invert any matrix that
48 * is possible to invert
49 * (non-uniform scaling, rotation, shearing, and translation, possibly others)
50 * warning: this function is SLOW */
51int Matrix4x4_Invert_Full (matrix4x4_t* out, const matrix4x4_t* in1);
52/* creates a matrix that does the opposite of the matrix provided
53 * only supports translate, rotate, scale (not scale3) matrices */
54void Matrix4x4_Invert_Simple (matrix4x4_t* out, const matrix4x4_t* in1);
55/* blends between two matrices, used primarily for animation interpolation
56 * (note: it is recommended to follow this with Matrix4x4_Normalize, a method
57 * known as nlerp rotation, often better for animation purposes than slerp) */
58void Matrix4x4_Interpolate (matrix4x4_t* out, matrix4x4_t* in1, matrix4x4_t* in2, double frac);
59/* zeros all matrix components, used with Matrix4x4_Accumulate */
61/* adds a weighted contribution from the supplied matrix, used to blend 3 or
62 * more matrices with weighting, it is recommended that Matrix4x4_Normalize be
63 * called afterward (a method known as nlerp rotation, often better for
64 * animation purposes than slerp) */
65void Matrix4x4_Accumulate (matrix4x4_t* out, matrix4x4_t* in, double weight);
66/* creates a matrix that does the same rotation and translation as the matrix
67 * provided, but no uniform scaling, does not support scale3 matrices */
69/* creates a matrix with vectors normalized individually (use after
70 * Matrix4x4_Accumulate) */
72/* modifies a matrix to have all vectors and origin reflected across the plane
73 * to the opposite side (at least if axisscale is -2) */
74void Matrix4x4_Reflect (matrix4x4_t* out, double normalx, double normaly, double normalz, double dist, double axisscale);
75
76/* creates an identity matrix
77 * (a matrix which does nothing) */
79/* creates a translate matrix
80 * (moves vectors) */
81void Matrix4x4_CreateTranslate (matrix4x4_t* out, double x, double y, double z);
82/* creates a rotate matrix
83 * (rotates vectors) */
84void Matrix4x4_CreateRotate (matrix4x4_t* out, double angle, double x, double y, double z);
85/* creates a scaling matrix
86 * (expands or contracts vectors)
87 * (warning: do not apply this kind of matrix to direction vectors) */
88void Matrix4x4_CreateScale (matrix4x4_t* out, double x);
89/* creates a squishing matrix
90 * (expands or contracts vectors differently in different axis)
91 * (warning: this is not reversed by Invert_Simple)
92 * (warning: do not apply this kind of matrix to direction vectors) */
93void Matrix4x4_CreateScale3 (matrix4x4_t* out, double x, double y, double z);
94/* creates a matrix for a quake entity */
95void Matrix4x4_CreateFromQuakeEntity (matrix4x4_t* out, double x, double y, double z, double pitch, double yaw, double roll, double scale);
96
97/* converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate */
98void Matrix4x4_ToVectors (const matrix4x4_t* in, float vx[3], float vy[3], float vz[3], float t[3]);
99/* creates a matrix4x4 from a set of 3D vectors for axial directions, and translate */
100void Matrix4x4_FromVectors (matrix4x4_t* out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
101
102/* converts a matrix4x4 to a double[16] array in the OpenGL orientation */
103void Matrix4x4_ToArrayDoubleGL (const matrix4x4_t* in, double out[16]);
104/* creates a matrix4x4 from a double[16] array in the OpenGL orientation */
105void Matrix4x4_FromArrayDoubleGL (matrix4x4_t* out, const double in[16]);
106/* converts a matrix4x4 to a double[16] array in the Direct3D orientation */
107void Matrix4x4_ToArrayDoubleD3D (const matrix4x4_t* in, double out[16]);
108/* creates a matrix4x4 from a double[16] array in the Direct3D orientation */
109void Matrix4x4_FromArrayDoubleD3D (matrix4x4_t* out, const double in[16]);
110
111/* converts a matrix4x4 to a float[16] array in the OpenGL orientation */
112void Matrix4x4_ToArrayFloatGL (const matrix4x4_t* in, float out[16]);
113/* creates a matrix4x4 from a float[16] array in the OpenGL orientation */
114void Matrix4x4_FromArrayFloatGL (matrix4x4_t* out, const float in[16]);
115/* converts a matrix4x4 to a float[16] array in the Direct3D orientation */
116void Matrix4x4_ToArrayFloatD3D (const matrix4x4_t* in, float out[16]);
117/* creates a matrix4x4 from a float[16] array in the Direct3D orientation */
118void Matrix4x4_FromArrayFloatD3D (matrix4x4_t* out, const float in[16]);
119
120/* converts a matrix4x4 to a float[12] array in the OpenGL orientation */
121void Matrix4x4_ToArray12FloatGL (const matrix4x4_t* in, float out[12]);
122/* creates a matrix4x4 from a float[12] array in the OpenGL orientation */
123void Matrix4x4_FromArray12FloatGL (matrix4x4_t* out, const float in[12]);
124/* converts a matrix4x4 to a float[12] array in the Direct3D orientation */
125void Matrix4x4_ToArray12FloatD3D (const matrix4x4_t* in, float out[12]);
126/* creates a matrix4x4 from a float[12] array in the Direct3D orientation */
127void Matrix4x4_FromArray12FloatD3D (matrix4x4_t* out, const float in[12]);
128
129/* creates a matrix4x4 from an origin and quaternion (used mostly with skeletal model formats such as PSK) */
130void Matrix4x4_FromOriginQuat (matrix4x4_t* m, double ox, double oy, double oz, double x, double y, double z, double w);
131/* creates an origin and quaternion from a matrix4x4_t, quat[3] is always positive */
132void Matrix4x4_ToOrigin3Quat4Float (const matrix4x4_t* m, float* origin, float* quat);
133/* creates a matrix4x4 from an origin and canonical unit-length quaternion (used mostly with skeletal model formats such as MD5) */
134void Matrix4x4_FromDoom3Joint (matrix4x4_t* m, double ox, double oy, double oz, double x, double y, double z);
135
136/* creates a matrix4x4_t from an origin and canonical unit-length quaternion in short[6] normalized format */
137void Matrix4x4_FromBonePose6s (matrix4x4_t* m, float originscale, const short* pose6s);
138/* creates a short[6] representation from normalized matrix4x4_t */
139void Matrix4x4_ToBonePose6s (const matrix4x4_t* m, float origininvscale, short* pose6s);
140
141/* blends two matrices together, at a given percentage (blend controls percentage of in2) */
142void Matrix4x4_Blend (matrix4x4_t* out, const matrix4x4_t* in1, const matrix4x4_t* in2, double blend);
143
144/* transforms a 3D vector through a matrix4x4 */
145void Matrix4x4_Transform (const matrix4x4_t* in, const float v[3], float out[3]);
146/* transforms a 4D vector through a matrix4x4
147 * (warning: if you don't know why you would need this, you don't need it)
148 * (warning: the 4th component of the vector should be 1.0) */
149void Matrix4x4_Transform4 (const matrix4x4_t* in, const float v[4], float out[4]);
150/* reverse transforms a 3D vector through a matrix4x4, at least for *simple*
151 * cases (rotation and translation *ONLY*), this attempts to undo the results
152 * of Transform */
153/*void Matrix4x4_SimpleUntransform (const matrix4x4_t* in, const float v[3], float out[3]); */
154/* transforms a direction vector through the rotation part of a matrix */
155void Matrix4x4_Transform3x3 (const matrix4x4_t* in, const float v[3], float out[3]);
156/* transforms a positive distance plane (A*x+B*y+C*z-D=0) through a rotation or translation matrix */
157void Matrix4x4_TransformPositivePlane (const matrix4x4_t* in, float x, float y, float z, float d, float* o);
158/* transforms a standard plane (A*x+B*y+C*z+D=0) through a rotation or translation matrix */
159void Matrix4x4_TransformStandardPlane (const matrix4x4_t* in, float x, float y, float z, float d, float* o);
160
161/* ease of use functions
162 * immediately applies a Translate to the matrix */
163void Matrix4x4_ConcatTranslate (matrix4x4_t* out, double x, double y, double z);
164/* immediately applies a Rotate to the matrix */
165void Matrix4x4_ConcatRotate (matrix4x4_t* out, double angle, double x, double y, double z);
166/* immediately applies a Scale to the matrix */
167void Matrix4x4_ConcatScale (matrix4x4_t* out, double x);
168/* immediately applies a Scale3 to the matrix */
169void Matrix4x4_ConcatScale3 (matrix4x4_t* out, double x, double y, double z);
170
171/* extracts origin vector (translate) from matrix */
172void Matrix4x4_OriginFromMatrix (const matrix4x4_t* in, float* out);
173/* extracts scaling factor from matrix (only works for uniform scaling) */
174double Matrix4x4_ScaleFromMatrix (const matrix4x4_t* in);
175
176/* replaces origin vector (translate) in matrix */
177void Matrix4x4_SetOrigin (matrix4x4_t* out, double x, double y, double z);
178/* moves origin vector (translate) in matrix by a simple translate */
179void Matrix4x4_AdjustOrigin (matrix4x4_t* out, double x, double y, double z);
180/* scales vectors of a matrix in place and allows you to scale origin as well */
181void Matrix4x4_Scale (matrix4x4_t* out, double rotatescale, double originscale);
182/* ensures each element of the 3x3 rotation matrix is facing in the + direction */
183void Matrix4x4_Abs (matrix4x4_t* out);
voidpf uLong int origin
Definition ioapi.h:45
static struct mdfour * m
Definition md4.cpp:35
QGL_EXTERN int GLboolean GLfloat * v
Definition r_gl.h:120
const matrix4x4_t identitymatrix
Definition r_matrix.cpp:24
void Matrix4x4_AdjustOrigin(matrix4x4_t *out, double x, double y, double z)
void Matrix4x4_Concat(matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2)
Definition r_matrix.cpp:90
void Matrix4x4_CreateIdentity(matrix4x4_t *out)
Definition r_matrix.cpp:597
void Matrix4x4_FromBonePose6s(matrix4x4_t *m, float originscale, const short *pose6s)
void Matrix4x4_ToBonePose6s(const matrix4x4_t *m, float origininvscale, short *pose6s)
void Matrix4x4_Clear(matrix4x4_t *out)
Definition r_matrix.cpp:522
void Matrix4x4_TransformStandardPlane(const matrix4x4_t *in, float x, float y, float z, float d, float *o)
void Matrix4x4_TransformPositivePlane(const matrix4x4_t *in, float x, float y, float z, float d, float *o)
void Matrix4x4_FromArray12FloatGL(matrix4x4_t *out, const float in[12])
void Matrix4x4_Transform(const matrix4x4_t *in, const float v[3], float out[3])
void Matrix4x4_Transform4(const matrix4x4_t *in, const float v[4], float out[4])
void Matrix4x4_FromOriginQuat(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z, double w)
void Matrix4x4_ToArrayDoubleGL(const matrix4x4_t *in, double out[16])
Definition r_matrix.cpp:989
void Matrix4x4_Blend(matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend)
void Matrix4x4_FromArrayFloatD3D(matrix4x4_t *out, const float in[16])
void Matrix4x4_ToArrayFloatGL(const matrix4x4_t *in, float out[16])
void Matrix4x4_CreateTranslate(matrix4x4_t *out, double x, double y, double z)
Definition r_matrix.cpp:617
void Matrix4x4_ToArray12FloatD3D(const matrix4x4_t *in, float out[12])
void Matrix4x4_ToArray12FloatGL(const matrix4x4_t *in, float out[12])
void Matrix4x4_Transpose(matrix4x4_t *out, const matrix4x4_t *in1)
Definition r_matrix.cpp:145
void Matrix4x4_Transform3x3(const matrix4x4_t *in, const float v[3], float out[3])
void Matrix4x4_FromArrayFloatGL(matrix4x4_t *out, const float in[16])
void Matrix4x4_FromArrayDoubleGL(matrix4x4_t *out, const double in[16])
void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale)
Definition r_matrix.cpp:748
void Matrix4x4_CopyTranslateOnly(matrix4x4_t *out, const matrix4x4_t *in)
Definition r_matrix.cpp:51
void Matrix4x4_FromArrayDoubleD3D(matrix4x4_t *out, const double in[16])
int Matrix4x4_Invert_Full(matrix4x4_t *out, const matrix4x4_t *in1)
Definition r_matrix.cpp:170
void Matrix4x4_CreateScale3(matrix4x4_t *out, double x, double y, double z)
Definition r_matrix.cpp:728
void Matrix4x4_ConcatScale3(matrix4x4_t *out, double x, double y, double z)
void Matrix4x4_ToArrayDoubleD3D(const matrix4x4_t *in, double out[16])
void Matrix4x4_SetOrigin(matrix4x4_t *out, double x, double y, double z)
void Matrix4x4_ConcatScale(matrix4x4_t *out, double x)
void Matrix4x4_Normalize3(matrix4x4_t *out, matrix4x4_t *in1)
Definition r_matrix.cpp:545
void Matrix4x4_ToOrigin3Quat4Float(const matrix4x4_t *m, float *origin, float *quat)
void Matrix4x4_FromArray12FloatD3D(matrix4x4_t *out, const float in[12])
void Matrix4x4_ToArrayFloatD3D(const matrix4x4_t *in, float out[16])
void Matrix4x4_Reflect(matrix4x4_t *out, double normalx, double normaly, double normalz, double dist, double axisscale)
Definition r_matrix.cpp:570
void Matrix4x4_CreateScale(matrix4x4_t *out, double x)
Definition r_matrix.cpp:708
void Matrix4x4_Interpolate(matrix4x4_t *out, matrix4x4_t *in1, matrix4x4_t *in2, double frac)
Definition r_matrix.cpp:515
void Matrix4x4_Invert_Simple(matrix4x4_t *out, const matrix4x4_t *in1)
Definition r_matrix.cpp:462
void Matrix4x4_Abs(matrix4x4_t *out)
void Matrix4x4_ConcatTranslate(matrix4x4_t *out, double x, double y, double z)
double Matrix4x4_ScaleFromMatrix(const matrix4x4_t *in)
void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3])
Definition r_matrix.cpp:950
void Matrix4x4_Normalize(matrix4x4_t *out, matrix4x4_t *in1)
Definition r_matrix.cpp:536
void Matrix4x4_Accumulate(matrix4x4_t *out, matrix4x4_t *in, double weight)
Definition r_matrix.cpp:529
void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3])
Definition r_matrix.cpp:919
void Matrix4x4_Copy(matrix4x4_t *out, const matrix4x4_t *in)
Definition r_matrix.cpp:26
void Matrix4x4_CreateRotate(matrix4x4_t *out, double angle, double x, double y, double z)
Definition r_matrix.cpp:656
void Matrix4x4_ConcatRotate(matrix4x4_t *out, double angle, double x, double y, double z)
void Matrix4x4_FromDoom3Joint(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z)
void Matrix4x4_Scale(matrix4x4_t *out, double rotatescale, double originscale)
void Matrix4x4_OriginFromMatrix(const matrix4x4_t *in, float *out)
void Matrix4x4_CopyRotateOnly(matrix4x4_t *out, const matrix4x4_t *in)
Definition r_matrix.cpp:31
float m[4][4]
Definition r_matrix.h:27
static const vec3_t scale