*** empty log message ***

This commit is contained in:
jiri 2020-01-12 08:55:26 +00:00
parent 2dd7737825
commit 23d53f9a34
4 changed files with 37 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/* /*
LA: linear algebra C++ interface library LA: linear algebra C++ interface library
Copyright (C) 2008-2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com> Copyright (C) 2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -186,6 +186,7 @@ return derivative;
} }
//optionally skip this for microcontrollers if not needed //optionally skip this for microcontrollers if not needed
//note that C++ standard headers automatically use float versions of the goniometric functions for T=float //note that C++ standard headers automatically use float versions of the goniometric functions for T=float
template<typename T> template<typename T>

View File

@ -1,6 +1,6 @@
/* /*
LA: linear algebra C++ interface library LA: linear algebra C++ interface library
Copyright (C) 2008-2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com> Copyright (C) 2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/* /*
LA: linear algebra C++ interface library LA: linear algebra C++ interface library
Copyright (C) 2008-2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com> Copyright (C) 2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -20,6 +20,33 @@
using namespace LA_Vecmat3; using namespace LA_Vecmat3;
//http://en.wikipedia.org/wiki/Fast_inverse_square_root
float LA_Vecmat3::fast_sqrtinv(float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
template<>
Vec3<float> & Vec3<float>::fast_normalize(void) {*this *= fast_sqrtinv(normsqr()); return *this;};
template<typename T>
Vec3<T>& Vec3<T>::fast_normalize(void) {normalize(); return *this;};
template<typename T> template<typename T>
const Vec3<T> Vec3<T>::operator*(const Mat3<T> &rhs) const const Vec3<T> Vec3<T>::operator*(const Mat3<T> &rhs) const
{ {

View File

@ -1,6 +1,6 @@
/* /*
LA: linear algebra C++ interface library LA: linear algebra C++ interface library
Copyright (C) 2008-2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com> Copyright (C) 2020 Jiri Pittner <jiri.pittner@jh-inst.cas.cz> or <jiri@pittnerovi.com>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -33,6 +33,8 @@
namespace LA_Vecmat3 { namespace LA_Vecmat3 {
float fast_sqrtinv(float);
//forward declaration //forward declaration
template <typename T> class Mat3; template <typename T> class Mat3;
@ -60,6 +62,7 @@ public:
inline T& operator[](const int i) {return q[i];}; inline T& operator[](const int i) {return q[i];};
//operations of Vec3s with scalars //operations of Vec3s with scalars
void clear() {memset(q,0,3*sizeof(T));}
Vec3& operator*=(const T rhs) {q[0]*=rhs; q[1]*=rhs; q[2]*=rhs; return *this;}; Vec3& operator*=(const T rhs) {q[0]*=rhs; q[1]*=rhs; q[2]*=rhs; return *this;};
Vec3& operator/=(const T rhs) {return *this *= ((T)1/rhs);}; Vec3& operator/=(const T rhs) {return *this *= ((T)1/rhs);};
const Vec3 operator*(const T rhs) const {return Vec3(*this) *= rhs;}; const Vec3 operator*(const T rhs) const {return Vec3(*this) *= rhs;};
@ -76,6 +79,7 @@ public:
T normsqr(void) const {return dot(*this);}; T normsqr(void) const {return dot(*this);};
T norm(void) const {return sqrt(normsqr());}; T norm(void) const {return sqrt(normsqr());};
Vec3& normalize(void) {*this /= norm(); return *this;}; Vec3& normalize(void) {*this /= norm(); return *this;};
Vec3& fast_normalize(void);
const Vec3 operator*(const Mat3<T> &rhs) const; const Vec3 operator*(const Mat3<T> &rhs) const;
//C-style IO //C-style IO
void fprintf(FILE *f, const char *format) const {::fprintf(f,format,q[0],q[1],q[2]);}; void fprintf(FILE *f, const char *format) const {::fprintf(f,format,q[0],q[1],q[2]);};
@ -113,6 +117,7 @@ public:
//operations of Mat3s with scalars //operations of Mat3s with scalars
void clear() {memset(&q[0][0],0,9*sizeof(T));}
Mat3& operator+=(const T rhs) {q[0][0]+=rhs; q[1][1]+=rhs; q[2][2]+=rhs; return *this;}; Mat3& operator+=(const T rhs) {q[0][0]+=rhs; q[1][1]+=rhs; q[2][2]+=rhs; return *this;};
Mat3& operator-=(const T rhs) {q[0][0]-=rhs; q[1][1]-=rhs; q[2][2]-=rhs; return *this;}; Mat3& operator-=(const T rhs) {q[0][0]-=rhs; q[1][1]-=rhs; q[2][2]-=rhs; return *this;};
const Mat3 operator+(const T rhs) const {return Mat3(*this) += rhs;}; const Mat3 operator+(const T rhs) const {return Mat3(*this) += rhs;};