//----------------------------------------------------------------------------- // Torque Game Engine // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- #ifndef DTSUTIL_H_ #define DTSUTIL_H_ #include "DTSTypes.h" #include "DTSShape.h" #include "DTSPlusTypes.h" #include "appNode.h" #ifdef _MSC_VER #pragma warning(disable : 4996) #endif namespace DTS { #ifndef M_PI const F64 M_PI = 3.14159265358979323846; #endif const S8 PATH_DELIM_CHAR = '\\'; const S8 PATH_DELIM_STR[] = "\\"; template inline const T & getmax(const T & t1, const T & t2) { return t1>t2 ? t1 : t2; } template inline const T & getmin(const T & t1, const T & t2) { return t1 inline void delElementAtIndex(std::vector & vec, S32 idx) { vec.erase(vec.begin() + idx); } template inline void insElementAtIndex(std::vector & vec, S32 idx, const T & el) { vec.insert(vec.begin() + idx,el); } template inline void delElement(std::vector & vec, const T & el) { for(S32 i=0;i inline bool containsElement(std::vector & vec, const T & el ) { S32 count = 0; for(S32 i=0;i 0) return true; else return false; } template inline void addUniqueElement(std::vector & vec, const T & el ) { if( !containsElement(vec, el) ) vec.push_back(el); } // add a method that Torque vectors has but std::vectors don't template inline void appendVector(std::vector & m1, const std::vector & m2) { m1.insert(m1.end(),m2.begin(),m2.end()); } inline bool isZero(F32 f, F32 tol) { return fabs(f) inline T* constructInPlace(T* p) { return new(p) T; } template inline void destructInPlace(T* p) { p->~T(); } struct AffineParts { Point3D trans; // Translation components Quaternion rot; // Essential rotation Quaternion scaleRot; // Stretch rotation Point3D scale; // Stretch factors F32 sign; // Sign of determinant }; extern void decomp_affine(const Matrix<4,4,F32> &, AffineParts *); extern void zapScale(Matrix<4,4,F32> &); extern void getLocalNodeTransform(AppNode * node, AppNode * parent, AffineParts & child0, AffineParts & parent0, const AppTime & time, Quaternion & rot, Point3D & trans, Quaternion & srot, Point3D & scale); extern void getBlendNodeTransform(AppNode * node, AppNode * parent, AffineParts & child0, AffineParts & parent0, const AppTime & time, const AppTime & referenceTime, Quaternion & rot, Point3D & trans, Quaternion & srot, Point3D & scale); extern void getDeltaTransform(AppNode * node, const AppTime & time1, const AppTime & time2, Quaternion & rot, Point3D & trans, Quaternion & srot, Point3D & scale); inline void setMembershipArray(std::vector & m, bool setTo, S32 a, S32 b) { if (m.size() < U32(b)) m.resize(b); for (S32 i=a; i & m, bool setTo, S32 a) { m[a]=setTo; } inline bool allSet(std::vector & m) { for (U32 i=0; i & m1, const std::vector & m2) { assert(m1.size()==m2.size()); for (U32 i=0; i & m1, const std::vector & m2) { assert(m1.size()==m2.size()); for (U32 i=0; i