GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
VectorTools.hh
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Tero Pulkkinen
3// Released under LGPL License.
4//
5// This file is part of Polygon.
6//
7// Polygon is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Polygon is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Library General Public License
18// along with Polygon. If not, see <http://www.gnu.org/licenses/>.
19//
20
21#ifndef VECTORTOOLS_HH
22#define VECTORTOOLS_HH
23#include <iostream>
24#include <cmath>
25#include <vector>
26
27//#pragma warning(disable:4244)
28//#pragma warning(disable:4305)
29
30struct BOX {
31 float start_x;
32 float end_x;
33 float start_y;
34 float end_y;
35 float start_z;
36 float end_z;
37};
38
39
40inline float Min(float a, float b)
41{
42 return a < b ? a : b;
43}
44
45inline float Max(float a, float b)
46{
47 return a > b ? a : b;
48}
49
51{
52public:
53 float xm, ym, zm;
54};
55
56class Vector;
57
58class Point
59{
60public:
61 Point() : x(0.0), y(0.0), z(0.0) { }
62 Point(float xx, float yy, float zz) : x(xx), y(yy), z(zz) { }
63 Point(const Vector &v);
64 friend bool operator==(const Point &p1, const Point &p2)
65 {
66 float dx = fabs(p1.x-p2.x);
67 float dy = fabs(p1.y-p2.y);
68 float dz = fabs(p1.z-p2.z);
69 if (dx<0.001 && dy<0.001 && dz<0.001) return true;
70 return false;
71 }
72 friend bool operator!=(const Point &p1, const Point &p2)
73 {
74 return !(p1==p2);
75 }
76public:
77 float x,y,z;
78public:
79 float Dist() const;
80 friend float Dist(const Point &a, const Point &b);
81
82 //void Normalize() { x/=s; y/=s; z/=s; s=1.0; }
83
84 static Point Origo() { Point p; p.x = 0; p.y = 0; p.z = 0; return p; }
85 static Point Interpolate(const Point &aVec, const Point &aVec2, float aVal)
86 {
87 Point v;
88 v.x = aVec.x*(1.0-aVal) + aVec2.x*(aVal);
89 v.y = aVec.y*(1.0-aVal) + aVec2.y*(aVal);
90 v.z = aVec.z*(1.0-aVal) + aVec2.z*(aVal);
91 //v.s = aVec.s*aVal + aVec2.s*(1.0-aVal);
92 return v;
93 }
94
95 void operator+=(const Vector &v);
96 void operator-=(const Vector &v);
97 friend Point operator+(const Point &p, const Vector &v);
98 friend Point operator-(const Point &p, const Vector &v);
99 friend std::ostream &operator<<(std::ostream &o, const Point &p);
100 friend std::istream &operator>>(std::istream &i, Point &p);
101};
102
103
104
106{
107public:
109 Point ToPoint();
110 void FromPoint(Point v);
111public:
113 float r;
114 float alfa;
115 float beta;
116};
117
118class VEC4
119{
120public:
121 float x,y,z,w;
122};
123
124class Vector // a function Point->Point
125{
126public:
127 // Zero is identity elment
128 Vector() : dx(0.0), dy(0.0), dz(0.0) { }
129 Vector(float ddx, float ddy, float ddz) : dx(ddx), dy(ddy), dz(ddz) { }
130 Vector(const Vector &aVec) : dx(aVec.dx), dy(aVec.dy), dz(aVec.dz) { }
131 Vector(const Point &aPoint) : dx(aPoint.x), dy(aPoint.y), dz(aPoint.z) { }
132 Point operator()(Point p) const { return ApplyPoint(p); }
133 //void Normalize() { dx/=ds; dy/=ds; dz/=ds; ds=1.0; }
134
136 {
137 Point r;
138 r.x = p.x + dx;
139 r.y = p.y + dy;
140 r.z = p.z + dz;
141 return r;
142 }
143 void operator+=(const Vector &aVec)
144 {
145 dx+=aVec.dx;
146 dy+=aVec.dy;
147 dz+=aVec.dz;
148 }
149 // addition is associative and commutative
150 friend Vector operator+(const Vector &aVec, const Vector &aVec2)
151 {
152 Vector v = aVec;
153 v += aVec2;
154 return v;
155 }
156 void operator*=(const float &aFloat)
157 {
158 dx*=aFloat;
159 dy*=aFloat;
160 dz*=aFloat;
161 }
162 void operator/=(const float &aFloat)
163 {
164 dx/=aFloat;
165 dy/=aFloat;
166 dz/=aFloat;
167 }
168 // scalar multiplication is associative (ab)v = a(bv)
169 // with 1.0 as multiplicative identity.
170 friend Vector operator*(const Vector &aVec, const float &aFloat)
171 {
172 Vector v = aVec;
173 v *= aFloat;
174 return v;
175 }
176 friend Vector operator*(const float &aFloat, const Vector &aVec)
177 {
178 return aVec * aFloat;
179 }
180 friend Vector operator/(const Vector &aVec, const float &aFloat)
181 {
182 return aVec * (1.0 / aFloat);
183 }
184
185 static float DotProduct(const Vector &aVec, const Vector &aVec2)
186 {
187 float r;
188 r = aVec.dx * aVec2.dx;
189 r += aVec.dy * aVec2.dy;
190 r += aVec.dz * aVec2.dz;
191 return r;
192 }
193 static Vector CrossProduct(const Vector &aVec, const Vector &aVec2)
194 {
195 Vector v;
196 v.dx = aVec.dy*aVec2.dz - aVec.dz*aVec2.dy;
197 v.dy = aVec.dz*aVec2.dx - aVec.dx*aVec2.dz;
198 v.dz = aVec.dx*aVec2.dy - aVec.dy*aVec2.dx;
199 return v;
200 }
201 static float FindProjectionLength(Vector u, Vector u_x)
202 {
203 float alfa = acos(DotProduct(u,u_x)/u.Dist()/u_x.Dist());
204 float a_length = u_x.Dist()*cos(alfa);
205 return a_length;
206 }
207 static std::pair<Vector,Vector> SplitToComponents(Vector u, Vector u_x)
208 {
209 float alfa = acos(DotProduct(u,u_x)/u.Dist()/u_x.Dist());
210 float a_length = u_x.Dist()*cos(alfa);
211 Vector a_vec = a_length * u_x;
212 Vector b_vec = -a_vec + u;
213 return std::make_pair(a_vec, b_vec);
214 }
215
216 static float Angle(const Vector &aVec, const Vector &aVec2);
217
218 // -x has property that x + (-x) = 0.
220 {
221 Vector v;
222 v.dx = -dx;
223 v.dy = -dy;
224 v.dz = -dz;
225 return v;
226 }
227
229 {
230 dx*=aMult.xm;
231 dy*=aMult.xm;
232 dz*=aMult.xm;
233 }
235 {
236 dx*=aMult.ym;
237 dy*=aMult.ym;
238 dz*=aMult.ym;
239 }
241 {
242 dx*=aMult.zm;
243 dy*=aMult.zm;
244 dz*=aMult.zm;
245 }
246
247 float Dist() const;
248 friend float Dist(const Vector &a, const Vector &b) { return (b-a).Dist(); }
249
250 // r = u_x*x + u_y*y + u_z*z
251 Vector UnitConvert(const Vector &u_x, const Vector &u_y, const Vector &u_z);
252
253 static Vector UnitX();
254 static Vector UnitY();
255 static Vector UnitZ();
256
257 friend Vector operator-(const Point &p1, const Point &p2)
258 {
259 Vector v;
260 v.dx = p1.x-p2.x;
261 v.dy = p1.y-p2.y;
262 v.dz = p1.z-p2.z;
263 return v;
264 }
265 friend std::ostream &operator<<(std::ostream &o, const Vector &p);
266 friend std::istream &operator>>(std::istream &i, Vector &p);
267public:
268 float dx,dy,dz;
269};
270
271
273{
274 float angle;
276};
277
278class Matrix // a function point->point
279{
280public:
281 friend Point operator*(const Point &p, const Matrix &m);
282 friend Vector operator*(const Vector &v, const Matrix &m);
283 friend Matrix operator*(const Matrix &m1, const Matrix &m2);
284 friend Matrix operator+(const Matrix &m1, const Matrix &m2);
285 static bool has_nan(const Matrix &m);
286public:
287 void operator*=(float v)
288 {
289 for(int i=0;i<16;i++)
290 matrix[i]*=v;
291 }
292 void operator*=(const Matrix &m)
293 {
294 *this = *this * m;
295 }
296 static bool Equal(Matrix m1, Matrix m2)
297 {
298 for(int i=0;i<16;i++)
299 if (std::fabs(m1.matrix[i]-m2.matrix[i])>0.000001) return false;
300 return true;
301 }
302 static Matrix Zero();
303 static Matrix KeepRotation(const Matrix &m);
304 static Matrix Transpose(const Matrix &m);
305 static Matrix XRotation(float rot);
306 static Matrix YRotation(float rot);
307 static Matrix ZRotation(float rot);
308 static Matrix Translate(float x, float y, float z);
309 static Matrix Scale(float x, float y, float z);
310 static Matrix ProjectionTrans(float z_min);
311 static Matrix PerspectiveProjection(float dist);
312 static Matrix Perspective(float fovy, float aspect, float near, float far);
313 static Matrix Perspective2(float left, float right, float bottom, float top, float near, float far);
314 static Matrix Ortho(float left, float right, float bottom, float top, float near, float far);
315 static Matrix gluLookAt(Point eye, Point center, Vector up);
318 static Matrix Identity();
319 static float Determinant(const Matrix &m);
320 static Matrix MultiplyMatrix(const Matrix &m, int count);
321 static Matrix RotateAroundAxis(const Vector &v, float angle);
322 static Matrix RotateAroundAxisPoint(const Point &p,
323 const Vector &v,
324 float angle);
325 static Matrix Inverse(const Matrix &m);
326 static Matrix Interpolate(const Matrix &m1, const Matrix &m2, float t); // t = [0.0..1.0]
327 static AxisAngle FindAxisAngle(const Matrix &m);
328 friend std::ostream &operator<<(std::ostream &o, const Matrix &m);
330 {
331 Vector v;
332 v.dx = matrix[3];
333 v.dy = matrix[4*1+3];
334 v.dz = matrix[4*2+3];
335 return v;
336 }
338 matrix[3] = v.dx;
339 matrix[4*1+3] = v.dy;
340 matrix[4*2+3] = v.dz;
341 }
342public:
343 float matrix[16];
344 //bool is_identity;
345};
346
347struct Point2d;
348
349class Plane
350{
351public:
353 : u_p(u_p), u_x(v1), u_y(v2)
354 {
355 //u_x = v1; // * (1.0/v1.Dist());
356 //u_y = v2;// * (1.0/v2.Dist());
357 }
358 Plane(const Plane &p) : u_p(p.u_p), u_x(p.u_x), u_y(p.u_y) { }
359 Plane() : u_p(0.0,0.0,0.0), u_x(0.0,0.0,0.0), u_y(0.0,0.0,0.0) { }
360 void Normalize() { u_x/=u_x.Dist(); u_y/=u_y.Dist(); }
361
362 float Dist(Point p) const;
363 float CoordsX(Point p) const;
364 float CoordsY(Point p) const;
365 bool WhichSideOfPlane(Point p) const;
366 Vector Normal(float length) const;
367 void RotateAroundNormal(float angle_in_rad);
368 Point Navigate(const Point2d &p);
369 Vector PlaneNormal() { return Normal(1.0); }
370 float Dist2(Point p);
371 bool LineSegmentIntersection(Point p1, Point p2, Point2d &outP);
372 bool TriangleIntersection(Point p1, Point p2, Point p3, Point2d &res1, Point2d &res2);
373public:
377};
378
379class Color
380{
381public:
382 // vector [(-1,-1,-1)..(1,1,1)]
383 Color() : r(0), g(0), b(0), alpha(255) { check(); }
384 Color(Vector v);
385 Color(float r_, float g_, float b_, float a_) : r(255.0*r_),g(255.0*g_), b(255.0*b_), alpha(255.0*a_) { check(); }
386 Color(double r_, double g_, double b_, double a_) : r(255.0*r_), g(255.0*g_), b(255.0*b_), alpha(255.0*a_) { check(); }
387 Color(int r, int g, int b);
388 Color(int r, int g, int b, int alpha);
389 Color(unsigned int color);
390 Color(Color&&x) : r(std::move(x.r)), g(std::move(x.g)), b(std::move(x.b)), alpha(std::move(x.alpha)) { }
391Color(const Color &x) : r(x.r), g(x.g), b(x.b), alpha(x.alpha) { }
392 Color &operator=(Color &&x) { r=std::move(x.r); g=std::move(x.g); b=std::move(x.b); alpha=std::move(x.alpha); return *this; }
393 Color &operator=(const Color &x) { r=x.r; g=x.g; b=x.b; alpha=x.alpha; return *this; }
394 void check();
395
396 friend std::ostream &operator<<(std::ostream &o, const Color &c)
397 {
398 o << "(" << c.r << "," << c.g << "," << c.b << "," << c.alpha << ")";
399 return o;
400 }
401
402 void operator*=(float k) { r *= k; g *=k; b *=k; /*alpha*=k;*/ check(); }
403 friend Color operator+(const Color &c1, const Color &c2)
404 {
405 Color res;
406 res.r = c1.r+c2.r;
407 res.g = c1.g+c2.g;
408 res.b = c1.b+c2.b;
409 res.alpha = c1.alpha+c2.alpha;
410 res.check();
411 return res;
412 }
413 Color clamp() const
414 {
415 Color c2 = *this;
416 if (c2.r>255) { c2.r=255; }
417 if (c2.g>255) { c2.g=255; }
418 if (c2.b>255) { c2.b=255; }
419 if (c2.alpha>255) { c2.alpha=255; }
420 if (c2.r<0) { c2.r=0; }
421 if (c2.g<0) { c2.g=0; }
422 if (c2.b<0) { c2.b=0; }
423 if (c2.alpha<0) { c2.alpha=0; }
424 return c2;
425 }
426 unsigned int Pixel() {
427 return (((unsigned int)alpha)<<24) + (((unsigned int)r) << 16) + (((unsigned int)g) << 8) + (unsigned int)b;
428 }
429 friend Color operator*(Color c, float val)
430 {
431 c*=val;
432 c.check();
433 return c;
434 }
435 friend Color operator*(float val, Color c)
436 {
437 c*=val;
438 c.check();
439 return c;
440 }
441 static unsigned int Average(std::vector<unsigned int> vec);
442 static unsigned short PixelConvert(unsigned int pixel)
443 {
444 //unsigned int r = pixel &0xff;
445 //unsigned int g = pixel &0xff00;
446 //unsigned int b = pixel &0xff0000;
447 return 0;
448 }
449 static unsigned int PixelCombine(unsigned int pixel1, unsigned int pixel2)
450 {
451 unsigned int b = pixel1 & 0xff;
452 unsigned int g = pixel1 & 0xff00;
453 unsigned int r = pixel1 & 0xff0000;
454 unsigned int a = pixel1 & 0xff000000;
455 unsigned int b2 = pixel2 & 0xff;
456 unsigned int g2 = pixel2 & 0xff00;
457 unsigned int r2 = pixel2 & 0xff0000;
458 unsigned int a2 = pixel2 & 0xff000000;
459 r+=r2;
460 g+=g2;
461 b+=b2;
462 a/=2;
463 a2/=2;
464 a+=a2;
465 r/=2;
466 g/=2;
467 b/=2;
468 b&=0xff;
469 g&=0xff00;
470 r&=0xff0000;
471 a&=0xff000000;
472 return r + g + b + a;
473 }
474 static Color Transparent() { Color c; c.alpha=0; c.r = 0; c.b = 0; c.g = 0; return c; }
475 static Color Black() { Color c; c.r=0; c.b=0; c.g = 0; c.alpha=255; return c; }
476 static Color White() { Color c; c.r=255; c.b=255; c.g=255; c.alpha=255; return c;}
477 static Color CubeCenter() { Color c; c.r=128; c.b=128; c.g=128; c.alpha=255; return c;}
478 static unsigned int ColorCube(float x, float y, float z, float sizex, float sizey, float sizez)
479 {
480 x/= sizex;
481 y/= sizey;
482 z/= sizez;
483 // now 0..1
484 x*=255.0;
485 y*=255.0;
486 z*=255.0;
487 unsigned int b = int(z) &0xff;
488 unsigned int g = (int(y)<<8) &0xff00;
489 unsigned int r = (int(x)<<16) &0xff0000;
490 unsigned int a = ((0xff)<<24) &0xff000000;
491 return r+g+b+a;
492 }
493 static unsigned int RangeChange(unsigned int color,
494 unsigned int source_upper,
495 unsigned int source_lower,
496 unsigned int range_upper,
497 unsigned int range_lower)
498 {
499 unsigned int b = color & 0xff;
500 unsigned int g = color & 0xff00;
501 unsigned int r = color & 0xff0000;
502 unsigned int a = color & 0xff000000;
503
504
505 unsigned int bsu = source_upper & 0xff;
506 unsigned int gsu = source_upper & 0xff00;
507 unsigned int rsu = source_upper & 0xff0000;
508 unsigned int asu = source_upper & 0xff000000;
509
510 unsigned int bsl = source_lower & 0xff;
511 unsigned int gsl = source_lower & 0xff00;
512 unsigned int rsl = source_lower & 0xff0000;
513 unsigned int asl = source_lower & 0xff000000;
514
515 unsigned int bu = range_upper & 0xff;
516 unsigned int gu = range_upper & 0xff00;
517 unsigned int ru = range_upper & 0xff0000;
518 unsigned int au = range_upper & 0xff000000;
519
520 unsigned int bl = range_lower & 0xff;
521 unsigned int gl = range_lower & 0xff00;
522 unsigned int rl = range_lower & 0xff0000;
523 unsigned int al = range_lower & 0xff000000;
524
525 b-=bsl;
526 g-=gsl;
527 r-=rsl;
528 a-=asl;
529
530 float bf = float(b);
531 float gf = float(g>>8);
532 float rf = float(r>>16);
533 float af = float(a>>24);
534
535 gsu >>=8;
536 rsu >>=16;
537 asu >>=24;
538
539 gsl >>=8;
540 rsl >>=16;
541 asl >>=24;
542
543 bf /= float(bsu-bsl);
544 gf /= float(gsu-gsl);
545 rf /= float(rsu-rsl);
546 af /= float(asu-asl);
547
548 unsigned int bc = bl + (unsigned int)(bf*(bu-bl));
549 unsigned int gc = gl + (unsigned int)(gf*(gu-gl));
550 unsigned int rc = rl + (unsigned int)(rf*(ru-rl));
551 unsigned int ac = al + (unsigned int)(af*(au-al));
552 bc = bc & 0xff;
553 gc = gc & 0xff00;
554 rc = rc & 0xff0000;
555 ac = ac & 0xff000000;
556 return rc+gc+bc+ac;
557
558 }
559 static unsigned int CubicInterpolate(unsigned int pixel1, unsigned int pixel2, float val)
560 {
561 return Interpolate(pixel1,pixel2,val);
562#if 0
563 unsigned int b = pixel1 & 0xff;
564 unsigned int g = pixel1 & 0xff00;
565 unsigned int r = pixel1 & 0xff0000;
566 unsigned int a = pixel1 & 0xff000000;
567 unsigned int b2 = pixel2 & 0xff;
568 unsigned int g2 = pixel2 & 0xff00;
569 unsigned int r2 = pixel2 & 0xff0000;
570 unsigned int a2 = pixel2 & 0xff000000;
571
572 float bf = b;
573 float gf = g>>8;
574 float rf = r>>16;
575 float af = a>>24;
576
577 float bf2 = b2;
578 float gf2 = g2>>8;
579 float rf2 = r2>>16;
580 float af2 = a2>>24;
581
582 bf /= 255.0;
583 gf /= 255.0;
584 rf /= 255.0;
585 af /= 255.0;
586
587 bf2 /= 255.0;
588 gf2 /= 255.0;
589 rf2 /= 255.0;
590 af2 /= 255.0;
591
592 bf = bf*bf;
593 gf = gf*gf;
594 rf = rf*rf;
595 af = af*af;
596
597 bf2 = bf2*bf2;
598 gf2 = gf2*gf2;
599 rf2 = rf2*rf2;
600 af2 = af2*af2;
601
602 float val1 = 1.0-val;
603 float b3 = val1*bf + val*bf2;
604 float g3 = val1*gf + val*gf2;
605 float r3 = val1*rf + val*rf2;
606 float a3 = val1*af + val*af2;
607
608 b3 = sqrt(b3);
609 g3 = sqrt(g3);
610 r3 = sqrt(r3);
611 a3 = sqrt(a3);
612
613 b3 *= 255.0;
614 g3 *= 255.0;
615 r3 *= 255.0;
616 a3 *= 255.0;
617
618 unsigned int b4 = b3;
619 unsigned int g4 = g3;
620 unsigned int r4 = r3;
621 unsigned int a4 = a3;
622
623 g4 <<= 8;
624 r4 <<= 16;
625 a4 <<= 24;
626 return r4+g4+b4+a4;
627#endif
628 }
629 static unsigned int max_color(unsigned int pixel1, unsigned int pixel2)
630 {
631 unsigned int b = pixel1 & 0xff;
632 unsigned int g = pixel1 & 0xff00;
633 unsigned int r = pixel1 & 0xff0000;
634 unsigned int a = pixel1 & 0xff000000;
635 unsigned int b2 = pixel2 & 0xff;
636 unsigned int g2 = pixel2 & 0xff00;
637 unsigned int r2 = pixel2 & 0xff0000;
638 unsigned int a2 = pixel2 & 0xff000000;
639
640 unsigned int mb = std::max(b,b2);
641 unsigned int mg = std::max(g,g2);
642 unsigned int mr = std::max(r,r2);
643 unsigned int ma = std::max(a,a2);
644
645 return mr+mg+mb+ma;
646
647 }
648 static unsigned int min_color(unsigned int pixel1, unsigned int pixel2)
649 {
650 unsigned int b = pixel1 & 0xff;
651 unsigned int g = pixel1 & 0xff00;
652 unsigned int r = pixel1 & 0xff0000;
653 unsigned int a = pixel1 & 0xff000000;
654 unsigned int b2 = pixel2 & 0xff;
655 unsigned int g2 = pixel2 & 0xff00;
656 unsigned int r2 = pixel2 & 0xff0000;
657 unsigned int a2 = pixel2 & 0xff000000;
658
659 unsigned int mb = std::min(b,b2);
660 unsigned int mg = std::min(g,g2);
661 unsigned int mr = std::min(r,r2);
662 unsigned int ma = std::min(a,a2);
663
664 return mr+mg+mb+ma;
665
666 }
667 static unsigned int Interpolate(unsigned int pixel1, unsigned int pixel2, float val)
668 {
669
670 unsigned int b = pixel1 & 0xff;
671 unsigned int g = pixel1 & 0xff00;
672 unsigned int r = pixel1 & 0xff0000;
673 unsigned int a = pixel1 & 0xff000000;
674 unsigned int b2 = pixel2 & 0xff;
675 unsigned int g2 = pixel2 & 0xff00;
676 unsigned int r2 = pixel2 & 0xff0000;
677 unsigned int a2 = pixel2 & 0xff000000;
678
679 a >>= 4;
680 a2 >>= 4;
681
682 float val1 = 1.0-val;
683 if (std::isnan(val)) { val=0.0; val1=1.0; }
684 unsigned int b3 = ((unsigned int)(b*val1 + b2*val)) & 0xff;
685 unsigned int g3 = ((unsigned int)(g*val1 + g2*val)) & 0xff00;
686 unsigned int r3 = ((unsigned int)(r*val1 + r2*val)) & 0xff0000;
687 unsigned int a3 = ((unsigned int)(a*val1 + a2*val)) & 0x0ff00000;
688 a3 <<= 4;
689 return r3+g3+b3+a3;
690 }
691
692 static Color Interpolate(const Color &aVec, const Color &aVec2, float aVal)
693 {
694 if (aVal < 0.0f) aVal = 0.0f;
695 if (aVal > 1.0f) aVal = 1.0f;
696 Color v;
697 v.r = int(float(aVec.r)*(1.0f-aVal) + float(aVec2.r)*aVal);
698 v.g = int(float(aVec.g)*(1.0f-aVal) + float(aVec2.g)*aVal);
699 v.b = int(float(aVec.b)*(1.0f-aVal) + float(aVec2.b)*aVal);
700 v.alpha = int(float(aVec.alpha)*(1.0-aVal) + float(aVec2.alpha)*aVal);
701 return v;
702 }
703
704 static Color Lighter(const Color &aVec, float aVal)
705 {
706 return Interpolate(aVec, Black(), aVal);
707 }
708 static Color Darker(const Color &aVec, float aVal)
709 {
710 return Interpolate(aVec, White(), aVal);
711 }
712 static Color AverageArray(Color *array, int size)
713 {
714 if (size==0) return Color(0,0,0,0);
715 int rr=0;
716 int gg=0;
717 int bb=0;
718 int aa=0;
719 for (int i=0;i<size;i++)
720 {
721 rr+=array[i].r;
722 gg+=array[i].g;
723 bb+=array[i].b;
724 aa+=array[i].alpha;
725 }
726 rr/=size;
727 gg/=size;
728 bb/=size;
729 aa/=size;
730 return Color(rr,gg,bb,aa);
731 }
732 float rf() const { return r/255.0; }
733 float gf() const { return g/255.0; }
734 float bf() const { return b/255.0; }
735 float af() const { return alpha/255.0; }
736 friend bool operator==(const Color &c1, const Color &c2)
737 {
738 return c1.r==c2.r &&
739 c1.g == c2.g &&
740 c1.b == c2.b &&
741 c1.alpha == c2.alpha;
742 }
743public:
744 int r,g,b; // each component 0.255
745 int alpha;
746};
747
749{
750 void OrthoNormalize();
751 void Scale(float x);
753};
754struct Coords
755{
756 void OrthoNormalize();
757 void Scale(float x);
758 void Reposition(Point p) { center = p; }
759 Point FindInternalCoords(Point external_coords) const;
760 Point FindExternalCoords(Point internal_coords) const;
763};
764Point UnitCube(Point p, Point pos, Vector u_x, Vector u_y, Vector u_z);
765Point UnitToCube(Point p, Point pos, Vector u_x, Vector u_y, Vector u_z);
767 Point bTL, Point bTR, Point bBL, Point bBR,
768 Point fTL, Point fTR, Point fBL, Point fBR);
769
770
771
773{
774public:
775 static float TriArea(Point p1, Point p2, Point p3);
776 static float QuadArea(Point p1, Point p2, Point p3, Point p4);
777};
778
779struct Line
780{
783};
784
785
787{
788public:
789 float x,y,z,w;
790
791 friend Quarternion operator+(const Quarternion &a, const Quarternion &b);
792 friend Quarternion operator*(const Quarternion &a, float x);
793 static Matrix QuarToMatrix(const Quarternion &q);
794 static Quarternion MatrixToQuar(const Matrix &m); // loses translation
795 static Quarternion NLerp(const Quarternion &q, const Quarternion &q2, float t);
796};
797
799{
800public:
801 LineProperties(Point p1, Point p2) : p1(p1), p2(p2)
802 {
803 }
804 // x=[0..1], angle=0..2pi
805 Plane PlaneFromLine(float x, float angle, float dist);
806 Point MiddlePoint(float x) const;
807 Vector PerpendicularVector(float angle, float length);
808 float Dist(Point p);
809 bool TriangleIntersection(Point p1, Point p2, Point p3, float &r);
810 bool TriangleIntersection(Point v1, Point v2, Point v3, float &u, float &v, float &t);
811 bool QuadIntersection(Point p1, Point p2, Point p3, Point p4, float &r);
812 bool BoxIntersection(BOX &b, float &tmin, float &tmax);
813 float LineCoords(Point p) const;
814 Matrix translate_to_p1() const { return Matrix::Translate(p1.x,p1.y,p1.z); }
815 Matrix translate_to_p2() const { return Matrix::Translate(p2.x,p2.y,p2.z); }
817 {
818 Vector v = p2-p1;
819 float angle = atan2(v.dy,v.dx);
820 return Matrix::ZRotation(angle);
821 }
823 {
824 Vector v = p2-p1;
825 float alfa = atan2(v.dy,v.dx);
826 if (fabs(v.dx)<0.001) { if (v.dy<0.0f) alfa=-3.14159f/2.0; else alfa=3.14159f/2.0; }
827 float beta = acos(v.dz/sqrt(v.dx*v.dx+v.dy*v.dy+v.dz*v.dz));
828 //if (std::isnan(alfa)) alfa=0.0f;
829 //if (std::isnan(beta)) beta=0.0f;
831 return m;
832 }
834 {
835 Matrix m = Matrix::Scale(-1.0,1.0,1.0)*Matrix::ZRotation(-3.14159256/2.0)*Matrix::XRotation(3.14159256/2.0);
836 return m;
837 }
839 {
840 Vector v = p2-p1;
841 float d = v.Dist();
842 return Matrix::Scale(d,1.0,1.0);
843 }
844private:
845 Point p1, p2;
846};
847
848
849struct PoseLine {
851 LineProperties l(p1,p2);
852 dist = l.Dist(p);
853 span_pos = l.LineCoords(p);
854 angle = 0.0; // TODO
855 }
857 {
858 LineProperties l(p1,p2);
861 return p+v;
862 }
863public:
864 float span_pos;
865 float dist;
866 float angle;
867};
868
869
870
871#if 1
872
874{
875public:
876 SphereProperties2(Point center, float radius) : center(center), radius(radius) { }
877 bool InsideSphere(Point p) const {
878 p-=center;
879 bool d = p.x*p.x+p.y*p.y+p.z*p.z < radius*radius;
880 return d;
881 }
882private:
883 Point center;
884 float radius;
885};
886
888{
889public:
890 RectProperties(Point tl, Point br) : tl(tl), br(br) { }
891 bool IntersectRect(Point tl2, Point br2)
892 {
893 float start_x = std::max(tl.x,tl2.x);
894 float end_x = std::min(br.x, br2.x);
895 if (start_x>end_x) return false;
896 float start_y = std::max(tl.y, tl2.y);
897 float end_y = std::min(br.y, br2.y);
898 if (start_y>end_y) return false;
899 return true;
900 }
901private:
902 Point tl,br;
903};
904#endif
905
906
907struct Vector2d;
908
910{
911 float x,y;
912 static Point2d NewPoint(float x, float y) { Point2d p; p.x = x; p.y = y; return p; }
913 static Point2d FromVector(const Vector2d &v);
914 void operator+=(const Point2d &p)
915 {
916 x += p.x;
917 y += p.y;
918 }
919 void operator+=(const Vector2d &p);
920 void operator-=(const Point2d &p)
921 {
922 x -= p.x;
923 y -= p.y;
924 }
925
926 void operator*=(float k)
927 {
928 x*=k;
929 y*=k;
930 }
931 friend Point2d operator+(const Point2d &p, const Point2d &p2)
932 {
933 Point2d res;
934 res.x = p.x + p2.x;
935 res.y = p.y + p2.y;
936 return res;
937 }
938 //friend Vector2d operator-(const Point2d &p1, const Point2d &p2)
939 //{
940 // Vector2d v;
941 // v.x = p1.x-p2.x;
942 // v.y = p1.y-p2.y;
943 // return v;
944 //}
945 friend Point2d operator+(const Point2d &p, const Vector2d &p2);
946 friend Point2d operator*(float x, const Point2d &p)
947 {
948 Point2d res;
949 res.x = x*p.x;
950 res.y = x*p.y;
951 return res;
952 }
953 friend std::ostream &operator<<(std::ostream &o, const Point2d &p);
954 friend std::istream &operator>>(std::istream &i, Point2d &p);
955};
956
958{
959 float det = (p2.x-p1.x)*(p3.y-p1.y) - (p2.y-p1.y)*(p3.x-p1.x);
960 return det * ((p2.x-p1.x)*(p.y-p1.y) - (p2.y-p1.y)*(p.x-p1.x)) >= 0 &&
961 det * ((p3.x-p2.x)*(p.y-p2.y) - (p3.y-p2.y)*(p.x-p2.x))>=0 &&
962 det * ((p1.x-p3.x)*(p.y-p3.y) - (p1.y-p3.y)*(p.x-p3.x))>=0;
963}
964
965bool IsWithInBoundingBox(Point2d p, Point2d top_left, Point2d bottom_right);
967 Point2d l2_p1, Point2d l2_p2);
969 Point2d l2_p1, Point2d l2_p2);
970
972{
973 float dx,dy;
974
975 void operator*=(float x)
976 {
977 dx *= x;
978 dy *= x;
979 }
980 void operator/=(float x)
981 {
982 dx /= x;
983 dy /= x;
984 }
985 float Length() const;
986 float Dist() const { return Length(); }
987 static float DotProduct(const Vector2d &v, const Vector2d &v2)
988 {
989 return v.dx*v2.dx+v.dy*v2.dy;
990 }
991 static Vector2d FromPoint(const Point2d &p)
992 {
993 Vector2d pp;
994 pp.dx = p.x;
995 pp.dy = p.y;
996 return pp;
997 }
998 Vector2d operator-() { Vector2d res; res.dx = -dx; res.dy = -dy; return res; }
999 friend Vector2d operator+(const Vector2d &p1, const Vector2d &p2)
1000 {
1001 Vector2d res;
1002 res.dx = p1.dx + p2.dx;
1003 res.dy = p1.dy + p2.dy;
1004 return res;
1005 }
1006 friend Vector2d operator*(float x, const Vector2d &p)
1007 {
1008 Vector2d res;
1009 res.dx = x*p.dx;
1010 res.dy = x*p.dy;
1011 return res;
1012 }
1013 friend Vector2d operator*(const Vector2d &p, float x)
1014 {
1015 Vector2d res;
1016 res.dx = x*p.dx;
1017 res.dy = x*p.dy;
1018 return res;
1019 }
1020
1021};
1022inline Vector2d operator-(const Point2d &p1, const Point2d &p2)
1023{
1024 Vector2d v;
1025 v.dx = p1.x-p2.x;
1026 v.dy = p1.y-p2.y;
1027 return v;
1028}
1029
1030inline void Point2d::operator+=(const Vector2d &p)
1031{
1032 x += p.dx;
1033 y += p.dy;
1034}
1036{
1037 Point2d p;
1038 p.x = v.dx;
1039 p.y = v.dy;
1040 return p;
1041}
1042inline Point2d operator+(const Point2d &p, const Vector2d &p2)
1043{
1044 Point2d res;
1045 res.x = p.x + p2.dx;
1046 res.y = p.y + p2.dy;
1047 return res;
1048}
1049
1050
1052{
1053public:
1054 TriangleProperties(Point p1, Point p2, Point p3) : p1(p1), p2(p2), p3(p3) { }
1056 {
1057 Point pp = p1+Vector(p2)+Vector(p3);
1058 pp.x /= 3.0;
1059 pp.y /= 3.0;
1060 pp.z /= 3.0;
1061 return pp;
1062 }
1063 float side_length_1_2() const
1064 {
1065 Vector v = p2-p1;
1066 return v.Dist();
1067 }
1068 float side_length_2_3() const
1069 {
1070 Vector v = p3-p2;
1071 return v.Dist();
1072 }
1073 float side_length_3_1() const
1074 {
1075 Vector v = p1-p3;
1076 return v.Dist();
1077 }
1079 {
1080 // get side lengths
1081 float a = side_length_1_2();
1082 float b = side_length_2_3();
1083 float c = side_length_3_1();
1084
1085 // barycentric coordinates
1086 float xx = a*a*(b*b+c*c-a*a);
1087 float yy = b*b*(c*c+a*a-b*b);
1088 float zz = c*c*(a*a+b*b-c*c);
1089
1090 // convert to point
1091 Point bary(xx,yy,zz);
1092 Point p = barycentric_to_point(bary);
1093 return p;
1094 }
1095 float circum_radius() const
1096 {
1097 float a = side_length_1_2();
1098 float b = side_length_2_3();
1099 float c = side_length_3_1();
1100 return a*b*c/sqrt((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c));
1101 }
1102 static Point uv_to_bary(float u, float v)
1103 { // use this with TriangleIntersection
1104 Point p(u,v,1.0-u-v);
1105 return p;
1106 }
1107
1109 {
1110 Point pp = Point(Vector(p1)*bary.x + Vector(p2)*bary.y + Vector(p3)*bary.z);
1111 return pp;
1112 }
1114 {
1115 Point B;
1116 B.x = ((v2.y-v3.y)*(p.x-v3.x) + (v3.x-v2.x)*(p.y-v3.y))/ ((v2.y-v3.y)*(v1.x-v3.x) + (v3.x-v2.x)*(v1.y-v3.y));
1117 B.y = ((v3.y-v1.y)*(p.x-v3.x) + (v1.x-v3.x)*(p.y-v3.y)) /((v3.y-v1.y)*(v2.x-v3.x)+(v1.x-v3.x)*(v2.y-v3.y));
1118 B.z = 1-B.x-B.y;
1119 return B;
1120 }
1121 static bool is_inside_triangle(Point bary)
1122 {
1123 return (bary.x >= 0.0) && (bary.x <=1.0) &&
1124 (bary.y>=0.0) && (bary.y<=1.0) &&
1125 (bary.z>=0.0) && (bary.z<=1.0);
1126 }
1127 bool is_inside_circum_sphere(Point p) const;
1128private:
1129 Point p1,p2,p3;
1130};
1131
1132
1134{
1135public:
1136 CubePlanes(Point p, Vector u_x, Vector u_y, Vector u_z) : p(p), u_x(u_x), u_y(u_y), u_z(u_z) { }
1137 Plane XY(float z, Point2d normalized_center) const
1138 {
1139 Point pp(p+normalized_center.x*u_x+normalized_center.y*u_y+z*u_z);
1140 return Plane(pp, u_x,u_y);
1141 }
1142 Plane YZ(float x, Point2d normalized_center) const
1143 {
1144 Point pp(p+x*u_x+normalized_center.x*u_y+normalized_center.y*u_z);
1145 return Plane(pp, u_y, u_z);
1146 }
1147 Plane XZ(float y, Point2d normalized_center) const
1148 {
1149 Point pp(p+normalized_center.x*u_x+y*u_y+normalized_center.y*u_z);
1150 return Plane(pp, u_x, u_z);
1151 }
1152private:
1153 Point p;
1154 Vector u_x;
1155 Vector u_y;
1156 Vector u_z;
1157};
1158
1160{ // intersection of plane and plane
1161public:
1162 PlaneIntersection(const Plane &p1, const Plane &p2);
1163 Line Intersection() const;
1164 float ProjectP1(Point2d p_in_plane1);
1165 float ProjectP2(Point2d p_in_plane2);
1166private:
1167 const Plane &p1;
1168 const Plane &p2;
1169 Line l;
1170};
1171// defined in Graph.cc
1172Line PlanePlaneIntersection(const Plane &p1, const Plane &p2);
1173
1174#if 0
1175class LineCircleIntersection
1176{
1177public:
1178 LineCircleIntersection(Point2d center, float radius,
1179 Point2d line1, Point2d line2)
1180 : center(center), radius(radius), line1(line1), line2(line2) { }
1181
1182private:
1183 //Point2d center;
1184 float radius;
1185 Point2d line1;
1186 Point2d line2;
1187};
1188#endif
1190{
1191public:
1194 Point line12_p1(float x) const { return line1_p1+Vector(line1_p2-line1_p1)*x; }
1195 Point line12_p2(float x) const { return line2_p1+Vector(line2_p2-line2_p1)*x; }
1196
1197 static Point LinePoint(Point p1, Point p2, float x)
1198 {
1199 return p1+Vector(p2-p1)*x;
1200 }
1201};
1202
1204{
1207 Point coords(float x, float y, float z)
1208 {
1209 Point p1 = front_plane.line12_p1(x);
1210 Point p2 = front_plane.line12_p2(x);
1211 Point pp = FlexiblePlane::LinePoint(p1,p2,y);
1212
1213 Point r1 = back_plane.line12_p1(x);
1214 Point r2 = back_plane.line12_p2(x);
1215 Point rp = FlexiblePlane::LinePoint(r1,r2,y);
1216
1217 return FlexiblePlane::LinePoint(pp,rp,z);
1218
1219 }
1220};
1221
1222FlexibleCube box(Point p1, float sx, float sy, float sz);
1223
1224
1225
1232
1233class GC2d
1234{
1235public:
1236 virtual void Draw2dObject(int id, FlexiblePlane pl, void *data)=0;
1237};
1238
1239class GC3d
1240{
1241public:
1242 virtual void Draw3dObject(int id, FlexibleCube c)=0;
1243};
1244
1246{
1247public:
1248 virtual void Draw(FlexiblePlane p, GC2d *gc) const=0;
1249};
1251{
1252public:
1253 virtual void Draw(FlexibleCube c, GC3d *gc) const=0;
1254};
1255
1257{
1258public:
1259 PolyMatrix(int sx, int sy) : sx(sx), sy(sy) {
1260 grid = new float[sx*sy];
1261 }
1263 : sx(m.sx), sy(m.sy)
1264 {
1265 grid = new float[sx*sy];
1266 for(int y=0;y<sy;y++)
1267 for(int x=0;x<sx;x++)
1268 grid[x+y*sx] = m.grid[x+y*sx];
1269 }
1271 {
1272 sx = m.sx;
1273 sy = m.sy;
1274 delete [] grid;
1275 grid = new float[sx*sy];
1276 for(int y=0;y<sy;y++)
1277 for(int x=0;x<sx;x++)
1278 grid[x+y*sx] = m.grid[x+y*sx];
1279 return *this;
1280 }
1281 static PolyMatrix ZeroMatrix(int sx, int sy);
1282 static PolyMatrix IdentityMatrix(int sx, int sy);
1283 static PolyMatrix df_per_dx(int sx, int sy);
1284 void set_val(int x, int y, float val) { grid[x+y*sx] = val; }
1285 float read_val(int x, int y) const { return grid[x+y*sx]; }
1286 ~PolyMatrix() { delete[] grid; }
1287public:
1288 int sx,sy;
1289 float *grid;
1290};
1291
1293{
1294public:
1295 static std::vector<float> basis_vector(int count, float val); //count=1: constant, count=2: x, count=3: x^2. etc.
1296 static float mul(std::vector<float> v1, std::vector<float> v2); // v2 should be basis_vector
1297 static std::vector<float> mul_matrix(const PolyMatrix &m, std::vector<float> &v);
1298 static std::vector<float> scale(std::vector<float> v, float c);
1299 static std::vector<float> add(std::vector<float> v1, std::vector<float> v2);
1300};
1301
1302class Pid
1303{
1304public:
1305 Pid(double p, double i, double d);
1306 Pid(double p, double i, double d, double f);
1307 void init();
1308 void setP(double p);
1309 void setI(double i);
1310 void setD(double d);
1311 void setF(double f);
1312 void setPID(double p, double i, double d);
1313 void setPID(double p, double i, double d, double f);
1314 void setMaxIOutput(double maximum);
1315 void setOutputLimits(double output);
1316 void setOutputLimits(double minimum, double maximum);
1317 void setDirection(bool reversed);
1318 void setSetpoint(double setpoint);
1319 double getOutput(double actual, double setpoint);
1320 double getOutput();
1321 double getOutput(double actual);
1322 void reset();
1323 void setOutputRampRate(double rate);
1324 void setSetpointRange(double range);
1325 void setOutputFilter(double strength);
1326 double clamp(double value, double min, double max);
1327 bool bounded(double value, double min, double max);
1328 void checkSigns();
1329private:
1330 double P,I,D,F;
1331 double maxIOutput, maxError, errorSum, maxOutput,minOutput,setpoint,lastActual;
1332 bool firstRun, reversed;
1333 double outputRampRate;
1334 double lastOutput;
1335 double outputFilter;
1336 double setpointRange;
1337};
1338
1339#endif
size dy
Definition GameApi_gui.cc:1727
@ ELine
Definition SeqApi.hh:12
Line PlanePlaneIntersection(const Plane &p1, const Plane &p2)
Definition VectorTools.cc:1866
Point2d LineLineIntersection(Point2d l1_p1, Point2d l1_p2, Point2d l2_p1, Point2d l2_p2)
Definition VectorTools.cc:1564
Point2d operator+(const Point2d &p, const Vector2d &p2)
Definition VectorTools.hh:1042
Vector2d operator-(const Point2d &p1, const Point2d &p2)
Definition VectorTools.hh:1022
bool PointIsInsideTriangle(Point2d p1, Point2d p2, Point2d p3, Point2d p)
Definition VectorTools.hh:957
Point UnitToFlex(Point p, Point bTL, Point bTR, Point bBL, Point bBR, Point fTL, Point fTR, Point fBL, Point fBR)
Definition VectorTools.cc:1343
Point UnitCube(Point p, Point pos, Vector u_x, Vector u_y, Vector u_z)
Definition VectorTools.cc:1325
bool LineLineIntersection_Parallel(Point2d l1_p1, Point2d l1_p2, Point2d l2_p1, Point2d l2_p2)
Definition VectorTools.cc:1549
float Max(float a, float b)
Definition VectorTools.hh:45
Point UnitToCube(Point p, Point pos, Vector u_x, Vector u_y, Vector u_z)
Definition VectorTools.cc:1334
FlexibleCube box(Point p1, float sx, float sy, float sz)
Definition VectorTools.cc:1529
float Min(float a, float b)
Definition VectorTools.hh:40
GcId
Definition VectorTools.hh:1227
@ EBitmap
Definition VectorTools.hh:1230
@ ERect
Definition VectorTools.hh:1228
bool IsWithInBoundingBox(Point2d p, Point2d top_left, Point2d bottom_right)
Definition VectorTools.cc:1583
Definition VectorTools.hh:773
static float TriArea(Point p1, Point p2, Point p3)
Definition VectorTools.cc:1852
static float QuadArea(Point p1, Point p2, Point p3, Point p4)
Definition VectorTools.cc:1861
Definition compiled_tests.cpp:1200
friend Color operator*(Color c, float val)
Definition VectorTools.hh:429
Color(double r_, double g_, double b_, double a_)
Definition VectorTools.hh:386
Color & operator=(Color &&x)
Definition VectorTools.hh:392
static unsigned int Interpolate(unsigned int pixel1, unsigned int pixel2, float val)
Definition VectorTools.hh:667
float af() const
Definition VectorTools.hh:735
unsigned int Pixel()
Definition VectorTools.hh:426
float bf() const
Definition VectorTools.hh:734
void check()
Definition VectorTools.cc:1113
int r
Definition VectorTools.hh:744
static Color Interpolate(const Color &aVec, const Color &aVec2, float aVal)
Definition VectorTools.hh:692
void operator*=(float k)
Definition VectorTools.hh:402
static Color AverageArray(Color *array, int size)
Definition VectorTools.hh:712
static unsigned short PixelConvert(unsigned int pixel)
Definition VectorTools.hh:442
static Color Darker(const Color &aVec, float aVal)
Definition VectorTools.hh:708
static unsigned int CubicInterpolate(unsigned int pixel1, unsigned int pixel2, float val)
Definition VectorTools.hh:559
static Color Transparent()
Definition VectorTools.hh:474
Color(const Color &x)
Definition VectorTools.hh:391
static unsigned int ColorCube(float x, float y, float z, float sizex, float sizey, float sizez)
Definition VectorTools.hh:478
static unsigned int Average(std::vector< unsigned int > vec)
Definition VectorTools.cc:1075
Color()
Definition VectorTools.hh:383
static Color CubeCenter()
Definition VectorTools.hh:477
int alpha
Definition VectorTools.hh:745
Color & operator=(const Color &x)
Definition VectorTools.hh:393
static unsigned int max_color(unsigned int pixel1, unsigned int pixel2)
Definition VectorTools.hh:629
static unsigned int min_color(unsigned int pixel1, unsigned int pixel2)
Definition VectorTools.hh:648
int g
Definition VectorTools.hh:744
static Color White()
Definition VectorTools.hh:476
friend std::ostream & operator<<(std::ostream &o, const Color &c)
Definition VectorTools.hh:396
static Color Lighter(const Color &aVec, float aVal)
Definition VectorTools.hh:704
float rf() const
Definition VectorTools.hh:732
Color(float r_, float g_, float b_, float a_)
Definition VectorTools.hh:385
static unsigned int PixelCombine(unsigned int pixel1, unsigned int pixel2)
Definition VectorTools.hh:449
Color clamp() const
Definition VectorTools.hh:413
Color(Color &&x)
Definition VectorTools.hh:390
friend bool operator==(const Color &c1, const Color &c2)
Definition VectorTools.hh:736
int b
Definition VectorTools.hh:744
float gf() const
Definition VectorTools.hh:733
static Color Black()
Definition VectorTools.hh:475
friend Color operator+(const Color &c1, const Color &c2)
Definition VectorTools.hh:403
friend Color operator*(float val, Color c)
Definition VectorTools.hh:435
static unsigned int RangeChange(unsigned int color, unsigned int source_upper, unsigned int source_lower, unsigned int range_upper, unsigned int range_lower)
Definition VectorTools.hh:493
Definition VectorTools.hh:51
float zm
Definition VectorTools.hh:53
float ym
Definition VectorTools.hh:53
float xm
Definition VectorTools.hh:53
Definition VectorTools.hh:1251
virtual void Draw(FlexibleCube c, GC3d *gc) const =0
Plane YZ(float x, Point2d normalized_center) const
Definition VectorTools.hh:1142
Plane XZ(float y, Point2d normalized_center) const
Definition VectorTools.hh:1147
CubePlanes(Point p, Vector u_x, Vector u_y, Vector u_z)
Definition VectorTools.hh:1136
Plane XY(float z, Point2d normalized_center) const
Definition VectorTools.hh:1137
Definition VectorTools.hh:1190
Point line1_p1
Definition VectorTools.hh:1192
static Point LinePoint(Point p1, Point p2, float x)
Definition VectorTools.hh:1197
Point line12_p2(float x) const
Definition VectorTools.hh:1195
Point line2_p2
Definition VectorTools.hh:1193
Point line12_p1(float x) const
Definition VectorTools.hh:1194
Point line2_p1
Definition VectorTools.hh:1193
Point line1_p2
Definition VectorTools.hh:1192
Definition VectorTools.hh:1234
virtual void Draw2dObject(int id, FlexiblePlane pl, void *data)=0
Definition VectorTools.hh:1240
virtual void Draw3dObject(int id, FlexibleCube c)=0
Definition VectorTools.hh:799
LineProperties(Point p1, Point p2)
Definition VectorTools.hh:801
Vector PerpendicularVector(float angle, float length)
Definition VectorTools.cc:1258
bool QuadIntersection(Point p1, Point p2, Point p3, Point p4, float &r)
Definition VectorTools.cc:1592
Matrix scale_length_in_2d() const
Definition VectorTools.hh:838
Matrix rotate_from_p1_in_3d() const
Definition VectorTools.hh:822
bool BoxIntersection(BOX &b, float &tmin, float &tmax)
Definition VectorTools.cc:1601
float LineCoords(Point p) const
Definition VectorTools.cc:1243
Point MiddlePoint(float x) const
Definition VectorTools.cc:1252
Plane PlaneFromLine(float x, float angle, float dist)
Definition VectorTools.cc:1233
bool TriangleIntersection(Point p1, Point p2, Point p3, float &r)
Definition VectorTools.cc:1648
Matrix rotate_z_from_p1_in_2d() const
Definition VectorTools.hh:816
Matrix translate_to_p2() const
Definition VectorTools.hh:815
float Dist(Point p)
Definition VectorTools.cc:1382
Matrix translate_to_p1() const
Definition VectorTools.hh:814
Matrix rotate_to_initial_pos() const
Definition VectorTools.hh:833
Definition VectorTools.hh:279
static Matrix PerspectiveProjection(float dist)
Definition VectorTools.cc:574
static float Determinant(const Matrix &m)
Definition VectorTools.cc:813
static Matrix Ortho(float left, float right, float bottom, float top, float near, float far)
Definition VectorTools.cc:656
float matrix[16]
Definition VectorTools.hh:343
friend Point operator*(const Point &p, const Matrix &m)
Definition VectorTools.cc:191
static Matrix Zero()
Definition VectorTools.cc:477
static Matrix XRotation(float rot)
Definition VectorTools.cc:498
static Matrix CartesianToSpherical(Point p)
Definition VectorTools.cc:686
static Matrix YRotation(float rot)
Definition VectorTools.cc:526
void operator*=(float v)
Definition VectorTools.hh:287
static Matrix ProjectionTrans(float z_min)
Definition VectorTools.cc:565
friend std::ostream & operator<<(std::ostream &o, const Matrix &m)
Definition VectorTools.cc:68
static Matrix Translate(float x, float y, float z)
Definition VectorTools.cc:547
static bool Equal(Matrix m1, Matrix m2)
Definition VectorTools.hh:296
static Matrix Perspective(float fovy, float aspect, float near, float far)
Definition VectorTools.cc:608
static Matrix Inverse(const Matrix &m)
Definition VectorTools.cc:859
static Matrix gluLookAt(Point eye, Point center, Vector up)
Definition VectorTools.cc:625
static bool has_nan(const Matrix &m)
Definition VectorTools.cc:429
static Matrix SphericalToCartesian(SphericalPoint p)
Definition VectorTools.cc:670
friend Matrix operator+(const Matrix &m1, const Matrix &m2)
Definition VectorTools.cc:217
static Matrix RotateAroundAxis(const Vector &v, float angle)
Definition VectorTools.cc:718
static Matrix ZRotation(float rot)
Definition VectorTools.cc:537
static Matrix Identity()
Definition VectorTools.cc:487
static Matrix Transpose(const Matrix &m)
Definition VectorTools.cc:1134
static Matrix Interpolate(const Matrix &m1, const Matrix &m2, float t)
Definition VectorTools.cc:983
Vector get_translate() const
Definition VectorTools.hh:329
static Matrix KeepRotation(const Matrix &m)
Definition VectorTools.cc:509
static Matrix Perspective2(float left, float right, float bottom, float top, float near, float far)
Definition VectorTools.cc:588
void set_translate(Vector v)
Definition VectorTools.hh:337
static AxisAngle FindAxisAngle(const Matrix &m)
Definition VectorTools.cc:1001
void operator*=(const Matrix &m)
Definition VectorTools.hh:292
static Matrix MultiplyMatrix(const Matrix &m, int count)
Definition VectorTools.cc:701
static Matrix Scale(float x, float y, float z)
Definition VectorTools.cc:556
static Matrix RotateAroundAxisPoint(const Point &p, const Vector &v, float angle)
Definition VectorTools.cc:711
void setOutputFilter(double strength)
Definition VectorTools.cc:2099
void setD(double d)
Definition VectorTools.cc:1966
void setOutputRampRate(double rate)
Definition VectorTools.cc:2091
double clamp(double value, double min, double max)
Definition VectorTools.cc:2105
bool bounded(double value, double min, double max)
Definition VectorTools.cc:2111
void setDirection(bool reversed)
Definition VectorTools.cc:2004
Pid(double p, double i, double d)
Definition VectorTools.cc:1921
void setOutputLimits(double output)
Definition VectorTools.cc:1992
void checkSigns()
Definition VectorTools.cc:2115
void setSetpointRange(double range)
Definition VectorTools.cc:2095
void setP(double p)
Definition VectorTools.cc:1950
void setI(double i)
Definition VectorTools.cc:1954
void setPID(double p, double i, double d)
Definition VectorTools.cc:1975
void setMaxIOutput(double maximum)
Definition VectorTools.cc:1985
void init()
Definition VectorTools.cc:1929
void setF(double f)
Definition VectorTools.cc:1970
void reset()
Definition VectorTools.cc:2086
double getOutput()
Definition VectorTools.cc:2078
void setSetpoint(double setpoint)
Definition VectorTools.cc:2008
float ProjectP1(Point2d p_in_plane1)
Definition VectorTools.cc:1369
Line Intersection() const
Definition VectorTools.cc:1365
float ProjectP2(Point2d p_in_plane2)
Definition VectorTools.cc:1375
PlaneIntersection(const Plane &p1, const Plane &p2)
Definition VectorTools.cc:1360
Definition VectorTools.hh:350
Vector Normal(float length) const
Definition VectorTools.cc:1401
Vector u_x
Definition VectorTools.hh:375
void Normalize()
Definition VectorTools.hh:360
float CoordsX(Point p) const
Definition VectorTools.cc:1031
bool WhichSideOfPlane(Point p) const
Definition VectorTools.cc:1011
bool TriangleIntersection(Point p1, Point p2, Point p3, Point2d &res1, Point2d &res2)
Definition VectorTools.cc:1501
Vector u_y
Definition VectorTools.hh:376
void RotateAroundNormal(float angle_in_rad)
Definition VectorTools.cc:1392
bool LineSegmentIntersection(Point p1, Point p2, Point2d &outP)
Definition VectorTools.cc:1476
Point Navigate(const Point2d &p)
Definition VectorTools.cc:1416
float Dist(Point p) const
Definition VectorTools.cc:1019
float Dist2(Point p)
Definition VectorTools.cc:1417
Plane(Point u_p, Vector v1, Vector v2)
Definition VectorTools.hh:352
Vector PlaneNormal()
Definition VectorTools.hh:369
float CoordsY(Point p) const
Definition VectorTools.cc:1038
Plane()
Definition VectorTools.hh:359
Plane(const Plane &p)
Definition VectorTools.hh:358
Point u_p
Definition VectorTools.hh:374
Definition VectorTools.hh:1257
static PolyMatrix ZeroMatrix(int sx, int sy)
Definition VectorTools.cc:1819
int sy
Definition VectorTools.hh:1288
PolyMatrix & operator=(const PolyMatrix &m)
Definition VectorTools.hh:1270
~PolyMatrix()
Definition VectorTools.hh:1286
float read_val(int x, int y) const
Definition VectorTools.hh:1285
int sx
Definition VectorTools.hh:1288
PolyMatrix(const PolyMatrix &m)
Definition VectorTools.hh:1262
static PolyMatrix df_per_dx(int sx, int sy)
Definition VectorTools.cc:1839
float * grid
Definition VectorTools.hh:1289
PolyMatrix(int sx, int sy)
Definition VectorTools.hh:1259
void set_val(int x, int y, float val)
Definition VectorTools.hh:1284
static PolyMatrix IdentityMatrix(int sx, int sy)
Definition VectorTools.cc:1829
Definition VectorTools.hh:1293
static std::vector< float > add(std::vector< float > v1, std::vector< float > v2)
Definition VectorTools.cc:1800
static std::vector< float > basis_vector(int count, float val)
Definition VectorTools.cc:1753
static float mul(std::vector< float > v1, std::vector< float > v2)
Definition VectorTools.cc:1764
static std::vector< float > mul_matrix(const PolyMatrix &m, std::vector< float > &v)
Definition VectorTools.cc:1776
static std::vector< float > scale(std::vector< float > v, float c)
Definition VectorTools.cc:1792
Definition VectorTools.hh:787
float x
Definition VectorTools.hh:789
static Matrix QuarToMatrix(const Quarternion &q)
Definition VectorTools.cc:1144
friend Quarternion operator*(const Quarternion &a, float x)
Definition VectorTools.cc:1217
static Quarternion MatrixToQuar(const Matrix &m)
Definition VectorTools.cc:1194
friend Quarternion operator+(const Quarternion &a, const Quarternion &b)
Definition VectorTools.cc:1208
float w
Definition VectorTools.hh:789
static Quarternion NLerp(const Quarternion &q, const Quarternion &q2, float t)
Definition VectorTools.cc:1227
float y
Definition VectorTools.hh:789
float z
Definition VectorTools.hh:789
bool IntersectRect(Point tl2, Point br2)
Definition VectorTools.hh:891
RectProperties(Point tl, Point br)
Definition VectorTools.hh:890
SphereProperties2(Point center, float radius)
Definition VectorTools.hh:876
bool InsideSphere(Point p) const
Definition VectorTools.hh:877
Definition VectorTools.hh:106
float r
Definition VectorTools.hh:113
float alfa
Definition VectorTools.hh:114
void FromPoint(Point v)
Definition VectorTools.cc:97
Point center
Definition VectorTools.hh:112
SphericalPoint(Point center)
Definition VectorTools.hh:108
float beta
Definition VectorTools.hh:115
Point ToPoint()
Definition VectorTools.cc:87
static Point uv_to_bary(float u, float v)
Definition VectorTools.hh:1102
bool is_inside_circum_sphere(Point p) const
Definition VectorTools.cc:1745
Point Center() const
Definition VectorTools.hh:1055
float side_length_1_2() const
Definition VectorTools.hh:1063
Point barycentric_to_point(Point bary) const
Definition VectorTools.hh:1108
float side_length_2_3() const
Definition VectorTools.hh:1068
float side_length_3_1() const
Definition VectorTools.hh:1073
static Point texture_to_barycentric(Point2d v1, Point2d v2, Point2d v3, Point2d p)
Definition VectorTools.hh:1113
TriangleProperties(Point p1, Point p2, Point p3)
Definition VectorTools.hh:1054
float circum_radius() const
Definition VectorTools.hh:1095
Point circum_center() const
Definition VectorTools.hh:1078
static bool is_inside_triangle(Point bary)
Definition VectorTools.hh:1121
Definition VectorTools.hh:119
float w
Definition VectorTools.hh:121
float y
Definition VectorTools.hh:121
float x
Definition VectorTools.hh:121
float z
Definition VectorTools.hh:121
Definition VectorTools.hh:125
Point operator()(Point p) const
Definition VectorTools.hh:132
void operator+=(const Vector &aVec)
Definition VectorTools.hh:143
Point ApplyPoint(Point p) const
Definition VectorTools.hh:135
void operator/=(const float &aFloat)
Definition VectorTools.hh:162
static float Angle(const Vector &aVec, const Vector &aVec2)
Definition VectorTools.cc:81
Vector UnitConvert(const Vector &u_x, const Vector &u_y, const Vector &u_z)
Definition VectorTools.cc:180
static Vector UnitZ()
Definition VectorTools.cc:171
friend Vector operator+(const Vector &aVec, const Vector &aVec2)
Definition VectorTools.hh:150
static std::pair< Vector, Vector > SplitToComponents(Vector u, Vector u_x)
Definition VectorTools.hh:207
static Vector UnitY()
Definition VectorTools.cc:163
float Dist() const
Definition VectorTools.cc:141
float dy
Definition VectorTools.hh:268
friend std::istream & operator>>(std::istream &i, Vector &p)
Definition VectorTools.cc:60
friend Vector operator*(const Vector &aVec, const float &aFloat)
Definition VectorTools.hh:170
friend Vector operator-(const Point &p1, const Point &p2)
Definition VectorTools.hh:257
static Vector UnitX()
Definition VectorTools.cc:155
Vector()
Definition VectorTools.hh:128
void ZMultiply(const ComponentMultipliers &aMult)
Definition VectorTools.hh:240
Vector(const Vector &aVec)
Definition VectorTools.hh:130
static float DotProduct(const Vector &aVec, const Vector &aVec2)
Definition VectorTools.hh:185
Vector operator-() const
Definition VectorTools.hh:219
friend float Dist(const Vector &a, const Vector &b)
Definition VectorTools.hh:248
static Vector CrossProduct(const Vector &aVec, const Vector &aVec2)
Definition VectorTools.hh:193
void operator*=(const float &aFloat)
Definition VectorTools.hh:156
float dz
Definition VectorTools.hh:268
friend Vector operator*(const float &aFloat, const Vector &aVec)
Definition VectorTools.hh:176
void YMultiply(const ComponentMultipliers &aMult)
Definition VectorTools.hh:234
static float FindProjectionLength(Vector u, Vector u_x)
Definition VectorTools.hh:201
Vector(float ddx, float ddy, float ddz)
Definition VectorTools.hh:129
friend Vector operator/(const Vector &aVec, const float &aFloat)
Definition VectorTools.hh:180
Vector(const Point &aPoint)
Definition VectorTools.hh:131
friend std::ostream & operator<<(std::ostream &o, const Vector &p)
Definition VectorTools.cc:54
float dx
Definition VectorTools.hh:268
void XMultiply(const ComponentMultipliers &aMult)
Definition VectorTools.hh:228
Definition VectorTools.hh:1246
virtual void Draw(FlexiblePlane p, GC2d *gc) const =0
border radius
Definition gameapi_example.php:45
background color
Definition gameapi_example.php:46
d
Definition meshpage.php:3895
lazy data
Definition meshpage.php:1583
n< br > font size
Definition meshpage.php:3536
STL namespace.
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition VectorTools.hh:273
float angle
Definition VectorTools.hh:274
Vector axis
Definition VectorTools.hh:275
Definition VectorTools.hh:30
float end_x
Definition VectorTools.hh:32
float end_y
Definition VectorTools.hh:34
float start_z
Definition VectorTools.hh:35
float end_z
Definition VectorTools.hh:36
float start_y
Definition VectorTools.hh:33
float start_x
Definition VectorTools.hh:31
Definition VectorTools.hh:755
Point FindExternalCoords(Point internal_coords) const
Definition VectorTools.cc:1282
Vector u_y
Definition VectorTools.hh:762
Point FindInternalCoords(Point external_coords) const
Definition VectorTools.cc:1274
Point center
Definition VectorTools.hh:761
void Scale(float x)
Definition VectorTools.cc:1318
Vector u_x
Definition VectorTools.hh:762
void OrthoNormalize()
Definition VectorTools.cc:1287
void Reposition(Point p)
Definition VectorTools.hh:758
Vector u_z
Definition VectorTools.hh:762
Definition VectorTools.hh:1204
FlexiblePlane back_plane
Definition VectorTools.hh:1206
Point coords(float x, float y, float z)
Definition VectorTools.hh:1207
FlexiblePlane front_plane
Definition VectorTools.hh:1205
Definition test.cpp:88
Point p
Definition VectorTools.hh:781
Vector dir
Definition VectorTools.hh:782
Definition VectorTools.hh:910
friend std::ostream & operator<<(std::ostream &o, const Point2d &p)
Definition VectorTools.cc:41
float x
Definition VectorTools.hh:911
float y
Definition VectorTools.hh:911
void operator+=(const Point2d &p)
Definition VectorTools.hh:914
void operator-=(const Point2d &p)
Definition VectorTools.hh:920
void operator*=(float k)
Definition VectorTools.hh:926
static Point2d FromVector(const Vector2d &v)
Definition VectorTools.hh:1035
friend std::istream & operator>>(std::istream &i, Point2d &p)
Definition VectorTools.cc:46
friend Point2d operator+(const Point2d &p, const Point2d &p2)
Definition VectorTools.hh:931
friend Point2d operator*(float x, const Point2d &p)
Definition VectorTools.hh:946
static Point2d NewPoint(float x, float y)
Definition VectorTools.hh:912
Definition Parser.cc:60
float x
Definition Parser.cc:60
float Dist() const
Definition VectorTools.cc:150
friend std::istream & operator>>(std::istream &i, Point &p)
Definition VectorTools.cc:35
static Point Origo()
Definition VectorTools.hh:84
friend Point operator+(const Point &p, const Vector &v)
Definition VectorTools.cc:120
friend bool operator==(const Point &p1, const Point &p2)
Definition VectorTools.hh:64
float y
Definition Parser.cc:60
friend bool operator!=(const Point &p1, const Point &p2)
Definition VectorTools.hh:72
void operator-=(const Vector &v)
Definition VectorTools.cc:127
void operator+=(const Vector &v)
Definition VectorTools.cc:110
friend Point operator-(const Point &p, const Vector &v)
Definition VectorTools.cc:133
float z
Definition Parser.cc:60
Point(float xx, float yy, float zz)
Definition VectorTools.hh:62
Point()
Definition VectorTools.hh:61
static Point Interpolate(const Point &aVec, const Point &aVec2, float aVal)
Definition VectorTools.hh:85
friend std::ostream & operator<<(std::ostream &o, const Point &p)
Definition VectorTools.cc:30
Point get_point(Point p1, Point p2) const
Definition VectorTools.hh:856
float dist
Definition VectorTools.hh:865
float span_pos
Definition VectorTools.hh:864
float angle
Definition VectorTools.hh:866
PoseLine(Point p1, Point p2, Point p)
Definition VectorTools.hh:850
Definition VectorTools.hh:749
void OrthoNormalize()
Definition VectorTools.cc:1300
Vector u_x
Definition VectorTools.hh:752
void Scale(float x)
Definition VectorTools.cc:1312
Vector u_y
Definition VectorTools.hh:752
Vector u_z
Definition VectorTools.hh:752
Definition VectorTools.hh:972
void operator/=(float x)
Definition VectorTools.hh:980
float Dist() const
Definition VectorTools.hh:986
void operator*=(float x)
Definition VectorTools.hh:975
float dy
Definition VectorTools.hh:973
static float DotProduct(const Vector2d &v, const Vector2d &v2)
Definition VectorTools.hh:987
friend Vector2d operator*(const Vector2d &p, float x)
Definition VectorTools.hh:1013
float dx
Definition VectorTools.hh:973
friend Vector2d operator+(const Vector2d &p1, const Vector2d &p2)
Definition VectorTools.hh:999
static Vector2d FromPoint(const Point2d &p)
Definition VectorTools.hh:991
friend Vector2d operator*(float x, const Vector2d &p)
Definition VectorTools.hh:1006
float Length() const
Definition VectorTools.cc:1390
Vector2d operator-()
Definition VectorTools.hh:998