-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec3.cpp
58 lines (49 loc) · 818 Bytes
/
vec3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "vec3.h"
#include <cmath>
#include <iostream>
Vec3::Vec3() {
x = 0;
y = 0;
z = 0;
}
Vec3::Vec3(float x_, float y_, float z_) {
x = x_;
y = y_;
z = z_;
}
Vec3::Vec3(const Vec3* o) {
//std::cout << o->x << " " << o->y << " " << o->z << std::endl;
x = o->x;
y = o->y;
z = o->z;
}
void Vec3::add(const Vec3* o) {
x = x + o->x;
y = y + o->y;
z = z + o->z;
}
void Vec3::sub(const Vec3* o) {
x = x - o->x;
y = y - o->y;
z = z - o->z;
}
float Vec3::dot(const Vec3* o) const {
float x_ = x * o->x;
float y_ = y * o->y;
float z_ = z * o->z;
return x_ + y_ + z_;
}
void Vec3::scal(const float s) {
x = x * s;
y = y * s;
z = z * s;
}
void Vec3::normalize() {
float l = length();
x /= l;
y /= l;
z /= l;
}
float Vec3::length() {
return sqrt(x*x+y*y+z*z);
}