Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
-97
@@ -1,97 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_eqT
|
||||
#define tools_eqT
|
||||
|
||||
namespace tools {
|
||||
|
||||
template <class NUMBER,class PREC>
|
||||
inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
|
||||
NUMBER diff = a_left - a_right;
|
||||
if(a_fabs(diff)>=a_prec) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class NUMBER,class PREC>
|
||||
inline bool is_zero(const NUMBER& a_left,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
|
||||
if(a_fabs(a_left)>=a_prec) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class VEC,class PREC>
|
||||
inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
//bool status = true;
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
|
||||
//{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
|
||||
return false;
|
||||
//status = false;
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
//return status;
|
||||
}
|
||||
|
||||
template <class VECVEC,class PREC>
|
||||
inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(const PREC&)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VECVEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// PREC(*a_fabs)(PREC) : /////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// for histo equals functions.
|
||||
|
||||
template <class NUMBER,class PREC>
|
||||
inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(NUMBER)) {
|
||||
NUMBER diff = a_left - a_right;
|
||||
if(a_fabs(diff)>=a_prec) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class VEC,class PREC>
|
||||
inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
//bool status = true;
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
|
||||
//{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
|
||||
return false;
|
||||
//status = false;
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
//return status;
|
||||
}
|
||||
|
||||
template <class VECVEC,class PREC>
|
||||
inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
|
||||
if(a_1.size()!=a_2.size()) return false;
|
||||
typedef typename VECVEC::size_type sz_t;
|
||||
sz_t sz = a_1.size();
|
||||
for(sz_t index=0;index<sz;index++) {
|
||||
if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
-236
@@ -1,236 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_mat3
|
||||
#define tools_mat3
|
||||
|
||||
#include "mat"
|
||||
|
||||
//#include <cmath>
|
||||
|
||||
namespace tools {
|
||||
|
||||
template <class T>
|
||||
class mat3 : public mat<T,3> {
|
||||
typedef mat<T,3> parent;
|
||||
typedef mat<T,3> pr;
|
||||
public:
|
||||
#ifdef TOOLS_MEM
|
||||
mat3(bool a_inc = true):parent(a_inc) {}
|
||||
#else
|
||||
mat3():parent() {}
|
||||
#endif
|
||||
mat3(const mat<T,3>& a_from):parent(a_from){}
|
||||
virtual ~mat3() {}
|
||||
public:
|
||||
mat3(const mat3& a_from):parent(a_from){}
|
||||
mat3& operator=(const mat3& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
mat3(const T& a_00,const T& a_01,const T& a_02, //first row
|
||||
const T& a_10,const T& a_11,const T& a_12, //second row
|
||||
const T& a_20,const T& a_21,const T& a_22) //third row
|
||||
{
|
||||
set_matrix(a_00,a_01,a_02,
|
||||
a_10,a_11,a_12,
|
||||
a_20,a_21,a_22);
|
||||
}
|
||||
public:
|
||||
void set_matrix(const mat3<T>& a_m){parent::set_matrix(a_m);}
|
||||
void set_matrix(const T& a_00,const T& a_01,const T& a_02, //1 row
|
||||
const T& a_10,const T& a_11,const T& a_12, //2 row
|
||||
const T& a_20,const T& a_21,const T& a_22) { //3 row
|
||||
//a_<R><C>
|
||||
//pr::m_vec[R + C * 3];
|
||||
pr::m_vec[0] = a_00;pr::m_vec[3] = a_01;pr::m_vec[6] = a_02;
|
||||
pr::m_vec[1] = a_10;pr::m_vec[4] = a_11;pr::m_vec[7] = a_12;
|
||||
pr::m_vec[2] = a_20;pr::m_vec[5] = a_21;pr::m_vec[8] = a_22;
|
||||
}
|
||||
|
||||
void set_scale(const T& a_s) {_set_scale(a_s,a_s,a_s,pr::m_vec);}
|
||||
void set_scale(const T& a_1,const T& a_2,const T& a_3) {_set_scale(a_1,a_2,a_3,pr::m_vec);}
|
||||
void set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
|
||||
_set_rotate(a_x,a_y,a_z,a_angle,pr::m_vec,a_sin,a_cos);
|
||||
}
|
||||
|
||||
bool get_rotate(T& a_x,T& a_y,T& a_z,T& a_angle,T(*a_acos)(T),T(*a_sin)(T),T(*a_sqrt)(T)) { //warning : acos and not cos.
|
||||
// used in tests/check_pauli. Same code as matTs/get_rotate.
|
||||
// we assume that we have a rotation matrix.
|
||||
// get (a_angle,a_n(x,y,z)) such that matrix is exp(a_angle*a_n*Rs) (passive(=coord) rotation) and then :
|
||||
// exp(a_angle*n*Rs) = cos_angle*I3+(1-cos_angle)*n*n+sin_theta*n*Rs
|
||||
// trace = 3*cos_angle+(1-cos_angle)*n2
|
||||
T cos_angle = T(0.5)*(pr::m_vec[0]+pr::m_vec[4]+pr::m_vec[8]-T(1));
|
||||
if((cos_angle<T(-1))||(T(1)<cos_angle)) { //matrix is not a rotation :
|
||||
a_angle = T(0);
|
||||
a_x = 0;
|
||||
a_y = 0;
|
||||
a_z = 0;
|
||||
return false;
|
||||
}
|
||||
if(cos_angle==T(1)) {
|
||||
a_angle = T(0);
|
||||
a_x = 0;
|
||||
a_y = 0;
|
||||
a_z = 1;
|
||||
return true; //vector is undefined but we return true anyway.
|
||||
}
|
||||
T one_minus_cos_angle = T(1)-cos_angle;
|
||||
T x2 = (pr::m_vec[0]-cos_angle)/one_minus_cos_angle;
|
||||
//T y2 = (pr::m_vec[4]-cos_angle)/one_minus_cos_angle;
|
||||
//T z2 = (pr::m_vec[8]-cos_angle)/one_minus_cos_angle;
|
||||
/*
|
||||
if((x2<T(0))||(y2<T(0))||(z2<T(0))||(x2+y2+z2)!=T(1)) { //not a rotation :
|
||||
a_angle = T(0);
|
||||
a_x = 0;
|
||||
a_y = 0;
|
||||
a_z = 0;
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
a_angle = a_acos(cos_angle); //in ]0,pi].
|
||||
T sin_angle = a_sin(a_angle); //in [0,1].
|
||||
if(sin_angle==T(0)) { //angle is pi. //sym part can determine vector, but up to a sign :
|
||||
// sym part is : cos_angle*I+(1-cos_angle)*n*n
|
||||
// cos_angle = -1
|
||||
T xy = T(0.5)*(pr::m_vec[3]+pr::m_vec[1])/one_minus_cos_angle;
|
||||
T xz = T(0.5)*(pr::m_vec[6]+pr::m_vec[2])/one_minus_cos_angle;
|
||||
//T yz = T(0.5)*(pr::m_vec[7]+pr::m_vec[5])/one_minus_cos_angle;
|
||||
a_x = a_sqrt(x2); //up to a sign.
|
||||
a_y = xy/a_x;
|
||||
a_z = xz/a_x;
|
||||
return true; //vector is defined up to a sign.
|
||||
}
|
||||
// antisym part is : sin(theta)*n.Rs
|
||||
a_z = T(0.5)*(pr::m_vec[3]-pr::m_vec[1])/sin_angle;
|
||||
a_y = T(-0.5)*(pr::m_vec[6]-pr::m_vec[2])/sin_angle; //warning : -1.
|
||||
a_x = T(0.5)*(pr::m_vec[7]-pr::m_vec[5])/sin_angle;
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
void mul_3(T& a_x,T& a_y,T& a_z) const {
|
||||
// a_[x,y,z] = this * a_[x,y,z]
|
||||
//pr::m_vec[R + C * 3];
|
||||
T x = pr::m_vec[0]*a_x+pr::m_vec[3]*a_y+pr::m_vec[6]*a_z;
|
||||
T y = pr::m_vec[1]*a_x+pr::m_vec[4]*a_y+pr::m_vec[7]*a_z;
|
||||
T z = pr::m_vec[2]*a_x+pr::m_vec[5]*a_y+pr::m_vec[8]*a_z;
|
||||
a_x = x;
|
||||
a_y = y;
|
||||
a_z = z;
|
||||
}
|
||||
|
||||
void mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
|
||||
T rot[9];
|
||||
_set_rotate(a_x,a_y,a_z,a_angle,rot,a_sin,a_cos);
|
||||
parent::_mul_mtx(rot);
|
||||
}
|
||||
|
||||
void left_mul_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T(*a_sin)(T),T(*a_cos)(T)) {
|
||||
T _m[9];
|
||||
_set_rotate(a_x,a_y,a_z,a_angle,_m,a_sin,a_cos);
|
||||
parent::_left_mul_mtx(_m);
|
||||
}
|
||||
|
||||
void v00(const T& a_value){pr::m_vec[0+0*3] = a_value;}
|
||||
void v10(const T& a_value){pr::m_vec[1+0*3] = a_value;}
|
||||
void v20(const T& a_value){pr::m_vec[2+0*3] = a_value;}
|
||||
|
||||
void v01(const T& a_value){pr::m_vec[0+1*3] = a_value;}
|
||||
void v11(const T& a_value){pr::m_vec[1+1*3] = a_value;}
|
||||
void v21(const T& a_value){pr::m_vec[2+1*3] = a_value;}
|
||||
|
||||
void v02(const T& a_value){pr::m_vec[0+2*3] = a_value;}
|
||||
void v12(const T& a_value){pr::m_vec[1+2*3] = a_value;}
|
||||
void v22(const T& a_value){pr::m_vec[2+2*3] = a_value;}
|
||||
|
||||
const T& v00() const {return pr::m_vec[0+0*3];}
|
||||
const T& v10() const {return pr::m_vec[1+0*3];}
|
||||
const T& v20() const {return pr::m_vec[2+0*3];}
|
||||
|
||||
const T& v01() const {return pr::m_vec[0+1*3];}
|
||||
const T& v11() const {return pr::m_vec[1+1*3];}
|
||||
const T& v21() const {return pr::m_vec[2+1*3];}
|
||||
|
||||
const T& v02() const {return pr::m_vec[0+2*3];}
|
||||
const T& v12() const {return pr::m_vec[1+2*3];}
|
||||
const T& v22() const {return pr::m_vec[2+2*3];}
|
||||
|
||||
protected:
|
||||
static void _set_scale(const T& a_1,const T& a_2,const T& a_3,T v[]) {
|
||||
v[0] = a_1;v[3] = 0;v[6] = 0;
|
||||
v[1] = 0;v[4] = a_2;v[7] = 0;
|
||||
v[2] = 0;v[5] = 0;v[8] = a_3;
|
||||
}
|
||||
|
||||
static void _set_rotate(const T& a_x,const T& a_y,const T& a_z,const T& a_angle,T v[],T(*a_sin)(T),T(*a_cos)(T)) {
|
||||
//WARNING : it models the rotation of an object (active rotation) = exp(-a_angle*n(a_x,a_y,a_z)*Rs).
|
||||
//WARNING : (a_x,a_y,a_z) must be a normalized vector.
|
||||
T si = a_sin(a_angle);
|
||||
T co = a_cos(a_angle);
|
||||
T x = a_x;
|
||||
T y = a_y;
|
||||
T z = a_z;
|
||||
T x2 = x*x;
|
||||
T y2 = y*y;
|
||||
T z2 = z*z;
|
||||
T xy = x*y;
|
||||
T xz = x*z;
|
||||
T yz = y*z;
|
||||
v[0] = x2+(1-x2)*co;v[3] = xy*(1-co)-z*si;v[6] = xz*(1-co)+y*si;
|
||||
v[1] = xy*(1-co)+z*si;v[4] = y2+(1-y2)*co;v[7] = yz*(1-co)-x*si;
|
||||
v[2] = xz*(1-co)-y*si;v[5] = yz*(1-co)+x*si;v[8] = z2+(1-z2)*co;
|
||||
|
||||
// If :
|
||||
// n =(x,y,z)
|
||||
// n2 = x2+y2+z2 = 1
|
||||
// n.E = x*E1+y*E2+z*E3
|
||||
// with :
|
||||
// E1 E2 E3
|
||||
// 0 0 0 0 0 -1 0 1 0
|
||||
// 0 0 1 0 0 0 -1 0 0
|
||||
// 0 -1 0 1 0 0 0 0 0
|
||||
//
|
||||
// R(r,c) = cos(theta)*Id(r,c)+(1-cos(theta))*nr*nc-sin(theta)*(n.E)(r,c)
|
||||
//
|
||||
// R = exp(-theta*(n.E))
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
private:static void check_instantiation() {mat3<float> dummy;}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////
|
||||
/// common matrices : //////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline const mat3<T>& mat3_zero() {
|
||||
static const mat3<T> s_v(false); //inc mem count = false
|
||||
return s_v;
|
||||
}
|
||||
|
||||
//for sf, mf :
|
||||
//template <class T>
|
||||
//inline const T* get_data(const mat3<T>& a_v) {return a_v.data();}
|
||||
|
||||
}
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tools {
|
||||
|
||||
template <class T>
|
||||
inline std::ostream& operator<<(std::ostream& a_out,const mat3<T>& a_mtx){
|
||||
const T* v = a_mtx.data();
|
||||
a_out << v[0] << "," << v[3] << "," << v[6] << std::endl
|
||||
<< v[1] << "," << v[4] << "," << v[7] << std::endl
|
||||
<< v[2] << "," << v[5] << "," << v[8] << std::endl;
|
||||
return a_out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_mat3d
|
||||
#define tools_mat3d
|
||||
|
||||
#include "mat3"
|
||||
#include <cmath>
|
||||
|
||||
namespace tools {
|
||||
|
||||
class mat3d : public mat3<double> {
|
||||
typedef mat3<double> parent;
|
||||
public:
|
||||
mat3d(){}
|
||||
virtual ~mat3d() {}
|
||||
public:
|
||||
mat3d(const mat3d& a_from):parent(a_from){}
|
||||
mat3d& operator=(const mat3d& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
mat3d(double a_00,double a_01,double a_02, //first row
|
||||
double a_10,double a_11,double a_12, //second row
|
||||
double a_20,double a_21,double a_22) //third row
|
||||
:parent(a_00,a_01,a_02,
|
||||
a_10,a_11,a_12,
|
||||
a_20,a_21,a_22)
|
||||
{}
|
||||
mat3d(const parent& a_from):parent(a_from){}
|
||||
mat3d& operator=(const parent& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
mat3d(const mat3<float>& a_from):parent(){
|
||||
for(unsigned int index=0;index<9;index++) {
|
||||
m_vec[index] = a_from.data()[index];
|
||||
}
|
||||
}
|
||||
mat3d& operator=(const mat3<float>& a_from){
|
||||
for(unsigned int index=0;index<9;index++) {
|
||||
m_vec[index] = a_from.data()[index];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
void set_rotate(const double& a_x,const double& a_y,const double& a_z,const double& a_angle) {
|
||||
parent::set_rotate(a_x,a_y,a_z,a_angle,::sin,::cos);
|
||||
}
|
||||
void mul_rotate(const double& a_x,const double& a_y,const double& a_z,const double& a_angle) {
|
||||
parent::mul_rotate(a_x,a_y,a_z,a_angle,::sin,::cos);
|
||||
}
|
||||
void left_mul_rotate(const double& a_x,const double& a_y,const double& a_z,const double& a_angle) {
|
||||
parent::left_mul_rotate(a_x,a_y,a_z,a_angle,::sin,::cos);
|
||||
}
|
||||
bool get_rotate(double& a_x,double& a_y,double& a_z,double& a_angle) {
|
||||
return parent::get_rotate(a_x,a_y,a_z,a_angle,::acos,::sin,::sqrt); //warning : acos and not cos.
|
||||
}
|
||||
public: //operators
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_mat3f
|
||||
#define tools_mat3f
|
||||
|
||||
#include "mat3"
|
||||
//#include "mathf"
|
||||
|
||||
namespace tools {
|
||||
|
||||
class mat3f : public mat3<float> {
|
||||
typedef mat3<float> parent;
|
||||
public:
|
||||
mat3f(){}
|
||||
mat3f(float a_00,float a_01,float a_02, //first row
|
||||
float a_10,float a_11,float a_12, //second row
|
||||
float a_20,float a_21,float a_22) //third row
|
||||
:parent(a_00,a_01,a_02,
|
||||
a_10,a_11,a_12,
|
||||
a_20,a_21,a_22)
|
||||
{}
|
||||
virtual ~mat3f() {}
|
||||
public:
|
||||
mat3f(const mat3f& a_from):parent(a_from){}
|
||||
mat3f& operator=(const mat3f& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
/*
|
||||
void set_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
|
||||
parent::set_rotate(a_x,a_y,a_z,a_angle,fsin,fcos);
|
||||
}
|
||||
void mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
|
||||
parent::mul_rotate(a_x,a_y,a_z,a_angle,fsin,fcos);
|
||||
}
|
||||
void left_mul_rotate(const float& a_x,const float& a_y,const float& a_z,const float& a_angle) {
|
||||
parent::left_mul_rotate(a_x,a_y,a_z,a_angle,fsin,fcos);
|
||||
}
|
||||
bool get_rotate(float& a_x,float& a_y,float& a_z,float& a_angle) {
|
||||
return parent::get_rotate(a_x,a_y,a_z,a_angle,facos,fsin,fsqrt); //warning : acos and not cos.
|
||||
}
|
||||
*/
|
||||
public: //operators
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_mat4d
|
||||
#define tools_mat4d
|
||||
|
||||
#include "mat4"
|
||||
#include <cmath>
|
||||
|
||||
namespace tools {
|
||||
|
||||
class mat4d : public mat4<double> {
|
||||
typedef mat4<double> parent;
|
||||
public:
|
||||
mat4d(){}
|
||||
virtual ~mat4d() {}
|
||||
public:
|
||||
mat4d(const mat4d& a_from):parent(a_from){}
|
||||
mat4d& operator=(const mat4d& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
mat4d(double a_00,double a_01,double a_02,double a_03, //first row
|
||||
double a_10,double a_11,double a_12,double a_13, //second row
|
||||
double a_20,double a_21,double a_22,double a_23, //third row
|
||||
double a_30,double a_31,double a_32,double a_33) //fourth row
|
||||
:parent(a_00,a_01,a_02,a_03,
|
||||
a_10,a_11,a_12,a_13,
|
||||
a_20,a_21,a_22,a_23,
|
||||
a_30,a_31,a_32,a_33)
|
||||
{}
|
||||
mat4d(const parent& a_from):parent(a_from){}
|
||||
mat4d& operator=(const parent& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
mat4d(const mat4<float>& a_from):parent(){
|
||||
for(unsigned int index=0;index<16;index++) {
|
||||
m_vec[index] = a_from.data()[index];
|
||||
}
|
||||
}
|
||||
mat4d& operator=(const mat4<float>& a_from){
|
||||
for(unsigned int index=0;index<16;index++) {
|
||||
m_vec[index] = a_from.data()[index];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
void set_rotate(const double& a_x,const double& a_y,const double& a_z,const double& a_angle) {
|
||||
parent::set_rotate(a_x,a_y,a_z,a_angle,::sin,::cos);
|
||||
}
|
||||
void mul_rotate(const double& a_x,const double& a_y,const double& a_z,const double& a_angle) {
|
||||
parent::mul_rotate(a_x,a_y,a_z,a_angle,::sin,::cos);
|
||||
}
|
||||
void left_mul_rotate(const double& a_x,const double& a_y,const double& a_z,const double& a_angle) {
|
||||
parent::left_mul_rotate(a_x,a_y,a_z,a_angle,::sin,::cos);
|
||||
}
|
||||
|
||||
template <class VEC>
|
||||
void set_rotate(const VEC& a_dir,double a_angle) {
|
||||
//WARNING : a_dir must be a normalized vector.
|
||||
parent::set_rotate(a_dir[0],a_dir[1],a_dir[2],a_angle,::sin,::cos);
|
||||
}
|
||||
|
||||
public: //backward compatibility
|
||||
void mul_2d(double& a_x,double& a_y) const {
|
||||
parent::mul_2(a_x,a_y);
|
||||
}
|
||||
void mul_3d(double& a_x,double& a_y,double& a_z) const {
|
||||
parent::mul_3(a_x,a_y,a_z);
|
||||
}
|
||||
void mul_4d(double& a_x,double& a_y,double& a_z,double& a_w) const {
|
||||
parent::mul_4(a_x,a_y,a_z,a_w);
|
||||
}
|
||||
public: //operators
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,67 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_rotd
|
||||
#define tools_rotd
|
||||
|
||||
// rotation done with quaternion.
|
||||
|
||||
#include "qrot"
|
||||
#include "vec3d"
|
||||
#include "vec4d"
|
||||
#include "mat3d"
|
||||
#include "mat4d"
|
||||
|
||||
namespace tools {
|
||||
|
||||
class rotd : public qrot<vec3d,vec4d> {
|
||||
typedef qrot<vec3d,vec4d> parent;
|
||||
private:
|
||||
rotd(double a_q0,double a_q1,double a_q2,double a_q3):parent(a_q0,a_q1,a_q2,a_q3){}
|
||||
public:
|
||||
rotd():parent() {} //zero rotation around the positive Z axis.
|
||||
rotd(const vec3d& a_axis,double a_radians):parent(a_axis,a_radians,::sin,::cos) {}
|
||||
rotd(const vec3d& a_from,const vec3d& a_to):parent(a_from,a_to,::sqrt,::fabs) {}
|
||||
virtual ~rotd(){}
|
||||
public:
|
||||
rotd(const rotd& a_from):parent(a_from) {}
|
||||
rotd& operator=(const rotd& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
rotd& operator*=(const rotd& a_q) {
|
||||
parent::operator*=(a_q);
|
||||
return *this;
|
||||
}
|
||||
rotd operator*(const rotd& a_r) const {
|
||||
rotd tmp(*this);
|
||||
tmp *= a_r;
|
||||
return tmp;
|
||||
}
|
||||
public:
|
||||
bool set_value(const vec3d& a_from,const vec3d& a_to){
|
||||
return parent::set_value(a_from,a_to,::sqrt,::fabs);
|
||||
}
|
||||
bool set_value(const vec3d& a_from,double a_a){
|
||||
return parent::set_value(a_from,a_a,::sin,::cos);
|
||||
}
|
||||
bool value(vec3d& a_from,double& a_a) const {
|
||||
return parent::value(a_from,a_a,::sin,::acos); //WARNING acos and not cos
|
||||
}
|
||||
|
||||
//NOTE : don't handle a static object because of mem balance.
|
||||
//static const rotd& identity() {
|
||||
// static const rotd s_v(0,0,0,1);
|
||||
// return s_v;
|
||||
//}
|
||||
|
||||
void value(mat4d& a_m) const {parent::value(a_m);}
|
||||
void set_value(const mat4d& a_m) {parent::set_value(a_m,::sqrt);}
|
||||
|
||||
double value(mat3d& a_m) const {return parent::value_3(a_m);}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,89 +0,0 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_vec4d
|
||||
#define tools_vec4d
|
||||
|
||||
#include "vec4"
|
||||
#include <cmath>
|
||||
|
||||
namespace tools {
|
||||
|
||||
class vec4d : public vec4<double> {
|
||||
typedef vec4<double> parent;
|
||||
public:
|
||||
vec4d():parent() {}
|
||||
vec4d(const double a_vec[4]):parent(a_vec) {}
|
||||
#ifdef TOOLS_MEM
|
||||
vec4d(const double& a0,const double& a1,const double& a2,const double& a3,bool a_inc = true):parent(a0,a1,a2,a3,a_inc){}
|
||||
#else
|
||||
vec4d(const double& a0,const double& a1,const double& a2,const double& a3):parent(a0,a1,a2,a3){}
|
||||
#endif
|
||||
virtual ~vec4d() {}
|
||||
public:
|
||||
vec4d(const vec4d& a_from):parent(a_from){}
|
||||
vec4d& operator=(const vec4d& a_from){parent::operator=(a_from);return *this;}
|
||||
public: //operators
|
||||
vec4d operator*(double a_v) const {
|
||||
return vec4d(m_data[0]*a_v,
|
||||
m_data[1]*a_v,
|
||||
m_data[2]*a_v,
|
||||
m_data[3]*a_v);
|
||||
}
|
||||
vec4d operator+(const vec4d& a_v) const {
|
||||
return vec4d(m_data[0]+a_v.m_data[0],
|
||||
m_data[1]+a_v.m_data[1],
|
||||
m_data[2]+a_v.m_data[2],
|
||||
m_data[3]+a_v.m_data[3]);
|
||||
}
|
||||
vec4d operator-(const vec4d& a_v) const {
|
||||
return vec4d(m_data[0]-a_v.m_data[0],
|
||||
m_data[1]-a_v.m_data[1],
|
||||
m_data[2]-a_v.m_data[2],
|
||||
m_data[3]-a_v.m_data[3]);
|
||||
}
|
||||
vec4d& operator+=(const vec4d& a_v) {
|
||||
m_data[0] += a_v.m_data[0];
|
||||
m_data[1] += a_v.m_data[1];
|
||||
m_data[2] += a_v.m_data[2];
|
||||
m_data[3] += a_v.m_data[3];
|
||||
return *this;
|
||||
}
|
||||
vec4d& operator*=(double a_v) {
|
||||
m_data[0] *= a_v;
|
||||
m_data[1] *= a_v;
|
||||
m_data[2] *= a_v;
|
||||
m_data[3] *= a_v;
|
||||
return *this;
|
||||
}
|
||||
vec4d operator-() const {
|
||||
return vec4d(-m_data[0],-m_data[1],-m_data[2],-m_data[3]);
|
||||
}
|
||||
public:
|
||||
double length() const {return parent::length(::sqrt);}
|
||||
double normalize() {return parent::normalize(::sqrt);}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
#include <vector>
|
||||
|
||||
namespace tools {
|
||||
|
||||
#ifndef SWIG
|
||||
//for sf, mf :
|
||||
inline bool set_from_vec(vec4d& a_v,const std::vector<double>& a_sv) {
|
||||
if(a_sv.size()!=4) return false;
|
||||
a_v[0] = a_sv[0];
|
||||
a_v[1] = a_sv[1];
|
||||
a_v[2] = a_sv[2];
|
||||
a_v[3] = a_sv[3];
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user