EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gpoint.h
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: Zhur
24 */
25 
26 #ifndef G_POINT_H
27 #define G_POINT_H
28 
29 #include "GaTypes.h"
30 #include "utils/misc.h"
31 
32 
33 class GPoint : public Ga::GaVec3 {
34 public:
35  GPoint():Ga::GaVec3(){}
37  GPoint(const Ga::GaFloat *v):Ga::GaVec3(v){}
39  GPoint(const GPoint& oth):Ga::GaVec3(oth){}
40  GPoint(const Ga::GaVec3& oth):Ga::GaVec3(oth){}
41 
42  // Public functions for manipulating 3D coordinates in space:
43  // Take existing (x,y,z) point and use that as the center of a sphere of 'radius' and
44  // modify it to be a new (x,y,z) point randomly placed on that sphere about the original
45  // center coordinate: (x,y,z)
46  void MakeRandomPointOnSphere(double radius)
47  {
48  double theta = MakeRandomFloat( 0.0, (2*M_PI) );
49  double phi = MakeRandomFloat( 0.0, (2*M_PI) );
50  x += radius * sin(theta) * cos(phi);
51  z += radius * sin(theta) * sin(phi);
52  y += radius * cos(theta);
53  }
54 
55  // Take existing (x,y,z) point and use that as the center of two spheres of 'radiusInner', the
56  // smaller radius sphere, and 'radiusOuter', the larger radius sphere, and modify
57  // the original coordinate to be a new (x,y,z) point randomly placed somewhere inside the volume
58  // enclosed between the smaller sphere and the large sphere
59  void MakeRandomPointOnSphereLayer(double radiusInner, double radiusOuter)
60  {
61  double theta = MakeRandomFloat( 0.0, (2*M_PI) );
62  double phi = MakeRandomFloat( 0.0, (2*M_PI) );
63  double intermediateRadius = MakeRandomFloat( radiusInner, radiusOuter );
64  x += intermediateRadius * sin(theta) * cos(phi);
65  z += intermediateRadius * sin(theta) * sin(phi);
66  y += intermediateRadius * cos(theta);
67  }
68 };
69 
70 class GVector : public Ga::GaVec3 {
71 public:
72  GVector():Ga::GaVec3(){}
74  GVector(const Ga::GaFloat *v):Ga::GaVec3(v){}
76  GVector(const GPoint& oth):Ga::GaVec3(oth){}
77  GVector(const Ga::GaVec3& oth):Ga::GaVec3(oth){}
78  GVector(const GPoint& from, const GPoint& to)
79  : Ga::GaVec3( (to.x-from.x), (to.y-from.y), (to.z-from.z) ) {}
80 };
81 
82 class GVector4 : public GVector {
83 public:
84  GVector4();
85  GVector4(const GPoint &them);
86  GVector4(double x, double y, double z, double w = 1.0f);
87 
88  inline void operator()(double nx, double ny, double nz, double nw) { pt[0] = nx; pt[1] = ny; pt[2] = nz; W = nw; }
89  double dot4(const GVector4 &them) const;
90  double dot4(const GPoint &them) const;
91 
92  inline const double w() const { return W; }
93 
94  double W;
95  double pt[3];
96 };
97 
98 #if 0
99 //TODO: inline most of this crap.
100 
101 class GPoint {
102 public:
103  GPoint();
104  GPoint(double x, double y, double z);
105 
106  inline void operator()(double nx, double ny, double nz) { pt[0] = nx; pt[1] = ny; pt[2] = nz; }
107 
108  inline const double x() const { return(pt[0]); }
109  inline const double y() const { return(pt[1]); }
110  inline const double z() const { return(pt[2]); }
111 
112  GPoint cross(const GPoint &them) const;
113  double dot3(const GPoint &them) const;
114 
115  const GPoint &operator+=(const GPoint &v2);
116  const GPoint &operator-=(const GPoint &v2);
117  const GPoint &operator*=(const double c);
118  const GPoint &operator/=(const double c);
119 
120  double pt[3];
121 
122 };
123 
124 GPoint operator+(const GPoint &v1, const GPoint &v2);
125 GPoint operator-(const GPoint &v1, const GPoint &v2);
126 GPoint operator*(const GPoint &v1, const double c);
127 GPoint operator/(const GPoint &v1, const double c);
128 GPoint operator*(const double c, const GPoint &v1);
129 GPoint operator/(const double c, const GPoint &v1);
130 
131 class GVector : public GPoint {
132 public:
133  GVector();
134  GVector(const GPoint &them);
135  GVector(const GPoint &from, const GPoint &to);
136  GVector(double x, double y, double z);
137 
138  void normalize();
139  double normalize_getlen(); //normalize and return the calculated length while your at it
140  double length() const;
141  double length2() const; //length squared
142 };
143 
144 class G2Point {
145 public:
146  G2Point();
147  G2Point(double x, double y);
148 
149  inline void operator()(double nx, double ny) { pt[0] = nx; pt[1] = ny; }
150 
151  inline const double x() const { return(pt[0]); }
152  inline const double y() const { return(pt[1]); }
153 
154  double pt[2];
155 };
156 
157 class G2iPoint {
158 public:
159  G2iPoint();
160  G2iPoint(int nx, int ny);
161 
162  inline void operator()(int nx, int ny) { x = nx; y = ny; }
163 
164  int x;
165  int y;
166 };
167 
168 inline bool operator==(const G2iPoint &pt1, const G2iPoint &pt2) {
169  return(pt1.x == pt2.x && pt1.y == pt2.y);
170 }
171 
172 inline bool operator!=(const G2iPoint &pt1, const G2iPoint &pt2) {
173  return(pt1.x != pt2.x || pt1.y != pt2.y);
174 }
175 
176 #endif
177 
178 #endif
void operator()(double nx, double ny, double nz, double nw)
Definition: gpoint.h:88
double dot4(const GVector4 &them) const
GaExpInl GaFloat length() const
Definition: GaTypes.h:156
itemID[count] Create count or of the specified() x() y(z)-Jump to the specified position in space.Stopped." ) COMMAND( translocate
GaExpInl GaVec3 & operator-=(const GaVec3 &oth)
Definition: GaTypes.h:104
GPoint(Ga::GaFloat X, Ga::GaFloat Y, Ga::GaFloat Z)
Definition: gpoint.h:38
GPoint(const Ga::GaVec3 &oth)
Definition: gpoint.h:40
GaExpInl GaVec3 & operator*=(GaFloat f)
Definition: GaTypes.h:113
GVector(const GPoint &oth)
Definition: gpoint.h:76
Definition: GaMath.h:26
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
GVector()
Definition: gpoint.h:72
GaExpInl GaVec3 & operator+=(const GaVec3 &oth)
Definition: GaTypes.h:95
GPoint()
Definition: gpoint.h:35
GaFloat x
Definition: GaTypes.h:207
const double w() const
Definition: gpoint.h:92
GVector(const Ga::GaFloat *v)
Definition: gpoint.h:74
GaExpInl GaFloat normalize()
Definition: GaTypes.h:163
GPoint(const Ga::GaFloat *v)
Definition: gpoint.h:37
EvilNumber operator+(const EvilNumber &val, const EvilNumber &val2)
Definition: EvilNumber.cpp:649
Definition: gpoint.h:33
EvilNumber operator/(const EvilNumber &val, const EvilNumber &val2)
Definition: EvilNumber.cpp:670
EvilNumber operator-(const EvilNumber &val, const EvilNumber &val2)
Definition: EvilNumber.cpp:656
GVector(Ga::GaFloat v)
Definition: gpoint.h:73
void MakeRandomPointOnSphereLayer(double radiusInner, double radiusOuter)
Definition: gpoint.h:59
GaExpInl GaVec3 & operator/=(GaFloat f)
Definition: GaTypes.h:122
GPoint(const GPoint &oth)
Definition: gpoint.h:39
double W
Definition: gpoint.h:94
GPoint(Ga::GaFloat v)
Definition: gpoint.h:36
GaFloat y
Definition: GaTypes.h:207
GVector(const GPoint &from, const GPoint &to)
Definition: gpoint.h:78
GVector(const Ga::GaVec3 &oth)
Definition: gpoint.h:77
EvilNumber operator*(const EvilNumber &val, const EvilNumber &val2)
Definition: EvilNumber.cpp:663
GaExpInl GaVec3()
Definition: GaTypes.h:45
double GaFloat
Definition: GaPreReqs.h:69
GVector(Ga::GaFloat X, Ga::GaFloat Y, Ga::GaFloat Z)
Definition: gpoint.h:75
Definition: gpoint.h:70
double pt[3]
Definition: gpoint.h:95
void MakeRandomPointOnSphere(double radius)
Definition: gpoint.h:46
GaFloat z
Definition: GaTypes.h:207