objectcontroller_L.cpp
Go to the documentation of this file.00001 #include "lugre_prefix.h"
00002 #include "lugre_luabind.h"
00003 #include "object.h"
00004 #include "objectcontroller.h"
00005
00006 using namespace Lugre;
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 extern "C" {
00031 #include "lua.h"
00032 #include "lauxlib.h"
00033 #include "lualib.h"
00034 }
00035
00036 class cObjectController_L : public cLuaBind<cObjectController> { public:
00038 virtual void RegisterMethods (lua_State *L) { PROFILE
00039 lua_register(L,"CreateObjectController", &cObjectController_L::CreateObjectController);
00040
00041 #define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cObjectController_L::methodname));
00042 REGISTER_METHOD(Destroy);
00043 REGISTER_METHOD(SetApproachObject);
00044 REGISTER_METHOD(SetApproachPosition);
00045 REGISTER_METHOD(IsTargetAlive);
00046 REGISTER_METHOD(DistanceToTarget);
00047 }
00048
00050 virtual void RegisterMembers () { PROFILE
00051 cObjectController* prototype = new cObjectController();
00052 cMemberVar_REGISTER(prototype, kVarType_Float, mfMaxAccel, 0);
00053 cMemberVar_REGISTER(prototype, kVarType_Float, mfApproachMinDist, 0);
00054 cMemberVar_REGISTER(prototype, kVarType_bool, mbStupid, 0);
00055 cMemberVar_REGISTER(prototype, kVarType_Float, mfMaxSpeed, 0);
00056
00057
00058
00059
00060 }
00061
00062
00063
00065 static int CreateObjectController (lua_State *L) { PROFILE
00066 return CreateUData(L,new cObjectController());
00067 }
00068
00069
00070
00071 static int Destroy (lua_State *L) { PROFILE
00072 delete checkudata_alive(L);
00073 return 0;
00074 }
00075
00077 static int SetApproachObject (lua_State *L) { PROFILE
00078 cObject* pTarget = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? cLuaBind<cObject>::checkudata(L,2) : 0;
00079 checkudata_alive(L)->SetTarget(pTarget ? (new cObjectContollerTargetObject(pTarget)) : 0);
00080 return 0;
00081 }
00082
00084 static int SetApproachPosition (lua_State *L) { PROFILE
00085 checkudata_alive(L)->SetTarget(new cObjectContollerTargetPosition(
00086 Ogre::Vector3(
00087 luaL_checknumber(L,2),
00088 luaL_checknumber(L,3),
00089 luaL_checknumber(L,4)
00090 )
00091 ));
00092 return 0;
00093 }
00094
00096
00097 static int DistanceToTarget (lua_State *L) { PROFILE
00098 cObjectController*p = checkudata_alive(L);
00099 if(p->mpApproachTarget && p->mpApproachTarget->IsAlive()){
00100 Vector3 other(
00101 luaL_checknumber(L,2),
00102 luaL_checknumber(L,3),
00103 luaL_checknumber(L,4));
00104 lua_pushnumber(L,p->mpApproachTarget->GetPosition().distance(other));
00105 } else {
00106 lua_pushnumber(L,0);
00107 }
00108 return 1;
00109 }
00110
00112 static int IsTargetAlive (lua_State *L) { PROFILE
00113 cObjectController*p = checkudata_alive(L);
00114 if(p->mpApproachTarget){
00115 lua_pushboolean(L,p->mpApproachTarget->IsAlive());
00116 } else {
00117 lua_pushboolean(L,false);
00118 }
00119 return 1;
00120 }
00121
00122 virtual const char* GetLuaTypeName () { return "sfz.objcontroller"; }
00123 };
00124
00125
00127 void cObjectController::LuaRegister (lua_State *L) { PROFILE
00128 cLuaBind<cObjectController>::GetSingletonPtr(new cObjectController_L())->LuaRegister(L);
00129 }
00130
00131
00132
00133
00134 #if 0
00135 using namespace Ogre;
00136
00137 class cObject;
00138 class lua_State;
00139
00140 class cObject_L : public cLuaBind<cObject> { public:
00142 virtual void RegisterMethods (lua_State *L) { PROFILE
00143 lua_register(L,"RayQuery", &cObject_L::RayQuery);
00144 lua_register(L,"GetIntersecting", &cObject_L::GetIntersecting);
00145 }
00146
00147
00148
00149
00150
00153 static int RayQuery (lua_State *L) { PROFILE
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 }
00170
00173 static int GetIntersecting (lua_State *L) { PROFILE
00174 std::set<size_t> resultset;
00175
00176
00177
00178
00179
00180 int nres = 0;
00181
00182
00183
00184
00185
00186
00187 return nres;
00188 }
00189
00190 virtual const char* GetLuaTypeName () { return "sfz.objcontroller"; }
00191 };
00192 #endif