-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec.cpp
56 lines (43 loc) · 1.19 KB
/
vec.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
#include "vec.h"
#include <iostream>
#include <cmath>
using namespace std;
createVector::createVector(float x, float y, float z) : x(x), y(y), z(z) { }
float createVector::getX() const {
return x;
}
void createVector::setX(float x) {
this->x = x;
}
float createVector::getY() const {
return y;
}
void createVector::setY(float y) {
this->y = y;
}
float createVector::getZ() const {
return z;
}
void createVector::setZ(float z) {
this->z = z;
}
const createVector createVector::operator+(const createVector & rhs) const {
return createVector(x + rhs.x, y + rhs.y, z + rhs.z);
}
const createVector createVector::operator-(const createVector & rhs) const {
return createVector(x - rhs.x, y - rhs.y, z - rhs.z);
}
const createVector createVector::operator*(float value) const {
return createVector(x*value, y*value, z*value);
}
const createVector createVector::operator/(float value) const {
return createVector(x/value, y/value, z/value);
}
void createVector::setXYZ(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
double createVector::getMagnitude() const {
return sqrt(x*x + y*y+ z*z);
}