Main Page
Namespaces
Classes
Files
File List
File Members
vec4.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 VEC4_HPP
22
#define VEC4_HPP
23
24
#include <string>
25
#include <iostream>
26
27
#include <
exception_cpe.hpp
>
28
29
namespace
cpe
30
{
31
class
vec3;
32
class
vec2;
33
35
class
vec4
36
{
37
public
:
38
39
// ********************************************* //
40
// ********************************************* //
41
// CONSTRUCTORS
42
// ********************************************* //
43
// ********************************************* //
44
46
vec4
();
48
vec4
(
const
double
&
x
,
const
double
&
y
,
const
double
&
z
,
const
double
&
w
);
49
50
// ********************************************* //
51
// ********************************************* //
52
// Get/set
53
// ********************************************* //
54
// ********************************************* //
55
57
const
double
&
x
()
const
;
59
double
&
x
();
61
const
double
&
y
()
const
;
63
double
&
y
();
65
const
double
&
z
()
const
;
67
double
&
z
();
69
const
double
&
w
()
const
;
71
double
&
w
();
72
74
const
double
&
operator[]
(
const
size_t
& k)
const
;
76
double
&
operator[]
(
const
size_t
& k);
78
const
double
&
operator()
(
const
size_t
& k)
const
;
80
double
&
operator()
(
const
size_t
& k);
81
83
void
set_zero
();
84
87
const
double
*
pointer
()
const
;
88
89
// ********************************************* //
90
// ********************************************* //
91
// Convert to lower dimension
92
// ********************************************* //
93
// ********************************************* //
94
96
vec3
to_vec3
()
const
;
98
vec2
to_vec2
()
const
;
99
100
101
102
// ********************************************* //
103
// ********************************************* //
104
// Math operation
105
// ********************************************* //
106
// ********************************************* //
107
109
double
dot
(
const
vec4
& p)
const
;
110
112
double
norm
()
const
;
114
double
norm2
()
const
;
116
vec4
normalized
()
const
;
117
118
119
120
121
122
123
// ********************************************* //
124
// ********************************************* //
125
// Operator +-*/
126
// ********************************************* //
127
// ********************************************* //
128
130
vec4
operator+
(
const
vec4
& p2)
const
;
132
vec4
operator+
(
const
double
& s)
const
;
133
135
vec4
operator-
(
const
vec4
& p2)
const
;
137
vec4
operator-
(
const
double
& s)
const
;
138
140
vec4
operator*
(
const
double
& s)
const
;
142
vec4
operator/
(
const
double
& s)
const
;
143
145
vec4
&
operator+=
(
const
vec4
& p);
147
vec4
&
operator+=
(
const
double
& s);
149
vec4
&
operator-=
(
const
vec4
& p);
151
vec4
&
operator-=
(
const
double
& s);
153
vec4
&
operator*=
(
const
double
& s);
155
vec4
&
operator/=
(
const
double
& s);
156
158
vec4
operator-
()
const
;
159
163
vec4
product_compontentwise
(
const
vec4
& p)
const
;
168
vec4
&
product_compontentwise_internal
(
const
vec4
& p);
170
void
scale
(
const
double
& sx,
const
double
& sy,
const
double
& sz,
const
double
& sw);
171
172
173
// ********************************************* //
174
// ********************************************* //
175
// Output
176
// ********************************************* //
177
// ********************************************* //
178
180
std::string
to_string
()
const
;
181
182
183
184
private
:
185
186
187
// ********************************************* //
188
// ********************************************* //
189
// Internal parameters
190
// ********************************************* //
191
// ********************************************* //
192
194
double
internal_x
;
196
double
internal_y
;
198
double
internal_z
;
200
double
internal_w
;
201
202
203
// ********************************************* //
204
// ********************************************* //
205
// Helper
206
// ********************************************* //
207
// ********************************************* //
208
210
void
assert_size
(
const
size_t
& k)
const
;
211
212
};
213
215
vec4
operator+
(
const
double
& s,
const
vec4
& p);
217
vec4
operator-
(
const
double
& s,
const
vec4
& p);
219
vec4
operator*
(
const
double
& s,
const
vec4
& p);
220
221
// ********************************************* //
222
// ********************************************* //
223
// Output
224
// ********************************************* //
225
// ********************************************* //
226
228
std::ostream&
operator<<
(std::ostream& stream,
const
vec4
& p);
229
231
class
exception_vec4
:
public
exception_cpe
232
{
233
public
:
234
236
exception_vec4
():
exception_cpe
(){}
238
exception_vec4
(
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){}
239
};
240
241
}
242
243
244
245
#endif
lib3d
vec4.hpp
Generated on Wed Mar 6 2013 11:12:44 by
1.8.3.1