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
(
const
double
& x00,
const
double
& x01,
const
double
& x02,
const
double
& x03,
52
const
double
& x10,
const
double
& x11,
const
double
& x12,
const
double
& x13,
53
const
double
& x20,
const
double
& x21,
const
double
& x22,
const
double
& x23,
54
const
double
& x30,
const
double
& x31,
const
double
& x32,
const
double
& 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,
const
double
& angle);
71
static
matrix4
scale
(
const
double
& s);
73
static
matrix4
scale
(
const
double
& s_x,
const
double
& s_y,
const
double
& s_z,
const
double
& 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
(
const
double
& fovy,
const
double
& aspect,
const
double
& z_near,
const
double
& z_far);
93
static
matrix4
projection_frustum
(
const
double
& left,
const
double
& right,
const
double
& bottom,
const
double
& top,
const
double
& near,
const
double
& far);
97
static
matrix4
projection_orthographic
(
const
double
& left,
const
double
& right,
const
double
& bottom,
const
double
& top,
const
double
& near,
const
double
& 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
const
double
&
operator()
(
const
size_t
& k1,
const
size_t
& k2)
const
;
113
double
&
operator()
(
const
size_t
& k1,
const
size_t
& k2);
114
117
const
double
*
pointer
()
const
;
120
double
*
pointer_unprotected
();
121
122
123
124
// ********************************************* //
125
// ********************************************* //
126
// Math operator
127
// ********************************************* //
128
// ********************************************* //
129
131
matrix4
operator+
(
const
matrix4
& m2)
const
;
133
matrix4
operator+
(
const
double
& s)
const
;
134
136
matrix4
operator-
(
const
matrix4
& m2)
const
;
138
matrix4
operator-
(
const
double
& s)
const
;
139
140
142
matrix4
operator*
(
const
double
& 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/
(
const
double
& s)
const
;
151
152
154
matrix4
&
operator+=
(
const
matrix4
& m);
156
matrix4
&
operator+=
(
const
double
& s);
158
matrix4
&
operator-=
(
const
matrix4
& m);
160
matrix4
&
operator-=
(
const
double
& s);
162
matrix4
&
operator*=
(
const
double
& s);
164
matrix4
&
operator/=
(
const
double
& 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<double>
to_vector
()
const
;
201
202
private
:
203
204
// ********************************************* //
205
// ********************************************* //
206
// Internal parameters
207
// ********************************************* //
208
// ********************************************* //
209
211
double
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+
(
const
double
& s,
const
matrix4& m);
249
matrix4
operator-
(
const
double
& s,
const
matrix4& m);
251
matrix4
operator*
(
const
double
& s,
const
matrix4& m);
252
253
}
254
255
#endif
lib3d
matrix4.hpp
Generated on Wed Mar 6 2013 11:12:44 by
1.8.3.1