tools.h

00001 
00002 
00003 
00004 
00005 stringc toStringC(int i)
00006 {
00007         char buf[16];
00008         itoa(i, buf, 10);
00009         buf[15] = 0;
00010         stringc result(buf);
00011         return result;
00012 }
00013 
00014 stringw toStringW(int i)
00015 {
00016         wchar_t buf[16];
00017         _itow(i, buf, 10);
00018         buf[15] = 0;
00019         stringw result(buf);
00020         return result;
00021 }
00022 
00023 stringw toStringW(char* name, v3 v)
00024 {
00025         char buf[128];
00026         sprintf(buf, "[%s] x:%+.4f y:%+.4f z:%+.4f", name, v.X, v.Y, v.Z); 
00027         buf[127] = 0;
00028         stringw result(buf);
00029         return result;
00030 }
00031 
00032 stringw toStringW(char* name, CalQuaternion q)
00033 {
00034         char buf[128];
00035         sprintf(buf, "[%s] x:%+.4f y:%+.4f z:%+.4f w:%+.4f", name, q.x, q.y, q.z, q.w); 
00036         buf[127] = 0;
00037         stringw result(buf);
00038         return result;
00039 }
00040 
00041 stringw toStringW(char* name, quaternion q)
00042 {
00043         char buf[128];
00044         sprintf(buf, "[%s] x:%+.4f y:%+.4f z:%+.4f w:%+.4f", name, q.X, q.Y, q.Z, q.W); 
00045         buf[127] = 0;
00046         stringw result(buf);
00047         return result;
00048 }
00049 
00050 stringw toStringW(char* name, int i)
00051 {
00052         char buf[64];
00053         sprintf(buf, "%s:%i", name, i); 
00054         buf[63] = 0;
00055         stringw result(buf);
00056         return result;
00057 }
00058 
00059 stringw toStringW(char* name, float f)
00060 {
00061         char buf[64];
00062         sprintf(buf, "%s:%f", name, f);
00063         buf[63] = 0;
00064         stringw result(buf);
00065         return result;
00066 }
00067 
00068 void addDbg(stringw text)
00069 {
00070         stringw old(dbg->getText());
00071         old.append("\n");
00072         stringw now(old + text);
00073         dbg->setText(now.c_str());
00074 }
00075 
00076 void addDbg(stringc text)
00077 {
00078         stringw old(dbg->getText());
00079         old.append("\n");
00080         old.append(text.c_str());
00081         stringw now(old);
00082         dbg->setText(now.c_str());
00083 }
00084 
00085 void addDbg(char* text)
00086 {
00087         stringw old(dbg->getText());
00088         old.append("\n");
00089         stringw now(old + text);
00090         dbg->setText(now.c_str());
00091 }
00092 
00093 void addDbg(char* text, v3 vector)
00094 {
00095         addDbg(toStringW(text, vector));
00096 }
00097 
00098 void addDbg(char* text, CalQuaternion q)
00099 {
00100         addDbg(toStringW(text, q));
00101 }
00102 
00103 void addDbg(char* text, quaternion q)
00104 {
00105         addDbg(toStringW(text, q));
00106 }
00107 
00108 void addDbg(char* text, int i)
00109 {
00110         addDbg(toStringW(text, i));
00111 }
00112 
00113 void addDbg(char* text, float f)
00114 {
00115         addDbg(toStringW(text, f));
00116 }
00117 
00118 void clrDbg()
00119 {
00120         dbg->setText(stringw("").c_str());
00121 }
00122 
00123 v3 getTargetAngle(vector3df v, vector3df r) 
00124 { 
00125    //v -current node position 
00126    //r -target node position 
00127 
00128    vector3df angle; 
00129    float x,y,z; 
00130    x = r.X - v.X; 
00131    y = r.Y - v.Y; 
00132    z = r.Z - v.Z; 
00133     
00134    //angle in X-Z plane 
00135    angle.Y = atan2 (x, z); 
00136    angle.Y *= (180 / PI); //converting from rad to degrees 
00137     
00138    //just making sure angle is somewhere between 0-360 degrees 
00139    if(angle.Y < 0) angle.Y += 360; 
00140    if(angle.Y >= 360) angle.Y -= 360; 
00141     
00142    //angle in Y-Z plane while Z and X axes are already rotated around Y 
00143    float z1 = sqrt(x*x + z*z); 
00144     
00145    angle.X = atan2 (z1, y); 
00146    angle.X *= (180 / PI); //converting from rad to degrees 
00147    angle.X -= 90; 
00148     
00149    //just making sure angle is somewhere between 0-360 degrees 
00150    if(angle.X < 0) angle.X += 360; 
00151    if(angle.X >= 360) angle.X -= 360; 
00152 
00153    return angle; 
00154 } 
00155 
00156 const stringc makeMediaString(char* fileName)
00157 {
00158         stringc result(MEDIAPATH);
00159         result.append(fileName);
00160         return result;
00161 }
00162 
00163 const stringc makeMediaString(irr::core::stringc fileName)
00164 {
00165         stringc result(MEDIAPATH);
00166         result.append(fileName);
00167         return result;
00168 }
00169 
00170 const stringc makeASCII(int i)
00171 {
00172         char buf[16];
00173         itoa(i, buf, 10);
00174         irr::core::stringc result(buf);
00175         return result;
00176 }
00177 
00178 int isInRange(int valToCheck, int minRange, int maxRange)
00179 {
00180         return ( (valToCheck >= minRange) && (valToCheck <= maxRange) );
00181 }
00182 
00183 int isInRange(float valToCheck, float minRange, float maxRange)
00184 {
00185         return ( (valToCheck >= minRange) && (valToCheck <= maxRange) );
00186 }
00187 
00188 // maps a float (in) from its range (inMin to inMax) to a targetRange (targetMin to targetMax)
00189 // example: mapToScale(-0.7f, 0.3f, 30.0f, -45.0f, 45.0f)
00190 // an input angle of 30.0 between its range from -45.0 to +45.0 degrees
00191 // shold be mapped to another range from 0.1 to 0.9
00192 // result would be 0.1 + ( (30+45) / 90 * (0.1-0.9) ) = 0.766
00193 float mapToScale(float targetMin, float targetMax, float in, float inMin, float inMax)
00194 {
00195         float result = 0.0f;
00196         
00197         if ( inMin<inMax && targetMin<targetMax && inMin<=in && inMax>=in )
00198         {
00199         // bring in to zero
00200         float zeroedresult = ( abs(in - inMin)) / ( abs(inMin - inMax) ) * ( abs(targetMin - targetMax) );
00201         result = targetMin + abs(zeroedresult);
00202         }
00203         else
00204         {
00205                 cout << "mapToScale() RANGE ERROR" << endl;
00206         }
00207 
00208         return result;
00209 }
00210 
00211 CalQuaternion irrToCalQuaternion(quaternion qIn)
00212 {
00213         CalQuaternion result(qIn.X, qIn.Y, qIn.Z, qIn.W);
00214         return result;
00215 }

Generated on Sun Dec 2 18:30:26 2007 for DrgonWings by  doxygen 1.5.4