00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asIrrHelper.h"
00018 #include "asLine2d.h"
00019 #include "asVector2d.h"
00020
00021
00022
00026 template<typename T>
00027 void constructor(void *memory)
00028 {
00029 new (memory) line2d<T>();
00030 }
00031
00035 template<typename T>
00036 void constructor(const line2d<T> &other, void *memory)
00037 {
00038 new (memory) line2d<T>(other);
00039 }
00040
00044 template<typename T>
00045 void constructor(const vector2d<T> &start, const vector2d<T> &end, void *memory)
00046 {
00047 new (memory) line2d<T>(start, end);
00048 }
00049
00053 template<typename T>
00054 void deconstructor(void *memory)
00055 {
00056 ((line2d<T>*)memory)->~line2d<T>();
00057 }
00058
00059
00064 template<typename T>
00065 void bindLine2dT(asIScriptEngine *engine, const char *typeName, const char *asType)
00066 {
00067
00068 int r;
00069 std::stringstream ss;
00070
00071
00072 r = engine->RegisterObjectType(typeName, sizeof(line2d<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CD); assert(r >= 0);
00073
00074
00075
00076 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructor<T>,
00077 (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00078
00079 ss.str("");
00080 ss << "void f(const " << typeName << " &in)";
00081 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00082 (const line2d<T>&, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00083
00084 ss.str("");
00085 ss << "void f(const " << getVector2dName(asType) << " &in, const " << getVector2dName(asType) << " &in)";
00086 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00087 (const vector2d<T>&, const vector2d<T>&, void*), void),
00088 asCALL_CDECL_OBJLAST); assert(r >= 0);
00089
00090 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructor<T>),
00091 asCALL_CDECL_OBJLAST); assert(r >= 0);
00092
00093
00094
00095 ss.str("");
00096 ss << typeName << " f(const " << typeName << " &in, const " << getVector2dName(asType) << " &in)";
00097 r = engine->RegisterGlobalBehaviour(asBEHAVE_ADD, ss.str().c_str(),
00098 asFUNCTIONPR((add< line2d<T>, line2d<T>, vector2d<T> >),
00099 (const line2d<T>&, const vector2d<T>&), line2d<T>),
00100 asCALL_CDECL); assert(r >= 0);
00101
00102
00103 ss.str("");
00104 ss << typeName << "& f(const " << getVector2dName(asType) << " &in)";
00105 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_ADD_ASSIGN, ss.str().c_str(),
00106 asMETHODPR(line2d<T>, operator+=, (const vector2d<T>&),
00107 line2d<T>&), asCALL_THISCALL); assert(r >= 0);
00108
00109
00110 ss.str("");
00111 ss << typeName << " f(const " << typeName << " &in, const " << getVector2dName(asType) << " &in)";
00112 r = engine->RegisterGlobalBehaviour(asBEHAVE_SUBTRACT, ss.str().c_str(),
00113 asFUNCTIONPR((substract< line2d<T>, line2d<T>, vector2d<T> >),
00114 (const line2d<T>&, const vector2d<T>&), line2d<T>),
00115 asCALL_CDECL); assert(r >= 0);
00116
00117
00118 ss.str("");
00119 ss << typeName << "& f(const " << getVector2dName(asType) << " &in)";
00120 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_SUB_ASSIGN, ss.str().c_str(),
00121 asMETHODPR(line2d<T>, operator-=, (const vector2d<T>&),
00122 line2d<T>&), asCALL_THISCALL); assert(r >= 0);
00123
00124
00125 ss.str("");
00126 ss << "bool f(const " << typeName << " &in, const " << typeName << " &in)";
00127 std::string declComparison = ss.str();
00128
00129 r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, declComparison.c_str(), asFUNCTIONPR(equal< line2d<T> >,
00130 (const line2d<T>&, const line2d<T>&), bool), asCALL_CDECL); assert(r >= 0);
00131 r = engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL, declComparison.c_str(), asFUNCTIONPR(not_equal< line2d<T> >,
00132 (const line2d<T>&, const line2d<T>&), bool), asCALL_CDECL); assert(r >= 0);
00133
00134
00135 ss.str("");
00136 ss << "f64 getAngleWith(const " << typeName << " &in)";
00137 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00138 asMETHOD(line2d<T>, getAngleWith), asCALL_THISCALL); assert(r >= 0);
00139
00140 ss.str("");
00141 ss << getVector2dName(asType) << " getClosestPoint(const " << getVector2dName(asType) << " &in)";
00142 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00143 asMETHOD(line2d<T>, getClosestPoint), asCALL_THISCALL); assert(r >= 0);
00144
00145 r = engine->RegisterObjectMethod(typeName, "f64 getLength()",
00146 asMETHOD(line2d<T>, getLength), asCALL_THISCALL); assert(r >= 0);
00147
00148 ss.str("");
00149 ss << asType << " getLengthSQ()";
00150 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00151 asMETHOD(line2d<T>, getLengthSQ), asCALL_THISCALL); assert(r >= 0);
00152
00153 ss.str("");
00154 ss << getVector2dName(asType) << " getMiddle()";
00155 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00156 asMETHOD(line2d<T>, getMiddle), asCALL_THISCALL); assert(r >= 0);
00157
00158 ss.str("");
00159 ss << asType << " getPointOrientation(const " << getVector2dName(asType) << " &in)";
00160 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00161 asMETHOD(line2d<T>, getPointOrientation), asCALL_THISCALL); assert(r >= 0);
00162
00163 ss.str("");
00164 ss << getVector2dName(asType) << " getUnitVector()";
00165 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00166 asMETHOD(line2d<T>, getUnitVector), asCALL_THISCALL); assert(r >= 0);
00167
00168 ss.str("");
00169 ss << getVector2dName(asType) << " getVector()";
00170 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00171 asMETHOD(line2d<T>, getVector), asCALL_THISCALL); assert(r >= 0);
00172
00173 ss.str("");
00174 ss << "bool intersectWith(const " << typeName << " &in, const " << getVector2dName(asType) << " &out)";
00175 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00176 asMETHOD(line2d<T>, intersectWith), asCALL_THISCALL); assert(r >= 0);
00177
00178 ss.str("");
00179 ss << "bool isPointBetweenStartAndEnd(const " << getVector2dName(asType) << " &in)";
00180 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00181 asMETHOD(line2d<T>, isPointBetweenStartAndEnd), asCALL_THISCALL); assert(r >= 0);
00182
00183 ss.str("");
00184 ss << "bool isPointOnLine(const " << typeName << " &in)";
00185 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00186 asMETHOD(line2d<T>, isPointOnLine), asCALL_THISCALL); assert(r >= 0);
00187
00188 ss.str("");
00189 ss << "void setLine(const " << typeName << " &in)";
00190 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00191 asMETHODPR(line2d<T>, setLine, (const line2d<T>&), void), asCALL_THISCALL); assert(r >= 0);
00192
00193 ss.str("");
00194 ss << "void setLine(const " << getVector2dName(asType) << " &in, const " << getVector2dName(asType) << " &in)";
00195 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00196 asMETHODPR(line2d<T>, setLine, (const vector2d<T>&, const vector2d<T>&), void),
00197 asCALL_THISCALL); assert(r >= 0);
00198
00199
00200 ss.str("");
00201 ss << getVector2dName(asType) << " end";
00202 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(line2d<T>, end)); assert(r >= 0);
00203
00204 ss.str("");
00205 ss << getVector2dName(asType) << " start";
00206 r = engine->RegisterObjectProperty(typeName, ss.str().c_str(), offsetof(line2d<T>, start)); assert(r >= 0);
00207 }
00208
00211 void bindLine2d(asIScriptEngine *engine)
00212 {
00213 bindLine2dT<f32>(engine, "line2df", "f32");
00214 bindLine2dT<s32>(engine, "line2di", "s32");
00215 }
00216
00219 std::string getLine2dName(const std::string &asType)
00220 {
00221 if(asType == "f32") return std::string("line2df");
00222 if(asType == "s32") return std::string("line2di");
00223 else return std::string("");
00224 }
00225
00226