Basic changes to introduce optional double precision

pull/947/head
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

@ -75,7 +75,7 @@ public:
// typedefs for our four configuration maps. // typedefs for our four configuration maps.
// We don't need more, so there is no need for a generic solution // We don't need more, so there is no need for a generic solution
typedef std::map<KeyType, int> IntPropertyMap; typedef std::map<KeyType, int> IntPropertyMap;
typedef std::map<KeyType, float> FloatPropertyMap; typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap; typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;

View File

@ -1246,6 +1246,9 @@ void SceneCombiner::Copy (aiMetadata** _dest, const aiMetadata* src)
case AI_FLOAT: case AI_FLOAT:
out.mData = new float(*static_cast<float*>(in.mData)); out.mData = new float(*static_cast<float*>(in.mData));
break; break;
case AI_DOUBLE:
out.mData = new double(*static_cast<double*>(in.mData));
break;
case AI_AISTRING: case AI_AISTRING:
out.mData = new aiString(*static_cast<aiString*>(in.mData)); out.mData = new aiString(*static_cast<aiString*>(in.mData));
break; break;

View File

@ -107,7 +107,7 @@ void SpatialSort::Append( const aiVector3D* pPositions, unsigned int pNumPositio
const aiVector3D* vec = reinterpret_cast<const aiVector3D*> (tempPointer + a * pElementOffset); const aiVector3D* vec = reinterpret_cast<const aiVector3D*> (tempPointer + a * pElementOffset);
// store position by index and distance // store position by index and distance
float distance = *vec * mPlaneNormal; ai_real distance = *vec * mPlaneNormal;
mPositions.push_back( Entry( a+initial, *vec, distance)); mPositions.push_back( Entry( a+initial, *vec, distance));
} }
@ -120,10 +120,10 @@ void SpatialSort::Append( const aiVector3D* pPositions, unsigned int pNumPositio
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns an iterator for all positions close to the given position. // Returns an iterator for all positions close to the given position.
void SpatialSort::FindPositions( const aiVector3D& pPosition, void SpatialSort::FindPositions( const aiVector3D& pPosition,
float pRadius, std::vector<unsigned int>& poResults) const ai_real pRadius, std::vector<unsigned int>& poResults) const
{ {
const float dist = pPosition * mPlaneNormal; const ai_real dist = pPosition * mPlaneNormal;
const float minDist = dist - pRadius, maxDist = dist + pRadius; const ai_real minDist = dist - pRadius, maxDist = dist + pRadius;
// clear the array in this strange fashion because a simple clear() would also deallocate // clear the array in this strange fashion because a simple clear() would also deallocate
// the array which we want to avoid // the array which we want to avoid
@ -160,7 +160,7 @@ void SpatialSort::FindPositions( const aiVector3D& pPosition,
// Mow start iterating from there until the first position lays outside of the distance range. // Mow start iterating from there until the first position lays outside of the distance range.
// Add all positions inside the distance range within the given radius to the result aray // Add all positions inside the distance range within the given radius to the result aray
std::vector<Entry>::const_iterator it = mPositions.begin() + index; std::vector<Entry>::const_iterator it = mPositions.begin() + index;
const float pSquared = pRadius*pRadius; const ai_real pSquared = pRadius*pRadius;
while( it->mDistance < maxDist) while( it->mDistance < maxDist)
{ {
if( (it->mPosition - pPosition).SquareLength() < pSquared) if( (it->mPosition - pPosition).SquareLength() < pSquared)
@ -186,19 +186,19 @@ namespace {
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
// Converts the bit pattern of a floating-point number to its signed integer representation. // Converts the bit pattern of a floating-point number to its signed integer representation.
BinFloat ToBinary( const float & pValue) { BinFloat ToBinary( const ai_real & pValue) {
// If this assertion fails, signed int is not big enough to store a float on your platform. // If this assertion fails, signed int is not big enough to store a float on your platform.
// Please correct the declaration of BinFloat a few lines above - but do it in a portable, // Please correct the declaration of BinFloat a few lines above - but do it in a portable,
// #ifdef'd manner! // #ifdef'd manner!
static_assert( sizeof(BinFloat) >= sizeof(float), "sizeof(BinFloat) >= sizeof(float)"); static_assert( sizeof(BinFloat) >= sizeof(ai_real), "sizeof(BinFloat) >= sizeof(ai_real)");
#if defined( _MSC_VER) #if defined( _MSC_VER)
// If this assertion fails, Visual C++ has finally moved to ILP64. This means that this // If this assertion fails, Visual C++ has finally moved to ILP64. This means that this
// code has just become legacy code! Find out the current value of _MSC_VER and modify // code has just become legacy code! Find out the current value of _MSC_VER and modify
// the #if above so it evaluates false on the current and all upcoming VC versions (or // the #if above so it evaluates false on the current and all upcoming VC versions (or
// on the current platform, if LP64 or LLP64 are still used on other platforms). // on the current platform, if LP64 or LLP64 are still used on other platforms).
static_assert( sizeof(BinFloat) == sizeof(float), "sizeof(BinFloat) == sizeof(float)"); static_assert( sizeof(BinFloat) == sizeof(ai_real), "sizeof(BinFloat) == sizeof(ai_real)");
// This works best on Visual C++, but other compilers have their problems with it. // This works best on Visual C++, but other compilers have their problems with it.
const BinFloat binValue = reinterpret_cast<BinFloat const &>(pValue); const BinFloat binValue = reinterpret_cast<BinFloat const &>(pValue);
@ -206,7 +206,7 @@ namespace {
// On many compilers, reinterpreting a float address as an integer causes aliasing // On many compilers, reinterpreting a float address as an integer causes aliasing
// problems. This is an ugly but more or less safe way of doing it. // problems. This is an ugly but more or less safe way of doing it.
union { union {
float asFloat; ai_real asFloat;
BinFloat asBin; BinFloat asBin;
} conversion; } conversion;
conversion.asBin = 0; // zero empty space in case sizeof(BinFloat) > sizeof(float) conversion.asBin = 0; // zero empty space in case sizeof(BinFloat) > sizeof(float)
@ -311,10 +311,10 @@ void SpatialSort::FindIdenticalPositions( const aiVector3D& pPosition,
unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int>& fill,float pRadius) const unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int>& fill,float pRadius) const
{ {
fill.resize(mPositions.size(),UINT_MAX); fill.resize(mPositions.size(),UINT_MAX);
float dist, maxDist; ai_real dist, maxDist;
unsigned int t=0; unsigned int t=0;
const float pSquared = pRadius*pRadius; const ai_real pSquared = pRadius*pRadius;
for (size_t i = 0; i < mPositions.size();) { for (size_t i = 0; i < mPositions.size();) {
dist = mPositions[i].mPosition * mPlaneNormal; dist = mPositions[i].mPosition * mPlaneNormal;
maxDist = dist + pRadius; maxDist = dist + pRadius;
@ -339,4 +339,3 @@ unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int>& fill,f
#endif #endif
return t; return t;
} }

View File

@ -117,7 +117,7 @@ public:
* @param poResults The container to store the indices of the found positions. * @param poResults The container to store the indices of the found positions.
* Will be emptied by the call so it may contain anything. * Will be emptied by the call so it may contain anything.
* @return An iterator to iterate over all vertices in the given area.*/ * @return An iterator to iterate over all vertices in the given area.*/
void FindPositions( const aiVector3D& pPosition, float pRadius, void FindPositions( const aiVector3D& pPosition, ai_real pRadius,
std::vector<unsigned int>& poResults) const; std::vector<unsigned int>& poResults) const;
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
@ -139,7 +139,7 @@ public:
* be counted in. * be counted in.
* @return Number of unique vertices (n). */ * @return Number of unique vertices (n). */
unsigned int GenerateMappingTable(std::vector<unsigned int>& fill, unsigned int GenerateMappingTable(std::vector<unsigned int>& fill,
float pRadius) const; ai_real pRadius) const;
protected: protected:
/** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */ /** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */
@ -151,10 +151,10 @@ protected:
{ {
unsigned int mIndex; ///< The vertex referred by this entry unsigned int mIndex; ///< The vertex referred by this entry
aiVector3D mPosition; ///< Position aiVector3D mPosition; ///< Position
float mDistance; ///< Distance of this vertex to the sorting plane ai_real mDistance; ///< Distance of this vertex to the sorting plane
Entry() { /** intentionally not initialized.*/ } Entry() { /** intentionally not initialized.*/ }
Entry( unsigned int pIndex, const aiVector3D& pPosition, float pDistance) Entry( unsigned int pIndex, const aiVector3D& pPosition, ai_real pDistance)
: mIndex( pIndex), mPosition( pPosition), mDistance( pDistance) : mIndex( pIndex), mPosition( pPosition), mDistance( pDistance)
{ } { }

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&,const Vertex&); friend Vertex operator - (const Vertex&,const Vertex&);
// friend Vertex operator + (const Vertex&,float); // friend Vertex operator + (const Vertex&,ai_real);
// friend Vertex operator - (const Vertex&,float); // friend Vertex operator - (const Vertex&,ai_real);
friend Vertex operator * (const Vertex&,float); friend Vertex operator * (const Vertex&,ai_real);
friend Vertex operator / (const Vertex&,float); friend Vertex operator / (const Vertex&,ai_real);
// friend Vertex operator + (float, const Vertex&); // friend Vertex operator + (ai_real, const Vertex&);
// friend Vertex operator - (float, const Vertex&); // friend Vertex operator - (ai_real, const Vertex&);
friend Vertex operator * (float, const Vertex&); friend Vertex operator * (ai_real, const Vertex&);
// friend Vertex operator / (float, const Vertex&); // friend Vertex operator / (ai_real, const Vertex&);
public: public:
@ -146,22 +146,22 @@ public:
/* /*
Vertex& operator += (float v) { Vertex& operator += (ai_real v) {
*this = *this+v; *this = *this+v;
return *this; return *this;
} }
Vertex& operator -= (float v) { Vertex& operator -= (ai_real v) {
*this = *this-v; *this = *this-v;
return *this; return *this;
} }
*/ */
Vertex& operator *= (float v) { Vertex& operator *= (ai_real v) {
*this = *this*v; *this = *this*v;
return *this; return *this;
} }
Vertex& operator /= (float v) { Vertex& operator /= (ai_real v) {
*this = *this/v; *this = *this/v;
return *this; return *this;
} }
@ -217,40 +217,40 @@ private:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** This time binary arithmetics of v0 with a floating-point number */ /** 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* // this is a heavy task for the compiler to optimize ... *pray*
Vertex res; Vertex res;
res.position = op<aiVector3D,float,aiVector3D>()(v0.position,f); res.position = op<aiVector3D,ai_real,aiVector3D>()(v0.position,f);
res.normal = op<aiVector3D,float,aiVector3D>()(v0.normal,f); res.normal = op<aiVector3D,ai_real,aiVector3D>()(v0.normal,f);
res.tangent = op<aiVector3D,float,aiVector3D>()(v0.tangent,f); res.tangent = op<aiVector3D,ai_real,aiVector3D>()(v0.tangent,f);
res.bitangent = op<aiVector3D,float,aiVector3D>()(v0.bitangent,f); res.bitangent = op<aiVector3D,ai_real,aiVector3D>()(v0.bitangent,f);
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { 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) { 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; return res;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** This time binary arithmetics of v0 with a floating-point number */ /** 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* // this is a heavy task for the compiler to optimize ... *pray*
Vertex res; Vertex res;
res.position = op<float,aiVector3D,aiVector3D>()(f,v0.position); res.position = op<ai_real,aiVector3D,aiVector3D>()(f,v0.position);
res.normal = op<float,aiVector3D,aiVector3D>()(f,v0.normal); res.normal = op<ai_real,aiVector3D,aiVector3D>()(f,v0.normal);
res.tangent = op<float,aiVector3D,aiVector3D>()(f,v0.tangent); res.tangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.tangent);
res.bitangent = op<float,aiVector3D,aiVector3D>()(f,v0.bitangent); res.bitangent = op<ai_real,aiVector3D,aiVector3D>()(f,v0.bitangent);
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { 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) { 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; 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); 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); 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); 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); 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); 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); 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); 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); return Vertex::BinaryOp<Intern::divides>(f,v0);
} }
*/ */

View File

@ -68,7 +68,21 @@ union _IEEESingle
uint32_t Exp : 8; uint32_t Exp : 8;
uint32_t Sign : 1; uint32_t Sign : 1;
} IEEE; } IEEE;
} ; };
// ---------------------------------------------------------------------------
/** Data structure to represent the bit pattern of a 64 Bit
* IEEE 754 floating-point number. */
union _IEEEDouble
{
double Double;
struct
{
uint64_t Frac : 52;
uint64_t Exp : 11;
uint64_t Sign : 1;
} IEEE;
};
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Check whether a given float is qNaN. /** Check whether a given float is qNaN.
@ -87,11 +101,19 @@ AI_FORCE_INLINE bool is_qnan(float in)
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Check whether a float is NOT qNaN. /** Check whether a given double is qNaN.
* @param in Input value */ * @param in Input value */
AI_FORCE_INLINE bool is_not_qnan(float in) AI_FORCE_INLINE bool is_qnan(double in)
{ {
return !is_qnan(in); // the straightforward solution does not work:
// return (in != in);
// compiler generates code like this
// load <in> to <register-with-different-width>
// compare <register-with-different-width> against <in>
// FIXME: Use <float> stuff instead? I think fpclassify needs C99
return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1 &&
reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Frac);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -105,10 +127,29 @@ AI_FORCE_INLINE bool is_special_float(float in)
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** @brief Get a fresh qnan. */ /** @brief check whether a double is either NaN or (+/-) INF.
AI_FORCE_INLINE float get_qnan() *
* Denorms return false, they're treated like normal values.
* @param in Input value */
AI_FORCE_INLINE bool is_special_float(double in)
{ {
return std::numeric_limits<float>::quiet_NaN(); return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1);
}
// ---------------------------------------------------------------------------
/** Check whether a float is NOT qNaN.
* @param in Input value */
template<class TReal>
AI_FORCE_INLINE bool is_not_qnan(TReal in)
{
return !is_qnan(in);
}
// ---------------------------------------------------------------------------
/** @brief Get a fresh qnan. */
AI_FORCE_INLINE ai_real get_qnan()
{
return std::numeric_limits<ai_real>::quiet_NaN();
} }
#endif // !! AI_QNAN_H_INCLUDED #endif // !! AI_QNAN_H_INCLUDED

View File

@ -330,7 +330,7 @@ public:
// typedefs for our four configuration maps. // typedefs for our four configuration maps.
// We don't need more, so there is no need for a generic solution // We don't need more, so there is no need for a generic solution
typedef std::map<KeyType, int> IntPropertyMap; typedef std::map<KeyType, int> IntPropertyMap;
typedef std::map<KeyType, float> FloatPropertyMap; typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap; typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
@ -380,7 +380,7 @@ public:
/** Set a floating-point configuration property. /** Set a floating-point configuration property.
* @see SetPropertyInteger() * @see SetPropertyInteger()
*/ */
bool SetPropertyFloat(const char* szName, float fValue); bool SetPropertyFloat(const char* szName, ai_real fValue);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Set a string configuration property. /** Set a string configuration property.
@ -425,8 +425,8 @@ public:
/** Get a floating-point configuration property /** Get a floating-point configuration property
* @see GetPropertyInteger() * @see GetPropertyInteger()
*/ */
float GetPropertyFloat(const char* szName, ai_real GetPropertyFloat(const char* szName,
float fErrorReturn = 10e10f) const; ai_real fErrorReturn = 10e10f) const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Get a string configuration property /** Get a string configuration property

View File

@ -421,7 +421,7 @@ struct Interpolator
* The interpolation algorithm depends on the type of the operands. * The interpolation algorithm depends on the type of the operands.
* aiQuaternion's and aiQuatKey's SLERP, the rest does a simple * aiQuaternion's and aiQuatKey's SLERP, the rest does a simple
* linear interpolation. */ * linear interpolation. */
void operator () (T& out,const T& a, const T& b, float d) const { void operator () (T& out,const T& a, const T& b, ai_real d) const {
out = a + (b-a)*d; out = a + (b-a)*d;
} }
}; // ! Interpolator <T> }; // ! Interpolator <T>
@ -431,7 +431,7 @@ struct Interpolator
template <> template <>
struct Interpolator <aiQuaternion> { struct Interpolator <aiQuaternion> {
void operator () (aiQuaternion& out,const aiQuaternion& a, void operator () (aiQuaternion& out,const aiQuaternion& a,
const aiQuaternion& b, float d) const const aiQuaternion& b, ai_real d) const
{ {
aiQuaternion::Interpolate(out,a,b,d); aiQuaternion::Interpolate(out,a,b,d);
} }
@ -440,7 +440,7 @@ struct Interpolator <aiQuaternion> {
template <> template <>
struct Interpolator <unsigned int> { struct Interpolator <unsigned int> {
void operator () (unsigned int& out,unsigned int a, void operator () (unsigned int& out,unsigned int a,
unsigned int b, float d) const unsigned int b, ai_real d) const
{ {
out = d>0.5f ? b : a; out = d>0.5f ? b : a;
} }
@ -449,7 +449,7 @@ struct Interpolator <unsigned int> {
template <> template <>
struct Interpolator <aiVectorKey> { struct Interpolator <aiVectorKey> {
void operator () (aiVector3D& out,const aiVectorKey& a, void operator () (aiVector3D& out,const aiVectorKey& a,
const aiVectorKey& b, float d) const const aiVectorKey& b, ai_real d) const
{ {
Interpolator<aiVector3D> ipl; Interpolator<aiVector3D> ipl;
ipl(out,a.mValue,b.mValue,d); ipl(out,a.mValue,b.mValue,d);
@ -459,7 +459,7 @@ struct Interpolator <aiVectorKey> {
template <> template <>
struct Interpolator <aiQuatKey> { struct Interpolator <aiQuatKey> {
void operator () (aiQuaternion& out, const aiQuatKey& a, void operator () (aiQuaternion& out, const aiQuatKey& a,
const aiQuatKey& b, float d) const const aiQuatKey& b, ai_real d) const
{ {
Interpolator<aiQuaternion> ipl; Interpolator<aiQuaternion> ipl;
ipl(out,a.mValue,b.mValue,d); ipl(out,a.mValue,b.mValue,d);
@ -469,7 +469,7 @@ struct Interpolator <aiQuatKey> {
template <> template <>
struct Interpolator <aiMeshKey> { struct Interpolator <aiMeshKey> {
void operator () (unsigned int& out, const aiMeshKey& a, void operator () (unsigned int& out, const aiMeshKey& a,
const aiMeshKey& b, float d) const const aiMeshKey& b, ai_real d) const
{ {
Interpolator<unsigned int> ipl; Interpolator<unsigned int> ipl;
ipl(out,a.mValue,b.mValue,d); ipl(out,a.mValue,b.mValue,d);

View File

@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_COLOR4D_H_INC #define AI_COLOR4D_H_INC
#include "./Compiler/pushpack1.h" #include "./Compiler/pushpack1.h"
#include "defs.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -90,12 +91,12 @@ public:
TReal r, g, b, a; TReal r, g, b, a;
} PACK_STRUCT; // !struct aiColor4D } PACK_STRUCT; // !struct aiColor4D
typedef aiColor4t<float> aiColor4D; typedef aiColor4t<ai_real> aiColor4D;
#else #else
struct aiColor4D { struct aiColor4D {
float r, g, b, a; ai_real r, g, b, a;
} PACK_STRUCT; } PACK_STRUCT;
#endif // __cplusplus #endif // __cplusplus

View File

@ -242,10 +242,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_MATH_TWO_PI_F (AI_MATH_PI_F * 2.0f) #define AI_MATH_TWO_PI_F (AI_MATH_PI_F * 2.0f)
#define AI_MATH_HALF_PI_F (AI_MATH_PI_F * 0.5f) #define AI_MATH_HALF_PI_F (AI_MATH_PI_F * 0.5f)
/* Tiny macro to convert from radians to degrees and back */
#define AI_DEG_TO_RAD(x) ((x)*0.0174532925f)
#define AI_RAD_TO_DEG(x) ((x)*57.2957795f)
/* Support for big-endian builds */ /* Support for big-endian builds */
#if defined(__BYTE_ORDER__) #if defined(__BYTE_ORDER__)
# if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) # if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@ -269,5 +265,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#define AI_MAX_ALLOC(type) ((256U * 1024 * 1024) / sizeof(type)) #define AI_MAX_ALLOC(type) ((256U * 1024 * 1024) / sizeof(type))
#ifdef AI_DOUBLE_PRECISION
typedef double ai_real;
/* Tiny macro to convert from radians to degrees and back */
#define AI_DEG_TO_RAD(x) ((x)*0.0174532925)
#define AI_RAD_TO_DEG(x) ((x)*57.2957795)
#else
typedef float ai_real;
/* Tiny macro to convert from radians to degrees and back */
#define AI_DEG_TO_RAD(x) ((x)*0.0174532925f)
#define AI_RAD_TO_DEG(x) ((x)*57.2957795f)
#endif // AI_SINGLEPRECISION
#endif // !! AI_DEFINES_H_INC #endif // !! AI_DEFINES_H_INC

View File

@ -477,13 +477,14 @@ struct aiUVTransform
* rotation center is 0.5f|0.5f. The default value * rotation center is 0.5f|0.5f. The default value
* 0.f. * 0.f.
*/ */
float mRotation; ai_real mRotation;
#ifdef __cplusplus #ifdef __cplusplus
aiUVTransform() aiUVTransform()
: mScaling (1.f,1.f) : mTranslation (0.0,0.0)
, mRotation (0.f) , mScaling (1.0,1.0)
, mRotation (0.0)
{ {
// nothing to be done here ... // nothing to be done here ...
} }

View File

@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_MATRIX3X3_H_INC #define AI_MATRIX3X3_H_INC
#include "./Compiler/pushpack1.h" #include "./Compiler/pushpack1.h"
#include "defs.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -166,14 +167,14 @@ public:
TReal c1, c2, c3; TReal c1, c2, c3;
} PACK_STRUCT; } PACK_STRUCT;
typedef aiMatrix3x3t<float> aiMatrix3x3; typedef aiMatrix3x3t<ai_real> aiMatrix3x3;
#else #else
struct aiMatrix3x3 { struct aiMatrix3x3 {
float a1, a2, a3; ai_real a1, a2, a3;
float b1, b2, b3; ai_real b1, b2, b3;
float c1, c2, c3; ai_real c1, c2, c3;
} PACK_STRUCT; } PACK_STRUCT;
#endif // __cplusplus #endif // __cplusplus

View File

@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vector3.h" #include "vector3.h"
#include "./Compiler/pushpack1.h" #include "./Compiler/pushpack1.h"
#include "defs.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -229,15 +230,15 @@ public:
TReal d1, d2, d3, d4; TReal d1, d2, d3, d4;
} PACK_STRUCT; } PACK_STRUCT;
typedef aiMatrix4x4t<float> aiMatrix4x4; typedef aiMatrix4x4t<ai_real> aiMatrix4x4;
#else #else
struct aiMatrix4x4 { struct aiMatrix4x4 {
float a1, a2, a3, a4; ai_real a1, a2, a3, a4;
float b1, b2, b3, b4; ai_real b1, b2, b3, b4;
float c1, c2, c3, c4; ai_real c1, c2, c3, c4;
float d1, d2, d3, d4; ai_real d1, d2, d3, d4;
} PACK_STRUCT; } PACK_STRUCT;

View File

@ -68,8 +68,9 @@ typedef enum aiMetadataType
AI_INT = 1, AI_INT = 1,
AI_UINT64 = 2, AI_UINT64 = 2,
AI_FLOAT = 3, AI_FLOAT = 3,
AI_AISTRING = 4, AI_DOUBLE = 4,
AI_AIVECTOR3D = 5, AI_AISTRING = 5,
AI_AIVECTOR3D = 6,
#ifndef SWIG #ifndef SWIG
FORCE_32BIT = INT_MAX FORCE_32BIT = INT_MAX
@ -108,6 +109,7 @@ inline aiMetadataType GetAiType( bool ) { return AI_BOOL; }
inline aiMetadataType GetAiType( int ) { return AI_INT; } inline aiMetadataType GetAiType( int ) { return AI_INT; }
inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; } inline aiMetadataType GetAiType( uint64_t ) { return AI_UINT64; }
inline aiMetadataType GetAiType( float ) { return AI_FLOAT; } inline aiMetadataType GetAiType( float ) { return AI_FLOAT; }
inline aiMetadataType GetAiType( double ) { return AI_DOUBLE; }
inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; } inline aiMetadataType GetAiType( aiString ) { return AI_AISTRING; }
inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; } inline aiMetadataType GetAiType( aiVector3D ) { return AI_AIVECTOR3D; }
@ -172,6 +174,9 @@ struct aiMetadata
case AI_FLOAT: case AI_FLOAT:
delete static_cast<float*>(data); delete static_cast<float*>(data);
break; break;
case AI_DOUBLE:
delete static_cast<double*>(data);
break;
case AI_AISTRING: case AI_AISTRING:
delete static_cast<aiString*>(data); delete static_cast<aiString*>(data);
break; break;
@ -248,5 +253,3 @@ struct aiMetadata
}; };
#endif // AI_METADATA_H_INC #endif // AI_METADATA_H_INC

View File

@ -47,6 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifdef __cplusplus #ifdef __cplusplus
#include "defs.h"
template <typename TReal> class aiVector3t; template <typename TReal> class aiVector3t;
template <typename TReal> class aiMatrix3x3t; template <typename TReal> class aiMatrix3x3t;
@ -113,12 +115,12 @@ public:
TReal w, x, y, z; TReal w, x, y, z;
} ; } ;
typedef aiQuaterniont<float> aiQuaternion; typedef aiQuaterniont<ai_real> aiQuaternion;
#else #else
struct aiQuaternion { struct aiQuaternion {
float w, x, y, z; ai_real w, x, y, z;
}; };
#endif #endif

View File

@ -124,7 +124,7 @@ struct aiPlane
{ {
#ifdef __cplusplus #ifdef __cplusplus
aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {} aiPlane () : a(0.f), b(0.f), c(0.f), d(0.f) {}
aiPlane (float _a, float _b, float _c, float _d) aiPlane (ai_real _a, ai_real _b, ai_real _c, ai_real _d)
: a(_a), b(_b), c(_c), d(_d) {} : a(_a), b(_b), c(_c), d(_d) {}
aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {} aiPlane (const aiPlane& o) : a(o.a), b(o.b), c(o.c), d(o.d) {}
@ -132,7 +132,7 @@ struct aiPlane
#endif // !__cplusplus #endif // !__cplusplus
//! Plane equation //! Plane equation
float a,b,c,d; ai_real a,b,c,d;
} PACK_STRUCT; // !struct aiPlane } PACK_STRUCT; // !struct aiPlane
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
@ -160,8 +160,8 @@ struct aiColor3D
{ {
#ifdef __cplusplus #ifdef __cplusplus
aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {} aiColor3D () : r(0.0f), g(0.0f), b(0.0f) {}
aiColor3D (float _r, float _g, float _b) : r(_r), g(_g), b(_b) {} aiColor3D (ai_real _r, ai_real _g, ai_real _b) : r(_r), g(_g), b(_b) {}
explicit aiColor3D (float _r) : r(_r), g(_r), b(_r) {} explicit aiColor3D (ai_real _r) : r(_r), g(_r), b(_r) {}
aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {} aiColor3D (const aiColor3D& o) : r(o.r), g(o.g), b(o.b) {}
/** Component-wise comparison */ /** Component-wise comparison */
@ -200,30 +200,30 @@ struct aiColor3D
} }
/** Multiply with a scalar */ /** Multiply with a scalar */
aiColor3D operator*(float f) const { aiColor3D operator*(ai_real f) const {
return aiColor3D(r*f,g*f,b*f); return aiColor3D(r*f,g*f,b*f);
} }
/** Access a specific color component */ /** Access a specific color component */
float operator[](unsigned int i) const { ai_real operator[](unsigned int i) const {
return *(&r + i); return *(&r + i);
} }
/** Access a specific color component */ /** Access a specific color component */
float& operator[](unsigned int i) { ai_real& operator[](unsigned int i) {
return *(&r + i); return *(&r + i);
} }
/** Check whether a color is black */ /** Check whether a color is black */
bool IsBlack() const { bool IsBlack() const {
static const float epsilon = 10e-3f; static const ai_real epsilon = 10e-3;
return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon; return std::fabs( r ) < epsilon && std::fabs( g ) < epsilon && std::fabs( b ) < epsilon;
} }
#endif // !__cplusplus #endif // !__cplusplus
//! Red, green and blue color values //! Red, green and blue color values
float r, g, b; ai_real r, g, b;
} PACK_STRUCT; // !struct aiColor3D } PACK_STRUCT; // !struct aiColor3D
#include "./Compiler/poppack1.h" #include "./Compiler/poppack1.h"

View File

@ -52,6 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif #endif
#include "./Compiler/pushpack1.h" #include "./Compiler/pushpack1.h"
#include "defs.h"
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
/** Represents a two-dimensional vector. /** Represents a two-dimensional vector.
@ -99,12 +100,12 @@ public:
TReal x, y; TReal x, y;
} PACK_STRUCT; } PACK_STRUCT;
typedef aiVector2t<float> aiVector2D; typedef aiVector2t<ai_real> aiVector2D;
#else #else
struct aiVector2D { struct aiVector2D {
float x, y; ai_real x, y;
}; };
#endif // __cplusplus #endif // __cplusplus

View File

@ -52,6 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif #endif
#include "./Compiler/pushpack1.h" #include "./Compiler/pushpack1.h"
#include "defs.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -130,12 +131,12 @@ public:
} PACK_STRUCT; } PACK_STRUCT;
typedef aiVector3t<float> aiVector3D; typedef aiVector3t<ai_real> aiVector3D;
#else #else
struct aiVector3D { struct aiVector3D {
float x, y, z; ai_real x, y, z;
} PACK_STRUCT; } PACK_STRUCT;
#endif // __cplusplus #endif // __cplusplus