blob: 66600330b839b16aa5d35ea9a6364e74779293b2 [file] [log] [blame]
Brian Pauld8bc5a92001-02-05 18:48:52 +00001/* $Id: m_matrix.h,v 1.3 2001/02/05 18:48:52 brianp Exp $ */
Keith Whitwell23caf202000-11-16 21:05:34 +00002
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
Brian Pauld8bc5a92001-02-05 18:48:52 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Keith Whitwell23caf202000-11-16 21:05:34 +00008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28#ifndef _M_MATRIX_H
29#define _M_MATRIX_H
30
31
32
33/* Give symbolic names to some of the entries in the matrix to help
34 * out with the rework of the viewport_map as a matrix transform.
35 */
36#define MAT_SX 0
37#define MAT_SY 5
38#define MAT_SZ 10
39#define MAT_TX 12
40#define MAT_TY 13
41#define MAT_TZ 14
42
43/*
44 * Different kinds of 4x4 transformation matrices:
45 */
46#define MATRIX_GENERAL 0 /* general 4x4 matrix */
47#define MATRIX_IDENTITY 1 /* identity matrix */
48#define MATRIX_3D_NO_ROT 2 /* ortho projection and others... */
49#define MATRIX_PERSPECTIVE 3 /* perspective projection matrix */
50#define MATRIX_2D 4 /* 2-D transformation */
51#define MATRIX_2D_NO_ROT 5 /* 2-D scale & translate only */
52#define MATRIX_3D 6 /* 3-D transformation */
53
54#define MAT_FLAG_IDENTITY 0
55#define MAT_FLAG_GENERAL 0x1
56#define MAT_FLAG_ROTATION 0x2
57#define MAT_FLAG_TRANSLATION 0x4
58#define MAT_FLAG_UNIFORM_SCALE 0x8
59#define MAT_FLAG_GENERAL_SCALE 0x10
60#define MAT_FLAG_GENERAL_3D 0x20
61#define MAT_FLAG_PERSPECTIVE 0x40
62#define MAT_FLAG_SINGULAR 0x80
63#define MAT_DIRTY_TYPE 0x100
64#define MAT_DIRTY_FLAGS 0x200
65#define MAT_DIRTY_INVERSE 0x400
66
67#define MAT_FLAGS_ANGLE_PRESERVING (MAT_FLAG_ROTATION | \
68 MAT_FLAG_TRANSLATION | \
69 MAT_FLAG_UNIFORM_SCALE)
70
71#define MAT_FLAGS_LENGTH_PRESERVING (MAT_FLAG_ROTATION | \
72 MAT_FLAG_TRANSLATION)
73
74#define MAT_FLAGS_3D (MAT_FLAG_ROTATION | \
75 MAT_FLAG_TRANSLATION | \
76 MAT_FLAG_UNIFORM_SCALE | \
77 MAT_FLAG_GENERAL_SCALE | \
78 MAT_FLAG_GENERAL_3D)
79
80#define MAT_FLAGS_GEOMETRY (MAT_FLAG_GENERAL | \
81 MAT_FLAG_ROTATION | \
82 MAT_FLAG_TRANSLATION | \
83 MAT_FLAG_UNIFORM_SCALE | \
84 MAT_FLAG_GENERAL_SCALE | \
85 MAT_FLAG_GENERAL_3D | \
86 MAT_FLAG_PERSPECTIVE | \
87 MAT_FLAG_SINGULAR)
88
89#define MAT_DIRTY (MAT_DIRTY_TYPE | \
90 MAT_DIRTY_FLAGS | \
91 MAT_DIRTY_INVERSE)
92
93#define TEST_MAT_FLAGS(mat, a) \
94 ((MAT_FLAGS_GEOMETRY & (~(a)) & ((mat)->flags) ) == 0)
95
96
97typedef struct {
98 GLfloat *m; /* 16-byte aligned */
99 GLfloat *inv; /* optional, 16-byte aligned */
100 GLuint flags;
101 GLuint type; /* one of the MATRIX_* values */
102} GLmatrix;
103
104
105
106
107extern void
108_math_matrix_ctr( GLmatrix *m );
109
110extern void
111_math_matrix_dtr( GLmatrix *m );
112
113extern void
114_math_matrix_alloc_inv( GLmatrix *m );
115
116extern void
117_math_matrix_mul_matrix( GLmatrix *dest, const GLmatrix *a, const GLmatrix *b );
118
119extern void
120_math_matrix_mul_floats( GLmatrix *dest, const GLfloat *b );
121
122extern void
123_math_matrix_loadf( GLmatrix *mat, const GLfloat *m );
124
125extern void
126_math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z );
127
128extern void
129_math_matrix_rotate( GLmatrix *m, GLfloat angle,
130 GLfloat x, GLfloat y, GLfloat z );
131
132extern void
133_math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z );
134
135extern void
136_math_matrix_ortho( GLmatrix *mat,
137 GLfloat left, GLfloat right,
138 GLfloat bottom, GLfloat top,
139 GLfloat nearval, GLfloat farval );
140
141extern void
Brian Pauld8bc5a92001-02-05 18:48:52 +0000142_math_matrix_frustum( GLmatrix *mat,
143 GLfloat left, GLfloat right,
144 GLfloat bottom, GLfloat top,
145 GLfloat nearval, GLfloat farval );
Keith Whitwell23caf202000-11-16 21:05:34 +0000146
147extern void
148_math_matrix_set_identity( GLmatrix *dest );
149
150extern void
151_math_matrix_copy( GLmatrix *to, const GLmatrix *from );
152
153extern void
Keith Whitwellad2ac212000-11-24 10:25:05 +0000154_math_matrix_analyse( GLmatrix *mat );
Keith Whitwell23caf202000-11-16 21:05:34 +0000155
156extern void
157_math_matrix_print( const GLmatrix *m );
158
159
160
161
162/* Related functions that don't actually operate on GLmatrix structs:
163 */
164extern void
165_math_transposef( GLfloat to[16], const GLfloat from[16] );
166
167extern void
168_math_transposed( GLdouble to[16], const GLdouble from[16] );
169
170extern void
171_math_transposefd( GLfloat to[16], const GLdouble from[16] );
172
173
174
175
176#endif