Main Page
Namespaces
Classes
Files
File List
File Members
vec3.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 VEC3_HPP
22
#define VEC3_HPP
23
24
#include <string>
25
#include <iostream>
26
27
#include <
exception_cpe.hpp
>
28
29
namespace
cpe
30
{
31
class
vec2;
32
34
class
vec3
35
{
36
public
:
37
38
// ********************************************* //
39
// ********************************************* //
40
// CONSTRUCTORS
41
// ********************************************* //
42
// ********************************************* //
43
45
vec3
();
47
vec3
(
float
x
,
float
y
,
float
z
);
48
49
// ********************************************* //
50
// ********************************************* //
51
// Get/set
52
// ********************************************* //
53
// ********************************************* //
54
56
float
x
()
const
;
58
float
&
x
();
60
float
y
()
const
;
62
float
&
y
();
64
float
z
()
const
;
66
float
&
z
();
67
69
float
operator[]
(
const
size_t
& k)
const
;
71
float
&
operator[]
(
const
size_t
& k);
73
float
operator()
(
const
size_t
& k)
const
;
75
float
&
operator()
(
const
size_t
& k);
76
78
void
set_zero
();
79
82
const
float
*
pointer
()
const
;
83
84
// ********************************************* //
85
// ********************************************* //
86
// Convert to lower dimension
87
// ********************************************* //
88
// ********************************************* //
89
91
vec2
to_vec2
()
const
;
92
93
94
// ********************************************* //
95
// ********************************************* //
96
// Math operation
97
// ********************************************* //
98
// ********************************************* //
99
101
float
dot
(
const
vec3
& p)
const
;
102
104
float
norm
()
const
;
106
float
norm2
()
const
;
108
vec3
normalized
()
const
;
109
111
vec3
cross
(
const
vec3
& p)
const
;
112
113
114
115
116
// ********************************************* //
117
// ********************************************* //
118
// Operator +-*/
119
// ********************************************* //
120
// ********************************************* //
121
123
vec3
operator+
(
const
vec3
& p2)
const
;
125
vec3
operator+
(
float
s)
const
;
126
128
vec3
operator-
(
const
vec3
& p2)
const
;
130
vec3
operator-
(
float
s)
const
;
131
132
134
vec3
operator*
(
float
s)
const
;
136
vec3
operator/
(
float
s)
const
;
137
139
vec3
&
operator+=
(
const
vec3
& p);
141
vec3
&
operator+=
(
float
s);
143
vec3
&
operator-=
(
const
vec3
& p);
145
vec3
&
operator-=
(
float
s);
147
vec3
&
operator*=
(
float
s);
149
vec3
&
operator/=
(
float
s);
150
152
vec3
operator-
()
const
;
153
157
vec3
product_compontentwise
(
const
vec3
& p)
const
;
162
vec3
&
product_compontentwise_internal
(
const
vec3
& p);
164
void
scale
(
float
sx,
float
sy,
float
sz);
165
166
167
// ********************************************* //
168
// ********************************************* //
169
// Output
170
// ********************************************* //
171
// ********************************************* //
172
174
std::string
to_string
()
const
;
175
176
177
178
private
:
179
180
181
// ********************************************* //
182
// ********************************************* //
183
// Internal parameters
184
// ********************************************* //
185
// ********************************************* //
186
188
float
internal_x
;
190
float
internal_y
;
192
float
internal_z
;
193
194
195
// ********************************************* //
196
// ********************************************* //
197
// Helper
198
// ********************************************* //
199
// ********************************************* //
200
202
void
assert_size
(
const
size_t
& k)
const
;
203
204
};
205
207
vec3
operator+
(
float
s,
const
vec3
& p);
209
vec3
operator-
(
float
s,
const
vec3
& p);
211
vec3
operator*
(
float
s,
const
vec3
& p);
212
213
// ********************************************* //
214
// ********************************************* //
215
// Output
216
// ********************************************* //
217
// ********************************************* //
218
220
std::ostream&
operator<<
(std::ostream& stream,
const
vec3
& p);
221
223
class
exception_vec3
:
public
exception_cpe
224
{
225
public
:
226
228
exception_vec3
():
exception_cpe
(){}
230
exception_vec3
(
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){}
231
};
232
233
}
234
235
236
237
#endif
lib3d
vec3.hpp
Generated on Fri Mar 29 2013 22:45:31 by
1.8.3.1