Vector.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_Dynacoe_POINT_INCLUDED
34 #define H_Dynacoe_POINT_INCLUDED
35 
36 /* Dynacoe::Vector
37  *
38  * A hybrid positional vector class
39  *
40  * Johnathan Corkery, 2014
41  */
42 
43 #include <string>
44 #include <vector>
45 
46 namespace Dynacoe {
47 
55 struct Vector {
58  Vector();
59 
60 
63  Vector(float x, float y, float z = 0.f);
64 
65 
66 
69  Vector(const std::vector<float> &);
70 
85  Vector(const std::string &);
86 
87 
91  float x;
92  float y;
93  float z;
95 
99  float Length() const;
100 
103  float Distance(const Vector &) const;
104 
105 
108  Vector operator/(const Vector &) const;
111  Vector operator*(const Vector &) const;
114  Vector operator+(const Vector &) const;
117  Vector operator-(const Vector &) const;
118 
119 
126 
127  Vector operator/(float) const;
128  Vector operator*(float) const;
129  Vector operator+(float) const;
130  Vector operator-(float) const;
132 
133 
134  bool operator==(const Dynacoe::Vector &) const;
135  bool operator!=(const Dynacoe::Vector &) const;
136 
137 
143  Vector & operator/=(const Vector &);
144  Vector & operator*=(const Vector &);
145  Vector & operator+=(const Vector &);
146  Vector & operator-=(const Vector &);
147 
148 
149  Vector & operator/=(float);
150  Vector & operator*=(float);
151  Vector & operator+=(float);
152  Vector & operator-=(float);
154 
156  Vector operator-() const;
157 
160  Vector Normalize() const;
161 
167  float Dot(const Vector &) const;
168 
174  float CrossFlat(const Vector &) const;
175 
176 
178  Vector Cross(const Vector &) const;
179 
180 
181 
182 
183 
184 
185 
186 
194 
197  float RotationXDiff(const Vector &) const;
198 
199 
202  float RotationXDiffRelative(const Vector &) const;
203 
204 
207 
208  float RotationX() const;
209 
211 
212 
213 
214 
215 
216 
217 
225 
228  float RotationYDiff(const Vector &) const;
229 
230 
233  float RotationYDiffRelative(const Vector &) const;
234 
235 
238  float RotationY() const;
240 
241 
242 
243 
244 
254 
255 
258  float RotationZDiff(const Vector &) const;
259 
260 
263  float RotationZDiffRelative(const Vector &) const;
264 
265 
268  float RotationZ() const;
270 
271 
272 
273 
274 
278  Vector RotateZ(float);
279  Vector RotateY(float);
280  Vector RotateX(float);
281 
282  Vector RotateZFrom(const Vector &, float);
283  Vector RotateYFrom(const Vector &, float);
284  Vector RotateXFrom(const Vector &, float);
286 
289  Vector Floor() const;
290 
294 
296  Vector & SetToFloor();
297 
298 
304  Vector & operator()(float, float);
305  Vector & operator()(float, float, float);
306  Vector & operator()(const Vector &);
308 
309 
310 
311 };
312 
313 };
314 
315 #endif
Vector & SetToNormalize()
Shorthand for (*this) = normalize().
Vector Cross(const Vector &) const
Returns the cross product.
3D and 2D positional vector.
Definition: Vector.h:55
Vector operator+(const Vector &) const
Adds all corresponding members and returns the outcome.
float RotationZDiffRelative(const Vector &) const
returns the angle between the 2 vectors in relation to (*this) in degrees
float Distance(const Vector &) const
Returns the distance of this vector to the other vector.
Vector Normalize() const
Returns a copy of the Vector with a magnitude of 1.
Definition: AssetID.h:37
float CrossFlat(const Vector &) const
Returns the 2D cross product.
float RotationX() const
returns the angle of the vector in degrees
Vector RotateZ(float)
Returns the result of rotating the vector by the specified degrees about the center.
float Length() const
Returns the length of the vector.
float Dot(const Vector &) const
returns the dot product of the two vectors.
float RotationXDiff(const Vector &) const
returns the YZ angle between the 2 vectors in relation to the origin in degrees
float RotationY() const
returns the angle of the vector in degrees.
Vector operator*(const Vector &) const
Multiplies all corresponding members and returns the outcome.
float RotationYDiff(const Vector &) const
Returns the zx angle between the 2 vectors in relation to the origin in degrees.
float RotationZ() const
returns the angle of the vector in degrees
Vector & SetToFloor()
Shorthand for (*this) = floor().
Vector operator/(const Vector &) const
Divides all corresponding members and returns the outcome.
Vector operator-() const
Negates all components.
float RotationYDiffRelative(const Vector &) const
returns the angle between the 2 vectors in relation to (*this) in degrees
Vector()
Initializes x, y, and z to 0.
Vector Floor() const
Returns a version of the vector with the fractional values of each component dropped.
float RotationXDiffRelative(const Vector &) const
returns the angle between the 2 vectors in relation to (*this) in degrees
float RotationZDiff(const Vector &) const
returns the XY angle between the 2 vectors in relation to the origin in degrees