Subversion Repositories shark

Rev

Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 pj 1
/* $Id: m_matrix.h,v 1.1 2003-02-28 11:48:05 pj Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  3.5
6
 *
7
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
8
 *
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
 
97
typedef 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
 
107
extern void
108
_math_matrix_ctr( GLmatrix *m );
109
 
110
extern void
111
_math_matrix_dtr( GLmatrix *m );
112
 
113
extern void
114
_math_matrix_alloc_inv( GLmatrix *m );
115
 
116
extern void
117
_math_matrix_mul_matrix( GLmatrix *dest, const GLmatrix *a, const GLmatrix *b );
118
 
119
extern void
120
_math_matrix_mul_floats( GLmatrix *dest, const GLfloat *b );
121
 
122
extern void
123
_math_matrix_loadf( GLmatrix *mat, const GLfloat *m );
124
 
125
extern void
126
_math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z );
127
 
128
extern void
129
_math_matrix_rotate( GLmatrix *m, GLfloat angle,
130
                     GLfloat x, GLfloat y, GLfloat z );
131
 
132
extern void
133
_math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z );
134
 
135
extern void
136
_math_matrix_ortho( GLmatrix *mat,
137
                    GLfloat left, GLfloat right,
138
                    GLfloat bottom, GLfloat top,
139
                    GLfloat nearval, GLfloat farval );
140
 
141
extern void
142
_math_matrix_frustum( GLmatrix *mat,
143
                      GLfloat left, GLfloat right,
144
                      GLfloat bottom, GLfloat top,
145
                      GLfloat nearval, GLfloat farval );
146
 
147
extern void
148
_math_matrix_set_identity( GLmatrix *dest );
149
 
150
extern void
151
_math_matrix_copy( GLmatrix *to, const GLmatrix *from );
152
 
153
extern void
154
_math_matrix_analyse( GLmatrix *mat );
155
 
156
extern void
157
_math_matrix_print( const GLmatrix *m );
158
 
159
 
160
 
161
 
162
/* Related functions that don't actually operate on GLmatrix structs:
163
 */
164
extern void
165
_math_transposef( GLfloat to[16], const GLfloat from[16] );
166
 
167
extern void
168
_math_transposed( GLdouble to[16], const GLdouble from[16] );
169
 
170
extern void
171
_math_transposefd( GLfloat to[16], const GLdouble from[16] );
172
 
173
 
174
 
175
 
176
#endif