K3dVM.cpp

Go to the documentation of this file.
00001 
00011 /***************************************************************************
00012  *   Copyright (C) 2007 by Jan Koci   *
00013  *   honza.koci@email.cz   *
00014  *   http://kengine.sourceforge.net/tutorial/
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  *   This program is distributed in the hope that it will be useful,       *
00022  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00024  *   GNU General Public License for more details.                          *
00025  *                                                                         *
00026  *   You should have received a copy of the GNU General Public License     *
00027  *   along with this program; if not, write to the                         *
00028  *   Free Software Foundation, Inc.,                                       *
00029  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00030  ***************************************************************************/
00031 
00032 #include "K3dVM.h"
00033 
00034 
00035 void *K3dVM::ms_pObject;        
00036 K3dLua *K3dVM::ms_pLua;
00037 K3dScene *K3dVM::ms_pScene;
00038 K3dGameData *K3dVM::ms_pGameData;
00039 K3dCameraBuild *K3dVM::ms_pCameraBuild;
00040 
00041 K3dVM::K3dVM(K3dGameData *_pGameData, K3dScene *_pScene)
00042 {
00043         ms_pGameData = _pGameData;
00044         ms_pScene = _pScene;
00045         // Set this virtual machine to the global game data
00046         ms_pGameData->SetVM(this);
00047         ms_pLua = ms_pGameData->GetLua();
00048         ms_pCameraBuild = new K3dCameraBuild(_pGameData);
00049         RegisterFunctions();
00050 }
00051 
00052 K3dVM::~K3dVM()
00053 {
00054         std::cout << "Destructor K3dVM::~K3dVM()" << endl;
00055         if(ms_pCameraBuild)
00056         {
00057                 delete ms_pCameraBuild;
00058                 ms_pCameraBuild = NULL;
00059         }
00060 }
00061 
00063 void K3dVM::RegisterFunctions()
00064 {
00065         std::cout << "void K3dVM::RegisterFunctions()" << endl;
00066         ms_pLua->LuaRegister("K3d_LoadMap", K3d_LoadMap);
00067         ms_pLua->LuaRegister("K3d_AddVertex", K3d_AddVertex);
00068         ms_pLua->LuaRegister("K3d_GetObject", K3d_GetObject);
00069         ms_pLua->LuaRegister("K3d_GetCamPos", K3d_GetCamPos);
00070         ms_pLua->LuaRegister("K3d_GetCamDir", K3d_GetCamDir);
00071         ms_pLua->LuaRegister("K3d_GetAimRay", K3d_GetAimRay);
00072         ms_pLua->LuaRegister("K3d_GetRayOrigDir", K3d_GetRayOrigDir);
00073         ms_pLua->LuaRegister("K3d_GetIntersection", K3d_GetIntersection);
00074         ms_pLua->LuaRegister("K3d_SetVertexPos", K3d_SetVertexPos);
00075         ms_pLua->LuaRegister("K3d_SetColor", K3d_SetColor);
00076         ms_pLua->LuaRegister("K3d_SetRay", K3d_SetRay);
00077         ms_pLua->LuaRegister("K3d_SetLine", K3d_SetLine);
00078         ms_pLua->LuaRegister("K3d_Hide", K3d_Hide);
00079         ms_pLua->LuaRegister("K3d_Print", K3d_Print);
00080         ms_pLua->LuaRegister("K3d_PrintValue", K3d_PrintValue);
00081         ms_pLua->LuaRegister("K3d_GetDistance", K3d_GetDistance);
00082         ms_pLua->LuaRegister("K3d_IsMouseLeft", K3d_IsMouseLeft);
00083         ms_pLua->LuaRegister("K3d_IsMouseRight", K3d_IsMouseRight);
00084         ms_pLua->LuaRegister("K3d_IsMouseLeftUp", K3d_IsMouseLeftUp);
00085         ms_pLua->LuaRegister("K3d_IsMouseRightUp", K3d_IsMouseRightUp);
00086         ms_pLua->LuaRegister("K3d_MoveByMouse", K3d_MoveByMouse);
00087         ms_pLua->LuaRegister("K3d_GetSpherePos", K3d_GetSpherePos);
00088         ms_pLua->LuaRegister("K3d_Wait", K3d_Wait);
00089         ms_pLua->LuaRegister("K3d_IncludeScript", K3d_IncludeScript);
00090         ms_pLua->LuaRegister("K3d_Link", K3d_Link);
00091         ms_pLua->LuaRegister("K3d_GetGuiObject" ,K3d_GetGuiObject);
00092         ms_pLua->LuaRegister("K3d_ButtonIsPressed",K3d_ButtonIsPressed);
00093         ms_pLua->LuaRegister("K3d_HideGui",K3d_HideGui);
00094         ms_pLua->LuaRegister("K3d_ShowGui",K3d_ShowGui);
00095         ms_pLua->LuaRegister("K3d_ShowFileListBox",K3d_ShowFileListBox);
00096         ms_pLua->LuaRegister("K3d_LoadMapFromListBox",K3d_LoadMapFromListBox);
00097         ms_pLua->LuaRegister("K3d_CheckKeyboardKey",K3d_CheckKeyboardKey);
00098         ms_pLua->LuaRegister("K3d_LoadNewScript",K3d_LoadNewScript);
00099         ms_pLua->LuaRegister("K3d_Exit",K3d_Exit);
00100 }
00101 
00104 void K3dVM::LoadScript(K3dString _strFilename)
00105 {
00106         std::cout << "void K3dVM::LoadScript()" << endl;
00107         std::cout << "_strFilename = " << _strFilename.GetString( ) << endl;
00108         if(!ms_pLua->LuaLoadFile(_strFilename.GetString().c_str()))
00109         {
00110                 ms_pLua->LuaError("void K3dVM::LoadScript(K3dString _strFilename) -- Error - cannot run script file: %s", ms_pLua->LuaToString(-1));
00111         }
00112 }
00113 
00115 void K3dVM::Engine_Init()
00116 {
00117         //ms_pLua->LuaCallEngine_Init();
00118         // Function to be called 
00119         ms_pLua->LuaGetGlobal("Engine_Init");
00120         // Do the call (0 arguments, 0 result) 
00121         if (ms_pLua->LuaPCall(0, 0, 0) != 0)
00122         {
00123         ms_pLua->LuaError("Error running function `Engine_Init': %s", lua_tostring(ms_pLua->GetLuaState(), -1));
00124         }
00125 }
00126 
00128 void K3dVM::Engine_Update()
00129 {
00130         // Function to be called 
00131         ms_pLua->LuaGetGlobal("Engine_Update");
00132         // do the call (0 arguments, 0 result) 
00133         if (ms_pLua->LuaPCall(0, 0, 0) != 0)
00134         {
00135         ms_pLua->LuaError("error running function `Engine_Update': %s", lua_tostring(ms_pLua->GetLuaState(), -1));
00136         }
00137 }
00138 
00140 void K3dVM::Engine_Delete()
00141 {
00142         std::cout << "void K3dVM::Engine_Delete()" << endl;
00143         lua_State *pLuaState = ms_pLua->GetLuaState();
00144         if(pLuaState)
00145         {
00146                 // Function to be called 
00147                 ms_pLua->LuaGetGlobal("Engine_Delete");
00148                 // do the call (0 arguments, 0 result) 
00149                 if (ms_pLua->LuaPCall(0, 0, 0) != 0)
00150                 {
00151                         ms_pLua->LuaError("error running function `Engine_Delete': %s", lua_tostring(ms_pLua->GetLuaState(), -1));
00152                 }
00153         }
00154         else
00155         {
00156                 cerr << "Error :: void K3dVM::Engine_Delete() -- lua_State is not initialized !!!" << endl;
00157         }
00158 }
00159 
00162 void K3dVM::LoadMap(K3dString &_strFilename)
00163 {
00164         std::cout << "void K3dVM::LoadMap()" << endl;
00165         std::cout << "_strFilename" << _strFilename.GetString() << endl;
00166         ms_pScene->Load( _strFilename);
00167 }
00168 
00170 int K3dVM::K3d_LoadMap(lua_State *_pState)
00171 {
00172         std::cout << "int K3dVM::K3d_LoadMap(lua_State *_pState)" << endl;
00173         // Cast the void pointer
00174         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00175         if (NULL == ms_pLua->GetLuaState())
00176         {
00177                 printf("Error Initializing lua\n");
00178                 return -1;
00179         }
00180         K3dString str;
00181         str = lua_tostring(_pState, 1);
00182         // Try call non static function
00183         pSomeClass->LoadMap(str);
00184         return 0;
00185 }
00186 
00191 int K3dVM::GetObject(const char* _strObjName, const int _iObjType)
00192 {
00193         // Get object index by object name and object type
00194         int iId = ms_pScene->FindObjectId(_strObjName, _iObjType);
00195         return iId;
00196 }
00197 
00198 int K3dVM::K3d_GetObject(lua_State *_pState)
00199 {
00200         // Cast the void pointer
00201         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00202         // Get function parameters
00203         const char* strObjName = (const char*) lua_tostring(_pState, 1);
00204         const int iObjType = (int) lua_tonumber(_pState, 2);
00205         // Try call non static function
00206         int iResult = pSomeClass->GetObject(strObjName, iObjType);
00207         if(ms_pLua->LuaCheckStack(_pState, 1))
00208         {
00209                  // Push result into script function
00210                 lua_pushnumber(_pState, iResult);
00211         }
00212         else
00213         {
00214                 cerr << "Error :: int K3dVM::K3d_GetObject() -- Lua stack overflow !!!" << endl;
00215                 return 0;
00216         }
00217         // Return number of results
00218         return 1;
00219 }
00220 
00224 void  K3dVM::GetCamPos(const int _iId, K3dVector3 &_rkCamPos)
00225 {
00226         _rkCamPos = ms_pGameData->GetCameraObjSP().Get(_iId)->GetCameraPos();
00227 }
00228 
00230 int  K3dVM::K3d_GetCamPos(lua_State *_pState)
00231 {
00232         // Cast the void pointer
00233         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00234         // Get function parameter
00235         int iCamId = (int) lua_tonumber(_pState, 1);
00236         K3dVector3 kCamPos;
00237         // Try call non static function
00238         pSomeClass->GetCamPos(iCamId, kCamPos);
00239         if(ms_pLua->LuaCheckStack(_pState, 3))
00240         {
00241                 // Push result camera position into script function
00242                 lua_pushnumber(_pState, kCamPos[0]);
00243                 lua_pushnumber(_pState, kCamPos[1]);
00244                 lua_pushnumber(_pState, kCamPos[2]);
00245         }
00246         else
00247         {
00248                 cerr << "Error :: int K3dVM::K3d_GetCamPos() -- Lua stack overflow !!!" << endl;
00249                 return 0;
00250         }
00251         // Return number of results
00252         return 3;
00253 }
00254 
00258 void  K3dVM::GetCamDir(const int _iId, K3dVector3 &_rkCamDir)
00259 {
00260         _rkCamDir = ms_pGameData->GetCameraObjSP().Get(_iId)->GetView();
00261 }
00262 
00264 int  K3dVM::K3d_GetCamDir(lua_State *_pState)
00265 {
00266         // Cast the void pointer
00267         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00268         // Get function parameter
00269         int iCamId = (int) lua_tonumber(_pState, 1);
00270         K3dVector3 kCamDir;
00271         // Try call non static function
00272         pSomeClass->GetCamDir(iCamId, kCamDir);
00273         if(ms_pLua->LuaCheckStack(_pState, 3))
00274         {
00275                 // Push result camera direction into script function
00276                 lua_pushnumber(_pState, kCamDir[0]);
00277                 lua_pushnumber(_pState, kCamDir[1]);
00278                 lua_pushnumber(_pState, kCamDir[2]);
00279         }
00280         else
00281         {
00282                 cerr << "Error :: int K3dVM::K3d_GetCamDir() -- Lua stack overflow !!!" << endl;
00283                 return 0;
00284         }
00285         // Return number of results
00286         return 3;
00287 }
00288 
00291 K3dRay *K3dVM::GetAimRay()
00292 {
00293         return ms_pGameData->GetRayObjSP().Get(ms_pGameData->GetAimRayId());
00294 }
00295 
00297 int  K3dVM::K3d_GetAimRay(lua_State *_pState)
00298 {
00299         // Cast the void pointer
00300         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00301         K3dRay *pRay = NULL;
00302         // Try call non static function
00303         pRay = pSomeClass->GetAimRay();
00304         if(ms_pLua->LuaCheckStack(_pState, 6))
00305         {
00306                 if(pRay)
00307                 {
00308                         // Push result camera direction into script function
00309                         lua_pushnumber(_pState, pRay->GetOrigin()->GetX());
00310                         lua_pushnumber(_pState, pRay->GetOrigin()->GetY());
00311                         lua_pushnumber(_pState, pRay->GetOrigin()->GetZ());
00312                         lua_pushnumber(_pState, pRay->GetDirection()->GetX());
00313                         lua_pushnumber(_pState, pRay->GetDirection()->GetY());
00314                         lua_pushnumber(_pState, pRay->GetDirection()->GetZ());
00315                 }
00316                 else
00317                 {
00318                         cerr << "Error -- K3dVM::K3d_GetAimRay() -- pRay doesn`t allocated ! " << endl;
00319                         exit(1);
00320                 }
00321         }
00322         else
00323         {
00324                 cerr << "Error :: int K3dVM::K3d_GetAimRay() -- Lua stack overflow !!!" << endl;
00325                 return 0;
00326         }
00327         // Return number of results
00328         return 6;
00329 }
00330 
00333 K3dRayObj *K3dVM::GetRayOrigDir(const int _iRayId)
00334 {
00335         return ms_pGameData->GetRayObjSP().Get(_iRayId);
00336 }
00337 
00339 int  K3dVM::K3d_GetRayOrigDir(lua_State *_pState)
00340 {
00341         // Cast the void pointer
00342         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00343         K3dRayObj *pRay = NULL;
00344         // Get function parameter
00345         int iRayId = (int) lua_tonumber(_pState, 1);
00346         // Try call non static function
00347         pRay = pSomeClass->GetRayOrigDir(iRayId);
00348 
00349         if(ms_pLua->LuaCheckStack(_pState, 6))
00350         {
00351                 if(pRay)
00352                 {
00353                         // Push result camera direction into script function
00354                         lua_pushnumber(_pState, pRay->GetOrigin()->GetX());
00355                         lua_pushnumber(_pState, pRay->GetOrigin()->GetY());
00356                         lua_pushnumber(_pState, pRay->GetOrigin()->GetZ());
00357                         lua_pushnumber(_pState, pRay->GetDirection()->GetX());
00358                         lua_pushnumber(_pState, pRay->GetDirection()->GetY());
00359                         lua_pushnumber(_pState, pRay->GetDirection()->GetZ());
00360                 }
00361                 else
00362                 {
00363                         cerr << "Error -- K3dVM::K3d_GetRayOrigDir() -- pRay doesn`t allocated ! " << endl;
00364                         exit(1);
00365                 }
00366         }
00367         else
00368         {
00369                 cerr << "Error :: int K3dVM::K3d_GetRayOrigDir() -- Lua stack overflow !!!" << endl;
00370                 return 0;
00371         }
00372         // Return number of results
00373         return 6;
00374 }
00375 
00382 bool K3dVM::GetIntersection(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1)
00383 {
00384         return  ms_pScene->GetIntersection( _iObjId0, _iObjId1, _iObjType0, _iObjType1);
00385 }
00386 
00394 bool K3dVM::GetIntersection(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1, K3dVector3 &_rkInrPoint)
00395 {
00396         return  ms_pScene->GetIntersection( _iObjId0, _iObjId1, _iObjType0, _iObjType1, _rkInrPoint);
00397 }
00398 
00400 int K3dVM::K3d_GetIntersection(lua_State *_pState)
00401 {
00402         // Cast the void pointer
00403         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00404         // Get function parameters
00405         int iObj0 = (int) lua_tonumber(_pState, 1);
00406         int iObj1 = (int) lua_tonumber(_pState, 2);
00407         int iObjType0 = (int) lua_tonumber(_pState, 3);
00408         int iObjType1 = (int) lua_tonumber(_pState, 4);
00409         bool bGetIntrPoint = (bool) lua_tonumber(_pState, 5);
00410         bool bIsIntr = false;
00411         // If we want return intersection point
00412         if(bGetIntrPoint)
00413         {
00414                 K3dVector3 kIntrPoint;
00415                 // Try call non static function
00416                 bIsIntr = pSomeClass->GetIntersection(iObj0, iObj1, iObjType0,iObjType1,kIntrPoint );
00417                 if(ms_pLua->LuaCheckStack(_pState, 4))
00418                 {
00419                         // Push result intersection into script function
00420                         lua_pushboolean(_pState, bIsIntr);
00421                         // Push result intersection point into script function
00422                         lua_pushnumber(_pState, kIntrPoint[0]);
00423                         lua_pushnumber(_pState, kIntrPoint[1]);
00424                         lua_pushnumber(_pState, kIntrPoint[2]);
00425                 }
00426                 else
00427                 {
00428                         cerr << "Error :: int K3dVM::K3d_GetIntersection() -- Lua stack overflow !!!" << endl;
00429                         return 0;
00430                 }
00431                 // Return number of results
00432                 return 4;
00433         }
00434         else
00435         {
00436                 // Try call non static function
00437                 bIsIntr = pSomeClass->GetIntersection(iObj0, iObj1, iObjType0,iObjType1);
00438                 if(ms_pLua->LuaCheckStack(_pState, 1))
00439                 {
00440                         // Push result intersection into script function
00441                         lua_pushboolean(_pState, bIsIntr);
00442                 }
00443                 else
00444                 {
00445                         cerr << "Error :: int K3dVM::K3d_GetIntersection() -- Lua stack overflow !!!" << endl;
00446                         return 0;
00447                 }
00448                 // Return number of results
00449                 return 1;
00450         }
00451 }
00452 
00462 int K3dVM::AddVertex(const float _x,const float _y,const float _z,const char _r,const char  _g,const char  _b,const int _size)
00463 {
00464         K3dVertexObj *pVertex = ms_pGameData->GetVertexBuild()->CreateNewVertexObj();
00465         pVertex->GetPosition()->GetX() = (float) _x;
00466         pVertex->GetPosition()->GetY() = (float) _y;
00467         pVertex->GetPosition()->GetZ() = (float) _z;
00468         pVertex->GetColor()->GetR() = (GLubyte) _r;
00469         pVertex->GetColor()->GetG() = (GLubyte) _g;
00470         pVertex->GetColor()->GetB() = (GLubyte) _b;
00471         pVertex->GetSize() = _size;
00472         // Return vertex index
00473         return pVertex->GetId();
00474 }
00475 
00477 int K3dVM::K3d_AddVertex(lua_State *_pState)
00478 {
00479         // Cast the void pointer
00480         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00481         // Get function parameters
00482         float x = (float) lua_tonumber(_pState, 1);
00483         float y = (float) lua_tonumber(_pState, 2);
00484         float z = (float) lua_tonumber(_pState, 3);
00485         char  r = (char ) lua_tonumber(_pState, 4);
00486         char  g = (char ) lua_tonumber(_pState, 5);
00487         char  b = (char ) lua_tonumber(_pState, 6);
00488         int iSize = (int) lua_tonumber(_pState, 7);
00489         // Try call non static function
00490         int iVertexId = pSomeClass->AddVertex(x,y,z,r,g,b,iSize);
00491         if(ms_pLua->LuaCheckStack(_pState, 1))
00492         {
00493                 // Push result into script function
00494                 lua_pushnumber(_pState, iVertexId);
00495         }
00496         else
00497         {
00498                 cerr << "Error :: int K3dVM::K3d_AddVertex() -- Lua stack overflow !!!" << endl;
00499                 return 0;
00500         }
00501         // Return number of results
00502         return 1;
00503 }
00504 
00510 void K3dVM::SetVertexPos(const int _iVertexId, const float _x,const float _y,const float _z)
00511 {
00512         K3dVertexObj *pVertex = ms_pGameData->GetVertexObjSP().Get(_iVertexId);
00513         pVertex->GetPosition()->GetX() = (float) _x;
00514         pVertex->GetPosition()->GetY() = (float) _y;
00515         pVertex->GetPosition()->GetZ() = (float) _z;
00516 }
00517 
00519 int K3dVM::K3d_SetVertexPos(lua_State *_pState)
00520 {
00521         // Cast the void pointer
00522         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00523         // Get function parameters
00524         int iVertexId = (int) lua_tonumber(_pState, 1);
00525         float x = (float) lua_tonumber(_pState, 2);
00526         float y = (float) lua_tonumber(_pState, 3);
00527         float z = (float) lua_tonumber(_pState, 4);
00528         // Call non static function
00529         pSomeClass->SetVertexPos(iVertexId, x,y,z);
00530         return 0;
00531 }
00532 
00539 void K3dVM::SetColor(const int _iObjId, const int _iObjType, const char _r,const char _g,const char _b)
00540 {
00541         ms_pScene->SetColor(_iObjId, _iObjType, _r, _g, _b);
00542 }
00543 
00544 int K3dVM::K3d_SetColor(lua_State *_pState)
00545 {
00546         // Cast the void pointer
00547         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00548         // Get function parameters
00549         int iObjId = (int) lua_tonumber(_pState, 1);
00550         int iObjType = (int) lua_tonumber(_pState, 2);
00551         char r = (char) lua_tonumber(_pState, 3);
00552         char g = (char) lua_tonumber(_pState, 4);
00553         char b = (char) lua_tonumber(_pState, 5);
00554         // Call non static function
00555         pSomeClass->SetColor(iObjId, iObjType,  r,g,b);
00556         return 0;
00557 }
00558 
00559 
00568 void K3dVM::SetRay(const int _iRayId, const float _origx,const float _origy,const float _origz,const float _dirx,const float _diry,const float _dirz)
00569 {
00570         K3dRay *pRay = ms_pGameData->GetRayObjSP().Get(_iRayId);
00571         pRay->GetOrigin()->GetX() = _origx;
00572         pRay->GetOrigin()->GetY() = _origy;
00573         pRay->GetOrigin()->GetZ() = _origz;
00574         pRay->GetDirection()->GetX() = _dirx;
00575         pRay->GetDirection()->GetY() = _diry;
00576         pRay->GetDirection()->GetZ() = _dirz;
00577 }
00578 
00580 int K3dVM::K3d_SetRay(lua_State *_pState)
00581 {
00582         // Cast the void pointer
00583         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00584         // Get function parameters
00585         int iRayId = (int) lua_tonumber(_pState, 1);
00586         int origx = (int) lua_tonumber(_pState, 2);
00587         int origy = (int) lua_tonumber(_pState, 3);
00588         int origz = (int) lua_tonumber(_pState, 4);
00589         int dirx = (int) lua_tonumber(_pState, 5);
00590         int diry = (int) lua_tonumber(_pState, 6);
00591         int dirz = (int) lua_tonumber(_pState, 7);
00592         // Call non static function
00593         pSomeClass->SetRay(iRayId, origx,origy,origz,dirx,diry,dirz);
00594         // Return number of results
00595         return 0;
00596 }
00597 
00606 void K3dVM::SetLine(const int _iLineId, const float _origx,const float _origy,const float _origz,const float _dirx,const float _diry,const float _dirz)
00607 {
00608         K3dLineObj *pLine = ms_pGameData->GetLineObjSP().Get(_iLineId);
00609         pLine->GetRelOrigin()->GetX() = _origx;
00610         pLine->GetRelOrigin()->GetY() = _origy;
00611         pLine->GetRelOrigin()->GetZ() = _origz;
00612         pLine->GetRelDirection()->GetX() = _dirx;
00613         pLine->GetRelDirection()->GetY() = _diry;
00614         pLine->GetRelDirection()->GetZ() = _dirz;
00615 }
00616 
00618 int K3dVM::K3d_SetLine(lua_State *_pState)
00619 {
00620         // Cast the void pointer
00621         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00622         // Get function parameters
00623         int iLineId = (int) lua_tonumber(_pState, 1);
00624         float origx = (float) lua_tonumber(_pState, 2);
00625         float origy = (float) lua_tonumber(_pState, 3);
00626         float origz = (float) lua_tonumber(_pState, 4);
00627         float dirx = (float) lua_tonumber(_pState, 5);
00628         float diry = (float) lua_tonumber(_pState, 6);
00629         float dirz = (float) lua_tonumber(_pState, 7);
00630         // Call non static function
00631         pSomeClass->SetLine(iLineId, origx,origy,origz,dirx,diry,dirz);
00632         // Return number of results
00633         return 0;
00634 }
00635 
00640 void K3dVM::Hide(const int _iObjId, const int _iObjType, const bool _bHide)
00641 {
00642         ms_pScene->Hide(_iObjId, _iObjType, _bHide);
00643 }
00644 
00646 int K3dVM::K3d_Hide(lua_State *_pState)
00647 {
00648         // Cast the void pointer
00649         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00650         // Get function parameters
00651         int iObjId = (int) lua_tonumber(_pState, 1);
00652         int iObjType = (int) lua_tonumber(_pState, 2);
00653         bool bHide = (bool) lua_toboolean(_pState, 3);
00654         // Call non static function
00655         pSomeClass->Hide(iObjId, iObjType, bHide);
00656         // Return number of results
00657         return 0;
00658 }
00659 
00663 void K3dVM::PrintValue(const char* _strComment,const float _fValue)
00664 {
00665         ms_pScene->DrawValue(_strComment, _fValue);
00666 }
00667 
00669 int K3dVM::K3d_PrintValue(lua_State *_pState)
00670 {
00671         // Cast the void pointer
00672         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00673         // Get function parameters
00674         const char* strComment = lua_tostring(_pState, 1);
00675         float fValue = (float) lua_tonumber(_pState, 2);
00676         // Call non static function
00677         pSomeClass->PrintValue(strComment, fValue);
00678         // Return number of results
00679         return 0;
00680 }
00681 
00684 void K3dVM::Print(const char* _str)
00685 {
00686         ms_pScene->DrawValue(_str);
00687 }
00688 
00690 int K3dVM::K3d_Print(lua_State *_pState)
00691 {
00692         // Cast the void pointer
00693         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00694         // Get function parameters
00695         const char* str = lua_tostring(_pState, 1);
00696         // Call non static function
00697         pSomeClass->Print(str);
00698         // Return number of results
00699         return 0;
00700 }
00701 
00708 float K3dVM::GetDistance(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1)
00709 {
00710         return  ms_pScene->GetDistance( _iObjId0, _iObjId1, _iObjType0, _iObjType1);
00711 }
00712 
00714 int K3dVM::K3d_GetDistance(lua_State *_pState)
00715 {
00716         // Cast the void pointer
00717         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00718         // Get function parameter
00719         int iObjId0 = (int) lua_tonumber(_pState, 1);
00720         int iObjId1 = (int) lua_tonumber(_pState, 2);
00721         int iObjType0 = (int) lua_tonumber(_pState, 3);
00722         int iObjType1 = (int) lua_tonumber(_pState, 4);
00723         // Try call non static function
00724         float fDist = pSomeClass->GetDistance(iObjId0,iObjId1,iObjType0,iObjType1);
00725         if(ms_pLua->LuaCheckStack(_pState, 1))
00726         {
00727                 // Push result camera direction into script function
00728                 lua_pushnumber(_pState, fDist);
00729         }
00730         else
00731         {
00732                 cerr << "Error :: int K3dVM::K3d_GetDistance() -- Lua stack overflow !!!" << endl;
00733                 return 0;
00734         }
00735         // Return number of results
00736         return 1;
00737 }
00738 
00740 bool K3dVM::IsMouseLeft()
00741 {
00742         K3dMouse *pMouse = ms_pGameData->GetMouse();
00743         return pMouse->MouseButtonLeft();
00744 }
00745 
00747 int K3dVM::K3d_IsMouseLeft(lua_State *_pState)
00748 {
00749         // Cast the void pointer
00750         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00751         bool bIsMouseLeft = pSomeClass->IsMouseLeft();
00752         if(ms_pLua->LuaCheckStack(_pState, 1))
00753         {
00754                 // Push result camera direction into script function
00755                 lua_pushboolean(_pState, bIsMouseLeft);
00756         }
00757         else
00758         {
00759                 cerr << "Error :: int K3dVM::K3d_IsMouseLeft() -- Lua stack overflow !!!" << endl;
00760                 return 0;
00761         }
00762         // Return number of results
00763         return 1;
00764 }
00765 
00767 bool K3dVM::IsMouseRight()
00768 {
00769         K3dMouse *pMouse = ms_pGameData->GetMouse();
00770         return pMouse->MouseButtonRight();
00771 }
00772 
00774 int K3dVM::K3d_IsMouseRight(lua_State *_pState)
00775 {
00776         // Cast the void pointer
00777         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00778         bool bIsMouseRight = pSomeClass->IsMouseRight();
00779         if(ms_pLua->LuaCheckStack(_pState, 1))
00780         {
00781                 // Push result camera direction into script function
00782                 lua_pushboolean(_pState, bIsMouseRight);
00783         }
00784         else
00785         {
00786                 cerr << "Error :: int K3dVM::K3d_IsMouseRight() -- Lua stack overflow !!!" << endl;
00787                 return 0;
00788         }
00789         // Return number of results
00790         return 1;
00791 }
00792 
00793 
00794 //
00796 bool K3dVM::IsMouseLeftUp()
00797 {
00798         K3dMouse *pMouse = ms_pGameData->GetMouse();
00799         return -pMouse->MouseButtonLeft();
00800 }
00801 
00803 int K3dVM::K3d_IsMouseLeftUp(lua_State *_pState)
00804 {
00805         // Cast the void pointer
00806         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00807         bool bIsMouseLeftUp = pSomeClass->IsMouseLeftUp();
00808         if(ms_pLua->LuaCheckStack(_pState, 1))
00809         {
00810                 // Push result camera direction into script function
00811                 lua_pushboolean(_pState, bIsMouseLeftUp);
00812         }
00813         else
00814         {
00815                 cerr << "Error :: int K3dVM::K3d_IsMouseLeftUp() -- Lua stack overflow !!!" << endl;
00816                 return 0;
00817         }
00818         // Return number of results
00819         return 1;
00820 }
00821 
00823 bool K3dVM::IsMouseRightUp()
00824 {
00825         K3dMouse *pMouse = ms_pGameData->GetMouse();
00826         return -pMouse->MouseButtonRight();
00827 }
00828 
00830 int K3dVM::K3d_IsMouseRightUp(lua_State *_pState)
00831 {
00832         // Cast the void pointer
00833         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00834         bool bIsMouseRightUp = pSomeClass->IsMouseRightUp();
00835         if(ms_pLua->LuaCheckStack(_pState, 1))
00836         {
00837                 // Push result camera direction into script function
00838                 lua_pushboolean(_pState, bIsMouseRightUp);
00839         }
00840         else
00841         {
00842                 cerr << "Error :: int K3dVM::K3d_IsMouseRightUp() -- Lua stack overflow !!!" << endl;
00843                 return 0;
00844         }
00845         // Return number of results
00846         return 1;
00847 }
00848 //
00849 
00851 void K3dVM::MoveByMouse(const int _iSphereId)
00852 {
00853         ms_pScene->MoveByMouse(_iSphereId);
00854 }
00855 
00857 int K3dVM::K3d_MoveByMouse(lua_State *_pState)
00858 {
00859         // Cast the void pointer
00860         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00861         // Get function parameter
00862         int iSphereId = (int) lua_tonumber(_pState, 1);
00863         pSomeClass->MoveByMouse(iSphereId);
00864         // Return number of results
00865         return 0;
00866 }
00867 
00872 void K3dVM::GetSpherePos(const int _iId, K3dVector3 &_rkPos)
00873 {
00874         _rkPos = *ms_pGameData->GetSphereObjSP().Get(_iId)->GetPosition();
00875 }
00876 
00878 int K3dVM::K3d_GetSpherePos(lua_State *_pState)
00879 {
00880         // Cast the void pointer
00881         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00882         // Get function parameter
00883         int iId = (int) lua_tonumber(_pState, 1);
00884         K3dVector3 kPos;
00885         // Try call non static function
00886         pSomeClass->GetSpherePos(iId, kPos);
00887         if(ms_pLua->LuaCheckStack(_pState, 3))
00888         {
00889                 // Push result camera position into script function
00890                 lua_pushnumber(_pState, kPos[0]);
00891                 lua_pushnumber(_pState, kPos[1]);
00892                 lua_pushnumber(_pState, kPos[2]);
00893         }
00894         else
00895         {
00896                 cerr << "Error :: int K3dVM::K3d_GetSpherePos() -- Lua stack overflow !!!" << endl;
00897                 return 0;
00898         }
00899         // Return number of results
00900         return 3;
00901 }
00902 
00906 bool K3dVM::Wait(const int _iMsec)
00907 {
00908         return ms_pGameData->GetTimer()->Wait(_iMsec);
00909 }
00910 
00912 int  K3dVM::K3d_Wait(lua_State *_pState)
00913 {
00914         // Cast the void pointer
00915         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00916         // Get function parameter
00917         int iMsec = (int) lua_tonumber(_pState, 1);
00918         // Try call non static function
00919         bool bWait = pSomeClass->Wait(iMsec);
00920         if(ms_pLua->LuaCheckStack(_pState, 1))
00921         {
00922                 lua_pushboolean(_pState, bWait);
00923         }
00924         else
00925         {
00926                 cerr << "Error :: int K3dVM::K3d_Wait() -- Lua stack overflow !!!" << endl;
00927                 return 0;
00928         }
00929         // Return number of results
00930         return 1;
00931 }
00932 
00934 void K3dVM::IncludeScript(const char* _strFileName)
00935 {
00936         K3dString strFilename = ms_pGameData->GetSysHome() + K3D_STR_SHARE_PATH + _strFileName;
00937         LoadScript(strFilename);
00938 }
00939 
00941 int K3dVM::K3d_IncludeScript(lua_State *_pState)
00942 {
00943         // Cast the void pointer
00944         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00945         // Get function parameter
00946         const char* strFileName = lua_tostring(_pState, 1);
00947         pSomeClass->IncludeScript(strFileName);
00948         cout << "Load script OK... " << endl;
00949         // Return number of results
00950         return 0;
00951 }
00952 
00958 void K3dVM::Link(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1)
00959 {
00960         ms_pScene->Link( _iObjId0, _iObjId1, _iObjType0, _iObjType1);
00961 }
00962 
00964 int K3dVM::K3d_Link(lua_State *_pState)
00965 {
00966         // Cast the void pointer
00967         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00968         // Get function parameters
00969         int iObjId0 = (int) lua_tonumber(_pState, 1);
00970         int iObjId1 = (int) lua_tonumber(_pState, 2);
00971         int iObjType0 = (int) lua_tonumber(_pState, 3);
00972         int iObjType1 = (int) lua_tonumber(_pState, 4);
00973         // Try call non static function
00974         pSomeClass->Link(iObjId0,iObjId1,iObjType0,iObjType1);
00975         // Return number of results
00976         return 0;
00977 }
00978 
00982 bool K3dVM::ButtonIsPressed(const int _iButtonId)
00983 {
00984         return ms_pScene->ButtonIsPressed(_iButtonId);
00985 }
00986 
00988 int K3dVM::K3d_ButtonIsPressed(lua_State *_pState)
00989 {
00990         // Cast the void pointer
00991         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
00992         // Get function parameters
00993         int iButtonId = (int) lua_tonumber(_pState, 1);
00994         // Try call non static function
00995         bool bIsButtonPressed = pSomeClass->ButtonIsPressed(iButtonId);
00996         if(ms_pLua->LuaCheckStack(_pState, 1))
00997         {
00998                 // Push result camera position into script function
00999                 lua_pushboolean(_pState, bIsButtonPressed);
01000         }
01001         else
01002         {
01003                 cerr << "Error :: int K3dVM::K3d_ButtonIsPressed() -- Lua stack overflow !!!" << endl;
01004                 return 0;
01005         }
01006         // Return number of results
01007         return 1;
01008 }
01009 
01014 int K3dVM::GetGuiObject(const char* _strObjName, const int _iObjType)
01015 {
01016         // Get object index by object name and object type
01017         int iId = ms_pScene->FindGuiObjectId(_strObjName, _iObjType);
01018         return iId;
01019 }
01020 
01022 int K3dVM::K3d_GetGuiObject(lua_State *_pState)
01023 {
01024         // Cast the void pointer
01025         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01026         // Get function parameters
01027         const char* strObjName = (const char*) lua_tostring(_pState, 1);
01028         const int iObjType = (int) lua_tonumber(_pState, 2);
01029         // Try call non static function
01030         int iResult = pSomeClass->GetGuiObject(strObjName, iObjType);
01031         if(ms_pLua->LuaCheckStack(_pState, 1))
01032         {
01033                 // Push result into script function
01034                 lua_pushnumber(_pState, iResult);
01035         }
01036         else
01037         {
01038                 cerr << "Error :: int K3dVM::K3d_GetGuiObject() -- Lua stack overflow !!!" << endl;
01039                 return 0;
01040         }
01041         // Return number of results
01042         return 1;
01043 }
01044 
01048 void K3dVM::HideGui(const int _iObjId, const int _iObjType)
01049 {
01050         ms_pScene->HideGui(_iObjId, _iObjType);
01051 }
01052 
01054 int K3dVM::K3d_HideGui(lua_State *_pState)
01055 {
01056         // Cast the void pointer
01057         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01058         // Get function parameters
01059         const int iObjId = (int) lua_tonumber(_pState, 1);
01060         const int iObjType = (int) lua_tonumber(_pState, 2);
01061         // Try call non static function
01062         pSomeClass->HideGui(iObjId, iObjType);
01063         // Return number of results
01064         return 0;
01065 }
01066 
01070 void K3dVM::ShowGui(const int _iObjId, const int _iObjType)
01071 {
01072         ms_pScene->ShowGui(_iObjId, _iObjType);
01073 }
01074 
01076 int K3dVM::K3d_ShowGui(lua_State *_pState)
01077 {
01078         // Cast the void pointer
01079         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01080         // Get function parameters
01081         const int iObjId = (int) lua_tonumber(_pState, 1);
01082         const int iObjType = (int) lua_tonumber(_pState, 2);
01083         // Try call non static function
01084         pSomeClass->ShowGui(iObjId, iObjType);
01085         // Return number of results
01086         return 0;
01087 }
01088 
01092 void K3dVM::ShowFileListBox(const int _iListModel, const char * _strPath)
01093 {
01094         ms_pScene->ShowFileListBox(_iListModel, _strPath);
01095 }
01096 
01098 int K3dVM::K3d_ShowFileListBox(lua_State *_pState)
01099 {
01100         // Cast the void pointer
01101         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01102         // Get function parameters
01103         const int iListModel = (int) lua_tonumber(_pState, 1);
01104         const char* strPath = lua_tostring(_pState, 2);
01105         // Try call non static function
01106         pSomeClass->ShowFileListBox(iListModel, strPath);
01107         // Return number of results
01108         return 0;
01109 }
01110 
01112 bool K3dVM::LoadMapFromListBox(const int _iListBoxId, const char * _strPath)
01113 {
01114         return ms_pScene->LoadMapFromListBox(_iListBoxId, _strPath);
01115 }
01116 
01118 int K3dVM::K3d_LoadMapFromListBox(lua_State *_pState)
01119 {
01120         // Cast the void pointer
01121         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01122         // Get function parameters
01123         const int iListBox = (int) lua_tonumber(_pState, 1);
01124         const char* strPath = lua_tostring(_pState, 2);
01125         // Try call non static function
01126         bool bIsLoad = pSomeClass->LoadMapFromListBox(iListBox, strPath);
01127         // Return result
01128         lua_pushboolean(_pState, bIsLoad);
01129         // Return number of results
01130         return 1;
01131 }
01132 
01136 bool K3dVM::CheckKeyboardKey(const char* _strKey)
01137 {
01138         // Get global keyboard map pointer
01139         K3dKeyMap *pKeyMap = ms_pGameData->GetKeyMap(); 
01140         K3dString str = _strKey;
01141         if(str == "Esc")
01142         {
01143                 return pKeyMap->GetKeyEsc();
01144         }
01145         return false;
01146 }
01147 int K3dVM::K3d_CheckKeyboardKey(lua_State *_pState)
01148 {
01149         // Cast the void pointer
01150         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01151         // Get function parameters
01152         const char* strKey = lua_tostring(_pState, 1);
01153         // Try call non static function
01154         bool bIsPressed = pSomeClass->CheckKeyboardKey(strKey);
01155         // Return result
01156         lua_pushboolean(_pState, bIsPressed);
01157         // Return number of results
01158         return 1;
01159 }
01160 
01163 void K3dVM::LoadNewScript(const char* _strFileName)
01164 {
01165         ms_pScene->LoadNewScript(_strFileName);
01166 }
01167 int K3dVM::K3d_LoadNewScript(lua_State *_pState)
01168 {
01169         // Cast the void pointer
01170         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01171         // Get function parameters
01172         const char* strFileName = lua_tostring(_pState, 1);
01173         // Try call non static function
01174         pSomeClass->LoadNewScript(strFileName);
01175         // Return number of results
01176         return 0;
01177 }
01178 
01180 void K3dVM::Exit()
01181 {
01182         cout << "Exit engine" << endl;
01183         ms_pScene->GetExit() = true;
01184 }
01185 int  K3dVM::K3d_Exit(lua_State *_pState)
01186 {
01187         // Cast the void pointer
01188         K3dVM *pSomeClass = (K3dVM*)ms_pObject;
01189         // Try call non static function
01190         pSomeClass->Exit();
01191         // Return number of results
01192         return 0;
01193 }
01194 

Generated on Thu Aug 16 23:53:27 2007 for K3dEngine by  doxygen 1.5.0