File: c3_tpl.h

package info (click to toggle)
enemylines7 0.6-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,640 kB
  • sloc: cpp: 21,756; makefile: 24
file content (258 lines) | stat: -rw-r--r-- 4,126 bytes parent folder | download | duplicates (3)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include <iostream>
#include <sstream>
#include <utility>
#include <cmath>
#include <limits>

using namespace std::rel_ops;

template <class T>class C3_tpl {
public:
	T x,y,z;

	C3_tpl() {x=0;y=0;z=0;}
	C3_tpl(T nx,T ny,T nz) {
		x=nx;y=ny;z=nz;
	}
	C3_tpl(T nx,T ny) {
		x=nx;y=ny;z=0;
	}
	C3_tpl(T n) {
		x=n;y=n;z=n;
	}

	T dot(C3_tpl <T> p) { return x*p.x y*p.y z*p.z; }
	T dot() { return x*x   y*y   z*z; }
	double magnitude() { return sqrt(dot()); }

	void normalize() {
		double mag=magnitude();
		x/=(T)mag;
		y/=(T)mag;
		z/=(T)mag;
	}
	void min() {
		x=std::numeric_limits<T>::min();
		y=std::numeric_limits<T>::min();
		z=std::numeric_limits<T>::min();
	}
	void max() {
		x=std::numeric_limits<T>::max();
		y=std::numeric_limits<T>::max();
		z=std::numeric_limits<T>::max();
	}

	T sum() { return fabs(x) fabs(y) fabs(z); }
	bool isnull() {
		if (z!=0) return false;
		if (y!=0) return false;
		if (x!=0) return false;
		return true;
	}
	bool exceeds(T min,T max) {
		if (x<min) return true;
		if (x>max) return true;
		if (y<min) return true;
		if (y>max) return true;
		if (z<min) return true;
		if (z>max) return true;
		return false;
	}

	C3_tpl <int> toint() {
		C3_tpl <int> i;

		i.x=static_cast<int>(x);
		i.y=static_cast<int>(y);
		i.z=static_cast<int>(z);
		return i;
	}
	C3_tpl <float> tofloat() {
		C3_tpl <float> i;

		i.x=static_cast<float>(x);
		i.y=static_cast<float>(y);
		i.z=static_cast<float>(z);
		return i;
	}



	C3_tpl <T> rotforward() {
		C3_tpl <T> r;
		static const float degtorad = M_PI/180;

		r.x=cosf(y*degtorad);
		r.y=sinf(x*degtorad);
		r.z=sinf(y*degtorad);
		return r;
	}

	float dist(C3_tpl <T>a) {
		float c;

		c=(a.x-x)*(a.x-x);
		c =(a.y-y)*(a.y-y);
		c =(a.z-z)*(a.z-z);
		c=sqrtf(c);
		return c;
	}

	bool too_far(C3_tpl <T>a,T max) {
		T n;
		n=a.x-x;
		if (n>max) return true;
		if (n<-max) return true;
		n=a.y-y;
		if (n>max) return true;
		if (n<-max) return true;
		n=a.z-z;
		if (n>max) return true;
		if (n<-max) return true;
		return false;
	}
	bool dist_below(C3_tpl <T>a,T b) {
		float c;

		c=(a.x-x)*(a.x-x);
		c =(a.y-y)*(a.y-y);
		c =(a.z-z)*(a.z-z);
		if (c<b) return true;
		return false;
	}

/////////
//Operators:
////////
	friend bool operator<(const C3_tpl &a,const C3_tpl &b) {
		unsigned int ia,ib;
		ia=a.x a.y*100 a.z*10000;
		ib=b.x b.y*100 b.z*10000;
		if (ia<ib) return true;
		return false;
	}
	
	friend bool operator==(const C3_tpl &a,const C3_tpl &b) {
		if (a.x!=b.x) return false;
		if (a.y!=b.y) return false;
		if (a.z!=b.z) return false;
		return true;
	}

	C3_tpl & operator =(const C3_tpl &a) {
		x =a.x;
		y =a.y;
		z =a.z;
		return (*this);	
	}
	C3_tpl & operator =(const T &a) {
		x =a;
		y =a;
		z =a;
		return (*this);	
	}
	C3_tpl operator (T b) {
		C3_tpl <T> c;

		c.x=x b;
		c.y=y b;
		c.z=z b;
		return c;
	}
	C3_tpl operator (C3_tpl <T>a) {
		C3_tpl <T> c;
		c.x=a.x x;
		c.y=a.y y;
		c.z=a.z z;
		return c;
	}


	C3_tpl & operator-=(const C3_tpl &a) {
		x-=a.x;
		y-=a.y;
		z-=a.z;
		return (*this);	
	}
	C3_tpl & operator-=(const T &a) {
		x-=a;
		y-=a;
		z-=a;
		return (*this);	
	}
	C3_tpl operator-(T b) {
		C3_tpl <T> c;

		c.x=x-b;
		c.y=y-b;
		c.z=z-b;
		return c;
	}
	C3_tpl operator-(C3_tpl <T>a) {
		C3_tpl <T> c;
		c.x=x-a.x;
		c.y=y-a.y;
		c.z=z-a.z;
		return c;
	}
	
	C3_tpl operator*(C3_tpl <T> b) {
		C3_tpl <T> c;

		c.x=x*b.x;
		c.y=y*b.y;
		c.z=z*b.z;
		return c;
	}
	C3_tpl operator*(T b) {
		C3_tpl <T> c;

		c.x=x*b;
		c.y=y*b;
		c.z=z*b;
		return c;
	}
	C3_tpl operator*=(T b) {
		x*=b;
		y*=b;
		z*=b;
		return (*this);
	}
	C3_tpl operator*=(C3_tpl <T> b) {
		x*=b.x;
		y*=b.y;
		z*=b.z;
		return (*this);
	}
	C3_tpl operator/=(C3_tpl <T> b) {
		x/=b.x;
		y/=b.y;
		z/=b.z;
		return (*this);
	}

	C3_tpl<T> operator/(T b) {
		C3_tpl <T> c;
		c.x=x/b;
		c.y=y/b;
		c.z=z/b;
		return c;
	}
	C3_tpl<T> operator/(C3_tpl <T> b) {
		C3_tpl <T> c;
		c.x=x/b.x;
		c.y=y/b.y;
		c.z=z/b.z;
		return c;
	}
	C3_tpl operator/=(T b) {
		x/=b;
		y/=b;
		z/=b;
		return (*this);
	}
};

template <class T> std::ostream& operator<< (std::ostream& s, C3_tpl <T>& v) {
   return s << v.x << " " << v.y << " " << v.z ;
}