EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Vector3D.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: eve-moo
24  */
25 
26 #include "Vector3D.h"
27 
28 double Vector3D::magnitude() const
29 {
30  double m;
31 
32  //calculate the length of the Vector3D
33  m = (x * x) + (y * y) + (z * z);
34  m = sqrt(m);
35 
36  return m;
37 }
38 
40 {
41  double m;
42 
43  //calculate the length of the Vector3D
44  m = (x * x) + (y * y) + (z * z);
45  m = sqrt(m);
46 
47  // if the length is zero then the Vector3D is zero so return
48  if (m == 0)
49  {
50  return;
51  }
52 
53  //Scale the Vector3D to a unit length
54  x /= m;
55  y /= m;
56  z /= m;
57 }
58 
59 double Vector3D::dotProduct(const Vector3D &v) const
60 {
61  return ((x * v.x) + (y * v.y) + (z * v.z));
62 }
63 
65 {
66  double nx = y * v.z - z * v.y;
67  double ny = z * v.x - x * v.z;
68  double nz = x * v.y - y * v.x;
69  return Vector3D(nx, ny, nz);
70 }
71 
73 {
74  Vector3D refl;
75  refl = norm * (-2 * dotProduct(norm));
76  refl = (*this) - refl;
77  return refl;
78 }
79 
80 Vector3D Vector3D::refraction(Vector3D norm, double fact) const
81 {
82  Vector3D refr;
83  double n_r = this->dotProduct(norm);
84  double k = 1 - (n_r * n_r);
85  k = 1 - (fact * fact) * k;
86  if (k < 0)
87  {
88  return refr;
89  }
90  refr = (*this) * fact;
91  refr -= norm * (fact * n_r + sqrt(k));
92  return refr;
93 }
94 
95 void Vector3D::set(double nx, double ny, double nz)
96 {
97  x = nx;
98  y = ny;
99  z = nz;
100 }
101 
102 void Vector3D::set(const Vector3D &v)
103 {
104  x = v.x;
105  y = v.y;
106  z = v.z;
107 }
108 
110 {
111  x = v.x;
112  y = v.y;
113  z = v.z;
114  return *this;
115 }
116 
118 {
119  return Vector3D(*this) += v;
120 }
121 
123 {
124  x += v.x;
125  y += v.y;
126  z += v.z;
127  return *this;
128 }
129 
131 {
132  return Vector3D(*this) -= v;
133 }
134 
136 {
137  x -= v.x;
138  y -= v.y;
139  z -= v.z;
140  return *this;
141 }
142 
144 {
145  return Vector3D(*this) *= v;
146 }
147 
149 {
150  x *= v.x;
151  y *= v.y;
152  z *= v.z;
153  return *this;
154 }
155 
157 {
158  return Vector3D(*this) /= v;
159 }
160 
162 {
163  x /= v.x;
164  y /= v.y;
165  z /= v.z;
166  return *this;
167 }
168 
169 Vector3D Vector3D::operator*(const double &k) const
170 {
171  return Vector3D(*this) *= k;
172 }
173 
175 {
176  x *= k;
177  y *= k;
178  z *= k;
179  return *this;
180 }
181 
182 Vector3D Vector3D::operator/(const double &k) const
183 {
184  return Vector3D(*this) /= k;
185 }
186 
188 {
189  x /= k;
190  y /= k;
191  z /= k;
192  return *this;
193 }
double z
Definition: Vector3D.h:40
void normalize()
Definition: Vector3D.cpp:39
Vector3D & operator=(const Vector3D &v)
Definition: Vector3D.cpp:109
Vector3D operator*(const Vector3D &v) const
Definition: Vector3D.cpp:143
Vector3D operator+(const Vector3D &v) const
Definition: Vector3D.cpp:117
Vector3D & operator-=(const Vector3D &v)
Definition: Vector3D.cpp:135
void set(double nx, double ny, double nz)
Definition: Vector3D.cpp:95
Vector3D refraction(Vector3D norm, double fact) const
Definition: Vector3D.cpp:80
double y
Definition: Vector3D.h:40
double magnitude() const
Definition: Vector3D.cpp:28
double dotProduct(const Vector3D &v) const
Definition: Vector3D.cpp:59
Vector3D reflection(Vector3D norm) const
Definition: Vector3D.cpp:72
Vector3D & operator/=(const Vector3D &v)
Definition: Vector3D.cpp:161
Vector3D()
Definition: Vector3D.h:42
Vector3D operator/(const Vector3D &v) const
Definition: Vector3D.cpp:156
Vector3D operator-(const Vector3D &v) const
Definition: Vector3D.cpp:130
double x
Definition: Vector3D.h:40
Vector3D crossProduct(const Vector3D &v) const
Definition: Vector3D.cpp:64
Vector3D & operator+=(const Vector3D &v)
Definition: Vector3D.cpp:122
Vector3D & operator*=(const Vector3D &v)
Definition: Vector3D.cpp:148