Blame view

rts/rtsPoint3d.h 3.07 KB
ebb721c7   David Mayerich   new repository fo...
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
  #ifndef RTSPOINT3D_H
  #define RTSPOINT3D_H
  #include "rtsVector3d.h"
  
  ///This class is used to store information about a 3D point.  It is designed to work with the class vector3D<T> for linear algebra operations.
  
  template <class T> class point3D
  {
  	//friend class vector3D<T>;
  public:
  	//data values
  	T x;
  	T y;
  	T z;
  
  	point3D();									///<Constructor initializes the point at the origin (0,0,0).
  	point3D(T new_x, T new_y, T new_z);			///<Constructor initializes the point to the position specified by (new_x, new_y, new_z).
  
  	//operators
  	bool operator==(point3D<T> param);			///<Overloaded boolean operator.  Returns true if the two oparands are at the same position.
  	bool operator!=(point3D<T> param);			///<Overloaded boolean operator for !=
  	point3D<T> operator+(vector3D<T> param);	///<Overloaded arithmetic oparator.  Returns the sum of the current point and a given vector.
  	point3D<T> operator-(vector3D<T> param);	///<Overloaded arithmetic operator.  Returns the sum of the current point and the negative of a given vector.
  	vector3D<T> operator-(point3D<T> param);	///<Overloaded arithmetic operator.  Returns the vector representing the space between two points.
  
  	//casting operators
  	template <class U> operator point3D<U>();  ///<Overloaded casting operator.  Allows casting between points of different types.
  
  	//output
  	friend ostream& operator<<(ostream& os, const point3D<T> &rhs)
  	{
  		os<<"("<<rhs.x<<","<<rhs.y<<","<<rhs.z<<")";
  		return os;
  	}
  
  	/*point3D<T> & operator=(const point3D<T> & rhs)
  	{
  		if(this != &rhs)
  		{
  			x = rhs.x;
  			y = rhs.y;
  			z = rhs.z;
  		}
  		return *this;
  	}*/
  	
  	void print();
  };
  
  template <class T>
  template <class U>
  point3D<T>::operator point3D<U>()
  {
  	point3D<U> cast_result(x, y, z);
  	return cast_result;
  }
  
  template <class T> point3D<T>::point3D()
  {
  	x=0;
  	y=0;
  	z=0;
  }
  
  template <class T> point3D<T>::point3D(T new_x, T new_y, T new_z)
  {
  	x=new_x;
  	y=new_y;
  	z=new_z;
  }
  
  template <class T>
  point3D<T> point3D<T>::operator -(vector3D<T> param)
  {
  	point3D<T> result;			//create the result
  	
  	result.x = x-param.x;		//perform the computation
  	result.y = y-param.y;
  	result.z = z-param.z;
  
  	return result;
  }
  
  template <class T>
  vector3D<T> point3D<T>::operator -(point3D<T> param)
  {
  	vector3D<T> result;
  	result.x = x - param.x;
  	result.y = y - param.y;
  	result.z = z - param.z;
  	
  	return result;
  }
  
  template <class T>
  point3D<T> point3D<T>::operator+(vector3D<T> param)
  {
  	point3D<T> result;			//create the result
  	
  	result.x = x+param.x;		//perform the computation
  	result.y = y+param.y;
  	result.z = z+param.z;
  
  	return result;
  }
  
  template <class T>
  bool point3D<T>::operator ==(point3D<T> param)
  {
  	if(x == param.x && y == param.y && z == param.z)
  		return true;
  	else
  		return false;
  }
  
  template <class T>
  bool point3D<T>::operator !=(point3D<T> param)
  {
  	if(x != param.x || y != param.y || z != param.z)
  		return true;
  	else
  		return false;
  }
  
  
  
  template <class T>
  void point3D<T>::print()
  {
  	cout<<"("<<x<<","<<y<<","<<z<<")"<<endl;
  }
  
  /*template <class T>
  ostream& point3D<T>::operator<<(ostream& os, point3D<T> &rhs)
  {
  	os<<"("<<x<<","<<y<<","<<z<<")";
  	return os;
  }
  */
  
  #endif