Varie correzioni.
This commit is contained in:
parent
807aec3803
commit
edb97e9493
|
@ -111,11 +111,11 @@ public:
|
|||
void SetZero();
|
||||
void SetIdentity();
|
||||
void SetDiagonal(const T k);
|
||||
void SetScale(const T sx, const T sy, const T sz);
|
||||
void SetTranslate(const Point3<T> &t);
|
||||
void SetTranslate(const T sx, const T sy, const T sz);
|
||||
Matrix44 &SetScale(const T sx, const T sy, const T sz);
|
||||
Matrix44 &SetTranslate(const Point3<T> &t);
|
||||
Matrix44 &SetTranslate(const T sx, const T sy, const T sz);
|
||||
///use radiants for angle.
|
||||
void SetRotate(T angle, const Point3<T> & axis);
|
||||
Matrix44 &SetRotate(T angle, const Point3<T> & axis);
|
||||
|
||||
T Determinant() const;
|
||||
};
|
||||
|
@ -142,10 +142,10 @@ protected:
|
|||
/*** Postmultiply (old Apply in the old interface).
|
||||
* SetTranslate, SetScale, SetRotate prepare the matrix for this.
|
||||
*/
|
||||
template <class T> Point4<T> operator*(const Point4<T> &p, const Matrix44<T> &m);
|
||||
template <class T> Point3<T> operator*(const Point3<T> &p, const Matrix44<T> &m);
|
||||
|
||||
///Premultiply (old Project in the old interface)
|
||||
template <class T> Point4<T> operator*(const Matrix44<T> &m, const Point4<T> &p);
|
||||
template <class T> Point3<T> operator*(const Matrix44<T> &m, const Point3<T> &p);
|
||||
|
||||
template <class T> Matrix44<T> &Transpose(Matrix44<T> &m);
|
||||
template <class T> Matrix44<T> &Invert(Matrix44<T> &m);
|
||||
|
@ -201,8 +201,8 @@ template <class T> Matrix44<T> Matrix44<T>::operator*(const Matrix44 &m) const {
|
|||
for(int j = 0; j < 4; j++) {
|
||||
T t = 0.0;
|
||||
for(int k = 0; k < 4; k++)
|
||||
t += element[i][k] * m.element[k][j];
|
||||
ret.element[i][j] = t;
|
||||
t += element(i, k) * m.element(k, j);
|
||||
ret.element(i, j) = t;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ template <class T> Point4<T> Matrix44<T>::operator*(const Point4<T> &v) const {
|
|||
for(int i = 0; i < 4; i++){
|
||||
T t = 0.0;
|
||||
for(int k = 0; k < 4; k++)
|
||||
t += element[i][k] * v[k];
|
||||
t += element(i,k) * v[k];
|
||||
ret[i] = t;
|
||||
}
|
||||
return ret;
|
||||
|
@ -255,7 +255,9 @@ template <class T> void Matrix44<T>::operator-=(const Matrix44 &m) {
|
|||
operator[](i) -= m[i];
|
||||
}
|
||||
template <class T> void Matrix44<T>::operator*=( const Matrix44 & m ) {
|
||||
for(int i = 0; i < 4; i++) {
|
||||
*this = *this *m;
|
||||
|
||||
/*for(int i = 0; i < 4; i++) { //sbagliato
|
||||
Point4<T> t(0, 0, 0, 0);
|
||||
for(int k = 0; k < 4; k++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
|
@ -264,7 +266,7 @@ template <class T> void Matrix44<T>::operator*=( const Matrix44 & m ) {
|
|||
}
|
||||
for(int l = 0; l < 4; l++)
|
||||
element(i, l) = t[l];
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
template <class T> void Matrix44<T>::operator*=( const T k ) {
|
||||
|
@ -289,27 +291,30 @@ template <class T> void Matrix44<T>::SetDiagonal(const T k) {
|
|||
element(3, 3) = 1;
|
||||
}
|
||||
|
||||
template <class T> void Matrix44<T>::SetScale(const T sx, const T sy, const T sz) {
|
||||
template <class T> Matrix44<T> &Matrix44<T>::SetScale(const T sx, const T sy, const T sz) {
|
||||
SetZero();
|
||||
element(0, 0) = sx;
|
||||
element(1, 1) = sy;
|
||||
element(2, 2) = sz;
|
||||
element(3, 3) = 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T> void Matrix44<T>::SetTranslate(const Point3<T> &t) {
|
||||
template <class T> Matrix44<T> &Matrix44<T>::SetTranslate(const Point3<T> &t) {
|
||||
SetTranslate(t[0], t[1], t[2]);
|
||||
return *this;
|
||||
}
|
||||
template <class T> void Matrix44<T>::SetTranslate(const T sx, const T sy, const T sz) {
|
||||
template <class T> Matrix44<T> &Matrix44<T>::SetTranslate(const T sx, const T sy, const T sz) {
|
||||
SetIdentity();
|
||||
element(3, 0) = sx;
|
||||
element(3, 1) = sy;
|
||||
element(3, 2) = sz;
|
||||
return *this;
|
||||
}
|
||||
template <class T> void Matrix44<T>::SetRotate(T angle, const Point3<T> & axis) {
|
||||
template <class T> Matrix44<T> &Matrix44<T>::SetRotate(T angle, const Point3<T> & axis) {
|
||||
//angle = angle*(T)3.14159265358979323846/180; e' in radianti!
|
||||
T c = Math<T>::Cos(angle);
|
||||
T s = Math<T>::Sin(angle);
|
||||
T c = math::Cos(angle);
|
||||
T s = math::Sin(angle);
|
||||
T q = 1-c;
|
||||
Point3<T> t = axis;
|
||||
t.Normalize();
|
||||
|
@ -329,6 +334,7 @@ template <class T> void Matrix44<T>::SetRotate(T angle, const Point3<T> & axis)
|
|||
element(1,3) = 0;
|
||||
element(2,3) = 0;
|
||||
element(3,3) = 1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -338,25 +344,25 @@ template <class T> T Matrix44<T>::Determinant() const {
|
|||
}
|
||||
|
||||
|
||||
template <class T> Point4<T> operator*(const Matrix44<T> &m, const Point4<T> &p) {
|
||||
template <class T> Point3<T> operator*(const Matrix44<T> &m, const Point3<T> &p) {
|
||||
T w;
|
||||
Point4<T> s;
|
||||
s.x() = a[0][0]*p.x() + a[0][1]*p.y() + a[0][2]*p.z() + a[0][3];
|
||||
s.y() = a[1][0]*p.x() + a[1][1]*p.y() + a[1][2]*p.z() + a[1][3];
|
||||
s.z() = a[2][0]*p.x() + a[2][1]*p.y() + a[2][2]*p.z() + a[2][3];
|
||||
s.w() = a[3][0]*p.x() + a[3][1]*p.y() + a[3][2]*p.z() + a[3][3];
|
||||
if(s.w()!= 0) s /= s.w();
|
||||
Point3<T> s;
|
||||
s[0] = m.element(0, 0)*p[0] + m.element(0, 1)*p[1] + m.element(0, 2)*p[2] + m.element(0, 3);
|
||||
s[1] = m.element(1, 0)*p[0] + m.element(1, 1)*p[1] + m.element(1, 2)*p[2] + m.element(1, 3);
|
||||
s[2] = m.element(2, 0)*p[0] + m.element(2, 1)*p[1] + m.element(2, 2)*p[2] + m.element(2, 3);
|
||||
w = m.element(3, 0)*p[0] + m.element(3, 1)*p[1] + m.element(3, 2)*p[2] + m.element(3, 3);
|
||||
if(w!= 0) s /= w;
|
||||
return s;
|
||||
}
|
||||
|
||||
template <class T> Point4<T> operator*(const Point4<T> &p, const Matrix44<T> &m) {
|
||||
template <class T> Point3<T> operator*(const Point3<T> &p, const Matrix44<T> &m) {
|
||||
T w;
|
||||
Point4<T> s;
|
||||
s.x() = a[0][0]*p.x() + a[1][0]*p.y() + a[2][0]*p.z() + a[3][0];
|
||||
s.y() = a[0][1]*p.x() + a[1][1]*p.y() + a[2][1]*p.z() + a[3][1];
|
||||
s.z() = a[0][2]*p.x() + a[1][2]*p.y() + a[2][2]*p.z() + a[3][2];
|
||||
s.w() = a[0][3]*p.x() + a[1][3]*p.y() + a[2][3]*p.z() + a[3][3];
|
||||
if(s.w() != 0) s /= s.w();
|
||||
Point3<T> s;
|
||||
s[0] = m.element(0, 0)*p[0] + m.element(1, 0)*p[1] + m.element(2, 0)*p[2] + m.element(3, 0);
|
||||
s[1] = m.element(0, 1)*p[0] + m.element(1, 1)*p[1] + m.element(2, 1)*p[2] + m.element(3, 1);
|
||||
s[2] = m.element(0, 2)*p[0] + m.element(1, 2)*p[1] + m.element(2, 2)*p[2] + m.element(3, 2);
|
||||
w = m.element(0, 3)*p[0] + m.element(1, 3)*p[1] + m.element(2, 3)*p[2] + m.element(3, 3);
|
||||
if(w != 0) s /= w;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
//Quaternion &operator*=(S d);
|
||||
Quaternion operator*(const Quaternion &q) const;
|
||||
Quaternion &operator*=(const Quaternion &q);
|
||||
void Conjugate();
|
||||
void Invert();
|
||||
|
||||
void FromAxis(const S phi, const Point3<S> &a);
|
||||
void ToAxis(S &phi, Point3<S> &a ) const;
|
||||
|
@ -84,7 +84,7 @@ template <class S> Quaternion<S> &Quaternion<S>::operator*=(const Quaternion &q)
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <class S> void Quaternion<S>::Conjugate() {
|
||||
template <class S> void Quaternion<S>::Invert() {
|
||||
V(1)*=-1;
|
||||
V(2)*=-1;
|
||||
V(3)*=-1;
|
||||
|
@ -92,12 +92,14 @@ template <class S> void Quaternion<S>::Conjugate() {
|
|||
|
||||
|
||||
template <class S> void Quaternion<S>::FromAxis(const S phi, const Point3<S> &a) {
|
||||
Point3<S> b = a;
|
||||
b.Normalize();
|
||||
S s = math::Sin(phi/(S(2.0)));
|
||||
|
||||
V(0) = math::Cos(phi/(S(2.0)));
|
||||
V(1) = a[0]*s;
|
||||
V(2) = a[1]*s;
|
||||
V(3) = a[2]*s;
|
||||
V(1) = b[0]*s;
|
||||
V(2) = b[1]*s;
|
||||
V(3) = b[2]*s;
|
||||
}
|
||||
|
||||
template <class S> void Quaternion<S>::ToAxis(S &phi, Point3<S> &a) const {
|
||||
|
@ -116,7 +118,7 @@ template <class S> void Quaternion<S>::ToAxis(S &phi, Point3<S> &a) const {
|
|||
|
||||
template <class S> Point3<S> Quaternion<S>::Rotate(const Point3<S> p) const {
|
||||
Quaternion<S> co = *this;
|
||||
co.Conjugate();
|
||||
co.Invert();
|
||||
|
||||
Quaternion<S> tmp(0, p.V(0), p.V(1), p.V(2));
|
||||
|
||||
|
|
Loading…
Reference in New Issue