00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asVector2d.h"
00018
00019 #ifdef __COMPILE_WITH_ANGELSCRIPT__
00020
00021 #include "asIrrHelper.h"
00022 #include "asLine2d.h"
00023
00024
00025
00029 template<typename T>
00030 void constructor(void *memory)
00031 {
00032 new (memory) line2d<T>();
00033 }
00034
00038 template<typename T>
00039 void constructor(const line2d<T> &other, void *memory)
00040 {
00041 new (memory) line2d<T>(other);
00042 }
00043
00047 template<typename T>
00048 void constructor(const vector2d<T> &start, const vector2d<T> &end, void *memory)
00049 {
00050 new (memory) line2d<T>(start, end);
00051 }
00052
00056 template<typename T>
00057 void deconstructor(void *memory)
00058 {
00059 ((line2d<T>*)memory)->~line2d<T>();
00060 }
00061
00062
00067 template<typename T>
00068 void bindLine2dT(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(line2d<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 line2d<T>&, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00086
00087 ss.str("");
00088 ss << "void f(const " << getVector2dName(asType) << " &in, const " << getVector2dName(asType) << " &in)";
00089 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00090 (const vector2d<T>&, const vector2d<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 " << getVector2dName(asType) << " &in)";
00100 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00101 asFUNCTIONPR((add< line2d<T>, line2d<T>, vector2d<T> >),
00102 (const line2d<T>&, const vector2d<T>&), line2d<T>),
00103 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00104
00105
00106 ss.str("");
00107 ss << typeName << "& opAddAssign(const " << getVector2dName(asType) << " &in)";
00108 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00109 asMETHODPR(line2d<T>, operator+=, (const vector2d<T>&),
00110 line2d<T>&), asCALL_THISCALL); assert(r >= 0);
00111
00112
00113 ss.str("");
00114 ss << typeName << " opSub(const " << getVector2dName(asType) << " &in)";
00115 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00116 asFUNCTIONPR((substract< line2d<T>, line2d<T>, vector2d<T> >),
00117 (const line2d<T>&, const vector2d<T>&), line2d<T>),
00118 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00119
00120
00121 ss.str("");
00122 ss << typeName << "& opSubAssign(const " << getVector2dName(asType) << " &in)";
00123 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00124 asMETHODPR(line2d<T>, operator-=, (const vector2d<T>&),
00125 line2d<T>&), asCALL_THISCALL); assert(r >= 0);
00126
00127
00128 ss.str("");
00129 ss << "bool opEquals(const " << typeName << " &in)";
00130 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(), asFUNCTIONPR(equal< line2d<T> >,
00131 (const line2d<T>&, const line2d<T>&), bool), asCALL_CDECL_OBJFIRST); assert(r >= 0);
00132
00133
00134 ss.str("");
00135 ss << "f64 getAngleWith(const " << typeName << " &in)";
00136 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00137 asMETHOD(line2d<T>, getAngleWith), asCALL_THISCALL); assert(r >= 0);
00138
00139 ss.str("");
00140 ss << getVector2dName(asType) << " getClosestPoint(const " << getVector2dName(asType) << " &in)";
00141 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00142 asMETHOD(line2d<T>, getClosestPoint), asCALL_THISCALL); assert(r >= 0);
00143
00144 r = engine->RegisterObjectMethod(typeName, "f64 getLength()",
00145 asMETHOD(line2d<T>, getLength), asCALL_THISCALL); assert(r >= 0);
00146
00147 ss.str("");
00148 ss << asType << " getLengthSQ()";
00149 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00150 asMETHOD(line2d<T>, getLengthSQ), asCALL_THISCALL); assert(r >= 0);
00151
00152 ss.str("");
00153 ss << getVector2dName(asType) << " getMiddle()";
00154 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00155 asMETHOD(line2d<T>, getMiddle), asCALL_THISCALL); assert(r >= 0);
00156
00157 ss.str("");
00158 ss << asType << " getPointOrientation(const " << getVector2dName(asType) << " &in)";
00159 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00160 asMETHOD(line2d<T>, getPointOrientation), asCALL_THISCALL); assert(r >= 0);
00161
00162 ss.str("");
00163 ss << getVector2dName(asType) << " getUnitVector()";
00164 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00165 asMETHOD(line2d<T>, getUnitVector), asCALL_THISCALL); assert(r >= 0);
00166
00167 ss.str("");
00168 ss << getVector2dName(asType) << " getVector()";
00169 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00170 asMETHOD(line2d<T>, getVector), asCALL_THISCALL); assert(r >= 0);
00171
00172 ss.str("");
00173 ss << "bool intersectWith(const " << typeName << " &in, const " << getVector2dName(asType) << " &out)";
00174 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00175 asMETHOD(line2d<T>, intersectWith), asCALL_THISCALL); assert(r >= 0);
00176
00177 ss.str("");
00178 ss << "bool isPointBetweenStartAndEnd(const " << getVector2dName(asType) << " &in)";
00179 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00180 asMETHOD(line2d<T>, isPointBetweenStartAndEnd), asCALL_THISCALL); assert(r >= 0);
00181
00182 ss.str("");
00183 ss << "bool isPointOnLine(const " << typeName << " &in)";
00184 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00185 asMETHOD(line2d<T>, isPointOnLine), asCALL_THISCALL); assert(r >= 0);
00186
00187 ss.str("");
00188 ss << "void setLine(const " << typeName << " &in)";
00189 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00190 asMETHODPR(line2d<T>, setLine, (const line2d<T>&), void), asCALL_THISCALL); assert(r >= 0);
00191
00192 ss.str("");
00193 ss << "void setLine(const " << getVector2dName(asType) << " &in, const " << getVector2dName(asType) << " &in)";
00194 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00195 asMETHODPR(line2d<T>, setLine, (const vector2d<T>&, const vector2d<T>&), void),
00196 asCALL_THISCALL); assert(r >= 0);
00197
00198
00199 ss.str("");
00200 ss << getVector2dName(asType) << " end";
00201 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(line2d<T>, end)); assert(r >= 0);
00202
00203 ss.str("");
00204 ss << getVector2dName(asType) << " start";
00205 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(line2d<T>, start)); assert(r >= 0);
00206 }
00207
00210 void bindLine2d(asIScriptEngine *engine)
00211 {
00212 bindLine2dT<f32>(engine, "line2df", "f32");
00213 bindLine2dT<s32>(engine, "line2di", "s32");
00214 }
00215
00218 std::string getLine2dName(const std::string &asType)
00219 {
00220 if(asType == "f32") return std::string("line2df");
00221 if(asType == "s32") return std::string("line2di");
00222 else return std::string("");
00223 }
00224
00225 #endif // __COMPILE_WITH_ANGELSCRIPT__
00226
00227