00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asIrrHelper.h"
00018 #include "asAabbox3d.h"
00019 #include "asVector3d.h"
00020 #include "asLine3d.h"
00021
00022
00023
00027 template<typename T>
00028 void constructor(void *memory)
00029 {
00030 new (memory) aabbox3d<T>();
00031 }
00032
00036 template<typename T>
00037 void constructor(T minX, T minY, T minZ, T maxX, T maxY, T maxZ, void *memory)
00038 {
00039 new (memory) aabbox3d<T>(minX, minY, minZ, maxX, maxY, maxZ);
00040 }
00041
00045 template<typename T>
00046 void constructor(const vector3d<T> &init, void *memory)
00047 {
00048 new (memory) aabbox3d<T>(init);
00049 }
00050
00054 template<typename T>
00055 void constructor(const vector3d<T> &min, const vector3d<T> &max, void *memory)
00056 {
00057 new (memory) aabbox3d<T>(min, max);
00058 }
00059
00063 template<typename T>
00064 void deconstructor(void *memory)
00065 {
00066 ((aabbox3d<T>*)memory)->~aabbox3d<T>();
00067 }
00068
00069
00074 template<typename T>
00075 void bindAabbox3dT(asIScriptEngine *engine, const char *typeName, const char *asType)
00076 {
00077
00078 int r;
00079 std::stringstream ss;
00080
00081
00082 r = engine->RegisterObjectType(typeName, sizeof(aabbox3d<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CD); assert(r >= 0);
00083
00084
00085
00086 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructor<T>,
00087 (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00088
00089 ss.str("");
00090 ss << "void f(" << asType << ", " << asType << ", " << asType << ", " << asType << ", "
00091 << asType << ", " << asType << ", " << asType << ")";
00092 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00093 (T, T, T, T, T, T, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00094
00095 ss.str("");
00096 ss << "void f(const " << getVector3dName(asType) << " &in)";
00097 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00098 (const vector3d<T>&, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00099
00100 ss.str("");
00101 ss << "void f(const " << getVector3dName(asType) << " &in, const " << getVector3dName(asType) << " &in)";
00102 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00103 (const vector3d<T>&, const vector3d<T>&, void*), void), asCALL_CDECL_OBJLAST);
00104 assert(r >= 0);
00105
00106 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructor<T>),
00107 asCALL_CDECL_OBJLAST); assert(r >= 0);
00108
00109
00110 ss.str("");
00111 ss << "bool f(const " << typeName << " &in, const " << typeName << " &in)";
00112 std::string declComparison = ss.str();
00113
00114 r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, declComparison.c_str(), asFUNCTIONPR(equal< aabbox3d<T> >,
00115 (const aabbox3d<T>&, const aabbox3d<T>&), bool), asCALL_CDECL); assert(r >= 0);
00116 r = engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL, declComparison.c_str(), asFUNCTIONPR(not_equal< aabbox3d<T> >,
00117 (const aabbox3d<T>&, const aabbox3d<T>&), bool), asCALL_CDECL); assert(r >= 0);
00118
00119
00120 ss.str("");
00121 ss << "void addInternalBox(const " << typeName << " &in)";
00122 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00123 asMETHOD(aabbox3d<T>, addInternalBox), asCALL_THISCALL); assert(r >= 0);
00124
00125 ss.str("");
00126 ss << "void addInternalPoint(const " << getVector3dName(asType) << " &in)";
00127 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00128 asMETHODPR(aabbox3d<T>, addInternalPoint, (const vector3d<T>&), void),
00129 asCALL_THISCALL); assert(r >= 0);
00130
00131 ss.str("");
00132 ss << asType << " getArea()";
00133 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00134 asMETHOD(aabbox3d<T>, getArea), asCALL_THISCALL); assert(r >= 0);
00135
00136 ss.str("");
00137 ss << getVector3dName(asType) << " getCenter()";
00138 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00139 asMETHOD(aabbox3d<T>, getCenter), asCALL_THISCALL); assert(r >= 0);
00140
00141 ss.str("");
00142 ss << getVector3dName(asType) << " getExtent()";
00143 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00144 asMETHOD(aabbox3d<T>, getExtent), asCALL_THISCALL); assert(r >= 0);
00145
00146 ss.str("");
00147 ss << typeName << " getInterpolated(const " << typeName << " &in, f64)";
00148 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00149 asMETHOD(aabbox3d<T>, getInterpolated), asCALL_THISCALL); assert(r >= 0);
00150
00151 ss.str("");
00152 ss << asType << " getVolume()";
00153 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00154 asMETHOD(aabbox3d<T>, getVolume), asCALL_THISCALL); assert(r >= 0);
00155
00156 ss.str("");
00157 ss << "bool intersectsWithBox(const " << typeName << " &in)";
00158 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00159 asMETHOD(aabbox3d<T>, intersectsWithBox), asCALL_THISCALL); assert(r >= 0);
00160
00161 ss.str("");
00162 ss << "bool intersectsWithLine(const " << getLine3dName(asType) << " &in)";
00163 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00164 asMETHODPR(aabbox3d<T>, intersectsWithLine, (const line3d<T>&) const, bool),
00165 asCALL_THISCALL); assert(r >= 0);
00166
00167 ss.str("");
00168 ss << "bool isFullInside(const " << typeName << " &in)";
00169 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00170 asMETHOD(aabbox3d<T>, isFullInside), asCALL_THISCALL); assert(r >= 0);
00171
00172 ss.str("");
00173 ss << "bool isPointInside(const " << getVector3dName(asType) << " &in)";
00174 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00175 asMETHOD(aabbox3d<T>, isPointInside), asCALL_THISCALL); assert(r >= 0);
00176
00177 ss.str("");
00178 ss << "bool isPointTotalInside(const " << getVector3dName(asType) << " &in)";
00179 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00180 asMETHOD(aabbox3d<T>, isPointTotalInside), asCALL_THISCALL); assert(r >= 0);
00181
00182 r = engine->RegisterObjectMethod(typeName, "void repair()",
00183 asMETHOD(aabbox3d<T>, repair), asCALL_THISCALL); assert(r >= 0);
00184
00185 ss.str("");
00186 ss << "void reset(const " << getVector3dName(asType) << " &in)";
00187 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00188 asMETHODPR(aabbox3d<T>, reset, (const vector3d<T>&), void), asCALL_THISCALL);
00189 assert(r >= 0);
00190
00191 ss.str("");
00192 ss << "void reset(const " << typeName << " &in)";
00193 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00194 asMETHODPR(aabbox3d<T>, reset, (const aabbox3d<T>&), void), asCALL_THISCALL);
00195 assert(r >= 0);
00196
00197 ss.str("");
00198 ss << "void reset(" << asType << ", " << asType << ", " << asType << ")";
00199 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00200 asMETHODPR(aabbox3d<T>, reset, (T, T, T), void), asCALL_THISCALL);
00201 assert(r >= 0);
00202
00203
00204 ss.str("");
00205 ss << getVector3dName(asType) << " MaxEdge";
00206 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(aabbox3d<T>, MaxEdge)); assert(r >= 0);
00207
00208 ss.str("");
00209 ss << getVector3dName(asType) << " MinEdge";
00210 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(aabbox3d<T>, MinEdge)); assert(r >= 0);
00211 }
00212
00215 void bindAabbox3d(asIScriptEngine *engine)
00216 {
00217 bindAabbox3dT<f32>(engine, "aabbox3df", "f32");
00218 bindAabbox3dT<s32>(engine, "aabbox3di", "s32");
00219 }
00220
00223 std::string getAabbox3dName(const std::string &asType)
00224 {
00225 if(asType == "f32") return std::string("aabbox3df");
00226 if(asType == "s32") return std::string("aabbox3di");
00227 else return std::string("");
00228 }
00229
00230