blob: 00bfcf8d166fc971439f0449b57cbba713cc3c15 [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001
2/*
3 * Mesa 3-D graphics library
4 * Version: 3.5
Gareth Hughes22144ab2001-03-12 00:48:37 +00005 *
Brian Pauld8bc5a92001-02-05 18:48:52 +00006 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Gareth Hughes22144ab2001-03-12 00:48:37 +00007 *
Keith Whitwell23caf202000-11-16 21:05:34 +00008 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
Gareth Hughes22144ab2001-03-12 00:48:37 +000014 *
Keith Whitwell23caf202000-11-16 21:05:34 +000015 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
Gareth Hughes22144ab2001-03-12 00:48:37 +000017 *
Keith Whitwell23caf202000-11-16 21:05:34 +000018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
Brian Paul449e47f2003-02-17 16:35:56 +000026/**
27 * \file math/m_matrix.h
28 * \brief Defines basic structures for matrix-handling.
29 */
30
Keith Whitwell23caf202000-11-16 21:05:34 +000031
32#ifndef _M_MATRIX_H
33#define _M_MATRIX_H
34
35
36
37/* Give symbolic names to some of the entries in the matrix to help
38 * out with the rework of the viewport_map as a matrix transform.
39 */
40#define MAT_SX 0
41#define MAT_SY 5
42#define MAT_SZ 10
43#define MAT_TX 12
44#define MAT_TY 13
45#define MAT_TZ 14
46
Keith Whitwell23caf202000-11-16 21:05:34 +000047
Brian Paul449e47f2003-02-17 16:35:56 +000048/**
49 * \defgroup MatFlags MAT_FLAG_XXX-flags
50 *
51 * Bitmasks to indicate different kinds of 4x4 matrices in
52 * GLmatrix::flags
53 */
54/*@{*/
Keith Whitwell23caf202000-11-16 21:05:34 +000055#define MAT_FLAG_IDENTITY 0
56#define MAT_FLAG_GENERAL 0x1
57#define MAT_FLAG_ROTATION 0x2
58#define MAT_FLAG_TRANSLATION 0x4
59#define MAT_FLAG_UNIFORM_SCALE 0x8
60#define MAT_FLAG_GENERAL_SCALE 0x10
61#define MAT_FLAG_GENERAL_3D 0x20
62#define MAT_FLAG_PERSPECTIVE 0x40
63#define MAT_FLAG_SINGULAR 0x80
64#define MAT_DIRTY_TYPE 0x100
65#define MAT_DIRTY_FLAGS 0x200
66#define MAT_DIRTY_INVERSE 0x400
Brian Paul449e47f2003-02-17 16:35:56 +000067/*@}*/
68
Keith Whitwell23caf202000-11-16 21:05:34 +000069
70#define MAT_FLAGS_ANGLE_PRESERVING (MAT_FLAG_ROTATION | \
71 MAT_FLAG_TRANSLATION | \
72 MAT_FLAG_UNIFORM_SCALE)
73
74#define MAT_FLAGS_LENGTH_PRESERVING (MAT_FLAG_ROTATION | \
75 MAT_FLAG_TRANSLATION)
76
77#define MAT_FLAGS_3D (MAT_FLAG_ROTATION | \
78 MAT_FLAG_TRANSLATION | \
79 MAT_FLAG_UNIFORM_SCALE | \
80 MAT_FLAG_GENERAL_SCALE | \
81 MAT_FLAG_GENERAL_3D)
82
83#define MAT_FLAGS_GEOMETRY (MAT_FLAG_GENERAL | \
84 MAT_FLAG_ROTATION | \
85 MAT_FLAG_TRANSLATION | \
86 MAT_FLAG_UNIFORM_SCALE | \
87 MAT_FLAG_GENERAL_SCALE | \
88 MAT_FLAG_GENERAL_3D | \
89 MAT_FLAG_PERSPECTIVE | \
90 MAT_FLAG_SINGULAR)
91
92#define MAT_DIRTY (MAT_DIRTY_TYPE | \
93 MAT_DIRTY_FLAGS | \
94 MAT_DIRTY_INVERSE)
95
96#define TEST_MAT_FLAGS(mat, a) \
97 ((MAT_FLAGS_GEOMETRY & (~(a)) & ((mat)->flags) ) == 0)
98
99
Brian Pauladb1a292003-02-25 19:27:06 +0000100enum matrix_type {
101 MATRIX_GENERAL, /**< general 4x4 matrix */
102 MATRIX_IDENTITY, /**< identity matrix */
103 MATRIX_3D_NO_ROT, /**< ortho projection and others... */
104 MATRIX_PERSPECTIVE,/**< perspective projection matrix */
105 MATRIX_2D, /**< 2-D transformation */
106 MATRIX_2D_NO_ROT, /**< 2-D scale & translate only */
107 MATRIX_3D /**< 3-D transformation */
108};
109
Keith Whitwell23caf202000-11-16 21:05:34 +0000110typedef struct {
111 GLfloat *m; /* 16-byte aligned */
112 GLfloat *inv; /* optional, 16-byte aligned */
Brian Paul449e47f2003-02-17 16:35:56 +0000113 GLuint flags; /**< possible values determined by (of \link
114 MatFlags MAT_FLAG_* flags\endlink) */
Brian Pauladb1a292003-02-25 19:27:06 +0000115
116 enum matrix_type type;
Keith Whitwell23caf202000-11-16 21:05:34 +0000117} GLmatrix;
118
119
120
121
122extern void
123_math_matrix_ctr( GLmatrix *m );
124
125extern void
126_math_matrix_dtr( GLmatrix *m );
127
128extern void
129_math_matrix_alloc_inv( GLmatrix *m );
130
131extern void
132_math_matrix_mul_matrix( GLmatrix *dest, const GLmatrix *a, const GLmatrix *b );
133
134extern void
135_math_matrix_mul_floats( GLmatrix *dest, const GLfloat *b );
136
Gareth Hughes22144ab2001-03-12 00:48:37 +0000137extern void
Keith Whitwell23caf202000-11-16 21:05:34 +0000138_math_matrix_loadf( GLmatrix *mat, const GLfloat *m );
139
Gareth Hughes22144ab2001-03-12 00:48:37 +0000140extern void
Keith Whitwell23caf202000-11-16 21:05:34 +0000141_math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z );
142
143extern void
Gareth Hughes22144ab2001-03-12 00:48:37 +0000144_math_matrix_rotate( GLmatrix *m, GLfloat angle,
Keith Whitwell23caf202000-11-16 21:05:34 +0000145 GLfloat x, GLfloat y, GLfloat z );
146
Gareth Hughes22144ab2001-03-12 00:48:37 +0000147extern void
Keith Whitwell23caf202000-11-16 21:05:34 +0000148_math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z );
149
150extern void
Gareth Hughes22144ab2001-03-12 00:48:37 +0000151_math_matrix_ortho( GLmatrix *mat,
Keith Whitwell23caf202000-11-16 21:05:34 +0000152 GLfloat left, GLfloat right,
Gareth Hughes22144ab2001-03-12 00:48:37 +0000153 GLfloat bottom, GLfloat top,
Keith Whitwell23caf202000-11-16 21:05:34 +0000154 GLfloat nearval, GLfloat farval );
155
156extern void
Gareth Hughes22144ab2001-03-12 00:48:37 +0000157_math_matrix_frustum( GLmatrix *mat,
Brian Pauld8bc5a92001-02-05 18:48:52 +0000158 GLfloat left, GLfloat right,
Gareth Hughes22144ab2001-03-12 00:48:37 +0000159 GLfloat bottom, GLfloat top,
Brian Pauld8bc5a92001-02-05 18:48:52 +0000160 GLfloat nearval, GLfloat farval );
Keith Whitwell23caf202000-11-16 21:05:34 +0000161
162extern void
163_math_matrix_set_identity( GLmatrix *dest );
164
Gareth Hughes22144ab2001-03-12 00:48:37 +0000165extern void
Keith Whitwell23caf202000-11-16 21:05:34 +0000166_math_matrix_copy( GLmatrix *to, const GLmatrix *from );
167
168extern void
Keith Whitwellad2ac212000-11-24 10:25:05 +0000169_math_matrix_analyse( GLmatrix *mat );
Keith Whitwell23caf202000-11-16 21:05:34 +0000170
171extern void
172_math_matrix_print( const GLmatrix *m );
173
174
175
176
177/* Related functions that don't actually operate on GLmatrix structs:
178 */
179extern void
180_math_transposef( GLfloat to[16], const GLfloat from[16] );
181
182extern void
183_math_transposed( GLdouble to[16], const GLdouble from[16] );
184
185extern void
186_math_transposefd( GLfloat to[16], const GLdouble from[16] );
187
188
189
190
191#endif