mElite
1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
mElite
Vector3.cpp
Go to the documentation of this file.
1
6
#include "
Vector3.h
"
7
#include <cmath>
8
9
Vector3::Vector3
() {
10
x
= 0;
11
y
= 0;
12
z
= 0;
13
}
14
15
Vector3::Vector3
(
const
Vector3
&v ) {
16
x
= v.
x
;
17
y
= v.
y
;
18
z
= v.
z
;
19
}
20
21
Vector3::Vector3
(
float
x
,
float
y
,
float
z
) {
22
this->x =
x
;
23
this->y =
y
;
24
this->z =
z
;
25
}
26
27
Vector3::~Vector3
() {
28
}
29
30
float
Vector3::at
(
Vector3Index
index ) {
31
switch
( index ) {
32
case
Vector3Index::x
:
33
return
this->
x
;
34
break
;
35
case
Vector3Index::y
:
36
return
this->
y
;
37
break
;
38
case
Vector3Index::z
:
39
return
this->
z
;
40
default
:
41
return
0;
42
}
43
}
44
45
float
Vector3::at
(
unsigned
__int8 index ) {
46
switch
( index ) {
47
case
0:
48
return
this->
x
;
49
break
;
50
case
1:
51
return
this->
y
;
52
break
;
53
case
2:
54
return
this->
z
;
55
default
:
56
return
0;
// no exception is thrown
57
}
58
}
59
64
Vector3
Vector3::operator+
(
const
Vector3
&v) {
65
Vector3
result;
66
67
result.
x
=
x
+ v.
x
;
68
result.
y
=
y
+ v.
y
;
69
result.
z
=
z
+ v.
z
;
70
71
return
result;
72
}
73
78
Vector3
Vector3::operator -
(
const
Vector3
&v ) {
79
Vector3
result;
80
result.
x
=
x
- v.
x
;
81
result.
y
=
y
- v.
y
;
82
result.
z
=
z
- v.
z
;
83
return
result;
84
}
85
89
Vector3
Vector3::operator-
(
void
) {
90
Vector3
result;
91
result.
x
= -
x
;
92
result.
y
= -
y
;
93
result.
z
= -
z
;
94
return
result;
95
}
96
100
Vector3
Vector3::operator*
(
float
t) {
101
Vector3
result;
102
result.
x
=
x
* t;
103
result.
y
=
y
* t;
104
result.
z
=
z
* t;
105
return
result;
106
}
107
108
112
Vector3
Vector3::operator/
(
float
t) {
113
Vector3
result;
114
result.
x
=
x
/ t;
115
result.
y
=
y
/ t;
116
result.
z
=
z
/ t;
117
return
result;
118
}
119
123
Vector3
Vector3::operator*
(
const
Vector3
&v) {
124
Vector3
result;
125
result.
x
=
y
* v.
z
-
z
* v.
y
;
126
result.
y
=
z
* v.
x
-
x
* v.
z
;
127
result.
z
=
x
* v.
y
-
y
* v.
x
;
128
return
result;
129
}
130
131
132
Vector3
Vector3::operator =
(
const
Vector3
&v ) {
133
Vector3
result =
Vector3
( v );
134
this->
x
= v.
x
;
135
this->
y
= v.
y
;
136
this->
z
= v.
z
;
137
return
result;
138
}
139
140
144
float
Vector3::length
() {
145
return
(
float
)sqrt(
x
*
x
+
y
*
y
+
z
*
z
);
146
}
147
151
void
Vector3::normalize
() {
152
float
len;
153
len =
length
();
154
if
(len) {
// only dvide if len is not equal to zero
155
x
/= len;
156
y
/= len;
157
z
/= len;
158
}
159
}
160
161
165
float
Vector3::innerProduct
(
const
Vector3
&v ) {
// or scalar product (_not_ multiplication with scalar!)
166
return
x
* v.
x
+
y
* v.
y
+
z
* v.
z
;
167
}
168
172
void
Vector3::copy
(
const
Vector3
&v ) {
173
x
= v.
x
;
174
y
= v.
y
;
175
z
= v.
z
;
176
}
177
181
void
Vector3::set
(
float
x
,
float
y
,
float
z
) {
182
this->x =
x
;
183
this->y =
y
;
184
this->z =
z
;
185
}
186
190
Vector3
Vector3::scalarMult
(
float
a ) {
191
Vector3
result;
192
result.
x
=
x
* a;
193
result.
y
=
y
* a;
194
result.
z
=
z
* a;
195
return
result;
196
}
Generated on Tue Oct 2 2012 14:38:38 for mElite by
1.8.2