bugfixes in vecmat3
This commit is contained in:
1 parent
dc7f9bef93
commit
e9fa634843
2 files changed
+17
-17
No files matched your search
+13
-13
@@ -27,15 +27,15 @@ namespace LA_Vecmat3 {
|
|||||||
//http://en.wikipedia.org/wiki/Fast_inverse_square_root
|
//http://en.wikipedia.org/wiki/Fast_inverse_square_root
|
||||||
float fast_sqrtinv(float number )
|
float fast_sqrtinv(float number )
|
||||||
{
|
{
|
||||||
long i;
|
int32_t i; //must be 32 bits like float
|
||||||
float x2, y;
|
float x2, y;
|
||||||
const float threehalfs = 1.5F;
|
const float threehalfs = 1.5F;
|
||||||
|
|
||||||
x2 = number * 0.5F;
|
x2 = number * 0.5F;
|
||||||
y = number;
|
y = number;
|
||||||
i = * ( long * ) &y; // evil floating point bit level hacking
|
memcpy(&i,&y,sizeof(i)); // evil floating point bit level hacking
|
||||||
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
|
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
|
||||||
y = * ( float * ) &i;
|
memcpy(&y,&i,sizeof(y));
|
||||||
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
|
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
|
||||||
y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
|
y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
|
||||||
|
|
||||||
@@ -355,7 +355,7 @@ case Euler_case('y','z','y'):
|
|||||||
a[1][0]= c3*s2;
|
a[1][0]= c3*s2;
|
||||||
a[1][1]= c2;
|
a[1][1]= c2;
|
||||||
a[1][2]= s2*s3;
|
a[1][2]= s2*s3;
|
||||||
a[2][0]= -c1*s3;
|
a[2][0]= -c1*s3-c2*c3*s1;
|
||||||
a[2][1]= s1*s2;
|
a[2][1]= s1*s2;
|
||||||
a[2][2]= c1*c3-c2*s1*s3;
|
a[2][2]= c1*c3-c2*s1*s3;
|
||||||
}
|
}
|
||||||
@@ -449,7 +449,7 @@ case Euler_case('z','y','x'):
|
|||||||
{
|
{
|
||||||
a[0][0]= c1*c2;
|
a[0][0]= c1*c2;
|
||||||
a[0][1]= c1*s2*s3-c3*s1;
|
a[0][1]= c1*s2*s3-c3*s1;
|
||||||
a[0][2]= s1*s2+c1*c3*s2;
|
a[0][2]= s1*s3+c1*c3*s2;
|
||||||
a[1][0]= c2*s1;
|
a[1][0]= c2*s1;
|
||||||
a[1][1]= c1*c3+s1*s2*s3;
|
a[1][1]= c1*c3+s1*s2*s3;
|
||||||
a[1][2]= c3*s1*s2-c1*s3;
|
a[1][2]= c3*s1*s2-c1*s3;
|
||||||
@@ -560,7 +560,7 @@ case Euler_case('x','y','z'):
|
|||||||
|
|
||||||
case Euler_case('y','x','z'):
|
case Euler_case('y','x','z'):
|
||||||
{
|
{
|
||||||
eul[0]=atan2(m31,m33);
|
eul[0]=atan2(m13,m33);
|
||||||
eul[1]=atan2(-m23,sqrt(1-m23*m23));
|
eul[1]=atan2(-m23,sqrt(1-m23*m23));
|
||||||
eul[2]=atan2(m21,m22);
|
eul[2]=atan2(m21,m22);
|
||||||
}
|
}
|
||||||
@@ -662,18 +662,18 @@ q[2][1]=q[1][2]=tmp;
|
|||||||
|
|
||||||
|
|
||||||
#ifndef QUAT_NO_RANDOM
|
#ifndef QUAT_NO_RANDOM
|
||||||
template <>
|
template <typename T>
|
||||||
void Vec3<double>::randomize(const double x)
|
void Vec3<T>::randomize(const T x)
|
||||||
{
|
{
|
||||||
for(int i=0;i<3;++i) q[i]=x*RANDDOUBLESIGNED();
|
for(int i=0;i<3;++i) q[i]=x*(T)RANDDOUBLESIGNED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <>
|
template <typename T>
|
||||||
void Mat3<double>::randomize(const double x, const bool symmetric)
|
void Mat3<T>::randomize(const T x, const bool symmetric)
|
||||||
{
|
{
|
||||||
if(symmetric) for(int i=0;i<3;++i) for(int j=0; j<=i; ++j) q[j][i]=q[i][j]=x*RANDDOUBLESIGNED();
|
if(symmetric) for(int i=0;i<3;++i) for(int j=0; j<=i; ++j) q[j][i]=q[i][j]=x*(T)RANDDOUBLESIGNED();
|
||||||
else for(int i=0;i<3;++i) for(int j=0; j<3; ++j) q[i][j]=x*RANDDOUBLESIGNED();
|
else for(int i=0;i<3;++i) for(int j=0; j<3; ++j) q[i][j]=x*(T)RANDDOUBLESIGNED();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifndef NO_NUMERIC_LIMITS
|
#ifndef NO_NUMERIC_LIMITS
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <type_traits>
|
|
||||||
#endif
|
#endif
|
||||||
|
#include <type_traits> //freestanding, needed for the deleted integer constructor of Mat3
|
||||||
|
|
||||||
namespace LA_Vecmat3 {
|
namespace LA_Vecmat3 {
|
||||||
|
|
||||||
@@ -115,8 +115,8 @@ public:
|
|||||||
//C-style IO
|
//C-style IO
|
||||||
int fprintf(FILE *f, const char *format) const {return ::fprintf(f,format,q[0],q[1],q[2]);};
|
int fprintf(FILE *f, const char *format) const {return ::fprintf(f,format,q[0],q[1],q[2]);};
|
||||||
int sprintf(char *f, const char *format) const {return ::sprintf(f,format,q[0],q[1],q[2]);};
|
int sprintf(char *f, const char *format) const {return ::sprintf(f,format,q[0],q[1],q[2]);};
|
||||||
int fscanf(FILE *f, const char *format) const {return ::fscanf(f,format,q[0],q[1],q[2]);};
|
int fscanf(FILE *f, const char *format) {return ::fscanf(f,format,&q[0],&q[1],&q[2]);};
|
||||||
int sscanf(char *f, const char *format) const {return ::sscanf(f,format,q[0],q[1],q[2]);};
|
int sscanf(const char *f, const char *format) {return ::sscanf(f,format,&q[0],&q[1],&q[2]);};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ public:
|
|||||||
const Vec3<T> linear_solve(const Vec3<T> &rhs, T *det = NULL) const; //alternative to simple_gaussj in simple.h
|
const Vec3<T> linear_solve(const Vec3<T> &rhs, T *det = NULL) const; //alternative to simple_gaussj in simple.h
|
||||||
//C-style IO
|
//C-style IO
|
||||||
int fprintf(FILE *f, const char *format) const {int n= ::fprintf(f,format,q[0][0],q[0][1],q[0][2]); n+=::fprintf(f,format,q[1][0],q[1][1],q[1][2]); n+=::fprintf(f,format,q[2][0],q[2][1],q[2][2]); return n;};
|
int fprintf(FILE *f, const char *format) const {int n= ::fprintf(f,format,q[0][0],q[0][1],q[0][2]); n+=::fprintf(f,format,q[1][0],q[1][1],q[1][2]); n+=::fprintf(f,format,q[2][0],q[2][1],q[2][2]); return n;};
|
||||||
int fscanf(FILE *f, const char *format) const {return ::fscanf(f,format,q[0][0],q[0][1],q[0][2]) + ::fscanf(f,format,q[1][0],q[1][1],q[1][2]) + ::fscanf(f,format,q[2][0],q[2][1],q[2][2]);};
|
int fscanf(FILE *f, const char *format) {return ::fscanf(f,format,&q[0][0],&q[0][1],&q[0][2]) + ::fscanf(f,format,&q[1][0],&q[1][1],&q[1][2]) + ::fscanf(f,format,&q[2][0],&q[2][1],&q[2][2]);};
|
||||||
void symmetrize(); //average offdiagonal elements
|
void symmetrize(); //average offdiagonal elements
|
||||||
bool eivec_sym(Vec3<T> &w, Mat3 &v, const bool sortdown=false) const; //only for real symmetric matrix, symmetry is not checked, returns false on success
|
bool eivec_sym(Vec3<T> &w, Mat3 &v, const bool sortdown=false) const; //only for real symmetric matrix, symmetry is not checked, returns false on success
|
||||||
T norm(const T scalar = 0) const;
|
T norm(const T scalar = 0) const;
|
||||||
|
|||||||
Reference in new issue
Block a user