Support unrar64.dll
[xy_vsfilter.git] / src / subpic / CoordGeom.h
blob4084d8b25d615f6c9798d9321d0dbe789d8cdca6
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #pragma once
24 #ifndef PI
25 #define PI (3.141592654f)
26 #endif
28 #define DegToRad(d) ((d)*PI/180.0)
29 #define RadToDeg(r) ((r)*180.0/PI)
30 #define Sgn(d) (IsZero(d) ? 0 : (d) > 0 ? 1 : -1)
31 #define SgnPow(d, p) (IsZero(d) ? 0 : (pow(fabs(d), p) * Sgn(d)))
33 class Vector
35 public:
36 float x, y, z;
38 Vector() {x = y = z = 0;}
39 Vector(float x, float y, float z);
40 void Set(float x, float y, float z);
42 Vector Normal(Vector& a, Vector& b);
43 float Angle(Vector& a, Vector& b);
44 float Angle(Vector& a);
45 void Angle(float& u, float& v); // returns spherical coords in radian, -PI/2 <= u <= PI/2, -PI <= v <= PI
46 Vector Angle(); // does like prev., returns 'u' in 'ret.x', and 'v' in 'ret.y'
48 Vector Unit();
49 Vector& Unitalize();
50 float Length();
51 float Sum(); // x + y + z
52 float CrossSum(); // xy + xz + yz
53 Vector Cross(); // xy, xz, yz
54 Vector Pow(float exp);
56 Vector& Min(Vector& a);
57 Vector& Max(Vector& a);
58 Vector Abs();
60 Vector Reflect(Vector& n);
61 Vector Refract(Vector& n, float nFront, float nBack, float* nOut = NULL);
62 Vector Refract2(Vector& n, float nFrom, float nTo, float* nOut = NULL);
64 Vector operator - ();
65 float& operator [] (int i);
67 float operator | (Vector& v); // dot
68 Vector operator % (Vector& v); // cross
70 bool operator == (const Vector& v) const;
71 bool operator != (const Vector& v) const;
73 Vector operator + (float d);
74 Vector operator + (Vector& v);
75 Vector operator - (float d);
76 Vector operator - (Vector& v);
77 Vector operator * (float d);
78 Vector operator * (Vector& v);
79 Vector operator / (float d);
80 Vector operator / (Vector& v);
81 Vector& operator += (float d);
82 Vector& operator += (Vector& v);
83 Vector& operator -= (float d);
84 Vector& operator -= (Vector& v);
85 Vector& operator *= (float d);
86 Vector& operator *= (Vector& v);
87 Vector& operator /= (float d);
88 Vector& operator /= (Vector& v);
91 class Ray
93 public:
94 Vector p, d;
96 Ray() {}
97 Ray(Vector& p, Vector& d);
98 void Set(Vector& p, Vector& d);
100 float GetDistanceFrom(Ray& r); // r = plane
101 float GetDistanceFrom(Vector& v); // v = point
103 Vector operator [] (float t);
106 class XForm
108 class Matrix
110 public:
111 float mat[4][4];
113 Matrix();
114 void Initalize();
116 Matrix operator * (Matrix& m);
117 Matrix& operator *= (Matrix& m);
118 } m;
120 bool m_isWorldToLocal;
122 public:
123 XForm() {}
124 XForm(Ray& r, Vector& s, bool isWorldToLocal = true);
126 void Initalize();
127 void Initalize(Ray& r, Vector& s, bool isWorldToLocal = true);
129 void operator *= (Vector& s); // scale
130 void operator += (Vector& t); // translate
131 void operator <<= (Vector& r); // rotate
133 void operator /= (Vector& s); // scale
134 void operator -= (Vector& t); // translate
135 void operator >>= (Vector& r); // rotate
137 // transformations
138 Vector operator < (Vector& n); // normal
139 Vector operator << (Vector& v); // vector
140 Ray operator << (Ray& r); // ray