00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asVector3d.h"
00018
00019 #ifdef __COMPILE_WITH_ANGELSCRIPT__
00020
00021 #include "asIrrHelper.h"
00022 #include "asLine3d.h"
00023
00024
00025
00029 template<typename T>
00030 void constructor(void *memory)
00031 {
00032 new (memory) line3d<T>();
00033 }
00034
00038 template<typename T>
00039 void constructor(const line3d<T> &other, void *memory)
00040 {
00041 new (memory) line3d<T>(other);
00042 }
00043
00047 template<typename T>
00048 void constructor(const vector3d<T> &start, const vector3d<T> &end, void *memory)
00049 {
00050 new (memory) line3d<T>(start, end);
00051 }
00052
00056 template<typename T>
00057 void deconstructor(void *memory)
00058 {
00059 ((line3d<T>*)memory)->~line3d<T>();
00060 }
00061
00062
00067 template<typename T>
00068 void bindLine3dT(asIScriptEngine *engine, const char *typeName, const char *asType)
00069 {
00070
00071 int r;
00072 std::stringstream ss;
00073
00074
00075 r = engine->RegisterObjectType(typeName, sizeof(line3d<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CD); assert(r >= 0);
00076
00077
00078
00079 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructor<T>,
00080 (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00081
00082 ss.str("");
00083 ss << "void f(const " << typeName << " &in)";
00084 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00085 (const line3d<T>&, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00086
00087 ss.str("");
00088 ss << "void f(const " << getVector3dName(asType) << " &in, const " << getVector3dName(asType) << " &in)";
00089 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00090 (const vector3d<T>&, const vector3d<T>&, void*), void),
00091 asCALL_CDECL_OBJLAST); assert(r >= 0);
00092
00093 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructor<T>),
00094 asCALL_CDECL_OBJLAST); assert(r >= 0);
00095
00096
00097
00098 ss.str("");
00099 ss << typeName << " opAdd(const " << getVector3dName(asType) << " &in)";
00100 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00101 asFUNCTIONPR((add< line3d<T>, line3d<T>, vector3d<T> >),
00102 (const line3d<T>&, const vector3d<T>&), line3d<T>),
00103 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00104
00105
00106 ss.str("");
00107 ss << typeName << "& opAddAssign(const " << getVector3dName(asType) << " &in)";
00108 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00109 asMETHODPR(line3d<T>, operator+=, (const vector3d<T>&),
00110 line3d<T>&), asCALL_THISCALL); assert(r >= 0);
00111
00112
00113 ss.str("");
00114 ss << typeName << " opSub(const " << getVector3dName(asType) << " &in)";
00115 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00116 asFUNCTIONPR((substract< line3d<T>, line3d<T>, vector3d<T> >),
00117 (const line3d<T>&, const vector3d<T>&), line3d<T>),
00118 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00119
00120
00121 ss.str("");
00122 ss << typeName << "& opSubAssign(const " << getVector3dName(asType) << " &in)";
00123 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00124 asMETHODPR(line3d<T>, operator-=, (const vector3d<T>&),
00125 line3d<T>&), asCALL_THISCALL); assert(r >= 0);
00126
00127
00128 ss.str("");
00129 ss << "bool opEquals(const " << typeName << " &in)";
00130
00131 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(), asFUNCTIONPR(equal< line3d<T> >,
00132 (const line3d<T>&, const line3d<T>&), bool), asCALL_CDECL_OBJFIRST); assert(r >= 0);
00133
00134
00135 ss.str("");
00136 ss << getVector3dName(asType) << " getClosestPoint(const " << getVector3dName(asType) << " &in)";
00137 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00138 asMETHOD(line3d<T>, getClosestPoint), asCALL_THISCALL); assert(r >= 0);
00139
00140 ss.str("");
00141 ss << "bool getIntersectionWithSphere(" << getVector3dName(asType) << ", " << asType << ", f64)";
00142 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00143 asMETHOD(line3d<T>, getIntersectionWithSphere), asCALL_THISCALL); assert(r >= 0);
00144
00145 ss.str("");
00146 ss << asType << " getLength()";
00147 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00148 asMETHOD(line3d<T>, getLength), asCALL_THISCALL); assert(r >= 0);
00149
00150 ss.str("");
00151 ss << asType << " getLengthSQ()";
00152 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00153 asMETHOD(line3d<T>, getLengthSQ), asCALL_THISCALL); assert(r >= 0);
00154
00155 ss.str("");
00156 ss << getVector3dName(asType) << " getMiddle()";
00157 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00158 asMETHOD(line3d<T>, getMiddle), asCALL_THISCALL); assert(r >= 0);
00159
00160 ss.str("");
00161 ss << getVector3dName(asType) << " getVector()";
00162 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00163 asMETHOD(line3d<T>, getVector), asCALL_THISCALL); assert(r >= 0);
00164
00165 ss.str("");
00166 ss << "bool isPointBetweenStartAndEnd(const " << getVector3dName(asType) << " &in)";
00167 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00168 asMETHOD(line3d<T>, isPointBetweenStartAndEnd), asCALL_THISCALL); assert(r >= 0);
00169
00170 ss.str("");
00171 ss << "void setLine(const " << typeName << " &in)";
00172 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00173 asMETHODPR(line3d<T>, setLine, (const line3d<T>&), void), asCALL_THISCALL); assert(r >= 0);
00174
00175 ss.str("");
00176 ss << "void setLine(const " << getVector3dName(asType) << " &in, const " << getVector3dName(asType) << " &in)";
00177 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00178 asMETHODPR(line3d<T>, setLine, (const vector3d<T>&, const vector3d<T>&), void),
00179 asCALL_THISCALL); assert(r >= 0);
00180
00181
00182 ss.str("");
00183 ss << getVector3dName(asType) << " end";
00184 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(line3d<T>, end)); assert(r >= 0);
00185
00186 ss.str("");
00187 ss << getVector3dName(asType) << " start";
00188 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(line3d<T>, start)); assert(r >= 0);
00189 }
00190
00193 void bindLine3d(asIScriptEngine *engine)
00194 {
00195 bindLine3dT<f32>(engine, "line3df", "f32");
00196 bindLine3dT<s32>(engine, "line3di", "s32");
00197 }
00198
00201 std::string getLine3dName(const std::string &asType)
00202 {
00203 if(asType == "f32") return std::string("line3df");
00204 if(asType == "s32") return std::string("line3di");
00205 else return std::string("");
00206 }
00207
00208 #endif // __COMPILE_WITH_ANGELSCRIPT__
00209
00210