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 "asMatrix4.h"
00023
00024
00025
00029 template<typename T>
00030 void constructor(void *memory)
00031 {
00032 new (memory) CMatrix4<T>();
00033 }
00034
00038 template<typename T>
00039 void constructor(const CMatrix4<T> &other, void *memory)
00040 {
00041 new (memory) CMatrix4<T>(other);
00042 }
00043
00047 template<typename T>
00048 void deconstructor(void *memory)
00049 {
00050 ((CMatrix4<T>*)memory)->~CMatrix4<T>();
00051 }
00052
00053
00058 template<typename T>
00059 void bindMatrix4T(asIScriptEngine *engine, const char *typeName, const char *asType)
00060 {
00061
00062 int r;
00063 std::stringstream ss;
00064
00065
00066 r = engine->RegisterObjectType(typeName, sizeof(CMatrix4<T>), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); assert(r >= 0);
00067
00068
00069
00070 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(constructor<T>,
00071 (void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00072
00073 ss.str("");
00074 ss << "void f(const " << typeName << " &in)";
00075 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_CONSTRUCT, ss.str().c_str(), asFUNCTIONPR(constructor<T>,
00076 (const CMatrix4<T>&, void*), void), asCALL_CDECL_OBJLAST); assert(r >= 0);
00077
00078 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(deconstructor<T>),
00079 asCALL_CDECL_OBJLAST); assert(r >= 0);
00080
00081
00082
00083 ss.str("");
00084 ss << typeName << " opAssign(const " << typeName << " &in)";
00085 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00086 asMETHODPR(CMatrix4<T>, operator=, (const CMatrix4<T>&),
00087 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00088
00089
00090 ss.str("");
00091 ss << typeName << " opMul(const " << typeName << " &in)";
00092 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00093 asFUNCTIONPR((multiply< CMatrix4<T>, CMatrix4<T>, CMatrix4<T> >),
00094 (const CMatrix4<T>&, const CMatrix4<T>&), CMatrix4<T>),
00095 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00096
00097
00098 ss.str("");
00099 ss << typeName << " opMulAssign(const " << typeName << " &in)";
00100 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00101 asMETHODPR(CMatrix4<T>, operator*=, (const CMatrix4<T>&),
00102 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00103
00104
00105 ss.str("");
00106 ss << typeName << " opAdd(const " << typeName << " &in)";
00107 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00108 asFUNCTIONPR((add< CMatrix4<T>, CMatrix4<T>, CMatrix4<T> >),
00109 (const CMatrix4<T>&, const CMatrix4<T>&), CMatrix4<T>),
00110 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00111
00112
00113 ss.str("");
00114 ss << typeName << "& opAddAssign(const " << typeName << " &in)";
00115 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00116 asMETHODPR(CMatrix4<T>, operator+=, (const CMatrix4<T>&),
00117 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00118
00119
00120 ss.str("");
00121 ss << typeName << " opSub(const " << typeName << " &in)";
00122 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00123 asFUNCTIONPR((substract< CMatrix4<T>, CMatrix4<T>, CMatrix4<T> >),
00124 (const CMatrix4<T>&, const CMatrix4<T>&), CMatrix4<T>),
00125 asCALL_CDECL_OBJFIRST); assert(r >= 0);
00126
00127
00128 ss.str("");
00129 ss << typeName << "& opSubAssign(const " << typeName << " &in)";
00130 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00131 asMETHODPR(CMatrix4<T>, operator-=, (const CMatrix4<T>&),
00132 CMatrix4<T>&), asCALL_THISCALL); assert(r >= 0);
00133
00134
00135 ss.str("");
00136 ss << "bool opEquals(const " << typeName << " &in)";
00137 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(), asFUNCTIONPR(equal< CMatrix4<T> >,
00138 (const CMatrix4<T>&, const CMatrix4<T>&), bool), asCALL_CDECL_OBJFIRST); assert(r >= 0);
00139
00140
00141 ss.str("");
00142 ss << "const " << asType << "& f(u32)";
00143 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_INDEX, ss.str().c_str(),
00144 asMETHODPR(CMatrix4<T>, operator[], (u32) const, const T&), asCALL_THISCALL); assert(r >= 0);
00145
00146 ss.str("");
00147 ss << asType << "& f(u32)";
00148 r = engine->RegisterObjectBehaviour(typeName, asBEHAVE_INDEX, ss.str().c_str(),
00149 asMETHODPR(CMatrix4<T>, operator[], (u32), T&), asCALL_THISCALL); assert(r >= 0);
00150
00151
00152
00153 r = engine->RegisterObjectMethod(typeName, "bool getDefinitelyIdentityMatrix()",
00154 asMETHOD(CMatrix4<T>, getDefinitelyIdentityMatrix), asCALL_THISCALL); assert(r >= 0);
00155
00156 ss.str("");
00157 ss << "bool getInverse(const " << typeName << " &out)";
00158 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00159 asMETHOD(CMatrix4<T>, getInverse), asCALL_THISCALL); assert(r >= 0);
00160
00161 ss.str("");
00162 ss << "bool getInversePrimitive(const " << typeName << " &out)";
00163 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00164 asMETHOD(CMatrix4<T>, getInversePrimitive), asCALL_THISCALL); assert(r >= 0);
00165
00166 ss.str("");
00167 ss << getVector3dName(asType) << " getRotationDegrees()";
00168 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00169 asMETHOD(CMatrix4<T>, getRotationDegrees), asCALL_THISCALL); assert(r >= 0);
00170
00171 ss.str("");
00172 ss << getVector3dName(asType) << " getScale()";
00173 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00174 asMETHOD(CMatrix4<T>, getScale), asCALL_THISCALL); assert(r >= 0);
00175
00176 ss.str("");
00177 ss << getVector3dName(asType) << " getTranslation()";
00178 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00179 asMETHOD(CMatrix4<T>, getTranslation), asCALL_THISCALL); assert(r >= 0);
00180
00181 ss.str("");
00182 ss << typeName << " getTransposed()";
00183 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00184 asMETHODPR(CMatrix4<T>, getTransposed, () const, CMatrix4<T>), asCALL_THISCALL); assert(r >= 0);
00185
00186 ss.str("");
00187 ss << getVector3dName(asType) << " interpolate(const " << typeName << " &in, f32)";
00188 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00189 asMETHOD(CMatrix4<T>, getTranslation), asCALL_THISCALL); assert(r >= 0);
00190
00191 ss.str("");
00192 ss << "void inverseRotateVect(const " << getVector3dName(asType) << " &in)";
00193 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00194 asMETHOD(CMatrix4<T>, inverseRotateVect), asCALL_THISCALL); assert(r >= 0);
00195
00196 ss.str("");
00197 ss << "void inverseTranslateVect(const " << getVector3dName(asType) << " &in)";
00198 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00199 asMETHOD(CMatrix4<T>, inverseTranslateVect), asCALL_THISCALL); assert(r >= 0);
00200
00201 r = engine->RegisterObjectMethod(typeName, "bool isIdentity()",
00202 asMETHOD(CMatrix4<T>, isIdentity), asCALL_THISCALL); assert(r >= 0);
00203
00204 r = engine->RegisterObjectMethod(typeName, "bool isIdentity_integer_base()",
00205 asMETHOD(CMatrix4<T>, isIdentity_integer_base), asCALL_THISCALL); assert(r >= 0);
00206
00207 ss.str("");
00208 ss << typeName << "& makeIndentity()";
00209 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00210 asMETHOD(CMatrix4<T>, isIdentity), asCALL_THISCALL); assert(r >= 0);
00211
00212 r = engine->RegisterObjectMethod(typeName, "bool makeInverse()",
00213 asMETHOD(CMatrix4<T>, makeInverse), asCALL_THISCALL); assert(r >= 0);
00214
00215 ss.str("");
00216 ss << "void rotateVect(" << getVector3dName(asType) << " &out, const " << getVector3dName(asType) << " &in)";
00217 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00218 asMETHODPR(CMatrix4<T>, rotateVect, (vector3d<T>&, const vector3d<T>&)
00219 const, void), asCALL_THISCALL); assert(r >= 0);
00220
00221 r = engine->RegisterObjectMethod(typeName, "void setDefinitelyIdentityMatrix(bool)",
00222 asMETHOD(CMatrix4<T>, setDefinitelyIdentityMatrix), asCALL_THISCALL); assert(r >= 0);
00223
00224 ss.str("");
00225 ss << typeName << "& setInverseRotationDegrees(const " << getVector3dName(asType) << " &in)";
00226 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00227 asMETHOD(CMatrix4<T>, setInverseRotationDegrees), asCALL_THISCALL); assert(r >= 0);
00228
00229 ss.str("");
00230 ss << typeName << "& setInverseRotationRadians(const " << getVector3dName(asType) << " &in)";
00231 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00232 asMETHOD(CMatrix4<T>, setInverseRotationRadians), asCALL_THISCALL); assert(r >= 0);
00233
00234 ss.str("");
00235 ss << typeName << "& setInverseTranslation(const " << getVector3dName(asType) << " &in)";
00236 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00237 asMETHOD(CMatrix4<T>, setInverseTranslation), asCALL_THISCALL); assert(r >= 0);
00238
00239 ss.str("");
00240 ss << typeName << "& setRotationDegrees(const " << getVector3dName(asType) << " &in)";
00241 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00242 asMETHOD(CMatrix4<T>, setRotationDegrees), asCALL_THISCALL); assert(r >= 0);
00243
00244 ss.str("");
00245 ss << typeName << "& setRotationRadians(const " << getVector3dName(asType) << " &in)";
00246 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00247 asMETHOD(CMatrix4<T>, setRotationRadians), asCALL_THISCALL); assert(r >= 0);
00248
00249 ss.str("");
00250 ss << typeName << "& setScale(const " << getVector3dName(asType) << " &in)";
00251 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00252 asMETHODPR(CMatrix4<T>, setScale, (const vector3d<T>&), CMatrix4<T>&),
00253 asCALL_THISCALL); assert(r >= 0);
00254
00255 ss.str("");
00256 ss << typeName << "& setScale(const " << asType << ")";
00257 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00258 asMETHODPR(CMatrix4<T>, setScale, (const vector3d<T>&), CMatrix4<T>&),
00259 asCALL_THISCALL); assert(r >= 0);
00260
00261 ss.str("");
00262 ss << typeName << "& setTextureScale(f32, f32)";
00263 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00264 asMETHOD(CMatrix4<T>, setTextureScale), asCALL_THISCALL); assert(r >= 0);
00265
00266 ss.str("");
00267 ss << typeName << "& setTextureScaleCenter(f32, f32)";
00268 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00269 asMETHOD(CMatrix4<T>, setTextureScaleCenter), asCALL_THISCALL); assert(r >= 0);
00270
00271 ss.str("");
00272 ss << typeName << "& setTextureTranslate(f32, f32)";
00273 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00274 asMETHOD(CMatrix4<T>, setTextureTranslate), asCALL_THISCALL); assert(r >= 0);
00275
00276 ss.str("");
00277 ss << typeName << "& setTextureTranslateTransposed(f32, f32)";
00278 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00279 asMETHOD(CMatrix4<T>, setTextureTranslateTransposed), asCALL_THISCALL); assert(r >= 0);
00280
00281 ss.str("");
00282 ss << typeName << "& setTranslation(const " << getVector3dName(asType) << " &in)";
00283 r = engine->RegisterObjectMethod(typeName, ss.str().c_str(),
00284 asMETHOD(CMatrix4<T>, setTranslation), asCALL_THISCALL); assert(r >= 0);
00285 }
00286
00289 void bindMatrix4(asIScriptEngine *engine)
00290 {
00291 bindMatrix4T<f32>(engine, "matrix4", "f32");
00292 }
00293
00296 std::string getMatrix4Name(const std::string &asType)
00297 {
00298 if(asType == "f32") return std::string("matrix4");
00299 else return std::string("");
00300 }
00301
00302 #endif // __COMPILE_WITH_ANGELSCRIPT__
00303
00304