Документ взят из кэша поисковой машины. Адрес оригинального документа : http://astro.uni-altai.ru/~aw/stellarium/api/VecMath_8hpp_source.html
Дата изменения: Unknown
Дата индексирования: Fri Feb 28 07:31:36 2014
Кодировка:

Поисковые слова: m 8
Stellarium: core/VecMath.hpp Source File
Stellarium 0.12.3
VecMath.hpp
1 /*
2  *
3  * Copyright (C) 2003 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) 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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 // Template vector and matrix library.
21 // Use column-major matrices, and in vectors, order vertices like this:
22 // x, y, z, w (or r, g, b, a), so they can be passed to Renderer.
23 
24 #ifndef _VECMATH_H_
25 #define _VECMATH_H_
26 
27 #include <cmath>
28 #include <QString>
29 
30 template<class T> class Vector2;
31 template<class T> class Vector3;
32 template<class T> class Vector4;
33 template<class T> class Matrix4;
34 
35 typedef Vector2<double> Vec2d;
36 typedef Vector2<float> Vec2f;
37 typedef Vector2<int> Vec2i;
38 
41 typedef Vector3<double> Vec3d;
42 
45 typedef Vector3<float> Vec3f;
46 
49 typedef Vector4<double> Vec4d;
50 
53 typedef Vector4<float> Vec4f;
54 
57 typedef Vector4<int> Vec4i;
58 
61 typedef Matrix4<double> Mat4d;
62 
65 typedef Matrix4<float> Mat4f;
66 
67 
71 template<class T> class Vector2
72 {
73 public:
74  inline Vector2();
75  inline Vector2(T, T);
76 
77  inline Vector2& operator=(const T*);
78  inline void set(T, T);
79 
80  inline bool operator==(const Vector2<T>&) const;
81  inline bool operator!=(const Vector2<T>&) const;
82 
83  inline const T& operator[](int x) const;
84  inline T& operator[](int);
85  inline operator const T*() const;
86  inline operator T*();
87 
88  inline void operator+=(const Vector2<T>&);
89  inline void operator-=(const Vector2<T>&);
90  inline void operator*=(T);
91  inline void operator/=(T);
92 
93  inline Vector2 operator-(const Vector2<T>&) const;
94  inline Vector2 operator+(const Vector2<T>&) const;
95 
96  inline Vector2 operator-() const;
97  inline Vector2 operator+() const;
98 
99  inline Vector2 operator*(T) const;
100  inline Vector2 operator/(T) const;
101 
102 
103  inline T dot(const Vector2<T>&) const;
104 
105  inline T length() const;
106  inline T lengthSquared() const;
107  inline void normalize();
108 
109  T v[2];
110 };
111 
112 
116 template<class T> class Vector3
117 {
118 public:
119  inline Vector3();
120  //inline Vector3(const Vector3&);
121  //template <class T2> inline Vector3(const Vector3<T2>&);
122  inline Vector3(T, T, T);
123  inline Vector3(T);
124 
125  //inline Vector3& operator=(const Vector3&);
126  inline Vector3& operator=(const T*);
127  //template <class T2> inline Vector3& operator=(const Vector3<T2>&);
128  inline void set(T, T, T);
129 
130  inline bool operator==(const Vector3<T>&) const;
131  inline bool operator!=(const Vector3<T>&) const;
132 
133  inline T& operator[](int);
134  inline const T& operator[](int) const;
135  inline operator const T*() const;
136  inline operator T*();
137  inline const T* data() const {return v;}
138  inline T* data() {return v;}
139 
140  inline void operator+=(const Vector3<T>&);
141  inline void operator-=(const Vector3<T>&);
142  inline void operator*=(T);
143  inline void operator/=(T);
144 
145  inline Vector3 operator-(const Vector3<T>&) const;
146  inline Vector3 operator+(const Vector3<T>&) const;
147 
148  inline Vector3 operator-() const;
149  inline Vector3 operator+() const;
150 
151  inline Vector3 operator*(T) const;
152  inline Vector3 operator/(T) const;
153 
154 
155  inline T dot(const Vector3<T>&) const;
156  inline Vector3 operator^(const Vector3<T>&) const;
157 
158  // Return latitude in rad
159  inline T latitude() const;
160  // Return longitude in rad
161  inline T longitude() const;
162 
163  // Distance in radian between two
164  inline T angle(const Vector3<T>&) const;
165  inline T angleNormalized(const Vector3<T>&) const;
166 
167  inline T length() const;
168  inline T lengthSquared() const;
169  inline void normalize();
170 
171  inline void transfo4d(const Mat4d&);
172  inline void transfo4d(const Mat4f&);
173  T v[3]; // The 3 values
174 
175  QString toString() const {return QString("[%1, %2, %3]").arg(v[0]).arg(v[1]).arg(v[2]);}
176  QString toStringLonLat() const {return QString("[") + QString::number(longitude()*180./M_PI, 'g', 12) + "," + QString::number(latitude()*180./M_PI, 'g', 12)+"]";}
177 };
178 
179 
183 template<class T> class Vector4