00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __COMMON_H__
00013 #define __COMMON_H__
00014
00015 #ifdef WIN_X64
00016 #pragma warning(disable:4005)
00017 #endif
00018
00020 const float EPSILON = 1e-5f;
00022 const float DEG2RAD = 0.017453293f;
00024 const float RAD2DEG = 57.29577951f;
00025
00027 const float MAX_FLOAT = 3.40282347e37F;
00029 const float MIN_FLOAT = -3.40282347e37F;
00030
00031 #include "3dmath.h"
00032 #include <wx/string.h>
00033
00034
00035 #ifdef GRAPHVIZ_SUPPORT
00036 #include <vector>
00037
00038 class wx_label_writer
00039 {
00040 public:
00041 wx_label_writer(std::vector<wxString> * _name) : name(_name) {}
00042 void operator()(std::ostream& out, const int& v) const
00043 {
00044 out << "[label=\"" << name->at(v).To8BitData() << "\"]";
00045 }
00046 private:
00047 std::vector<wxString> * name;
00048 };
00049 #endif
00050
00051
00052 #ifdef __WINDOWS__
00053 #define DLLIMPORT __declspec(dllimport)
00054 #define DLLEXPORT __declspec(dllexport)
00055 #else
00056 #define DLLIMPORT __attribute__ ((visibility("default")))
00057 #define DLLEXPORT
00058 #define __max(a,b) (((a) > (b)) ? (a) : (b))
00059 #define __min(a,b) (((a) < (b)) ? (a) : (b))
00060 #define _strnicmp strncasecmp
00061 #define _isnan isnan
00062 #endif
00063
00064 #define SAFE_DELETE(a)\
00065 {if (a)\
00066 delete (a);\
00067 (a) = NULL;}
00068
00069 #define SAFE_DELETE_ARR(a)\
00070 {if (a)\
00071 delete [] (a);\
00072 (a) = NULL;}
00073
00074 #define SAFE_DELETE_ARR_EACH(a, cnt)\
00075 for (unsigned _xx_ = 0; _xx_ < (cnt); _xx_++)\
00076 SAFE_DELETE((a)[_xx_])
00077
00078 #define SAFE_RELEASE(a)\
00079 {if (a)\
00080 (a)->Release();}
00081
00083 const wxString TRUE_STRINGS[] = { wxT("true"), wxT("enable"), wxT("enabled"), wxT("on"), wxT("yes"), wxT("1") };
00084 const size_t TRUE_STRINGS_COUNT = 6;
00085 const unsigned GL_ID_NONE = (unsigned)~(unsigned(0));
00086
00087 typedef vector2 VECTOR2;
00088 typedef vector3 VECTOR3;
00089 typedef vector4 VECTOR4;
00090 typedef matrix MATRIX;
00091 typedef plane PLANE;
00092
00093 #define VECTOR3_XAXIS VECTOR3(1,0,0)
00094 #define VECTOR3_YAXIS VECTOR3(0,1,0)
00095 #define VECTOR3_ZAXIS VECTOR3(0,0,1)
00096
00098
00099 inline wxString CloneWxString(const wxString & str)
00100 {
00101 wxString cloned;
00102 return cloned.append(str);
00103 }
00104
00106 inline bool isTrue(const wxString & val)
00107 {
00108 for (size_t i = 0; i < TRUE_STRINGS_COUNT; i++)
00109 if (val.IsSameAs(TRUE_STRINGS[i], false))
00110 return true;
00111 return false;
00112 }
00113
00115 inline int roundVR(float x)
00116 {
00117 return int(x > 0.0f ? x + 0.5f : x - 0.5f);
00118 }
00119
00121 inline int roundVR(double x)
00122 {
00123 return int(x > 0.0 ? x + 0.5 : x - 0.5);
00124 }
00125
00127 #define ABS absolute
00128
00130 template <typename T>
00131 inline T absolute(T x)
00132 {
00133 return ( x >= 0 ? x : -x );
00134 }
00135
00137 inline int random(int min, int max)
00138 {
00139 return rand()%(max-min+1) + min;
00140 }
00141
00143 inline float random(float min, float max)
00144 {
00145 return float(rand())/RAND_MAX * (max - min) + min;
00146 }
00147
00149 inline double random(double min, double max)
00150 {
00151 return double(rand())/RAND_MAX * (max - min) + min;
00152 }
00153
00154 #endif