VecMath.hpp   VecMath.hpp 
skipping to change at line 21 skipping to change at line 21
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
// Template vector and matrix library. // Template vector and matrix library.
// Use column-major matrices, and in vectors, order vertices like this: // Use OpenGL compatible ordering ie. you can pass a matrix or vector to
// x, y, z, w (or r, g, b, a), so they can be passed to Renderer. // openGL functions without changes in the ordering
#ifndef _VECMATH_H_ #ifndef _VECMATH_H_
#define _VECMATH_H_ #define _VECMATH_H_
#include "config.h"
#include <cmath> #include <cmath>
#include <QString> #include <QString>
template<class T> class Vector2; template<class T> class Vector2;
template<class T> class Vector3; template<class T> class Vector3;
template<class T> class Vector4; template<class T> class Vector4;
template<class T> class Matrix4; template<class T> class Matrix4;
typedef Vector2<double> Vec2d; typedef Vector2<double> Vec2d;
typedef Vector2<float> Vec2f; typedef Vector2<float> Vec2f;
typedef Vector2<int> Vec2i; typedef Vector2<int> Vec2i;
//! @typedef Vec3d //! @typedef Vec3d
//! A 3d vector of doubles. //! A 3d vector of doubles compatible with openGL.
typedef Vector3<double> Vec3d; typedef Vector3<double> Vec3d;
//! @typedef Vec3f //! @typedef Vec3f
//! A 3d vector of floats. //! A 3d vector of floats compatible with openGL.
typedef Vector3<float> Vec3f; typedef Vector3<float> Vec3f;
//! @typedef Vec4d //! @typedef Vec4d
//! A 4d vector of doubles. //! A 4d vector of doubles compatible with openGL.
typedef Vector4<double> Vec4d; typedef Vector4<double> Vec4d;
//! @typedef Vec4f //! @typedef Vec4f
//! A 4d vector of floats. //! A 4d vector of floats compatible with openGL.
typedef Vector4<float> Vec4f; typedef Vector4<float> Vec4f;
//! @typedef Vec4i //! @typedef Vec4i
//! A 4d vector of ints. //! A 4d vector of ints compatible with openGL.
typedef Vector4<int> Vec4i; typedef Vector4<int> Vec4i;
//! @typedef Mat4d //! @typedef Mat4d
//! A 4x4 matrix of doubles. //! A 4x4 matrix of doubles compatible with openGL.
typedef Matrix4<double> Mat4d; typedef Matrix4<double> Mat4d;
//! @typedef Mat4f //! @typedef Mat4f
//! A 4x4 matrix of floats. //! A 4x4 matrix of floats compatible with openGL.
typedef Matrix4<float> Mat4f; typedef Matrix4<float> Mat4f;
//! @class Vector2 //! @class Vector2
//! A templatized 2d vector. //! A templatized 2d vector compatible with openGL.
//! Use Vec2d or Vec2f typdef for vectors of double and float respectively. //! Use Vec2d or Vec2f typdef for vectors of double and float respectively.
template<class T> class Vector2 template<class T> class Vector2
{ {
public: public:
inline Vector2(); inline Vector2();
inline Vector2(T, T); inline Vector2(T, T);
inline Vector2& operator=(const T*); inline Vector2& operator=(const T*);
inline void set(T, T); inline void set(T, T);
skipping to change at line 111 skipping to change at line 113
inline T dot(const Vector2<T>&) const; inline T dot(const Vector2<T>&) const;
inline T length() const; inline T length() const;
inline T lengthSquared() const; inline T lengthSquared() const;
inline void normalize(); inline void normalize();
T v[2]; T v[2];
}; };
//! @class Vector3 //! @class Vector3
//! A templatized 3d vector. //! A templatized 3d vector compatible with openGL.
//! Use Vec3d or Vec3f typdef for vectors of double and float respectively. //! Use Vec3d or Vec3f typdef for vectors of double and float respectively.
template<class T> class Vector3 template<class T> class Vector3
{ {
public: public:
inline Vector3(); inline Vector3();
//inline Vector3(const Vector3&); //inline Vector3(const Vector3&);
//template <class T2> inline Vector3(const Vector3<T2>&); //template <class T2> inline Vector3(const Vector3<T2>&);
inline Vector3(T, T, T); inline Vector3(T, T, T);
inline Vector3(T); inline Vector3(T);
skipping to change at line 176 skipping to change at line 178
inline void transfo4d(const Mat4d&); inline void transfo4d(const Mat4d&);
inline void transfo4d(const Mat4f&); inline void transfo4d(const Mat4f&);
T v[3]; // The 3 values T v[3]; // The 3 values
QString toString() const {return QString("[%1, %2, %3]").arg(v[0]).a rg(v[1]).arg(v[2]);} QString toString() const {return QString("[%1, %2, %3]").arg(v[0]).a rg(v[1]).arg(v[2]);}
QString toStringLonLat() const {return QString("[") + QString::numbe r(longitude()*180./M_PI, 'g', 12) + "," + QString::number(latitude()*180./M _PI, 'g', 12)+"]";} QString toStringLonLat() const {return QString("[") + QString::numbe r(longitude()*180./M_PI, 'g', 12) + "," + QString::number(latitude()*180./M _PI, 'g', 12)+"]";}
}; };
//! @class Vector4 //! @class Vector4
//! A templatized 4d vector. //! A templatized 4d vector compatible with openGL.
//! Use Vec4d or Vec4f typdef for vectors of double and float respectively. //! Use Vec4d or Vec4f typdef for vectors of double and float respectively.
template<class T> class Vector4 template<class T> class Vector4
{ {
public: public:
inline Vector4(); inline Vector4();
inline Vector4(const Vector3<T>&); inline Vector4(const Vector3<T>&);
inline Vector4(T, T, T); inline Vector4(T, T, T);
inline Vector4(T, T, T, T); inline Vector4(T, T, T, T);
inline Vector4& operator=(const Vector3<T>&); inline Vector4& operator=(const Vector3<T>&);
skipping to change at line 224 skipping to change at line 226
inline T length() const; inline T length() const;
inline T lengthSquared() const; inline T lengthSquared() const;
inline void normalize(); inline void normalize();
inline void transfo4d(const Mat4d&); inline void transfo4d(const Mat4d&);
T v[4]; // The 4 values T v[4]; // The 4 values
}; };
//! @class Matrix4 //! @class Matrix4
//! A templatized column-major 4x4 matrix. //! A templatized column-major 4x4 matrix compatible with openGL.
//! Use Mat4d or Mat4f typdef for matrices of doubles and floats respective ly. //! Use Mat4d or Mat4f typdef for matrices of doubles and floats respective ly.
template<class T> class Matrix4 template<class T> class Matrix4
{ {
public: public:
Matrix4(); Matrix4();
Matrix4(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T); Matrix4(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);
Matrix4(const T*); Matrix4(const T*);
Matrix4(const Vector4<T>&, const Vector4<T>&, Matrix4(const Vector4<T>&, const Vector4<T>&,
const Vector4<T>&, const Vector4<T>&); const Vector4<T>&, const Vector4<T>&);
skipping to change at line 973 skipping to change at line 975
* Code ripped from the GLU library * Code ripped from the GLU library
* Compute inverse of 4x4 transformation matrix. * Compute inverse of 4x4 transformation matrix.
* Code contributed by Jacques Leroy jle@star.be * Code contributed by Jacques Leroy jle@star.be
* Return zero matrix on failure (singular matrix) * Return zero matrix on failure (singular matrix)
*/ */
template<class T> Matrix4<T> Matrix4<T>::inverse() const template<class T> Matrix4<T> Matrix4<T>::inverse() const
{ {
const T * m = r; const T * m = r;
T out[16]; T out[16];
/* NB. Matrices used by StelRenderer are COLUMN major. */ /* NB. OpenGL Matrices are COLUMN major. */
#define SWAP_ROWS(a, b) { T *_tmp = a; (a)=(b); (b)=_tmp; } #define SWAP_ROWS(a, b) { T *_tmp = a; (a)=(b); (b)=_tmp; }
#define MAT(m,r,c) (m)[(c)*4+(r)] #define MAT(m,r,c) (m)[(c)*4+(r)]
T wtmp[4][8]; T wtmp[4][8];
T m0, m1, m2, m3, s; T m0, m1, m2, m3, s;
T *r0, *r1, *r2, *r3; T *r0, *r1, *r2, *r3;
r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3]; r0 = wtmp[0], r1 = wtmp[1], r2 = wtmp[2], r3 = wtmp[3];
r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1), r0[0] = MAT(m, 0, 0), r0[1] = MAT(m, 0, 1),
 End of changes. 14 change blocks. 
14 lines changed or deleted 16 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/