00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "asIrrHelper.h"
00018 #include "asMatrix4.h"
00019 #include "asVector3d.h"
00020
00021
00022
00026 template<typename T>
00027 void constructor(void *memory)
00028 {
00029 new (memory) CMatrix4<T>();
00030 }
00031
00035 template<typename T>
00036 void constructor(const CMatrix4<T> &other, void *memory)
00037 {
00038 new (memory) CMatrix4<T>(other);
00039 }
00040
00044 template<typename T>
00045 void deconstructor(void *memory)
00046 {
00047 ((CMatrix4<T>*)memory)->~CMatrix4<T>();
00048 }
00049
00050
00055 template<typename T>
00056 void bindMatrix4T(asIScriptEngine *engine, const char *typeName, const char *asType)
00057 {
00058
00059 int r;
00060 std::stringstream ss;
00061
00062
00063 r = engine->RegisterObjectType(typeName, sizeof(CMatrix4<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); assert(r >= 0);
00064
00065
00066
00067 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructor<T>,
00068 (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00069
00070 ss.str("");
00071 ss << "void f(const " << typeName << " &in)";
00072 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00073 (const CMatrix4<T>&, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00074
00075 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructor<T>),
00076 asCALL_CDECL_OBJLAST); assert(r >= 0);
00077
00078
00079 ss.str("");
00080 ss << typeName << " f(const " << typeName << " &in, const " << typeName << " &in)";
00081 std::string declActionType = ss.str();
00082
00083 ss.str("");
00084 ss << typeName << " f(const " << typeName << " &in, " << asType << ")";
00085 std::string declActionValue = ss.str();
00086
00087 ss.str("");
00088 ss << typeName << "& f(const " << typeName << " &in)";
00089 std::string declAssignType = ss.str();
00090
00091 ss.str("");
00092 ss << typeName << "& f(const " << asType << ")";
00093 std::string declAssignValue = ss.str();
00094
00095
00096 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_ASSIGNMENT, declAssignType.c_str(),
00097 asMETHODPR(CMatrix4<T>, operator=, (const CMatrix4<T>&),
00098 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00099
00100
00101 r = engine->RegisterGlobalBehaviour(asBEHAVE_MULTIPLY, declActionType.c_str(),
00102 asFUNCTIONPR((multiply< CMatrix4<T>, CMatrix4<T>, CMatrix4<T> >),
00103 (const CMatrix4<T>&, const CMatrix4<T>&), CMatrix4<T>),
00104 asCALL_CDECL); assert(r >= 0);
00105
00106
00107 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_MUL_ASSIGN, declAssignType.c_str(),
00108 asMETHODPR(CMatrix4<T>, operator*=, (const CMatrix4<T>&),
00109 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00110
00111
00112 r = engine->RegisterGlobalBehaviour(asBEHAVE_ADD, declActionType.c_str(),
00113 asFUNCTIONPR((add< CMatrix4<T>, CMatrix4<T>, CMatrix4<T> >),
00114 (const CMatrix4<T>&, const CMatrix4<T>&), CMatrix4<T>),
00115 asCALL_CDECL); assert(r >= 0);
00116
00117
00118 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_ADD_ASSIGN, declAssignType.c_str(),
00119 asMETHODPR(CMatrix4<T>, operator+=, (const CMatrix4<T>&),
00120 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00121
00122
00123 r = engine->RegisterGlobalBehaviour(asBEHAVE_SUBTRACT, declActionType.c_str(),
00124 asFUNCTIONPR((substract< CMatrix4<T>, CMatrix4<T>, CMatrix4<T> >),
00125 (const CMatrix4<T>&, const CMatrix4<T>&), CMatrix4<T>),
00126 asCALL_CDECL); assert(r >= 0);
00127
00128
00129 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_SUB_ASSIGN, declAssignType.c_str(),
00130 asMETHODPR(CMatrix4<T>, operator-=, (const CMatrix4<T>&),
00131 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00132
00133
00134 ss.str("");
00135 ss << "bool f(const " << typeName << " &in, const " << typeName << " &in)";
00136 std::string declComparison = ss.str();
00137
00138 r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, declComparison.c_str(), asFUNCTIONPR(equal< CMatrix4<T> >,
00139 (const CMatrix4<T>&, const CMatrix4<T>&), bool), asCALL_CDECL); assert(r >= 0);
00140 r = engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL, declComparison.c_str(), asFUNCTIONPR(not_equal< CMatrix4<T> >,
00141 (const CMatrix4<T>&, const CMatrix4<T>&), bool), asCALL_CDECL); assert(r >= 0);
00142
00143
00144 ss.str("");
00145 ss << "const " << asType << "& f(u32)";
00146 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_INDEX, ss.str().c_str(),
00147 asMETHODPR(CMatrix4<T>, operator[], (u32) const, const T&), asCALL_THISCALL); assert(r >= 0);
00148
00149 ss.str("");
00150 ss << asType << "& f(u32)";
00151 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_INDEX, ss.str().c_str(),
00152 asMETHODPR(CMatrix4<T>, operator[], (u32), T&), asCALL_THISCALL); assert(r >= 0);
00153
00154
00155
00156 r = engine->RegisterObjectMethod(typeName, "bool getDefinitelyIdentityMatrix()",
00157 asMETHOD(CMatrix4<T>, getDefinitelyIdentityMatrix), asCALL_THISCALL); assert(r >= 0);
00158
00159 ss.str("");
00160 ss << "bool getInverse(const " << typeName << " &out)";
00161 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00162 asMETHOD(CMatrix4<T>, getInverse), asCALL_THISCALL); assert(r >= 0);
00163
00164 ss.str("");
00165 ss << "bool getInversePrimitive(const " << typeName << " &out)";
00166 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00167 asMETHOD(CMatrix4<T>, getInversePrimitive), asCALL_THISCALL); assert(r >= 0);
00168
00169 ss.str("");
00170 ss << getVector3dName(asType) << " getRotationDegrees()";
00171 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00172 asMETHOD(CMatrix4<T>, getRotationDegrees), asCALL_THISCALL); assert(r >= 0);
00173
00174 ss.str("");
00175 ss << getVector3dName(asType) << " getScale()";
00176 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00177 asMETHOD(CMatrix4<T>, getScale), asCALL_THISCALL); assert(r >= 0);
00178
00179 ss.str("");
00180 ss << getVector3dName(asType) << " getTranslation()";
00181 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00182 asMETHOD(CMatrix4<T>, getTranslation), asCALL_THISCALL); assert(r >= 0);
00183
00184 ss.str("");
00185 ss << typeName << " getTransposed()";
00186 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00187 asMETHODPR(CMatrix4<T>, getTransposed, () const, CMatrix4<T>), asCALL_THISCALL); assert(r >= 0);
00188
00189 ss.str("");
00190 ss << getVector3dName(asType) << " interpolate(const " << typeName << " &in, f32)";
00191 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00192 asMETHOD(CMatrix4<T>, getTranslation), asCALL_THISCALL); assert(r >= 0);
00193
00194 ss.str("");
00195 ss << "void inverseRotateVect(const " << getVector3dName(asType) << " &in)";
00196 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00197 asMETHOD(CMatrix4<T>, inverseRotateVect), asCALL_THISCALL); assert(r >= 0);
00198
00199 ss.str("");
00200 ss << "void inverseTranslateVect(const " << getVector3dName(asType) << " &in)";
00201 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00202 asMETHOD(CMatrix4<T>, inverseTranslateVect), asCALL_THISCALL); assert(r >= 0);
00203
00204 r = engine->RegisterObjectMethod(typeName, "bool isIdentity()",
00205 asMETHOD(CMatrix4<T>, isIdentity), asCALL_THISCALL); assert(r >= 0);
00206
00207 r = engine->RegisterObjectMethod(typeName, "bool isIdentity_integer_base()",
00208 asMETHOD(CMatrix4<T>, isIdentity_integer_base), asCALL_THISCALL); assert(r >= 0);
00209
00210 ss.str("");
00211 ss << typeName << "& makeIndentity()";
00212 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00213 asMETHOD(CMatrix4<T>, isIdentity), asCALL_THISCALL); assert(r >= 0);
00214
00215 r = engine->RegisterObjectMethod(typeName, "bool makeInverse()",
00216 asMETHOD(CMatrix4<T>, makeInverse), asCALL_THISCALL); assert(r >= 0);
00217
00218 ss.str("");
00219 ss << "void rotateVect(" << getVector3dName(asType) << " &out, const " << getVector3dName(asType) << " &in)";
00220 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00221 asMETHODPR(CMatrix4<T>, rotateVect, (vector3d<T>&, const vector3d<T>&)
00222 const, void), asCALL_THISCALL); assert(r >= 0);
00223
00224 r = engine->RegisterObjectMethod(typeName, "void setDefinitelyIdentityMatrix(bool)",
00225 asMETHOD(CMatrix4<T>, setDefinitelyIdentityMatrix), asCALL_THISCALL); assert(r >= 0);
00226
00227 ss.str("");
00228 ss << typeName << "& setInverseRotationDegrees(const " << getVector3dName(asType) << " &in)";
00229 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00230 asMETHOD(CMatrix4<T>, setInverseRotationDegrees), asCALL_THISCALL); assert(r >= 0);
00231
00232 ss.str("");
00233 ss << typeName << "& setInverseRotationRadians(const " << getVector3dName(asType) << " &in)";
00234 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00235 asMETHOD(CMatrix4<T>, setInverseRotationRadians), asCALL_THISCALL); assert(r >= 0);
00236
00237 ss.str("");
00238 ss << typeName << "& setInverseTranslation(const " << getVector3dName(asType) << " &in)";
00239 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00240 asMETHOD(CMatrix4<T>, setInverseTranslation), asCALL_THISCALL); assert(r >= 0);
00241
00242 ss.str("");
00243 ss << typeName << "& setRotationDegrees(const " << getVector3dName(asType) << " &in)";
00244 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00245 asMETHOD(CMatrix4<T>, setRotationDegrees), asCALL_THISCALL); assert(r >= 0);
00246
00247 ss.str("");
00248 ss << typeName << "& setRotationRadians(const " << getVector3dName(asType) << " &in)";
00249 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00250 asMETHOD(CMatrix4<T>, setRotationRadians), asCALL_THISCALL); assert(r >= 0);
00251
00252 ss.str("");
00253 ss << typeName << "& setScale(const " << getVector3dName(asType) << " &in)";
00254 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00255 asMETHODPR(CMatrix4<T>, setScale, (const vector3d<T>&), CMatrix4<T>&),
00256 asCALL_THISCALL); assert(r >= 0);
00257
00258 ss.str("");
00259 ss << typeName << "& setScale(const " << asType << ")";
00260 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00261 asMETHODPR(CMatrix4<T>, setScale, (const vector3d<T>&), CMatrix4<T>&),
00262 asCALL_THISCALL); assert(r >= 0);
00263
00264 ss.str("");
00265 ss << typeName << "& setTextureScale(f32, f32)";
00266 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00267 asMETHOD(CMatrix4<T>, setTextureScale), asCALL_THISCALL); assert(r >= 0);
00268
00269 ss.str("");
00270 ss << typeName << "& setTextureScaleCenter(f32, f32)";
00271 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00272 asMETHOD(CMatrix4<T>, setTextureScaleCenter), asCALL_THISCALL); assert(r >= 0);
00273
00274 ss.str("");
00275 ss << typeName << "& setTextureTranslate(f32, f32)";
00276 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00277 asMETHOD(CMatrix4<T>, setTextureTranslate), asCALL_THISCALL); assert(r >= 0);
00278
00279 ss.str("");
00280 ss << typeName << "& setTextureTranslateTransposed(f32, f32)";
00281 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00282 asMETHOD(CMatrix4<T>, setTextureTranslateTransposed), asCALL_THISCALL); assert(r >= 0);
00283
00284 ss.str("");
00285 ss << typeName << "& setTranslation(const " << getVector3dName(asType) << " &in)";
00286 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00287 asMETHOD(CMatrix4<T>, setTranslation), asCALL_THISCALL); assert(r >= 0);
00288 }
00289
00292 void bindMatrix4(asIScriptEngine *engine)
00293 {
00294 bindMatrix4T<f32>(engine, "matrix4", "f32");
00295 }
00296
00299 std::string getMatrix4Name(const std::string &asType)
00300 {
00301 if(asType == "f32") return std::string("matrix4");
00302 else return std::string("");
00303 }
00304
00305