Main Page
Namespaces
Classes
Files
File List
File Members
matrix4.hpp
Go to the documentation of this file.
1
/*
2
** TP CPE Lyon
3
** Copyright (C) 2013 Damien Rohmer
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (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. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
20
#ifndef MATRIX4_HPP
21
#define MATRIX4_HPP
22
23
#include <iostream>
24
#include <vector>
25
26
#include <
exception_cpe.hpp
>
27
28
namespace
cpe
29
{
30
class
vec3;
31
class
vec4;
32
class
matrix3;
33
35
class
matrix4
36
{
37
38
39
public
:
40
41
// ********************************************* //
42
// ********************************************* //
43
// CONSTRUCTORS
44
// ********************************************* //
45
// ********************************************* //
46
48
matrix4
();
50
matrix4
(
float
x00,
float
x01,
float
x02,
float
x03,
51
float
x10,
float
x11,
float
x12,
float
x13,
52
float
x20,
float
x21,
float
x22,
float
x23,
53
float
x30,
float
x31,
float
x32,
float
x33);
55
matrix4
(
const
matrix3
&
m
);
56
57
// ********************************************* //
58
// ********************************************* //
59
// Special initialization
60
// ********************************************* //
61
// ********************************************* //
62
64
static
matrix4
identity
();
66
static
matrix4
zeros
();
68
static
matrix4
rotation
(
const
vec3
& axis,
float
angle);
70
static
matrix4
scale
(
float
s);
72
static
matrix4
scale
(
float
s_x,
float
s_y,
float
s_z,
float
s_w);
74
static
matrix4
translation
(
const
vec3
&
translation
);
76
static
matrix4
transformation
(
const
matrix3
& m3,
const
vec3
& translation);
77
78
// ********************************************* //
79
// ********************************************* //
80
// Projection matrix (emulate glu(t) functions)
81
// ********************************************* //
82
// ********************************************* //
83
88
static
matrix4
projection_perspective
(
float
fovy,
float
aspect,
float
z_near,
float
z_far);
92
static
matrix4
projection_frustum
(
float
left,
float
right,
float
bottom,
float
top,
float
near,
float
far);
96
static
matrix4
projection_orthographic
(
float
left,
float
right,
float
bottom,
float
top,
float
near,
float
far);
100
static
matrix4
projection_look_at
(
const
matrix4
& current_matrix,
const
vec3
& eye,
const
vec3
& center,
const
vec3
& up);
101
102
103
// ********************************************* //
104
// ********************************************* //
105
// Element access
106
// ********************************************* //
107
// ********************************************* //
108
110
float
operator()
(
const
size_t
& k1,
const
size_t
& k2)
const
;
112
float
&
operator()
(
const
size_t
& k1,
const
size_t
& k2);
113
116
const
float
*
pointer
()
const
;
119
float
*
pointer_unprotected
();
120
121
122
123
// ********************************************* //
124
// ********************************************* //
125
// Math operator
126
// ********************************************* //
127
// ********************************************* //
128
130
matrix4
operator+
(
const
matrix4
& m2)
const
;
132
matrix4
operator+
(
float
s)
const
;
133
135
matrix4
operator-
(
const
matrix4
& m2)
const
;
137
matrix4
operator-
(
float
s)
const
;
138
139
141
matrix4
operator*
(
float
s)
const
;
143
vec4
operator*
(
const
vec4
& v)
const
;
145
vec3
operator*
(
const
vec3
& v)
const
;
147
matrix4
operator*
(
const
matrix4
& m2)
const
;
149
matrix4
operator/
(
float
s)
const
;
150
151
153
matrix4
&
operator+=
(
const
matrix4
& m);
155
matrix4
&
operator+=
(
float
s);
157
matrix4
&
operator-=
(
const
matrix4
& m);
159
matrix4
&
operator-=
(
float
s);
161
matrix4
&
operator*=
(
float
s);
163
matrix4
&
operator/=
(
float
s);
164
166
matrix4
operator-
()
const
;
167
169
matrix4
product_compontentwise
(
const
matrix4
& m)
const
;
171
matrix4
&
product_compontentwise_internal
(
const
matrix4
& m);
172
174
matrix4
transposed
()
const
;
175
176
// ********************************************* //
177
// ********************************************* //
178
// Deformation
179
// ********************************************* //
180
// ********************************************* //
181
183
matrix4
translated
(
const
vec3
& translation)
const
;
185
void
translate_internal
(
const
vec3
& translation);
186
187
188
189
190
191
192
// ********************************************* //
193
// ********************************************* //
194
// Projection matrix
195
// ********************************************* //
196
// ********************************************* //
197
199
std::vector<float>
to_vector
()
const
;
200
201
private
:
202
203
// ********************************************* //
204
// ********************************************* //
205
// Internal parameters
206
// ********************************************* //
207
// ********************************************* //
208
210
float
m[16];
211
212
213
// ********************************************* //
214
// ********************************************* //
215
// Helper
216
// ********************************************* //
217
// ********************************************* //
218
220
void
assert_size
(
const
size_t
& k1,
const
size_t
& k2)
const
;
221
222
};
223
224
// ********************************************* //
225
// ********************************************* //
226
// Output
227
// ********************************************* //
228
// ********************************************* //
229
231
std::ostream&
operator<<
(std::ostream& stream,
const
matrix4
& m);
232
233
235
class
exception_matrix4
:
public
exception_cpe
236
{
237
public
:
238
240
exception_matrix4
():
exception_cpe
(){}
242
exception_matrix4
(
const
std::string& msg_param,
const
std::string& file_param,
const
std::string& caller_param,
const
int
& line_param):
exception_cpe
(msg_param,file_param,caller_param,line_param){}
243
};
244
246
matrix4
operator+
(
float
s,
const
matrix4& m);
248
matrix4
operator-
(
float
s,
const
matrix4& m);
250
matrix4
operator*
(
float
s,
const
matrix4& m);
251
252
}
253
254
#endif
lib3d
matrix4.hpp
Generated on Sun Apr 28 2013 11:11:29 by
1.8.3.1