-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvector3D.cpp
184 lines (133 loc) · 4.16 KB
/
vector3D.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// vectorMath.cpp
// Xcode
//
// Created by jacob on 7/11/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#include "vector3D.h"
Vector3d::Vector3d()
{
location.x = location.y = location.z = 0.0f;
//previousLocation.x = previousLocation.y = previousLocation. z = 0.0f;
//direction.x = direction.y = direction.z = 0.0f;
}
Vector3d::Vector3d(double x, double y, double z)
{
location.x = x;
location.y = y;
location.z = z;
//direction.x = direction.y = direction.z = 0.0f;
}
Vector3d::Vector3d(const coords &c, const directionCos &dir)
{
location.x = c.x;
location.y = c.y;
location.z = c.z;
//previousLocation.x = previousLocation.y = previousLocation.z = 0.0f;
// Initialize the direction cosine structure.
withDirection();
assert(direction.get() != NULL);
direction->x = dir.x;
direction->y = dir.y;
direction->z = dir.z;
}
Vector3d::~Vector3d()
{
}
// Here we overload the - operator so we can subtract vectors
boost::shared_ptr<Vector3d> Vector3d::operator-(Vector3d &rhs)
{
boost::shared_ptr<Vector3d> result(new Vector3d);
// Test if the 'rhs' vector has direction. If so update accordingly.
if (rhs.hasDirection())
{
// Initialize the direction portion of the vector.
result->withDirection();
// Assign directions.
result->setDirX(rhs.getDirX());
result->setDirY(rhs.getDirY());
result->setDirZ(rhs.getDirZ());
}
// Bounds are zero based. That is, the interval is between 0 -> upper bound.
//result->location.x = this->location.x - abs((this->location.x) - (rhs.location.x));
result->location.x = (this->location.x) - (rhs.location.x);
result->location.y = (this->location.y) - (rhs.location.y);
result->location.z = (this->location.z) - (rhs.location.z);
return result;
}
// Here we overload the + operator so we can add vectors together
boost::shared_ptr<Vector3d> Vector3d::operator+(Vector3d &rhs)
{
boost::shared_ptr<Vector3d> result(new Vector3d);
// Test if the 'rhs' vector has direction. If so update accordingly.
if (this->hasDirection())
{
// Initialize the direction portion of the vector.
result->withDirection();
// Assign directions.
result->setDirX(this->getDirX());
result->setDirY(this->getDirY());
result->setDirZ(this->getDirZ());
}
result->location.x = (this->location.x) + (rhs.location.x);
result->location.y = (this->location.y) + (rhs.location.y);
result->location.z = (this->location.z) + (rhs.location.z);
return result;
}
boost::shared_ptr<Vector3d> Vector3d::operator*(double num)
{
return boost::shared_ptr<Vector3d> (new Vector3d(location.x * num,
location.y * num,
location.z * num));
}
// XXX: Is this correct?
boost::shared_ptr<Vector3d> Vector3d::operator*(Vector3d &rhs)
{
boost::shared_ptr<Vector3d> result(new Vector3d);
result->location.x = (this->location.x) * (rhs.location.x);
result->location.y = (this->location.y) * (rhs.location.y);
result->location.z = (this->location.z) * (rhs.location.z);
return result;
}
bool Vector3d::operator&(Vector3d &rhs)
{
return ((this->location.x && rhs.location.x) ||
(this->location.y && rhs.location.y) ||
(this->location.z && rhs.location.z));
}
boost::shared_ptr<directionCos> Vector3d::getDirection(void)
{
assert(direction != NULL);
return this->direction;
}
double Vector3d::getDirX(void)
{
assert(direction != NULL);
return direction->x;
}
double Vector3d::getDirY(void)
{
assert(direction != NULL);
return direction->y;
}
double Vector3d::getDirZ(void)
{
assert(direction != NULL);
return direction->z;
}
void Vector3d::setDirX(double x)
{
assert(direction != NULL);
direction->x = x;
}
void Vector3d::setDirY(double y)
{
assert(direction != NULL);
direction->y = y;
}
void Vector3d::setDirZ(double z)
{
assert(direction != NULL);
direction->z = z;
}