matrix3.hpp
Go to the documentation of this file.
1 /*
2 ** TP CPE Lyon
3 ** Copyright (C) 2014 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 #pragma once
20 
21 
22 #ifndef MATRIX3_HPP
23 #define MATRIX3_HPP
24 
25 #include <iostream>
26 #include <vector>
27 
28 
29 
30 namespace cpe
31 {
32 class vec3;
33 
34 
36 class matrix3
37 {
38 
39 public:
40 
41  // ********************************************* //
42  // ********************************************* //
43  // CONSTRUCTORS
44  // ********************************************* //
45  // ********************************************* //
46 
48  matrix3();
50  matrix3(float x00,float x01,float x02,
51  float x10,float x11,float x12,
52  float x20,float x21,float x22);
53 
54  // ********************************************* //
55  // ********************************************* //
56  // Special initialization
57  // ********************************************* //
58  // ********************************************* //
59 
61  static matrix3 identity();
63  static matrix3 zeros();
65  static matrix3 rotation(const vec3& axis,float angle);
67  static matrix3 scale(float s);
69  static matrix3 scale(float s_x,float s_y,float s_z);
70 
71 
72  // ********************************************* //
73  // ********************************************* //
74  // Element access
75  // ********************************************* //
76  // ********************************************* //
77 
79  float operator()(const size_t& k1,const size_t& k2) const;
81  float& operator()(const size_t& k1,const size_t& k2);
82 
85  const float* pointer() const;
88  float* pointer_unprotected();
89 
90 
91 
92  // ********************************************* //
93  // ********************************************* //
94  // Math operator
95  // ********************************************* //
96  // ********************************************* //
97 
99  matrix3 operator+(const matrix3& m2) const;
101  matrix3 operator+(float s) const;
102 
104  matrix3 operator-(const matrix3& m2) const;
106  matrix3 operator-(float s) const;
107 
108 
110  matrix3 operator*(float s) const;
112  vec3 operator*(const vec3& v) const;
114  matrix3 operator*(const matrix3& m2) const;
116  matrix3 operator/(float s) const;
117 
118 
120  matrix3& operator+=(const matrix3& m);
122  matrix3& operator+=(float s);
124  matrix3& operator-=(const matrix3& m);
126  matrix3& operator-=(float s);
128  matrix3& operator*=(float s);
130  matrix3& operator/=(float s);
131 
133  matrix3 operator-() const;
134 
136  matrix3 product_compontentwise(const matrix3& m) const;
139 
141  matrix3 transposed() const;
142 
143 
144 
145  // ********************************************* //
146  // ********************************************* //
147  // Projection matrix
148  // ********************************************* //
149  // ********************************************* //
150 
152  std::vector<float> to_vector() const;
153 
154 private:
155 
156  // ********************************************* //
157  // ********************************************* //
158  // Internal parameters
159  // ********************************************* //
160  // ********************************************* //
161 
163  float m[9];
164 
165 
166  // ********************************************* //
167  // ********************************************* //
168  // Helper
169  // ********************************************* //
170  // ********************************************* //
171 
173  void assert_size(const size_t& k1,const size_t& k2) const;
174 
175 };
176 
178 matrix3 operator+(float s,const matrix3& m);
180 matrix3 operator-(float s,const matrix3& m);
182 matrix3 operator*(float s,const matrix3& m);
183 
184 // ********************************************* //
185 // ********************************************* //
186 // Output
187 // ********************************************* //
188 // ********************************************* //
189 
191 std::ostream& operator<<(std::ostream& stream,const matrix3& m);
192 
193 
194 
195 
196 
197 }
198 
199 #endif
matrix3 & product_compontentwise_internal(const matrix3 &m)
does componentwise multiplication
Definition: matrix3.cpp:240
matrix3 operator*(float s) const
multiply by a scalar operator
Definition: matrix3.cpp:144
matrix3 operator/(float s) const
divide by a scalar operator
Definition: matrix3.cpp:175
matrix3 product_compontentwise(const matrix3 &m) const
does componentwise multiplication
Definition: matrix3.cpp:232
matrix3 operator-() const
unary negation
Definition: matrix3.cpp:226
static matrix3 identity()
build identity matrix
Definition: matrix3.cpp:48
matrix3 & operator*=(float s)
internal *
Definition: matrix3.cpp:212
matrix3 & operator+=(const matrix3 &m)
internal +
Definition: matrix3.cpp:182
float * pointer_unprotected()
fast pointer access
Definition: matrix3.cpp:271
matrix3 & operator/=(float s)
internal /
Definition: matrix3.cpp:219
Matrix 3x3.
Definition: matrix3.hpp:36
matrix1x4 operator-(float s, const matrix1x4 &m)
operator
Definition: matrix1x4.cpp:82
matrix1x4 operator+(float s, const matrix1x4 &m)
operator
Definition: matrix1x4.cpp:61
static matrix3 scale(float s)
build scaling matrix
Definition: matrix3.cpp:71
static matrix3 rotation(const vec3 &axis, float angle)
build rotation matrix
Definition: matrix3.cpp:58
float operator()(const size_t &k1, const size_t &k2) const
Access to the k_th entry (k in [0,2])
Definition: matrix3.cpp:81
static matrix3 zeros()
build zero matrix
Definition: matrix3.cpp:52
matrix3 transposed() const
transpose matrix
Definition: matrix3.cpp:284
float m[9]
internal storage of the matrix
Definition: matrix3.hpp:163
matrix1x4 operator*(float s, const matrix1x4 &m)
multiply by a scalar operator
Definition: matrix1x4.cpp:93
const float * pointer() const
fast pointer access
Definition: matrix3.cpp:267
std::ostream & operator<<(std::ostream &stream, const matrix1x4 &_m)
output the vector in ostream
Definition: matrix1x4.cpp:182
matrix3 operator+(const matrix3 &m2) const
operator
Definition: matrix3.cpp:92
Vectors/Points 3D.
Definition: vec3.hpp:36
void assert_size(const size_t &k1, const size_t &k2) const
assert that a size_t belongs to [[0,2]]
Definition: matrix3.cpp:257
matrix3 & operator-=(const matrix3 &m)
internal -
Definition: matrix3.cpp:197
std::vector< float > to_vector() const
convert 3x3 matrix into a vector of float of size 9
Definition: matrix3.cpp:275
matrix3()
empty constructor (identity)
Definition: matrix3.cpp:33