Basic changes to introduce optional double precision

This commit is contained in:
Chris Russ
2016-07-15 12:53:49 +10:00
parent 45fae27aed
commit 2f7e3dcdcc
18 changed files with 167 additions and 106 deletions

View File

@@ -94,15 +94,15 @@ class Vertex
friend Vertex operator + (const Vertex&,const Vertex&);
friend Vertex operator - (const Vertex&,const Vertex&);
// friend Vertex operator + (const Vertex&,float);
// friend Vertex operator - (const Vertex&,float);
friend Vertex operator * (const Vertex&,float);
friend Vertex operator / (const Vertex&,float);
// friend Vertex operator + (const Vertex&,ai_real);
// friend Vertex operator - (const Vertex&,ai_real);
friend Vertex operator * (const Vertex&,ai_real);
friend Vertex operator / (const Vertex&,ai_real);
// friend Vertex operator + (float, const Vertex&);
// friend Vertex operator - (float, const Vertex&);
friend Vertex operator * (float, const Vertex&);
// friend Vertex operator / (float, const Vertex&);
// friend Vertex operator + (ai_real, const Vertex&);
// friend Vertex operator - (ai_real, const Vertex&);
friend Vertex operator * (ai_real, const Vertex&);
// friend Vertex operator / (ai_real, const Vertex&);
public:
@@ -146,22 +146,22 @@ public:
/*
Vertex& operator += (float v) {
Vertex& operator += (ai_real v) {
*this = *this+v;
return *this;
}
Vertex& operator -= (float v) {
Vertex& operator -= (ai_real v) {
*this = *this-v;
return *this;
}
*/
Vertex& operator *= (float v) {
Vertex& operator *= (ai_real v) {
*this = *this*v;
return *this;
}
Vertex& operator /= (float v) {
Vertex& operator /= (ai_real v) {
*this = *this/v;
return *this;
}
@@ -217,40 +217,40 @@ private:
// ----------------------------------------------------------------------------
/** This time binary arithmetics of v0 with a floating-point number */
template <template <typename, typename, typename> class op> static Vertex BinaryOp(const Vertex& v0, float f) {
template <template <typename, typename, typename> class op> static Vertex BinaryOp(const Vertex& v0, ai_real f) {
// this is a heavy task for the compiler to optimize ... *pray*
Vertex res;
res.position = op<aiVector3D,float,aiVector3D>()(v0.position,f);
res.normal = op<aiVector3D,float,aiVector3D>()(v0.normal,f);
res.tangent = op<aiVector3D,float,aiVector3D>()(v0.tangent,f);
res.bitangent = op<aiVector3D,float,aiVector3D>()(v0.bitangent,f);
res.position = op<aiVector3D,ai_real,aiVector3D>()(v0.position,f);
res.normal = op<aiVector3D,ai_real,aiVector3D>()(v0.normal,f);
res.tangent = op<aiVector3D,ai_real,aiVector3D>()(v0.tangent,f);
res.bitangent = op<aiVector3D,ai_real,aiVector3D>()(v0.bitangent,f);
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
res.texcoords[i] = op<aiVector3D,float,aiVector3D>()(v0.texcoords[i],f);
res.texcoords[i] = op<aiVector3D,ai_real,aiVector3D>()(v0.texcoords[i],f);
}
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
res.colors[i] = op<aiColor4D,float,aiColor4D>()(v0.colors[i],f);
res.colors[i] = op<aiColor4D,ai_real,aiColor4D>()(v0.colors[i],f);
}
return res;
}
// ----------------------------------------------------------------------------
/** This time binary arithmetics of v0 with a floating-point number */
template <template <typename, typename, typename> class op> static Vertex BinaryOp(float f, const Vertex& v0) {
template <template <typename, typename, typename> class op> static Vertex BinaryOp(ai_real f, const Vertex& v0) {
// this is a heavy task for the compiler to optimize ... *pray*
Vertex res;
res.position = op<float,aiVector3D,aiVector3D>()(f,v0.position);
res.normal = op<float,aiVector3D,aiVector3D>()(f,v0.normal);
res.tangent = op<float,aiVector3D,aiVector3D>()(f,v0.tangent);
res.bitangent = op<float,aiVector3D,aiVector3D>()(f,v0.bitangent);
res.position = op<ai_real,aiVector3D,aiVector3D>()(f,v0.position);
res.normal = op<ai_real,aiVector3D,aiVector3D>()(f,v0.normal);
res.tangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.tangent);
res.bitangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.bitangent);
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
res.texcoords[i] = op<float,aiVector3D,aiVector3D>()(f,v0.texcoords[i]);
res.texcoords[i] = op<ai_real,aiVector3D,aiVector3D>()(f,v0.texcoords[i]);
}
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
res.colors[i] = op<float,aiColor4D,aiColor4D>()(f,v0.colors[i]);
res.colors[i] = op<ai_real,aiColor4D,aiColor4D>()(f,v0.colors[i]);
}
return res;
}
@@ -279,41 +279,41 @@ AI_FORCE_INLINE Vertex operator - (const Vertex& v0,const Vertex& v1) {
// ------------------------------------------------------------------------------------------------
/*
AI_FORCE_INLINE Vertex operator + (const Vertex& v0,float f) {
AI_FORCE_INLINE Vertex operator + (const Vertex& v0,ai_real f) {
return Vertex::BinaryOp<Intern::plus>(v0,f);
}
AI_FORCE_INLINE Vertex operator - (const Vertex& v0,float f) {
AI_FORCE_INLINE Vertex operator - (const Vertex& v0,ai_real f) {
return Vertex::BinaryOp<Intern::minus>(v0,f);
}
*/
AI_FORCE_INLINE Vertex operator * (const Vertex& v0,float f) {
AI_FORCE_INLINE Vertex operator * (const Vertex& v0,ai_real f) {
return Vertex::BinaryOp<Intern::multiplies>(v0,f);
}
AI_FORCE_INLINE Vertex operator / (const Vertex& v0,float f) {
AI_FORCE_INLINE Vertex operator / (const Vertex& v0,ai_real f) {
return Vertex::BinaryOp<Intern::multiplies>(v0,1.f/f);
}
// ------------------------------------------------------------------------------------------------
/*
AI_FORCE_INLINE Vertex operator + (float f,const Vertex& v0) {
AI_FORCE_INLINE Vertex operator + (ai_real f,const Vertex& v0) {
return Vertex::BinaryOp<Intern::plus>(f,v0);
}
AI_FORCE_INLINE Vertex operator - (float f,const Vertex& v0) {
AI_FORCE_INLINE Vertex operator - (ai_real f,const Vertex& v0) {
return Vertex::BinaryOp<Intern::minus>(f,v0);
}
*/
AI_FORCE_INLINE Vertex operator * (float f,const Vertex& v0) {
AI_FORCE_INLINE Vertex operator * (ai_real f,const Vertex& v0) {
return Vertex::BinaryOp<Intern::multiplies>(f,v0);
}
/*
AI_FORCE_INLINE Vertex operator / (float f,const Vertex& v0) {
AI_FORCE_INLINE Vertex operator / (ai_real f,const Vertex& v0) {
return Vertex::BinaryOp<Intern::divides>(f,v0);
}
*/