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
21
#ifndef MATRIX4_HPP
22
#define MATRIX4_HPP
23
24
#include <iostream>
25
#include <vector>
26
27
#include <
exception_cpe.hpp
>
28
29
namespace
cpe
30
{
31
class
vec3;
32
class
vec4;
33
class
matrix3;
34
36
class
matrix4
37
{
38
39
40
public
:
41
42
// ********************************************* //
43
// ********************************************* //
44
// CONSTRUCTORS
45
// ********************************************* //
46
// ********************************************* //
47
49
matrix4
();
51
matrix4
(
float
x00,
float
x01,
float
x02,
float
x03,
52
float
x10,
float
x11,
float
x12,
float
x13,
53
float
x20,
float
x21,
float
x22,
float
x23,
54
float
x30,
float
x31,
float
x32,
float
x33);
56
matrix4
(
const
matrix3
&
m
);
57
58
// ********************************************* //
59
// ********************************************* //
60
// Special initialization
61
// ********************************************* //
62
// ********************************************* //
63
65
static
matrix4
identity
();
67
static
matrix4
zeros
();
69
static
matrix4
rotation
(
const
vec3
& axis,
float
angle);
71
static
matrix4
scale
(
float
s);
73
static
matrix4
scale
(
float
s_x,
float
s_y,
float
s_z,
float
s_w);
75
static
matrix4
translation
(
const
vec3
&
translation
);
77
static
matrix4
transformation
(
const
matrix3
& m3,
const
vec3
& translation);
78
79
// ********************************************* //
80
// ********************************************* //
81
// Projection matrix (emulate glu(t) functions)
82
// ********************************************* //
83
// ********************************************* //
84
89
static
matrix4
projection_perspective
(
float
fovy,
float
aspect,
float
z_near,
float
z_far);
93
static
matrix4
projection_frustum
(
float
left,
float
right,
float
bottom,
float
top,
float
near,
float
far);
97
static
matrix4
projection_orthographic
(
float
left,
float
right,
float
bottom,
float
top,
float
near,
float
far);
101
static
matrix4
projection_look_at
(
const
matrix4
& current_matrix,
const
vec3
& eye,
const
vec3
& center,
const
vec3
& up);
102
103
104
// ********************************************* //
105
// ********************************************* //
106
// Element access
107
// ********************************************* //
108
// ********************************************* //
109
111
float
operator()
(
const
size_t
& k1,
const
size_t
& k2)
const
;
113
float
&
operator()
(
const
size_t
& k1,
const
size_t
& k2);
114
117
const
float
*
pointer
()
const
;
120
float
*
pointer_unprotected
();
121
122
123
124
// ********************************************* //
125
// ********************************************* //
126
// Math operator
127
// ********************************************* //
128
// ********************************************* //
129
131
matrix4
operator+
(
const
matrix4
& m2)
const
;
133
matrix4
operator+
(
float
s)
const
;
134
136
matrix4
operator-
(
const
matrix4
& m2)
const
;
138
matrix4
operator-
(
float
s)
const
;
139
140
142
matrix4
operator*
(
float
s)
const
;
144
vec4
operator*
(
const
vec4
& v)
const
;
146
vec3
operator*
(
const
vec3
& v)
const
;
148
matrix4
operator*
(
const
matrix4
& m2)
const
;
150
matrix4
operator/
(
float
s)
const
;
151
152
154
matrix4
&
operator+=
(
const
matrix4
& m);
156
matrix4
&
operator+=
(
float
s);
158
matrix4
&
operator-=
(
const
matrix4
& m);
160
matrix4
&
operator-=
(
float
s);
162
matrix4
&
operator*=
(
float
s);
164
matrix4
&
operator/=
(
float
s);
165
167
matrix4
operator-
()
const
;
168
170
matrix4
product_compontentwise
(
const
matrix4
& m)
const
;
172
matrix4
&
product_compontentwise_internal
(
const
matrix4
& m);
173
175
matrix4
transposed
()
const
;
176
177
// ********************************************* //
178
// ********************************************* //
179
// Deformation
180
// ********************************************* //
181
// ********************************************* //
182
184
matrix4
translated
(
const
vec3
& translation)
const
;
186
void
translate_internal
(
const
vec3
& translation);
187
188
189
190
191
192
193
// ********************************************* //
194
// ********************************************* //
195
// Projection matrix
196
// ********************************************* //
197
// ********************************************* //
198
200
std::vector<float>
to_vector
()
const
;
201
202
private
:
203
204
// ********************************************* //
205
// ********************************************* //
206
// Internal parameters
207
// ********************************************* //
208
// ********************************************* //
209
211
float
m[16];
212
213
214
// ********************************************* //
215
// ********************************************* //
216
// Helper
217
// ********************************************* //
218
// ********************************************* //
219
221
void
assert_size
(
const
size_t
& k1,
const
size_t
& k2)
const
;
222
223
};
224
225
// ********************************************* //
226
// ********************************************* //
227
// Output
228
// ********************************************* //
229
// ********************************************* //
230
232
std::ostream&
operator<<
(std::ostream& stream,
const
matrix4
& m);
233
234
236
class
exception_matrix4
:
public
exception_cpe
237
{
238
public
:
239
241
exception_matrix4
():
exception_cpe
(){}
243
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){}
244
};
245
247
matrix4
operator+
(
float
s,
const
matrix4& m);
249
matrix4
operator-
(
float
s,
const
matrix4& m);
251
matrix4
operator*
(
float
s,
const
matrix4& m);
252
253
}
254
255
#endif
lib3d
matrix4.hpp
Generated on Fri Mar 29 2013 22:45:31 by
1.8.3.1