lugre_scripting.ogre.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include <assert.h>
00003 #include <stdarg.h>
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include "lugre_net.h"
00007 #include "lugre_fifo.h"
00008 #include "lugre_game.h"
00009 #include "lugre_listener.h"
00010 #include "lugre_scripting.h"
00011 #include "lugre_input.h"
00012 #include "lugre_robstring.h"
00013 #include "lugre_gfx3D.h"
00014 #include "lugre_gfx2D.h"
00015 #include "lugre_widget.h"
00016 #include "lugre_luabind.h"
00017 #include "lugre_luabind_direct.h"
00018 #include "lugre_shell.h"
00019 #include "lugre_timer.h"
00020 #include "lugre_ogrewrapper.h"
00021 #include "lugre_bitmask.h"
00022 #include "lugre_camera.h"
00023 #include "lugre_viewport.h"
00024 #include "lugre_rendertexture.h"
00025 #include "lugre_sound.h"
00026 #include <Ogre.h>
00027 #include <OgreResourceManager.h>
00028 #include <OgreFontManager.h>
00029 #include <OgreTextAreaOverlayElement.h>
00030 #include <OgreMeshSerializer.h>
00031 #include <OgreCompositorManager.h>
00032 //~ #include "OgreTerrainSceneManager.h"
00033 #include "lugre_luaxml.h"
00034 #include "lugre_meshshape.h"
00035 #include "lugre_meshbuffer.h"
00036 #include "lugre_spritelist.h"
00037 
00038 #if LUGRE_PLATFORM == LUGRE_PLATFORM_APPLE
00039 #include <OIS/OIS.h>
00040 #else
00041 #include <OIS.h>
00042 #endif
00043 
00044 #if defined OIS_LINUX_PLATFORM && 0
00045 #include "linux/LinuxMouse.h"
00046 #endif
00047 
00048 
00049 using namespace Lugre;
00050 
00051     
00052 namespace Lugre {
00053     void    DisplayNotice           (const char* szMsg); 
00054     void    DisplayErrorMessage     (const char* szMsg); 
00055     void    Material_LuaRegister    (void *L);
00056     void    Beam_LuaRegister        (void *L);
00057     void    PrintLuaStackTrace      ();
00058     void    ProfileDumpCallCount    (); 
00059     void    OgreForceCloseFullscreen ();
00060     void    ClearUnusedParticleSystemCache (); // see gfx3d
00061     void    PrintOgreExceptionAndTipps(Ogre::Exception& e);
00062     void    OgreWrapperSetCustomSceneMgrType    (std::string sCustomSceneMgrType);
00063     void    OgreWrapperSetEnableUnicode         (bool bState);
00064     
00065     void    PrintExceptionTipps (std::string sDescr) {
00066         cScripting::GetSingletonPtr()->LuaCall("LugreExceptionTipps","s",sDescr.c_str());
00067     }
00068 };
00069 
00070 
00071 
00076 int     FIFO_RayPickTri     (cFIFO& pVertexBuf,cFIFO& pIndexBuf,int iNumFaces,int iVertexPosOffset,int iVertexStride,const float fBoundRad,const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,float* pfHitDist) {
00077     if (!Ogre::Ray(vRayPos,vRayDir).intersects(Ogre::Sphere(Ogre::Vector3::ZERO,fBoundRad)).first) return -1;
00078     int     iFaceHit = -1;
00079     float   myHitDist = 0;
00080     unsigned int*   pI = (unsigned int*)pIndexBuf.HackGetRawReader(); if (sizeof(int) != 4) return -2; 
00081     const char*     pV = pVertexBuf.HackGetRawReader() + iVertexPosOffset; 
00082     #define FIFO_RayPick_GetVertexPosBase(i) ((float*)(pV+(i)*iVertexStride))
00083     for (int iFace=0;iFace<iNumFaces;++iFace) {
00084         float* a = FIFO_RayPick_GetVertexPosBase(pI[0]);
00085         float* b = FIFO_RayPick_GetVertexPosBase(pI[1]);
00086         float* c = FIFO_RayPick_GetVertexPosBase(pI[2]);
00087     
00088         if (IntersectRayTriangle(vRayPos,vRayDir,
00089             Ogre::Vector3(a[0],a[1],a[2]),
00090             Ogre::Vector3(b[0],b[1],b[2]),
00091             Ogre::Vector3(c[0],c[1],c[2]),&myHitDist)) {
00092             if (iFaceHit == -1 || myHitDist < *pfHitDist) { *pfHitDist = myHitDist; iFaceHit = iFace; }
00093         }
00094         pI += 3;
00095     }
00096     return iFaceHit;
00097 }
00098 
00099 int     FIFO_RayPickTri_Ex      (cFIFO& pVertexBuf,cFIFO& pIndexBuf,int iNumFaces,int iVertexPosOffset,int iVertexStride,const float fBoundRad,const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,const Ogre::Vector3& vPos,const Ogre::Quaternion& qRot,const Ogre::Vector3& vScale,float* pfHitDist) {
00100     Ogre::Quaternion invrot     = qRot.Inverse();
00101     return FIFO_RayPickTri(pVertexBuf,pIndexBuf,iNumFaces,iVertexPosOffset,iVertexStride,fBoundRad,(invrot*(vRayPos - vPos))/vScale,(invrot * vRayDir)/ vScale,pfHitDist);
00102 }
00103 
00105 static int                      l_FIFO_RayPickTri_Ex (lua_State *L) { PROFILE
00106     cFIFO& pVertexBuf   = *cLuaBind<cFIFO>::checkudata_alive(L,1);
00107     cFIFO& pIndexBuf    = *cLuaBind<cFIFO>::checkudata_alive(L,2);
00108     
00109     int iNumFaces           = luaL_checkint(L,3);
00110     int iVertexPosOffset    = luaL_checkint(L,4);
00111     int iVertexStride       = luaL_checkint(L,5);
00112     float fBoundRad         = luaL_checknumber(L,6);
00113     
00114     // don't use ++i or something here, the compiler might mix the order
00115     Ogre::Vector3       vRayPos(    luaL_checknumber(L,7),luaL_checknumber(L,8),luaL_checknumber(L,9));
00116     Ogre::Vector3       vRayDir(    luaL_checknumber(L,10),luaL_checknumber(L,11),luaL_checknumber(L,12));
00117     Ogre::Vector3       vPos(       luaL_checknumber(L,13),luaL_checknumber(L,14),luaL_checknumber(L,15));
00118     float   qw      = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,16,1.0);
00119     float   qx      = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,17,0.0);
00120     float   qy      = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,18,0.0);
00121     float   qz      = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,19,0.0);
00122     float   scalex  = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,20,1.0);
00123     float   scaley  = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,21,1.0);
00124     float   scalez  = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,22,1.0);
00125     
00126     Ogre::Quaternion    qRot(qw,qx,qy,qz);
00127     Ogre::Vector3       vScale(scalex,scaley,scalez);
00128     float fHitDist = 0;
00129     int iFaceNum = FIFO_RayPickTri_Ex(pVertexBuf,pIndexBuf,iNumFaces,iVertexPosOffset,iVertexStride,fBoundRad,vRayPos,vRayDir,vPos,qRot,vScale,&fHitDist);
00130     bool bHit = iFaceNum != -1;
00131     lua_pushboolean(L,bHit);
00132     lua_pushnumber(L,fHitDist);
00133     lua_pushnumber(L,iFaceNum);
00134     return 3;
00135 }
00136 
00138 static int                      l_ExportOgreFont (lua_State *L) { PROFILE
00139     std::string sFontName   = luaL_checkstring(L,1);
00140     
00141     Ogre::FontPtr pFont = Ogre::FontManager::getSingleton().getByName(sFontName);
00142     if (pFont.isNull()) return 0;
00143     pFont->load();
00144     Ogre::MaterialPtr pMaterial = pFont->getMaterial();
00145     lua_pushstring(L,pMaterial->getName().c_str());
00146     
00147     // export glyph infos
00148     lua_newtable(L);
00149     Ogre::Font::CodePoint i = 0; // typedef Ogre::uint32 Ogre::Font::CodePoint
00150     int iFailCounter = 0;
00151     do {
00152         const Ogre::Font::UVRect& myRect = pFont->getGlyphTexCoords(i);
00153         if (myRect.bottom != myRect.top && myRect.right != myRect.left) { // nullrect for undefined codepoints
00154             const Ogre::Font::GlyphInfo& glyph = pFont->getGlyphInfo(i);
00155                 
00156             // construct glyph entry
00157             lua_newtable(L);
00158             #define MYSET(name,value) lua_pushstring(L,#name); lua_pushnumber(L,value); lua_rawset(L,-3); // k,v,set(L,tableindex)
00159             MYSET(left          ,glyph.uvRect.left      )
00160             MYSET(top           ,glyph.uvRect.top       ) 
00161             MYSET(right         ,glyph.uvRect.right     )
00162             MYSET(bottom        ,glyph.uvRect.bottom    )
00163             MYSET(aspectRatio   ,glyph.aspectRatio      )
00164             #undef MYSET
00165             
00166             // add glyph entry to glyphtable
00167             lua_rawseti(L,-2,glyph.codePoint); 
00168             iFailCounter = 0;
00169         } else {
00170             if (++iFailCounter > 256) break;
00171         }
00172         //~ if ((i%256) == 0) printf("%08x\n",(int)i);
00173     } while (++i != 0);
00174     
00175     return 2;
00176 }
00177 
00178 
00180 static int          l_CloneMesh (lua_State *L) { PROFILE
00181     std::string sOldMeshName    = luaL_checkstring(L,1);
00182     std::string sNewMeshName    = cOgreWrapper::GetSingleton().GetUniqueName();
00183     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sOldMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00184     if (mesh.isNull()) return 0;
00185     mesh->clone(sNewMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00186     lua_pushstring(L,sNewMeshName.c_str());
00187     return 1;
00188 }
00189 
00191 static int      l_MeshBuildEdgeList (lua_State *L) { PROFILE
00192     std::string sMeshName   = luaL_checkstring(L,1);
00193     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00194     if (!mesh.isNull()) mesh->buildEdgeList();
00195     return 0;
00196 }
00197 
00198 
00199 
00201 static int l_ReloadParticleTemplate (lua_State *L) { PROFILE
00202     std::string sName           = luaL_checkstring(L,1);
00203     std::string sFilePath       = luaL_checkstring(L,2);
00204     Ogre::ParticleSystemManager& psm = Ogre::ParticleSystemManager::getSingleton();
00205     
00206     Ogre::ParticleSystem* pPS = psm.getTemplate(sName);
00207     if (!pPS) { printf("ReloadParticleTemplate %s : particlesystem not found\n",sName.c_str()); return 0; }
00208     
00209     std::string sOrigin = pPS->getOrigin();
00210     printf("ReloadParticleTemplate %s : origin=%s\n",sName.c_str(),sOrigin.c_str());
00211     
00212     ClearUnusedParticleSystemCache();
00213     
00214     Ogre::ParticleSystemManager::ParticleSystemTemplateIterator itor = psm.getTemplateIterator();
00215     std::vector<Ogre::ParticleSystem*> killme;
00216     while (itor.hasMoreElements()) {
00217         Ogre::ParticleSystem* pPS2 = itor.getNext();
00218         if (pPS2->getOrigin() == sOrigin) {
00219             killme.push_back(pPS2);
00220             pPS2->removeAllEmitters();
00221         }
00222     }
00223     for (std::vector<Ogre::ParticleSystem*>::iterator itor2=killme.begin();itor2!=killme.end();++itor2) 
00224         psm.removeTemplate((*itor2)->getName());
00225     
00226     //~ psm.removeAllTemplates();
00227     //~ psm.removeTemplate(sName);
00228     
00229     //~ Ogre::ResourceGroupManager::getSingleton().unloadResourceGroup(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00230     //~ Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00231     //~ Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
00232     
00233     
00234     std::ifstream fp;
00235     // Always open in binary mode
00236     fp.open(sFilePath.c_str(), std::ios::in | std::ios::binary);
00237     if(!fp) { printf("ReloadParticleTemplate %s : file not found\n",sName.c_str()); return 0; }
00238 
00239     // Wrap as a stream
00240     std::string sFileStreamName = sFilePath + cOgreWrapper::GetSingleton().GetUniqueName();
00241     Ogre::DataStreamPtr stream(new Ogre::FileStreamDataStream(sFileStreamName, &fp, false));
00242     
00243     if (!stream.isNull())
00244     {
00245         psm.parseScript(stream,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00246     } else {
00247         printf("ReloadParticleTemplate %s : couldn't open stream\n",sName.c_str()); return 0;
00248     }
00249     
00250     //~ void    parseScript (DataStreamPtr &stream, const String &groupName)
00251     //~ void    removeAllTemplates (bool deleteTemplate=true)
00252     return 0;
00253 }
00254 
00256 static int l_ReloadMesh (lua_State *L) { PROFILE
00257     std::string sMeshName   = luaL_checkstring(L,1);
00258     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00259     if (mesh.isNull()) return 0;
00260     if(mesh->isReloadable()){
00261         mesh->reload();
00262     }
00263     return 0;
00264 }
00265 
00266 void    TransformSubMeshTexCoords   (Ogre::SubMesh& pSubMesh,const float u0,const float v0,const float u1,const float v1);
00267 
00270 static int l_TransformSubMeshTexCoords (lua_State *L) { PROFILE
00271     std::string sMeshName       = luaL_checkstring(L,1);
00272     int         iSubMeshIndex   = luaL_checkint(L,2);   
00273     float       u0              = luaL_checknumber(L,3);    
00274     float       v0              = luaL_checknumber(L,4);    
00275     float       u1              = luaL_checknumber(L,5);    
00276     float       v1              = luaL_checknumber(L,6);    
00277     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00278     if (mesh.isNull()) return 0;
00279     if (iSubMeshIndex < 0) return 0;
00280     if (mesh->getNumSubMeshes() <= iSubMeshIndex) return 0;
00281     TransformSubMeshTexCoords(*mesh->getSubMesh(iSubMeshIndex),u0,v0,u1,v1);
00282     return 0;
00283 }
00284 
00285 
00286 
00288 static int l_MeshBuildTangentVectors (lua_State *L) { PROFILE
00289     std::string sMeshName   = luaL_checkstring(L,1);
00290     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00291     if (mesh.isNull()) return 0;
00292     // Build tangent vectors, all our meshes use only 1 texture coordset 
00293     // Note we can build into VES_TANGENT now (SM2+)
00294     unsigned short src, dest;
00295     if (!mesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
00296     {
00297         mesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
00298         // Second mode cleans mirrored / rotated UVs but requires quality models
00299         //pMesh->buildTangentVectors(VES_TANGENT, src, dest, true, true);
00300     }
00301     return 0;
00302 }
00303             
00304 
00306 static int l_SetMeshSubMaterial (lua_State *L) { PROFILE
00307     std::string sMeshName   = luaL_checkstring(L,1);
00308     unsigned int iSubMeshIndex = luaL_checkint(L,2);
00309     std::string sMatName    = luaL_checkstring(L,3);
00310     
00311     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00312     if (mesh.isNull()) return 0;
00313     if (iSubMeshIndex < 0) return 0;
00314     if (mesh->getNumSubMeshes() <= iSubMeshIndex) return 0;
00315     
00316     mesh->getSubMesh(iSubMeshIndex)->setMaterialName(sMatName);
00317     
00318     return 0;
00319 }
00320 
00322 static int l_GetMeshSubMeshCount (lua_State *L) { PROFILE
00323     std::string sMeshName   = luaL_checkstring(L,1);
00324     
00325     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00326     if (mesh.isNull()) return 0;
00327     
00328     lua_pushnumber(L,mesh->getNumSubMeshes());
00329     return 1;
00330 }
00331 
00333 static int l_GetMeshSubMaterial (lua_State *L) { PROFILE
00334     std::string sMeshName   = luaL_checkstring(L,1);
00335     unsigned int iSubMeshIndex = luaL_checkint(L,2);
00336     
00337     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(sMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00338     if (mesh.isNull()) return 0;
00339     if (mesh->getNumSubMeshes() <= iSubMeshIndex) return 0;
00340     
00341     lua_pushstring(L,mesh->getSubMesh(iSubMeshIndex)->getMaterialName().c_str());
00342     return 1;
00343 }
00344 
00345 
00346 
00349 static int l_OgreCreateWindow (lua_State *L) { PROFILE
00350     bool bConfigRestoreOrDialog = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? (lua_isboolean(L,1) ? lua_toboolean(L,1) : luaL_checkint(L,1)) : true;
00351     try {
00352         bool res = cOgreWrapper::GetSingleton().CreateOgreWindow(bConfigRestoreOrDialog);
00353         lua_pushboolean(L,res);
00354         return 1;
00355     } catch( Ogre::Exception& e ) {
00356         printf("warning, OgreWrapper::CreateWindow failed with exception\n");
00357         PrintOgreExceptionAndTipps(e);
00358     }
00359     return 0;
00360 }
00361 
00362 
00364 static int l_InitOgre (lua_State *L) { PROFILE
00365     std::string sWindowTitle    = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "Lugre";
00366     std::string sOgrePluginPath = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkstring(L,2) : "/usr/local/lib/OGRE";
00367     std::string sOgreBaseDir    = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkstring(L,3) : "./";
00368     bool bAutoCreateWindow      = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? (lua_isboolean(L,4) ? lua_toboolean(L,4) : luaL_checkint(L,4)) : true;
00369     
00370     try {
00371         bool res = cOgreWrapper::GetSingleton().Init(sWindowTitle.c_str(),sOgrePluginPath.c_str(),sOgreBaseDir.c_str(),bAutoCreateWindow);
00372         lua_pushboolean(L,res);
00373         return 1;
00374     } catch( Ogre::Exception& e ) {
00375         printf("warning, InitOgre failed with exception\n");
00376         PrintOgreExceptionAndTipps(e);
00377     }
00378     return 0;
00379 }
00380 
00381 int MyLuaReturnStringList (lua_State *L,std::vector<std::string> l) {
00382     if (!lua_checkstack(L,l.size())) return 0;
00383     for (int i=0;i<l.size();++i) lua_pushstring(L,l[i].c_str());
00384     return l.size();
00385 }
00386 
00388 static int l_Ogre_ListRenderSystems (lua_State *L) { PROFILE return MyLuaReturnStringList(L,cOgreWrapper::GetSingleton().ListRenderSystems()); }
00389 
00391 static int l_Ogre_SetRenderSystemByName (lua_State *L) { PROFILE
00392     std::string sRenderSysName = luaL_checkstring(L,1);
00393     cOgreWrapper::GetSingleton().SetRenderSystemByName(sRenderSysName);
00394     return 0;
00395 }
00396 
00398 static int l_Ogre_SetConfigOption   (lua_State *L) { PROFILE
00399     std::string sName = luaL_checkstring(L,1);
00400     std::string sValue = luaL_checkstring(L,2);
00401     cOgreWrapper::GetSingleton().SetConfigOption(sName,sValue);
00402     return 0;
00403 }
00405 static int l_Ogre_GetConfigOption   (lua_State *L) { PROFILE
00406     std::string sName = luaL_checkstring(L,1);
00407     lua_pushstring(L,cOgreWrapper::GetSingleton().GetConfigOption(sName).c_str());
00408     return 1;
00409 }
00410 
00412 static int l_Ogre_ListConfigOptionNames (lua_State *L) { PROFILE
00413     std::string sRenderSysName = luaL_checkstring(L,1);
00414     return MyLuaReturnStringList(L,cOgreWrapper::GetSingleton().ListConfigOptionNames(sRenderSysName));
00415 }
00416 
00418 static int l_Ogre_ListPossibleValuesForConfigOption (lua_State *L) { PROFILE
00419     std::string sRenderSysName      = luaL_checkstring(L,1);
00420     std::string sConfigOptionName   = luaL_checkstring(L,2);
00421     return MyLuaReturnStringList(L,cOgreWrapper::GetSingleton().ListPossibleValuesForConfigOption(sRenderSysName,sConfigOptionName));
00422 }
00423 
00424 
00426 static int                  l_QuaternionToAngleAxis (lua_State *L) { PROFILE
00427     static  Ogre::Radian    angle;
00428     static  Vector3         axis;
00429     Ogre::Quaternion(   luaL_checknumber(L,1),
00430                         luaL_checknumber(L,2),
00431                         luaL_checknumber(L,3),
00432                         luaL_checknumber(L,4)).ToAngleAxis(angle,axis);
00433     lua_pushnumber(L,angle.valueRadians());
00434     lua_pushnumber(L,axis.x);
00435     lua_pushnumber(L,axis.y);
00436     lua_pushnumber(L,axis.z);
00437     return 4;
00438 }
00439 
00441 static int                  l_QuaternionFromAxes (lua_State *L) { PROFILE
00442     Vector3         x(luaL_checknumber(L,1), luaL_checknumber(L,2), luaL_checknumber(L,3));
00443     Vector3         y(luaL_checknumber(L,4), luaL_checknumber(L,5), luaL_checknumber(L,6));
00444     Vector3         z(luaL_checknumber(L,7), luaL_checknumber(L,8), luaL_checknumber(L,9));
00445     
00446     Ogre::Quaternion q( x,y,z );
00447 
00448     lua_pushnumber(L, q.w);
00449     lua_pushnumber(L, q.x);
00450     lua_pushnumber(L, q.y);
00451     lua_pushnumber(L, q.z);
00452     return 4;
00453 }
00454 
00456 static int                  l_QuaternionFromRotationMatrix (lua_State *L) { PROFILE
00457     Real arr[3][3];
00458     
00459     int c = 1;
00460     for(int i = 0;i < 9; ++i){
00461         arr[(i - (i % 3)) / 3][i % 3] = luaL_checknumber(L,c);
00462         ++c;
00463     }
00464     
00465     Ogre::Matrix3 m(arr);
00466     Ogre::Quaternion q( m );
00467 
00468     lua_pushnumber(L, q.w);
00469     lua_pushnumber(L, q.x);
00470     lua_pushnumber(L, q.y);
00471     lua_pushnumber(L, q.z);
00472     return 4;
00473 }
00474 
00476 static int                  l_QuaternionSlerp   (lua_State *L) { PROFILE
00477     static  Ogre::Radian    angle;
00478     static  Vector3         axis;
00479     Ogre::Quaternion q( luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00480     Ogre::Quaternion p( luaL_checknumber(L,5),luaL_checknumber(L,6),luaL_checknumber(L,7),luaL_checknumber(L,8));
00481     float t = luaL_checknumber(L,9);
00482     bool bShortestPath = (lua_gettop(L) >= 10 && !lua_isnil(L,10)) ? (lua_isboolean(L,10) ? lua_toboolean(L,10) : luaL_checkint(L,10)) : true;
00483     Ogre::Quaternion m = Ogre::Quaternion::Slerp(t,p,q,bShortestPath);
00484     lua_pushnumber(L,m.w);
00485     lua_pushnumber(L,m.x);
00486     lua_pushnumber(L,m.y);
00487     lua_pushnumber(L,m.z);
00488     return 4;
00489 }
00490 
00491 
00492 
00494 static int l_OgreAddCompositor (lua_State *L) { PROFILE
00495     Ogre::Viewport* pViewport = cLuaBind<cViewport>::checkudata_alive(L,1)->mpViewport;
00496 //  printf("pViewport=%08x\n",pViewport);
00497     if (pViewport)
00498     {
00499         const char *name = luaL_checkstring(L,2);
00500         Ogre::CompositorManager::getSingleton().addCompositor(pViewport, name);
00501         Ogre::CompositorManager::getSingleton().setCompositorEnabled(pViewport, name, true);
00502     }
00503     else
00504     {
00505         return 0;
00506     }
00507     return 0;
00508 }
00509 
00511 static int l_OgreRemoveCompositor (lua_State *L) { PROFILE
00512     Ogre::Viewport* pViewport = cLuaBind<cViewport>::checkudata_alive(L,1)->mpViewport;
00513     if (pViewport)
00514     {
00515         const char *name = luaL_checkstring(L,2);
00516         Ogre::CompositorManager::getSingleton().setCompositorEnabled(pViewport, name, false);
00517         Ogre::CompositorManager::getSingleton().removeCompositor(pViewport, name);
00518     }
00519     else
00520     {
00521         return 0;
00522     }
00523     return 0;
00524 }
00525 
00527 static int          l_OgreCompositor_AddListener_SSAO   (lua_State *L) { PROFILE
00528     Ogre::Viewport* pViewport = cLuaBind<cViewport>::checkudata_alive(L,1)->mpViewport;
00529     if (pViewport)
00530     {
00531         std::string sCompoName      = cLuaBindDirectQuickWrapHelper::ParamString(L,2);
00532         std::string sCamName        = cLuaBindDirectQuickWrapHelper::ParamString(L,3);
00533         std::string sSceneMgrName   = cLuaBindDirectQuickWrapHelper::ParamStringDefault(L,4,"main");
00534         int iMyPassID               = cLuaBindDirectQuickWrapHelper::ParamIntDefault(L,5,42);
00535         
00536         Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str()); if (!pSceneMgr) return 0;
00537         Ogre::Camera* pCam = pSceneMgr->getCamera(sCamName); if (!pCam) return 0; //mgr.cam
00538         
00539         //~ Ogre::CompositorManager::getSingleton().setCompositorEnabled(pViewport, name, false);
00540         //~ Ogre::CompositorManager::getSingleton().removeCompositor(pViewport, name);
00541         class cMySSAOListener: public Ogre::CompositorInstance::Listener { public:
00542             int iMyPassID;
00543             Ogre::Camera* pCam;
00544             cMySSAOListener (int iMyPassID,Ogre::Camera* pCam) : iMyPassID(iMyPassID), pCam(pCam) {}
00545             
00546             // this callback we will use to modify SSAO parameters
00547             void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
00548             {
00549                 if (pass_id != iMyPassID) // not SSAO, return
00550                     return;
00551 
00552                 // this is the camera you're using
00553                 Ogre::Camera *cam = pCam; // mgr.cam
00554 
00555                 // calculate the far-top-right corner in view-space
00556                 Ogre::Vector3 farCorner = cam->getViewMatrix(true) * cam->getWorldSpaceCorners()[4];
00557 
00558                 // get the pass
00559                 Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
00560 
00561                 // get the vertex shader parameters
00562                 Ogre::GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters();
00563                 // set the camera's far-top-right corner
00564                 if (params->_findNamedConstantDefinition("farCorner"))
00565                     params->setNamedConstant("farCorner", farCorner);
00566 
00567                 // get the fragment shader parameters
00568                 params = pass->getFragmentProgramParameters();
00569                 // set the projection matrix we need
00570                 static const Ogre::Matrix4 CLIP_SPACE_TO_IMAGE_SPACE(
00571                     0.5,    0,    0,  0.5,
00572                     0,   -0.5,    0,  0.5,
00573                     0,      0,    1,    0,
00574                     0,      0,    0,    1);
00575                 if (params->_findNamedConstantDefinition("ptMat"))
00576                     params->setNamedConstant("ptMat", CLIP_SPACE_TO_IMAGE_SPACE * cam->getProjectionMatrixWithRSDepth());
00577                 if (params->_findNamedConstantDefinition("far"))
00578                     params->setNamedConstant("far", cam->getFarClipDistance());
00579             }
00580         };
00581         
00582         
00583         class cMyCompositorHelper { public:
00584             static Ogre::CompositorInstance* GetCompositor (Ogre::Viewport *vp, const Ogre::String &compositor) {
00585                 Ogre::CompositorManager& self = Ogre::CompositorManager::getSingleton();
00586                 Ogre::CompositorChain *chain = self.getCompositorChain(vp);
00587                 Ogre::CompositorChain::InstanceIterator it = chain->getCompositors();
00588                 for(size_t pos=0; pos < chain->getNumCompositors(); ++pos) {
00589                     Ogre::CompositorInstance *instance = chain->getCompositor(pos);
00590                     if(instance->getCompositor()->getName() == compositor) return instance;
00591                 }
00592                 return 0;
00593             }
00594         };
00595         
00596         Ogre::CompositorInstance* p = cMyCompositorHelper::GetCompositor(pViewport,sCompoName);
00597         if (p) p->addListener(new cMySSAOListener(iMyPassID,pCam)); // warning, memleak if done more than once during application life
00598     }
00599     else
00600     {
00601         return 0;
00602     }
00603     return 0;
00604 }
00605 
00606 
00607 
00608 
00609 
00610 
00614 static int l_OgreMemoryUsage (lua_State *L) { PROFILE
00615     std::string part(luaL_checkstring(L,1));
00616     size_t mem = 0;
00617     
00618 #ifdef OGRE_VERSION_SUFFIX
00619     if(part.find("compositor") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::CompositorManager::getSingleton().getMemoryUsage();
00620     if(part.find("font") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::FontManager::getSingleton().getMemoryUsage();
00621     if(part.find("gpuprogram") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::GpuProgramManager::getSingleton().getMemoryUsage();
00622     if(part.find("highlevelgpuprogram") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::HighLevelGpuProgramManager::getSingleton().getMemoryUsage();
00623     if(part.find("material") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::MaterialManager::getSingleton().getMemoryUsage();
00624     if(part.find("mesh") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::MeshManager::getSingleton().getMemoryUsage();
00625     if(part.find("skeleton") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::SkeletonManager::getSingleton().getMemoryUsage();
00626     if(part.find("texture") != std::string::npos || part.find("all") != std::string::npos)mem += Ogre::TextureManager::getSingleton().getMemoryUsage();
00627 #endif
00628     
00629     lua_pushnumber(L, mem);
00630     return 1;
00631 }
00632 
00634 static int l_OgreMeshAvailable (lua_State *L) { PROFILE
00635     const char *name = luaL_checkstring(L,1);
00636     bool ret;
00637     
00638     try {
00639         Ogre::MeshManager::getSingleton().load(name,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00640         ret = true;
00641     } catch (...) {
00642             ret = false;
00643     }
00644     
00645     lua_pushboolean(L, ret);
00646     return 1;
00647 }
00648 
00652 static int l_OgreMaterialNameKnown (lua_State *L) { PROFILE
00653     std::string sMatName = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "";
00654     if (sMatName.size() > 0) {
00655         Ogre::MaterialPtr pMaterial = Ogre::MaterialManager::getSingleton().getByName(sMatName.c_str());
00656         lua_pushboolean(L,!pMaterial.isNull());
00657     } else {
00658         lua_pushboolean(L,false);
00659     }
00660     return 1;
00661 }
00662 
00663 
00664 
00666 static int l_OgreMaterialAvailable (lua_State *L) { PROFILE
00667     assert(0 && "DON'T USE ME, ALWAYS RETURNS TRUE");
00668     // TODO, this code does not work, use l_OgreMaterialNameKnown  above
00669     const char *name = luaL_checkstring(L,1);
00670     bool ret;
00671     
00672     try {
00673         Ogre::MaterialManager::getSingleton().load(name,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00674         ret = true;
00675     } catch (...) {
00676             ret = false;
00677     }
00678     
00679     lua_pushboolean(L, ret);
00680     return 1;
00681 }
00682 
00684 static int l_OgreTextureAvailable (lua_State *L) { PROFILE
00685     const char *name = luaL_checkstring(L,1);
00686     bool ret;
00687     
00688     try {
00689         Ogre::TextureManager::getSingleton().load(name,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00690         ret = true;
00691     } catch (...) {
00692             ret = false;
00693     }
00694     
00695     lua_pushboolean(L, ret);
00696     return 1;
00697 }
00698 
00699 
00700 
00701 static int l_Client_SetSkybox (lua_State *L) { PROFILE
00702     cOgreWrapper::GetSingleton().SetSkybox( (lua_gettop(L) > 0 && !lua_isnil(L,1)) ? luaL_checkstring(L, 1) : 0 , true );
00703     return 0;
00704 }
00705 
00706 static int l_Client_SetFog (lua_State *L) { PROFILE
00707     int i=0;
00708     int numargs=lua_gettop(L);
00709     int iFogMode            = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checkint(L, ++i) : 0;
00710     Ogre::Real r            = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 1;
00711     Ogre::Real g            = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 1;
00712     Ogre::Real b            = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 1;
00713     Ogre::Real a            = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 1;
00714     Ogre::Real expDensity   = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 0.001;
00715     Ogre::Real linearStart  = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 0.0;
00716     Ogre::Real linearEnd    = (numargs > i && !lua_isnil(L,i+1)) ? luaL_checknumber(L, ++i) : 1.0;
00717     /*
00718     void    setFog (FogMode mode=FOG_NONE, const ColourValue &colour=ColourValue::White, 
00719                     Real expDensity=0.001, Real linearStart=0.0, Real linearEnd=1.0)
00720     0=FOG_NONE  No fog. Duh.
00721     1=FOG_EXP   Fog density increases exponentially from the camera (fog = 1/e^(distance * density)).
00722     2=FOG_EXP2  Fog density increases at the square of FOG_EXP, i.e. even quicker (fog = 1/e^(distance * density)^2).
00723     3=FOG_LINEAR    Fog density increases linearly between the start and end distances.
00724     */
00725     Ogre::FogMode      myFogMode = Ogre::FOG_NONE;
00726     if (iFogMode == 1) myFogMode = Ogre::FOG_EXP;
00727     if (iFogMode == 2) myFogMode = Ogre::FOG_EXP2;
00728     if (iFogMode == 3) myFogMode = Ogre::FOG_LINEAR;
00729     cOgreWrapper::GetSingleton().mSceneMgr->setFog(myFogMode,Ogre::ColourValue(r,g,b,a),expDensity,linearStart,linearEnd);
00730     return 0;
00731 }
00732 
00733 static int l_Client_RenderOneFrame (lua_State *L) { PROFILE
00734     cGame::GetSingleton().RenderOneFrame();
00735     return 0;
00736 }
00737 
00738 
00740 static int l_Client_SetShadowListener (lua_State *L) { PROFILE
00741     std::string sSceneMgrName   = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "main";
00742     
00743     Ogre::Real fNearClip = cLuaBindDirectQuickWrapHelper::ParamNumberDefault(L,2,0.01);
00744     
00745     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00746     
00747     class cMyShadowListener: public Ogre::SceneManager::Listener { public:
00748         Ogre::Real fNearClip;
00749         
00750         cMyShadowListener(Ogre::Real fNearClip) : fNearClip(fNearClip) {}
00751             
00752         // this is a callback we'll be using to set up our shadow camera
00753         void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam, size_t)
00754         {
00755             // basically, here we do some forceful camera near/far clip attenuation
00756             // yeah.  simplistic, but it works nicely.  this is the function I was talking
00757             // about you ignoring above in the Mgr declaration.
00758             float range = light->getAttenuationRange();
00759             cam->setNearClipDistance(fNearClip);
00760             cam->setFarClipDistance(range);
00761             // we just use a small near clip so that the light doesn't "miss" anything
00762             // that can shadow stuff.  and the far clip is equal to the lights' range.
00763             // (thus, if the light only covers 15 units of objects, it can only
00764             // shadow 15 units - the rest of it should be attenuated away, and not rendered)
00765         }
00766 
00767         // these are pure virtual but we don't need them...  so just make them empty
00768         // otherwise we get "cannot declare of type Mgr due to missing abstract
00769         // functions" and so on
00770         void shadowTexturesUpdated(size_t) {}
00771         void shadowTextureReceiverPreViewProj(Ogre::Light*, Ogre::Frustum*) {}
00772         void preFindVisibleObjects(Ogre::SceneManager*, Ogre::SceneManager::IlluminationRenderStage, Ogre::Viewport*) {}
00773         void postFindVisibleObjects(Ogre::SceneManager*, Ogre::SceneManager::IlluminationRenderStage, Ogre::Viewport*) {}
00774     };
00775 
00776     if (pSceneMgr) pSceneMgr->addListener(new cMyShadowListener(fNearClip)); // warning, memleak if done more than once during application life
00777 
00778     return 0;
00779 }
00780 
00782 static int l_Client_SetAmbientLight (lua_State *L) { PROFILE
00783     std::string sSceneMgrName   = (lua_gettop(L) >= 5 && !lua_isnil(L,5)) ? luaL_checkstring(L,5) : "main";
00784     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00785     if (pSceneMgr) pSceneMgr->setAmbientLight(Ogre::ColourValue(luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4)));
00786     return 0;
00787 }
00788 
00790 static int l_Client_ClearLights (lua_State *L) { PROFILE
00791     std::string sSceneMgrName   = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "main";
00792     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00793     if (pSceneMgr) pSceneMgr->destroyAllLights();
00794     return 0;
00795 }
00796 
00798 static int l_Client_AddPointLight (lua_State *L) { PROFILE
00799     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00800     if (!pSceneMgr) return 0;
00801     std::string sName = cOgreWrapper::GetSingleton().GetUniqueName();
00802     Ogre::Light* pLight = pSceneMgr->createLight( sName );
00803     pLight->setType( Ogre::Light::LT_POINT );
00804     pLight->setPosition(luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3));
00805     if (lua_gettop(L) >= 4) pLight->setDiffuseColour(luaL_checknumber(L,4),luaL_checknumber(L,5),luaL_checknumber(L,6));
00806     if (lua_gettop(L) >= 7) pLight->setSpecularColour(luaL_checknumber(L,7),luaL_checknumber(L,8),luaL_checknumber(L,9));
00807     if (lua_gettop(L) >= 10) pLight->setAttenuation(luaL_checknumber(L,10),luaL_checknumber(L,11),luaL_checknumber(L,12),luaL_checknumber(L,13));
00808     //pLight->setCastShadows(false);        //lights shouldn cast shadows !! dont look good and destroys normal shadows
00809     lua_pushstring(L,sName.c_str());
00810     return 1;
00811 }
00812 
00814 static int l_Client_AttachLight (lua_State *L) { PROFILE
00815     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager("main");
00816     if (!pSceneMgr) return 0;
00817 
00818     const char *name = luaL_checkstring(L,1);
00819     cGfx3D *p = cLuaBind<cGfx3D>::checkudata_alive(L,2);
00820 
00821     LUGRE_TRY
00822 
00823     Ogre::Light* pLight = pSceneMgr->getLight( name );
00824     
00825     if(pLight && p){
00826         if (p->mpSceneNode) p->mpSceneNode->attachObject(pLight);
00827     }
00828     
00829     LUGRE_CATCH
00830     
00831     return 0;
00832 }
00833 
00834 
00836 static int l_Client_DetatchLight (lua_State *L) { PROFILE
00837     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager("main");
00838     if (!pSceneMgr) return 0;
00839 
00840     const char *name = luaL_checkstring(L,1);
00841 
00842     LUGRE_TRY
00843 
00844     Ogre::Light* pLight = pSceneMgr->getLight( name );
00845     
00846     if(pLight){
00847         // OGRE16 only : pLight->detatchFromParent();
00848         Ogre::SceneNode *n = pLight->getParentSceneNode();
00849         if(n){
00850             n->detachObject(pLight->getName());
00851         }
00852     }
00853     
00854     LUGRE_CATCH
00855     
00856     return 0;
00857 }
00858 
00859 
00861 static int l_Client_AddDirectionalLight (lua_State *L) { PROFILE
00862     std::string sSceneMgrName   = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? luaL_checkstring(L,4) : "main";
00863     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneMgrName.c_str());
00864     if (!pSceneMgr) return 0;
00865     std::string sName = cOgreWrapper::GetSingleton().GetUniqueName();
00866     Ogre::Light* pLight = pSceneMgr->createLight( sName );
00867     pLight->setType( Ogre::Light::LT_DIRECTIONAL );
00868     pLight->setDirection(luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3));
00869     lua_pushstring(L,sName.c_str());
00870     return 1;
00871 }
00872 
00874 static int l_Client_SetLightPosition (lua_State *L) { PROFILE
00875     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00876     const char *name = luaL_checkstring(L,1);
00877     
00878     LUGRE_TRY
00879     
00880     Ogre::Light* pLight = pSceneMgr->getLight( name );
00881     
00882     if(pLight){
00883         pLight->setPosition(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00884     }
00885     
00886     LUGRE_CATCH
00887     
00888     return 0;
00889 }
00890 
00892 static int l_Client_SetLightDirection (lua_State *L) { PROFILE
00893     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00894     const char *name = luaL_checkstring(L,1);
00895     
00896     LUGRE_TRY
00897     
00898     Ogre::Light* pLight = pSceneMgr->getLight( name );
00899     
00900     if(pLight){
00901         pLight->setDirection(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00902     }
00903     
00904     LUGRE_CATCH
00905     
00906     return 0;
00907 }
00908 
00910 static int l_Client_RemoveLight (lua_State *L) { PROFILE
00911     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00912     const char *name = luaL_checkstring(L,1);
00913     pSceneMgr->destroyLight( name );
00914     return 0;
00915 }
00916 
00917 static int l_Client_DeleteLight (lua_State *L) { PROFILE
00918     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00919     if (pSceneMgr) pSceneMgr->destroyLight(luaL_checkstring(L,1));
00920     return 0;
00921 }
00922 
00924 static int l_Client_SetLightSpecularColor (lua_State *L) { PROFILE
00925     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00926     const char *name = luaL_checkstring(L,1);
00927     
00928     LUGRE_TRY
00929     
00930     Ogre::Light* pLight = pSceneMgr->getLight( name );
00931     
00932     if(pLight){
00933         pLight->setSpecularColour(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00934     }
00935     
00936     LUGRE_CATCH
00937     
00938     return 0;
00939 }
00940 
00941 
00943 static int l_Client_SetLightPowerScale (lua_State *L) { PROFILE
00944     LUGRE_TRY
00945     
00946     Ogre::Light* pLight = cOgreWrapper::GetSingleton().mSceneMgr->getLight( luaL_checkstring(L,1) );
00947     if(pLight) pLight->setPowerScale(luaL_checknumber(L,2));
00948     
00949     LUGRE_CATCH
00950     
00951     return 0;
00952 }
00953 
00955 static int l_Client_SetLightDiffuseColor (lua_State *L) { PROFILE
00956     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00957     const char *name = luaL_checkstring(L,1);
00958     
00959     LUGRE_TRY
00960     
00961     Ogre::Light* pLight = pSceneMgr->getLight( name );
00962     
00963     if(pLight){
00964         pLight->setDiffuseColour(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4));
00965     }
00966     
00967     LUGRE_CATCH
00968     
00969     return 0;
00970 }
00971 
00973 static int l_Client_SetLightAttenuation (lua_State *L) { PROFILE
00974     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
00975     const char *name = luaL_checkstring(L,1);
00976     
00977     LUGRE_TRY
00978     
00979     Ogre::Light* pLight = pSceneMgr->getLight( name );
00980     
00981     if(pLight){
00982         pLight->setAttenuation(luaL_checknumber(L,2),luaL_checknumber(L,3),luaL_checknumber(L,4),luaL_checknumber(L,5));
00983     }
00984     
00985     LUGRE_CATCH
00986     
00987     return 0;
00988 }
00989 
00991 static int            l_Client_TakeGridScreenshot (lua_State *L) { PROFILE
00992     std::string sPrefix = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "screenshots/";
00993     std::string filename = strprintf( "%shighres_%d",sPrefix.c_str(), cShell::GetTicks() );
00994     std::string ext = ".jpg";
00995     cOgreWrapper::GetSingleton().TakeGridScreenshot(3,filename,ext,true);
00996     return 0;
00997 }
00998 
01000 static int        l_Client_TakeScreenshot (lua_State *L) { PROFILE
01001     std::string sPrefix = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? luaL_checkstring(L,1) : "screenshots/";
01002     cOgreWrapper::GetSingleton().TakeScreenshot(sPrefix.c_str());
01003     return 0;
01004 }
01005 
01007 static int l_Client_ShowOgreConfig (lua_State *L) { PROFILE
01008     bool bIsFullscreen = cOgreWrapper::GetSingleton().mWindow->isFullScreen();
01009     printf("Client_ShowOgreConfig fullscreen=%d\n",bIsFullscreen);
01010     bIsFullscreen = true; // detection fails in linux ?
01011     if (bIsFullscreen) {
01012         // hide window to make config window visible in fullscreen mode, evil hack since this is not supported by ogre
01013         OgreForceCloseFullscreen();
01014     }
01015     lua_pushboolean(L,cOgreWrapper::GetSingleton().mRoot->showConfigDialog());
01016     if (bIsFullscreen) cShell::mbAlive = false;
01017     // the application shoudl terminate after this
01018     // terminates the game if changes were made
01019     return 1;
01020 }
01021 
01024 static int l_TriangleRayPick (lua_State *L) { PROFILE
01025     // don't use ++i or something here, the compiler might mix the order
01026     Ogre::Vector3   a(      luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3));
01027     Ogre::Vector3   b(      luaL_checknumber(L,4),luaL_checknumber(L,5),luaL_checknumber(L,6));
01028     Ogre::Vector3   c(      luaL_checknumber(L,7),luaL_checknumber(L,8),luaL_checknumber(L,9));
01029     Ogre::Vector3   vRayPos(luaL_checknumber(L,10),luaL_checknumber(L,11),luaL_checknumber(L,12));
01030     Ogre::Vector3   vRayDir(luaL_checknumber(L,13),luaL_checknumber(L,14),luaL_checknumber(L,15));
01031     float myHitDist;
01032     if (!IntersectRayTriangle(vRayPos,vRayDir,a,b,c,&myHitDist)) return 0;
01033     lua_pushnumber(L,myHitDist);
01034     return 1;
01035 }
01036 
01037 
01041 static int l_TriangleRayPickEx (lua_State *L) { PROFILE
01042     // don't use ++i or something here, the compiler might mix the order
01043     Ogre::Vector3   a(      luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3));
01044     Ogre::Vector3   b(      luaL_checknumber(L,4),luaL_checknumber(L,5),luaL_checknumber(L,6));
01045     Ogre::Vector3   c(      luaL_checknumber(L,7),luaL_checknumber(L,8),luaL_checknumber(L,9));
01046     Ogre::Vector3   vRayPos(luaL_checknumber(L,10),luaL_checknumber(L,11),luaL_checknumber(L,12));
01047     Ogre::Vector3   vRayDir(luaL_checknumber(L,13),luaL_checknumber(L,14),luaL_checknumber(L,15));
01048     float myHitDist;
01049     float pfABC[3];
01050     if (!IntersectRayTriangle(vRayPos,vRayDir,a,b,c,&myHitDist,pfABC)) return 0;
01051     lua_pushnumber(L,myHitDist);
01052     lua_pushnumber(L,pfABC[0]);
01053     lua_pushnumber(L,pfABC[1]);
01054     lua_pushnumber(L,pfABC[2]);
01055     return 4;
01056 }
01057 
01058 
01060 static int l_SphereRayPick (lua_State *L) { PROFILE
01061     // don't use ++i or something here, the compiler might mix the order
01062     Ogre::Vector3   vSpherePos( luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3));
01063     float           fSphereRad = luaL_checknumber(L,4);
01064     Ogre::Vector3   vRayPos(    luaL_checknumber(L,5),luaL_checknumber(L,6),luaL_checknumber(L,7));
01065     Ogre::Vector3   vRayDir(    luaL_checknumber(L,8),luaL_checknumber(L,9),luaL_checknumber(L,10));
01066     
01067     std::pair<bool, Real> hit = Ogre::Ray(vRayPos,vRayDir).intersects(Ogre::Sphere(vSpherePos,fSphereRad));
01068     if (!hit.first) return 0;
01069     lua_pushnumber(L,hit.second);
01070     return 1;
01071 }
01072 
01074 static int          l_PlaneRayPick (lua_State *L) { PROFILE
01075     // don't use ++i or something here, the compiler might mix the order
01076     Ogre::Vector3   vPlanePos(      luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3));
01077     Ogre::Vector3   vPlaneNormal(   luaL_checknumber(L,4),luaL_checknumber(L,5),luaL_checknumber(L,6));
01078     Ogre::Vector3   vRayPos(        luaL_checknumber(L,7),luaL_checknumber(L,8),luaL_checknumber(L,9));
01079     Ogre::Vector3   vRayDir(        luaL_checknumber(L,10),luaL_checknumber(L,11),luaL_checknumber(L,12));
01080     
01081     /*printf("c++:PlaneRayPick(%0.2f,%0.2f,%0.2f, %0.2f,%0.2f,%0.2f, %0.2f,%0.2f,%0.2f, %0.2f,%0.2f,%0.2f)\n",
01082         vPlanePos.x,vPlanePos.y,vPlanePos.z,
01083         vPlaneNormal.x,vPlaneNormal.y,vPlaneNormal.z,
01084         vRayPos.x,vRayPos.y,vRayPos.z,
01085         vRayDir.x,vRayDir.y,vRayDir.z
01086         );*/
01087     std::pair<bool, Real> hit = Ogre::Ray(vRayPos,vRayDir).intersects(Ogre::Plane(vPlaneNormal,vPlanePos));
01088     if (!hit.first) return 0;
01089     lua_pushnumber(L,hit.second);
01090     return 1;
01091 }
01092 
01093 
01094 static int l_UnloadMeshName (lua_State *L) { PROFILE
01095     const char* szMeshName = luaL_checkstring(L,1);
01096     Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(szMeshName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
01097     if (mesh.isNull()) return 0;
01098     mesh->unload();
01099     UnloadMeshShape(szMeshName);
01100     //Ogre::MeshManager::getSingleton().unload(luaL_checkstring(L,1));
01101     return 0;
01102 }
01103 
01104 static int l_UnloadMaterialName (lua_State *L) { PROFILE
01105     const char* szName = luaL_checkstring(L,1);
01106     Ogre::MaterialPtr p = Ogre::MaterialManager::getSingleton().load(szName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
01107     if (p.isNull()) return 0;
01108     p->unload();
01109     return 0;
01110 }
01111 
01112 static int l_UnloadTextureName (lua_State *L) { PROFILE
01113     const char* szName = luaL_checkstring(L,1);
01114     Ogre::TexturePtr p = Ogre::TextureManager::getSingleton().load(szName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
01115     if (p.isNull()) return 0;
01116     p->unload();
01117     return 0;
01118 }
01119 
01120 static int l_CountMeshTriangles (lua_State *L) { PROFILE
01121     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01122                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01123     int res = 0;
01124     for (int i=0;i<pMesh->getNumSubMeshes();++i) {
01125         Ogre::SubMesh *pSub = pMesh->getSubMesh(i);
01126         if (pSub && pSub->indexData) res += pSub->indexData->indexCount / 3;
01127     }
01128     lua_pushnumber(L,res);
01129     return 1;
01130 }
01131 
01133 static int l_MeshGetBounds (lua_State *L) { PROFILE
01134     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01135                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01136     if (pMesh.isNull()) return 0;
01137     const Ogre::AxisAlignedBox& mybounds = pMesh->getBounds();
01138     lua_pushnumber(L,mybounds.getMinimum().x);
01139     lua_pushnumber(L,mybounds.getMinimum().y);
01140     lua_pushnumber(L,mybounds.getMinimum().z);
01141     lua_pushnumber(L,mybounds.getMaximum().x);
01142     lua_pushnumber(L,mybounds.getMaximum().y);
01143     lua_pushnumber(L,mybounds.getMaximum().z);
01144     return 6;
01145 }
01146 
01148 static int l_MeshSetBounds (lua_State *L) { PROFILE
01149     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01150                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01151     if (!pMesh.isNull()) {
01152         pMesh->_setBounds(Ogre::AxisAlignedBox( mymin(luaL_checknumber(L,2),luaL_checknumber(L,5)),
01153                                                 mymin(luaL_checknumber(L,3),luaL_checknumber(L,6)),
01154                                                 mymin(luaL_checknumber(L,4),luaL_checknumber(L,7)),
01155                                                 mymax(luaL_checknumber(L,2),luaL_checknumber(L,5)),
01156                                                 mymax(luaL_checknumber(L,3),luaL_checknumber(L,6)),
01157                                                 mymax(luaL_checknumber(L,4),luaL_checknumber(L,7))
01158                                                 ));
01159     }
01160     return 0;
01161 }
01162 
01164 static int l_MeshGetBoundRad (lua_State *L) { PROFILE
01165     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01166                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01167     if (pMesh.isNull()) return 0;
01168     lua_pushnumber(L,pMesh->getBoundingSphereRadius());
01169     return 1;
01170 }
01171 
01173 static int l_MeshSetBoundRad (lua_State *L) { PROFILE
01174     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01175                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01176     if (!pMesh.isNull()) pMesh->_setBoundingSphereRadius(luaL_checknumber(L,2));
01177     return 0;
01178 }
01179 
01180 
01181 
01183 static int l_ExportMesh     (lua_State *L) { PROFILE 
01184     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01185                     // autodetect group location
01186                     //Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
01187                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01188     Ogre::MeshSerializer myExporter;
01189     //Ogre::Mesh* pMesh = pEntity->getMesh().get();
01190     myExporter.exportMesh(pMesh.get(),luaL_checkstring(L,2)); 
01191     return 0;
01192 }
01193 
01195 void    TransformMesh   (Ogre::Mesh* pMesh,const Ogre::Vector3& vMove,const Ogre::Vector3& vScale,const Ogre::Quaternion& qRot);
01196 
01199 static int l_TransformMesh      (lua_State *L) { PROFILE 
01200     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01201                     // autodetect group location
01202                     //Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
01203                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01204     
01205     Ogre::Vector3 vMove(    luaL_checknumber(L,2),
01206                             luaL_checknumber(L,3),
01207                             luaL_checknumber(L,4));
01208     Ogre::Vector3 vScale(   luaL_checknumber(L,5),
01209                             luaL_checknumber(L,6),
01210                             luaL_checknumber(L,7));
01211     Ogre::Quaternion qRot(  luaL_checknumber(L,8),
01212                             luaL_checknumber(L,9),
01213                             luaL_checknumber(L,10),
01214                             luaL_checknumber(L,11));
01215     TransformMesh(pMesh.get(),vMove,vScale,qRot);
01216     
01217     //Ogre::MeshSerializer myExporter;
01218     //Ogre::Mesh* pMesh = pEntity->getMesh().get();   pMesh.get()
01219     return 0;
01220 }
01221 
01223 void    MeshReadOutExactBounds  (Ogre::Mesh* pMesh,Ogre::Vector3& vMin,Ogre::Vector3& vMax);
01224 
01226 static int                        l_MeshReadOutExactBounds  (lua_State *L) { PROFILE 
01227     Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().load(luaL_checkstring(L,1),
01228                     Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
01229     
01230     Ogre::Vector3 vMin;
01231     Ogre::Vector3 vMax;
01232     MeshReadOutExactBounds(pMesh.get(),vMin,vMax);
01233     lua_pushnumber(L,vMin.x);
01234     lua_pushnumber(L,vMin.y);
01235     lua_pushnumber(L,vMin.z);
01236     lua_pushnumber(L,vMax.x);
01237     lua_pushnumber(L,vMax.y);
01238     lua_pushnumber(L,vMax.z);
01239     return 6;
01240 }
01241 
01242 
01244 static int l_GetScreenRay       (lua_State *L) { PROFILE 
01245     cOgreWrapper& ogrewrapper = cOgreWrapper::GetSingleton();
01246     Ogre::Ray myray(ogrewrapper.mCamera->getCameraToViewportRay(luaL_checknumber(L,1),luaL_checknumber(L,2)));
01247     lua_pushnumber(L,myray.getOrigin().x);
01248     lua_pushnumber(L,myray.getOrigin().y);
01249     lua_pushnumber(L,myray.getOrigin().z);
01250     lua_pushnumber(L,myray.getDirection().x);
01251     lua_pushnumber(L,myray.getDirection().y);
01252     lua_pushnumber(L,myray.getDirection().z);
01253     return 6;
01254 }
01255 
01257 static int      l_GetMaxZ       (lua_State *L) { PROFILE 
01258     lua_pushnumber(L,Ogre::Root::getSingleton().getRenderSystem()->getMaximumDepthInputValue());
01259     return 1;
01260 }
01261 
01262 
01264 static int                          l_ProjectPos    (lua_State *L) { PROFILE 
01265     bool        bIsInFront;
01266     Ogre::Real  fX,fY;
01267     bIsInFront = cOgreWrapper::GetSingleton().ProjectPos(
01268         Ogre::Vector3(luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3)),fX,fY);
01269     lua_pushboolean(L,bIsInFront);
01270     lua_pushnumber(L,fX);
01271     lua_pushnumber(L,fY);
01272     return 3;
01273 }
01274 
01276 static int                              l_ProjectSizeAndPos (lua_State *L) { PROFILE 
01277     bool        bIsInFront;
01278     Ogre::Real  fX,fY,fCX,fCY;
01279     bIsInFront = cOgreWrapper::GetSingleton().ProjectSizeAndPos(
01280         Ogre::Vector3(luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3)),fX,fY,luaL_checknumber(L,4),fCX,fCY);
01281     lua_pushboolean(L,bIsInFront);
01282     lua_pushnumber(L,fX);
01283     lua_pushnumber(L,fY);
01284     lua_pushnumber(L,fCX);
01285     lua_pushnumber(L,fCY);
01286     return 5;
01287 }
01288 
01290 static int                          l_ProjectSizeAndPosEx   (lua_State *L) { PROFILE 
01291     Ogre::Vector3 s;
01292     Ogre::Vector3 p = cOgreWrapper::GetSingleton().ProjectSizeAndPosEx(
01293         Ogre::Vector3(luaL_checknumber(L,1),luaL_checknumber(L,2),luaL_checknumber(L,3)),luaL_checknumber(L,4),s);
01294     lua_pushnumber(L,p.x);
01295     lua_pushnumber(L,p.y);
01296     lua_pushnumber(L,p.z);
01297     lua_pushnumber(L,s.x);
01298     lua_pushnumber(L,s.y);
01299     lua_pushnumber(L,s.z);
01300     return 6;
01301 }
01302 
01303 
01305 static int          l_OgreWrapperSetCustomSceneMgrType  (lua_State *L) { PROFILE
01306     OgreWrapperSetCustomSceneMgrType(luaL_checkstring(L,1));    
01307     return 0;
01308 }
01309 
01311 static int          l_OgreWrapperSetEnableUnicode   (lua_State *L) { PROFILE
01312     OgreWrapperSetEnableUnicode(luaL_checkbool(L,1));   
01313     return 0;
01314 }
01315 
01316 
01318 static int          l_OgreSceneMgr_SetWorldGeometry     (lua_State *L) { PROFILE
01319     std::string sSceneManagerName   = luaL_checkstring(L,1);
01320     std::string sData               = luaL_checkstring(L,2);
01321     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneManagerName.c_str());
01322     if (pSceneMgr) pSceneMgr->setWorldGeometry(sData.c_str());
01323     return 0;
01324 }
01325 
01328 static int          l_OgreSceneMgr_GetType  (lua_State *L) { PROFILE
01329     std::string sSceneManagerName   = luaL_checkstring(L,1);
01330     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneManagerName.c_str());
01331     if (!pSceneMgr) return 0;
01332     lua_pushstring(L,pSceneMgr->getTypeName().c_str());
01333     return 1;
01334 }
01335 
01336 
01337 /*
01338 not usable due to hard-to-find headers (i don't want to copy them due to versions) and linker error
01339 undefined reference to `Ogre::TerrainSceneManager::getHeightAt(float, float)'
01343 static int          l_OgreSceneMgr_TerrainGetHeightAt   (lua_State *L) { PROFILE
01344     std::string sSceneManagerName   = luaL_checkstring(L,1);
01345     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneManagerName.c_str());
01346     if (!pSceneMgr) return 0;
01347     float x = luaL_checknumber(L,2);
01348     float z = luaL_checknumber(L,3);
01349     lua_pushnumber(L,reinterpret_cast<Ogre::TerrainSceneManager*>(pSceneMgr)->getHeightAt(x,z)); 
01350     return 1;
01351 }
01352 */
01353 
01354 
01358 static int          l_OgreSceneMgr_RaySceneQuery    (lua_State *L) { PROFILE
01359     std::string sSceneManagerName   = luaL_checkstring(L,1);
01360     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().GetSceneManager(sSceneManagerName.c_str());
01361     if (!pSceneMgr) return 0;
01362     Ogre::Vector3 vRayPos( luaL_checknumber(L,2), luaL_checknumber(L,3), luaL_checknumber(L,4) );
01363     Ogre::Vector3 vRayDir( luaL_checknumber(L,5), luaL_checknumber(L,6), luaL_checknumber(L,7) );
01364     Ogre::RaySceneQuery* raySceneQuery = pSceneMgr->createRayQuery(Ogre::Ray(vRayPos,vRayDir));
01365     //~ raySceneQuery->setRay(updateRay);
01366     Ogre::RaySceneQueryResult& qryResult = raySceneQuery->execute();
01367     Ogre::RaySceneQueryResult::iterator i = qryResult.begin();
01368     while (i != qryResult.end()) {
01369         if (i->worldFragment)
01370         {
01371             lua_pushnumber(L,i->worldFragment->singleIntersection.x); 
01372             lua_pushnumber(L,i->worldFragment->singleIntersection.y); 
01373             lua_pushnumber(L,i->worldFragment->singleIntersection.z); 
01374             lua_pushnumber(L,i->distance); 
01375             pSceneMgr->destroyQuery(raySceneQuery);
01376             return 4;
01377         }
01378         ++i;
01379     }
01380     pSceneMgr->destroyQuery(raySceneQuery);
01381     return 0;
01382 }
01383 
01385 static int l_CreateSceneManager     (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01386     std::string sSceneManagerName   = luaL_checkstring(L,1);
01387     std::string sSceneMgrType       = (lua_gettop(L) >= 2 && !lua_isnil(L,1)) ? (luaL_checkstring(L,2)) : "";
01388     // sSceneMgrType
01389     if (sSceneMgrType.size() > 0) {
01390         cOgreWrapper::GetSingleton().mRoot->createSceneManager(sSceneMgrType.c_str(),sSceneManagerName.c_str());
01391     } else {
01392         cOgreWrapper::GetSingleton().mRoot->createSceneManager(Ogre::ST_GENERIC,sSceneManagerName.c_str());
01393     }
01394     return 0;
01395 }
01396 
01398 static int l_OgreMeshTextures   (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01399     Ogre::MeshSerializer* meshSerializer = new Ogre::MeshSerializer();
01400     const char *szMeshName = luaL_checkstring(L,1);
01401 
01402     //printf("open file: %s\n",szMeshName);
01403     // model file
01404     std::ifstream ifs;
01405     ifs.open(szMeshName, std::ios_base::in | std::ios_base::binary);
01406     Ogre::DataStreamPtr stream(new Ogre::FileStreamDataStream(&ifs, false));
01407 
01408     if(ifs.is_open()){
01409         //printf("create tmp mesh\n");
01410         // create tmp mesh import resource
01411         Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().create("l_OgreMeshTextureMissing_conversion", 
01412             Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
01413 
01414         //printf("import\n");
01415         // import
01416         meshSerializer->importMesh(stream, mesh.getPointer());
01417         
01418         if(!mesh.isNull()){
01419             // iterator over submeshes
01420             Ogre::Mesh::SubMeshIterator it = mesh->getSubMeshIterator();
01421             int i = 1;
01422             lua_newtable(L);
01423             while(it.hasMoreElements()){
01424                 Ogre::SubMesh *submesh = it.getNext();
01425                 std::string tex = submesh->getMaterialName();
01426                 //printf("material found: %s\n",tex.c_str());
01427                 lua_pushstring(L,tex.c_str()); lua_rawseti(L,-2,i);
01428                 ++i;
01429             }
01430         }
01431         
01432         // remove all stuff
01433         Ogre::MeshManager::getSingleton().remove("l_OgreMeshTextureMissing_conversion");
01434         
01435         ifs.close();
01436     } else {
01437         printf("ERROR can't open file: %s\n",szMeshName);
01438     }
01439 
01440     delete meshSerializer;
01441         
01442     return 1;
01443 }
01444 
01445 static int l_OgreLoadedMeshTextures (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01446     std::string sMeshName = luaL_checkstring(L,1);
01447     const char *meshname = sMeshName.c_str();
01448 
01449     if(meshname){
01450         try {
01451                 // data seem ok, so read out the mesh
01452                 Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().load(meshname,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
01453                 if (mesh.isNull()) return 0;
01454     
01455                 Ogre::Mesh::SubMeshIterator sit = mesh->getSubMeshIterator();
01456                 int i = 1;
01457                 lua_newtable(L);
01458                 while(sit.hasMoreElements()){
01459                     Ogre::SubMesh *submesh = sit.getNext();
01460                     std::string tex = submesh->getMaterialName();
01461                     //printf("material found: %s\n",tex.c_str());
01462                     lua_pushstring(L,tex.c_str()); lua_rawseti(L,-2,i);
01463                     ++i;
01464                 }
01465             } catch (Ogre::FileNotFoundException e){
01466                 printf("ERROR file not found, so HueMesh(%s) canceled\n",meshname);
01467             }
01468     }
01469     return 1;
01470 }
01471 
01473 static int l_OgreShadowTechnique    (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01474     const char *tech = luaL_checkstring(L,1);
01475     Ogre::SceneManager *p = cOgreWrapper::GetSingleton().mSceneMgr;
01476     
01477     if(p){
01478         if(strcmp(tech,"stencil_modulative") == 0)p->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE);
01479         else if(strcmp(tech,"stencil_additive") == 0)p->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
01480         else if(strcmp(tech,"texture_modulative") == 0)p->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE);
01481         else if(strcmp(tech,"texture_additive") == 0)p->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE);
01482         else if(strcmp(tech,"texture_additive_integrated") == 0)p->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
01483         else if(strcmp(tech,"texture_modulative_integrated") == 0)p->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
01484         else p->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
01485     }
01486         
01487     return 0;
01488 }
01489 
01491 static int              l_OgreSetShadowTextureSize  (lua_State *L) { PROFILE
01492     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureSize(luaL_checkint(L,1));
01493     return 0;
01494 }
01495 
01496 
01497 
01499 static int              l_OgreSetShadowFarDistance  (lua_State *L) { PROFILE
01500     cOgreWrapper::GetSingleton().mSceneMgr->setShadowFarDistance(luaL_checknumber(L,1));
01501     return 0;
01502 }
01503 
01505 static int              l_OgreSetShadowDirLightTextureOffset    (lua_State *L) { PROFILE
01506     cOgreWrapper::GetSingleton().mSceneMgr->setShadowDirLightTextureOffset(luaL_checknumber(L,1));
01507     return 0;
01508 }
01509 
01511 static int              l_OgreSetShadowTextureFadeStart (lua_State *L) { PROFILE
01512     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureFadeStart(luaL_checknumber(L,1));
01513     return 0;
01514 }
01515 
01517 static int              l_OgreSetShadowTextureFadeEnd   (lua_State *L) { PROFILE
01518     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureFadeEnd(luaL_checknumber(L,1));
01519     return 0;
01520 }
01521 
01523 static int              l_OgreSetShadowTexturePixelFormat   (lua_State *L) { PROFILE
01524     Ogre::PixelFormat pf = (lua_gettop(L) >= 2 && !lua_isnil(L,1)) ? ((Ogre::PixelFormat)luaL_checkint(L,1)) : Ogre::PF_FLOAT16_R;
01525     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTexturePixelFormat(pf);
01526     return 0;
01527 }
01528 
01530 static int              l_OgreSetShadowCasterRenderBackFaces    (lua_State *L) { PROFILE
01531     cOgreWrapper::GetSingleton().mSceneMgr->setShadowCasterRenderBackFaces(lua_toboolean(L,1));
01532     return 0;
01533 }
01534 
01536 static int              l_OgrePixelFormatList   (lua_State *L) { PROFILE
01537     lua_newtable(L);
01538     
01539     #define OgrePixelFormatList_REGISTER(pf) lua_pushstring(L,#pf); lua_pushnumber(L,(int)Ogre::pf); lua_rawset(L,-3); // k,v,set(L,tableindex)
01540     OgrePixelFormatList_REGISTER(PF_UNKNOWN)        //  Unknown pixel format.
01541     OgrePixelFormatList_REGISTER(PF_L8)             //      8-bit pixel format, all bits luminace.
01542     OgrePixelFormatList_REGISTER(PF_BYTE_L)         //
01543     OgrePixelFormatList_REGISTER(PF_L16)            //      16-bit pixel format, all bits luminace.
01544     OgrePixelFormatList_REGISTER(PF_SHORT_L)        //
01545     OgrePixelFormatList_REGISTER(PF_A8)             //      8-bit pixel format, all bits alpha.
01546     OgrePixelFormatList_REGISTER(PF_BYTE_A)         //
01547     OgrePixelFormatList_REGISTER(PF_A4L4)           //  8-bit pixel format, 4 bits alpha, 4 bits luminace.
01548     OgrePixelFormatList_REGISTER(PF_BYTE_LA)        //  2 byte pixel format, 1 byte luminance, 1 byte alpha
01549     OgrePixelFormatList_REGISTER(PF_R5G6B5)         //  16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
01550     OgrePixelFormatList_REGISTER(PF_B5G6R5)         //  16-bit pixel format, 5 bits red, 6 bits green, 5 bits blue.
01551     OgrePixelFormatList_REGISTER(PF_R3G3B2)         //  8-bit pixel format, 2 bits blue, 3 bits green, 3 bits red.
01552     OgrePixelFormatList_REGISTER(PF_A4R4G4B4)       //  16-bit pixel format, 4 bits for alpha, red, green and blue.
01553     OgrePixelFormatList_REGISTER(PF_A1R5G5B5)       //  16-bit pixel format, 5 bits for blue, green, red and 1 for alpha.
01554     OgrePixelFormatList_REGISTER(PF_R8G8B8)         //  24-bit pixel format, 8 bits for red, green and blue.
01555     OgrePixelFormatList_REGISTER(PF_B8G8R8)         //  24-bit pixel format, 8 bits for blue, green and red.
01556     OgrePixelFormatList_REGISTER(PF_A8R8G8B8)       //  32-bit pixel format, 8 bits for alpha, red, green and blue.
01557     OgrePixelFormatList_REGISTER(PF_A8B8G8R8)       //  32-bit pixel format, 8 bits for blue, green, red and alpha.
01558     OgrePixelFormatList_REGISTER(PF_B8G8R8A8)       //  32-bit pixel format, 8 bits for blue, green, red and alpha.
01559     OgrePixelFormatList_REGISTER(PF_R8G8B8A8)       //  32-bit pixel format, 8 bits for red, green, blue and alpha.
01560     OgrePixelFormatList_REGISTER(PF_X8R8G8B8)       //  32-bit pixel format, 8 bits for red, 8 bits for green, 8 bits for blue like PF_A8R8G8B8, but alpha will get discarded
01561     OgrePixelFormatList_REGISTER(PF_X8B8G8R8)       //  32-bit pixel format, 8 bits for blue, 8 bits for green, 8 bits for red like PF_A8B8G8R8, but alpha will get discarded
01562     OgrePixelFormatList_REGISTER(PF_BYTE_RGB)       //  3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
01563     OgrePixelFormatList_REGISTER(PF_BYTE_BGR)       //  3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
01564     OgrePixelFormatList_REGISTER(PF_BYTE_BGRA)      //  4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
01565     OgrePixelFormatList_REGISTER(PF_BYTE_RGBA)      //  4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
01566     OgrePixelFormatList_REGISTER(PF_A2R10G10B10)    //  32-bit pixel format, 2 bits for alpha, 10 bits for red, green and blue.
01567     OgrePixelFormatList_REGISTER(PF_A2B10G10R10)    //  32-bit pixel format, 10 bits for blue, green and red, 2 bits for alpha.
01568     OgrePixelFormatList_REGISTER(PF_DXT1)           //  DDS (DirectDraw Surface) DXT1 format.
01569     OgrePixelFormatList_REGISTER(PF_DXT2)           //  DDS (DirectDraw Surface) DXT2 format.
01570     OgrePixelFormatList_REGISTER(PF_DXT3)           //  DDS (DirectDraw Surface) DXT3 format.
01571     OgrePixelFormatList_REGISTER(PF_DXT4)           //  DDS (DirectDraw Surface) DXT4 format.
01572     OgrePixelFormatList_REGISTER(PF_DXT5)           //  DDS (DirectDraw Surface) DXT5 format.
01573     OgrePixelFormatList_REGISTER(PF_FLOAT16_R)      //
01574     OgrePixelFormatList_REGISTER(PF_FLOAT16_RGB)    //
01575     OgrePixelFormatList_REGISTER(PF_FLOAT16_RGBA)   //
01576     OgrePixelFormatList_REGISTER(PF_FLOAT32_R)      //
01577     OgrePixelFormatList_REGISTER(PF_FLOAT32_RGB)    //
01578     OgrePixelFormatList_REGISTER(PF_FLOAT32_RGBA)   //
01579     OgrePixelFormatList_REGISTER(PF_FLOAT16_GR)     //
01580     OgrePixelFormatList_REGISTER(PF_FLOAT32_GR)     //
01581     OgrePixelFormatList_REGISTER(PF_DEPTH)          //
01582     OgrePixelFormatList_REGISTER(PF_SHORT_RGBA)     //
01583     OgrePixelFormatList_REGISTER(PF_SHORT_GR)       //
01584     OgrePixelFormatList_REGISTER(PF_SHORT_RGB)      //
01585     OgrePixelFormatList_REGISTER(PF_COUNT)          //
01586     return 1;
01587 }
01588 
01589 
01591 static int              l_OgreSetShadowTextureSelfShadow    (lua_State *L) { PROFILE
01592     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureSelfShadow(lua_toboolean(L,1));
01593     return 0;
01594 }
01595 
01597 static int              l_OgreSetShadowTextureCasterMaterial            (lua_State *L) { PROFILE
01598     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureCasterMaterial(luaL_checkstring(L,1));
01599     return 0;
01600 }
01601 
01603 static int              l_OgreSetShadowTextureReceiverMaterial  (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01604     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureReceiverMaterial(luaL_checkstring(L,1));
01605     return 0;
01606 }
01607 
01609 static int l_OgreAmbientLight   (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01610     float r = luaL_checknumber(L,1);
01611     float g = luaL_checknumber(L,2);
01612     float b = luaL_checknumber(L,3);
01613     Ogre::SceneManager *p = cOgreWrapper::GetSingleton().mSceneMgr;
01614     
01615     if(p){
01616         p->setAmbientLight( ColourValue( r, g, b ) );
01617     }
01618     
01619     return 0;
01620 }
01621 
01623 static int l_GetUniqueName  (lua_State *L) { PROFILE  // TODO : move to seperate file ?
01624     std::string n = cOgreWrapper::GetSingleton().GetUniqueName();
01625     lua_pushstring(L,n.c_str());
01626     return 1;
01627 }
01628 
01630 static int l_OgreLastFPS    (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().mfLastFPS);return 1; }
01632 static int l_OgreAvgFPS (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().mfAvgFPS);return 1; }
01634 static int l_OgreBestFPS    (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().mfBestFPS);return 1; }
01636 static int l_OgreWorstFPS   (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().mfWorstFPS);return 1; }
01638 static int l_OgreBestFrameTime  (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().miBestFrameTime);return 1; }
01640 static int l_OgreWorstFrameTime (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().miWorstFrameTime);return 1; }
01642 static int l_OgreTriangleCount  (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().miTriangleCount);return 1; }
01644 static int l_OgreBatchCount (lua_State *L) { PROFILE lua_pushnumber(L,cOgreWrapper::GetSingleton().miBatchCount);return 1; }
01645 
01646 
01647 static int l_OgreRenderSystemIsOpenGL   (lua_State *L) { PROFILE 
01648     lua_pushboolean(L,(Ogre::Root::getSingleton().getRenderSystem()->getName().find("GL") != Ogre::String::npos));
01649     return 1;
01650 }
01651 
01655 static int l_OgreAddResLoc  (lua_State *L) { PROFILE 
01656     std::string sArchName   = luaL_checkstring(L, 1);
01657     std::string sTypeName   = luaL_checkstring(L, 2);
01658     std::string sSecName    = luaL_checkstring(L, 3);
01659     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(sArchName,sTypeName,sSecName);
01660     return 0;
01661 }
01662 
01663 static int l_OgreInitResLocs    (lua_State *L) { PROFILE 
01664     Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
01665     return 0;
01666 }
01667 
01669 static int l_IterateOverMeshTriangles   (lua_State *L) { PROFILE 
01670     int fun;
01671     std::string sMeshName;
01672     
01673     fun = luaL_ref(L, LUA_REGISTRYINDEX);
01674     sMeshName   = luaL_checkstring(L, 1);
01675     lua_pop(L,1);
01676     
01677     Ogre::MeshPtr pm = Ogre::MeshManager::getSingleton().load(sMeshName,
01678         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
01679     
01680     if (pm.isNull()) return 0;
01681         
01682     MeshShape mshape(pm);
01683     
01684     mshape.Update(0);
01685     
01686     // iterator over all triangles and call given callback
01687     for (int i=0;i<mshape.mlIndices.size();i+=3) {
01688         Ogre::Vector3 a = mshape.mlVertices[mshape.mlIndices[i+0]];
01689         Ogre::Vector3 b = mshape.mlVertices[mshape.mlIndices[i+1]];
01690         Ogre::Vector3 c = mshape.mlVertices[mshape.mlIndices[i+2]];
01691         
01692         lua_rawgeti(L, LUA_REGISTRYINDEX, fun);
01693         
01694         lua_pushnumber(L,a.x);
01695         lua_pushnumber(L,a.y);
01696         lua_pushnumber(L,a.z);
01697         
01698         lua_pushnumber(L,b.x);
01699         lua_pushnumber(L,b.y);
01700         lua_pushnumber(L,b.z);
01701         
01702         lua_pushnumber(L,c.x);
01703         lua_pushnumber(L,c.y);
01704         lua_pushnumber(L,c.z);
01705         
01706         lua_call(L, 9, 0); // TODO : see also PCallWithErrFuncWrapper for protected call in case of error (for error messages)
01707     }
01708     
01709     luaL_unref(L, LUA_REGISTRYINDEX, fun);
01710     
01711     lua_pushnumber(L,mshape.mvMin.x);
01712     lua_pushnumber(L,mshape.mvMin.y);
01713     lua_pushnumber(L,mshape.mvMin.z);
01714     lua_pushnumber(L,mshape.mvMax.x);
01715     lua_pushnumber(L,mshape.mvMax.y);
01716     lua_pushnumber(L,mshape.mvMax.z);
01717     
01718     return 6;
01719 }
01720 
01721 // lua : FreeOldUnusedParticleSystems( limit )
01722 static int l_FreeOldUnusedParticleSystems   (lua_State *L) { PROFILE 
01723     FreeOldUnusedParticleSystems(luaL_checkint(L,1));
01724     return 0;
01725 }
01726 
01727 // lua : bhit,bhitdist,aabbhitfacenormalx,aabbhitfacenormaly,aabbhitfacenormalz = RayAABBQuery( x, y, z, dx, dy, dz, aabbx,aabby,aabbz, aabbdx, aabbdy, aabbdz )
01728 static int l_RayAABBQuery   (lua_State *L) { PROFILE 
01729 
01730     Ogre::Vector3 vRayPos( luaL_checknumber(L,1), luaL_checknumber(L,2), luaL_checknumber(L,3) );
01731     Ogre::Vector3 vRayDir( luaL_checknumber(L,4), luaL_checknumber(L,5), luaL_checknumber(L,6) );
01732     Ogre::Vector3 vAABBPos( luaL_checknumber(L,7), luaL_checknumber(L,8), luaL_checknumber(L,9) );
01733     Ogre::Vector3 vAABBDir( luaL_checknumber(L,10), luaL_checknumber(L,11), luaL_checknumber(L,12) );
01734     Ogre::AxisAlignedBox aabb(vAABBPos, vAABBPos+vAABBDir);
01735     
01736     float fHitDist;
01737     int fAABBHitFaceNormalX;
01738     int fAABBHitFaceNormalY;
01739     int fAABBHitFaceNormalZ;
01740     
01741     bool hit = cOgreWrapper::GetSingleton().RayAABBQuery(vRayPos, vRayDir, aabb, &fHitDist, &fAABBHitFaceNormalX, &fAABBHitFaceNormalY, &fAABBHitFaceNormalZ);
01742     
01743     if(hit){
01744         
01745         lua_pushboolean(L,hit);
01746         lua_pushnumber(L,fHitDist);
01747         lua_pushnumber(L,fAABBHitFaceNormalX);
01748         lua_pushnumber(L,fAABBHitFaceNormalY);
01749         lua_pushnumber(L,fAABBHitFaceNormalZ);
01750         
01751         return 5;
01752     } else {
01753         return 0;
01754     }
01755 }
01756 
01757 
01758 
01759 
01760 // lua :  void    Light_SetCastShadows  (sLightName,bool)
01761 static int      l_Light_SetCastShadows  (lua_State *L) { PROFILE 
01762     Ogre::SceneManager* pSceneMgr = cOgreWrapper::GetSingleton().mSceneMgr;
01763     const char *name = luaL_checkstring(L,1);
01764     
01765     LUGRE_TRY
01766     
01767     Ogre::Light* pLight = pSceneMgr->getLight( name );
01768     if(pLight) pLight->setCastShadows(luaL_checkbool(L,2));
01769     
01770     LUGRE_CATCH
01771     
01772     return 0;
01773 }
01774 
01775 // lua :  void    SceneMgr_SetShadowTextureCount    (iCount)
01776 static int      l_OgreSetShadowTextureCount (lua_State *L) { PROFILE 
01777     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureCount(luaL_checkint(L,1));
01778     return 0;
01779 }
01780 
01783 static int      l_OgreSetShadowTextureSettings  (lua_State *L) { PROFILE 
01784     cOgreWrapper::GetSingleton().mSceneMgr->setShadowTextureSettings(luaL_checkint(L,1),luaL_checkint(L,2),(Ogre::PixelFormat)luaL_checkint(L,3));
01785     return 0;
01786 }
01787 
01789 static int        l_MouseGrab   (lua_State *L) { PROFILE 
01790     bool bGrab = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? lua_toboolean(L,1) : true;
01791     #if defined OIS_LINUX_PLATFORM && 0
01792     OIS::LinuxMouse* p = static_cast<OIS::LinuxMouse*>(cOgreWrapper::GetSingleton().mMouse);
01793     p->grab(bGrab);
01794     #endif
01795     return 0;
01796 }
01797 
01799 static int        l_MouseHide   (lua_State *L) { PROFILE 
01800     bool bHide = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? lua_toboolean(L,1) : true;
01801     #if defined OIS_LINUX_PLATFORM && 0
01802     OIS::LinuxMouse* p = static_cast<OIS::LinuxMouse*>(cOgreWrapper::GetSingleton().mMouse);
01803     p->hide(bHide);
01804     #endif
01805     return 0;
01806 }
01807 
01808 extern bool gOISHideMouse;
01809 extern bool gOISGrabInput;
01810 
01812 static int        l_SetOgreInputOptions (lua_State *L) { PROFILE 
01813     gOISHideMouse = (lua_gettop(L) >= 1 && !lua_isnil(L,1)) ? lua_toboolean(L,1) : false;
01814     gOISGrabInput = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? lua_toboolean(L,2) : false;
01815     return 0;
01816 }
01817 
01818 /*
01819 static int l_Client_SetMouseSensitivity (lua_State *L) { PROFILE
01820     cClient* client = cGame::GetSingleton().mpClient;
01821     if (client) client->mfMouseSensitivity = luaL_checknumber(L,1);
01822     return 0;
01823 }
01824 
01825 
01826 
01827 static int l_Client_SetInvertMouse (lua_State *L) { PROFILE
01828     cClient* client = cGame::GetSingleton().mpClient;
01829     if (client) client->mbInvertMouse = luaL_checkint(L,1) != 0;
01830     return 0;
01831 }
01832 
01833 
01834 static int l_Client_SetCamera (lua_State *L) { PROFILE
01835     int i=0;
01836     Real x = luaL_checknumber(L,++i);
01837     Real y = luaL_checknumber(L,++i);
01838     Real z = luaL_checknumber(L,++i);
01839     Real qw = luaL_checknumber(L,++i);
01840     Real qx = luaL_checknumber(L,++i);
01841     Real qy = luaL_checknumber(L,++i);
01842     Real qz = luaL_checknumber(L,++i);
01843     cClient* client = cGame::GetSingleton().mpClient;
01844     if (client)
01845             client->SetCamera(Vector3(x,y,z),Quaternion(qw,qx,qy,qz));
01846     else    printf("l_Client_SetCamera called from lua on non-client");
01847     return 0;
01848 }
01849 
01850 static int l_Client_ForceCamRot (lua_State *L) { PROFILE
01851     int i=0;
01852     Real qw = luaL_checknumber(L,++i);
01853     Real qx = luaL_checknumber(L,++i);
01854     Real qy = luaL_checknumber(L,++i);
01855     Real qz = luaL_checknumber(L,++i);
01856     cClient* client = cGame::GetSingleton().mpClient;
01857     if (client)
01858             client->ForceCamRot(Quaternion(qw,qx,qy,qz));
01859     else    printf("l_Client_ForceCamRot called from lua on non-client");
01860     return 0;
01861 }
01862 
01863 static int l_Client_CameraLookAt (lua_State *L) { PROFILE
01864     int i=0;
01865     Real x = luaL_checknumber(L,++i);
01866     Real y = luaL_checknumber(L,++i);
01867     Real z = luaL_checknumber(L,++i);
01868     cClient* client = cGame::GetSingleton().mpClient;
01869     if (client)
01870             client->CameraLookAt(Vector3(x,y,z));
01871     else    printf("l_Client_CameraLookAt called from lua on non-client");
01872     return 0;
01873 }
01874 */
01875 
01878 static int        l_GetOgreVersion  (lua_State *L) { PROFILE 
01879     lua_pushnumber(L,OGRE_VERSION);
01880     return 1;
01881 }
01882 
01883 
01884 void    RegisterLua_Ogre_GlobalFunctions    (lua_State* L) {
01885     lua_register(L,"GetOgreVersion",                            l_GetOgreVersion);
01886     lua_register(L,"SetOgreInputOptions",                       l_SetOgreInputOptions);
01887     lua_register(L,"MouseGrab",                                 l_MouseGrab);
01888     lua_register(L,"MouseHide",                                 l_MouseHide);
01889     lua_register(L,"InitOgre",                                  l_InitOgre);
01890     
01891     lua_register(L,"Ogre_ListRenderSystems",                    l_Ogre_ListRenderSystems);
01892     lua_register(L,"Ogre_SetRenderSystemByName",                l_Ogre_SetRenderSystemByName);
01893     lua_register(L,"Ogre_SetConfigOption",                      l_Ogre_SetConfigOption);
01894     lua_register(L,"Ogre_GetConfigOption",                      l_Ogre_GetConfigOption);
01895     lua_register(L,"Ogre_ListConfigOptionNames",                l_Ogre_ListConfigOptionNames);
01896     lua_register(L,"Ogre_ListPossibleValuesForConfigOption",    l_Ogre_ListPossibleValuesForConfigOption);
01897     
01898     lua_register(L,"OgreCreateWindow",                          l_OgreCreateWindow);
01899     lua_register(L,"FIFO_RayPickTri_Ex",                        l_FIFO_RayPickTri_Ex);
01900     lua_register(L,"ExportOgreFont",                            l_ExportOgreFont);
01901     lua_register(L,"CloneMesh",                                 l_CloneMesh);
01902     lua_register(L,"MeshBuildEdgeList",                         l_MeshBuildEdgeList);
01903     lua_register(L,"ReloadMesh",                                l_ReloadMesh);
01904     lua_register(L,"ReloadParticleTemplate",                    l_ReloadParticleTemplate);
01905     lua_register(L,"TransformSubMeshTexCoords",                 l_TransformSubMeshTexCoords);
01906     lua_register(L,"MeshBuildTangentVectors",                   l_MeshBuildTangentVectors);
01907     lua_register(L,"SetMeshSubMaterial",                        l_SetMeshSubMaterial);
01908     lua_register(L,"GetMeshSubMaterial",                        l_GetMeshSubMaterial);
01909     lua_register(L,"GetMeshSubMeshCount",                       l_GetMeshSubMeshCount);
01910     
01911     lua_register(L,"QuaternionFromAxes",            l_QuaternionFromAxes);
01912     lua_register(L,"QuaternionFromRotationMatrix",          l_QuaternionFromRotationMatrix);
01913     lua_register(L,"QuaternionToAngleAxis",         l_QuaternionToAngleAxis);
01914     lua_register(L,"QuaternionSlerp",               l_QuaternionSlerp);
01915     lua_register(L,"MeshGetBounds",                 l_MeshGetBounds);
01916     lua_register(L,"MeshSetBounds",                 l_MeshSetBounds);
01917     lua_register(L,"MeshGetBoundRad",               l_MeshGetBoundRad);
01918     lua_register(L,"MeshSetBoundRad",               l_MeshSetBoundRad);
01919     //lua_register(L,"Client_SetMaxFPS",            l_Client_SetMaxFPS);
01920     //lua_register(L,"Client_GetMaxFPS",            l_Client_GetMaxFPS);
01921     
01922     lua_register(L,"Client_ShowOgreConfig",         l_Client_ShowOgreConfig);
01923     lua_register(L,"Client_TakeScreenshot",         l_Client_TakeScreenshot);
01924     lua_register(L,"Client_TakeGridScreenshot",     l_Client_TakeGridScreenshot);
01925     //lua_register(L,"Client_SetCamera",            l_Client_SetCamera);
01926     //lua_register(L,"Client_ForceCamRot",          l_Client_ForceCamRot);
01927     //lua_register(L,"Client_CameraLookAt",         l_Client_CameraLookAt);
01928 
01929     lua_register(L,"Client_SetSkybox",              l_Client_SetSkybox);
01930     lua_register(L,"Client_SetFog",                 l_Client_SetFog);
01931     lua_register(L,"Client_RenderOneFrame",         l_Client_RenderOneFrame);
01932     
01933     lua_register(L,"Client_SetShadowListener",      l_Client_SetShadowListener);
01934     lua_register(L,"Client_SetAmbientLight",        l_Client_SetAmbientLight);
01935     lua_register(L,"Client_ClearLights",            l_Client_ClearLights);
01936     lua_register(L,"Client_AddPointLight",          l_Client_AddPointLight);
01937     lua_register(L,"Client_AddDirectionalLight",    l_Client_AddDirectionalLight);
01938     lua_register(L,"Client_AttachLight",            l_Client_AttachLight);
01939     lua_register(L,"Client_DetatchLight",           l_Client_DetatchLight);
01940     lua_register(L,"Client_SetLightPosition",       l_Client_SetLightPosition);
01941     lua_register(L,"Client_SetLightDirection",      l_Client_SetLightDirection);
01942     lua_register(L,"Client_SetLightSpecularColor",  l_Client_SetLightSpecularColor);
01943     lua_register(L,"Client_SetLightDiffuseColor",   l_Client_SetLightDiffuseColor);
01944     lua_register(L,"Client_SetLightAttenuation",    l_Client_SetLightAttenuation);
01945     lua_register(L,"Client_RemoveLight",            l_Client_RemoveLight);
01946     lua_register(L,"Client_DeleteLight",            l_Client_DeleteLight);
01947 
01948     lua_register(L,"SphereRayPick",                 l_SphereRayPick);
01949     lua_register(L,"TriangleRayPick",               l_TriangleRayPick);
01950     lua_register(L,"TriangleRayPickEx",             l_TriangleRayPickEx);
01951     lua_register(L,"PlaneRayPick",                  l_PlaneRayPick);
01952     lua_register(L,"UnloadMeshName",                l_UnloadMeshName);
01953     lua_register(L,"UnloadTextureName",             l_UnloadTextureName);
01954     lua_register(L,"UnloadMaterialName",            l_UnloadMaterialName);
01955     lua_register(L,"CountMeshTriangles",            l_CountMeshTriangles);
01956     
01957     lua_register(L,"ExportMesh",                    l_ExportMesh);
01958     lua_register(L,"TransformMesh",                 l_TransformMesh);
01959     lua_register(L,"MeshReadOutExactBounds",        l_MeshReadOutExactBounds);
01960     lua_register(L,"CreateSceneManager",            l_CreateSceneManager);
01961     lua_register(L,"OgreSceneMgr_SetWorldGeometry",         l_OgreSceneMgr_SetWorldGeometry);
01962     lua_register(L,"OgreWrapperSetCustomSceneMgrType",      l_OgreWrapperSetCustomSceneMgrType);
01963     lua_register(L,"OgreWrapperSetEnableUnicode",           l_OgreWrapperSetEnableUnicode);
01964     lua_register(L,"OgreSceneMgr_RaySceneQuery",            l_OgreSceneMgr_RaySceneQuery);
01965     //~ lua_register(L,"OgreSceneMgr_TerrainGetHeightAt",       l_OgreSceneMgr_TerrainGetHeightAt);
01966     lua_register(L,"OgreSceneMgr_GetType",                  l_OgreSceneMgr_GetType);
01967     lua_register(L,"GetUniqueName",                 l_GetUniqueName);
01968     lua_register(L,"GetScreenRay",                  l_GetScreenRay);
01969     lua_register(L,"GetMaxZ",                       l_GetMaxZ);
01970     lua_register(L,"ProjectPos",                    l_ProjectPos);
01971     lua_register(L,"ProjectSizeAndPosEx",           l_ProjectSizeAndPosEx);
01972     lua_register(L,"ProjectSizeAndPos",             l_ProjectSizeAndPos);
01973     lua_register(L,"OgreMemoryUsage",               l_OgreMemoryUsage);
01974     lua_register(L,"OgreMeshAvailable",             l_OgreMeshAvailable);
01975     lua_register(L,"OgreMaterialNameKnown",         l_OgreMaterialNameKnown);
01976     lua_register(L,"OgreMaterialAvailable",         l_OgreMaterialAvailable);
01977     lua_register(L,"OgreTextureAvailable",          l_OgreTextureAvailable);
01978     lua_register(L,"OgreMeshTextures",              l_OgreMeshTextures);
01979     //new
01980     lua_register(L,"OgreLoadedMeshTextures",        l_OgreLoadedMeshTextures);
01981     lua_register(L,"OgreAddCompositor",             l_OgreAddCompositor);
01982     lua_register(L,"OgreRemoveCompositor",          l_OgreRemoveCompositor);
01983     lua_register(L,"OgreCompositor_AddListener_SSAO",           l_OgreCompositor_AddListener_SSAO);
01984     // shadow stuff
01985     lua_register(L,"OgreSetShadowTextureFadeStart",                     l_OgreSetShadowTextureFadeStart);
01986     lua_register(L,"OgreSetShadowTextureFadeEnd",                       l_OgreSetShadowTextureFadeEnd);
01987     lua_register(L,"OgreSetShadowDirLightTextureOffset",                l_OgreSetShadowDirLightTextureOffset);
01988     lua_register(L,"OgreSetShadowFarDistance",                          l_OgreSetShadowFarDistance);
01989     lua_register(L,"OgreSetShadowTextureSize",                          l_OgreSetShadowTextureSize);
01990     lua_register(L,"OgreSetShadowTexturePixelFormat",                   l_OgreSetShadowTexturePixelFormat);
01991     lua_register(L,"OgreSetShadowCasterRenderBackFaces",                l_OgreSetShadowCasterRenderBackFaces);
01992     lua_register(L,"OgrePixelFormatList",                               l_OgrePixelFormatList);
01993     lua_register(L,"OgreSetShadowTextureSelfShadow",                    l_OgreSetShadowTextureSelfShadow);
01994     lua_register(L,"OgreSetShadowTextureCasterMaterial",                l_OgreSetShadowTextureCasterMaterial);
01995     lua_register(L,"OgreSetShadowTextureReceiverMaterial",              l_OgreSetShadowTextureReceiverMaterial);
01996     lua_register(L,"OgreShadowTechnique",           l_OgreShadowTechnique);
01997     lua_register(L,"OgreAmbientLight",              l_OgreAmbientLight);
01998     lua_register(L,"Light_SetCastShadows",          l_Light_SetCastShadows);
01999     lua_register(L,"OgreSetShadowTextureCount",     l_OgreSetShadowTextureCount);
02000     lua_register(L,"OgreSetShadowTextureSettings",  l_OgreSetShadowTextureSettings);
02001     // some statistic stuff
02002     lua_register(L,"OgreLastFPS",                   l_OgreLastFPS);
02003     lua_register(L,"OgreAvgFPS",                    l_OgreAvgFPS);
02004     lua_register(L,"OgreBestFPS",                   l_OgreBestFPS);
02005     lua_register(L,"OgreWorstFPS",                  l_OgreWorstFPS);
02006     lua_register(L,"OgreBestFrameTime",             l_OgreBestFrameTime);
02007     lua_register(L,"OgreWorstFrameTime",            l_OgreWorstFrameTime);
02008     lua_register(L,"OgreTriangleCount",             l_OgreTriangleCount);
02009     lua_register(L,"OgreBatchCount",                l_OgreBatchCount);
02010     lua_register(L,"OgreRenderSystemIsOpenGL",      l_OgreRenderSystemIsOpenGL);
02011     lua_register(L,"OgreAddResLoc",                 l_OgreAddResLoc);
02012     lua_register(L,"OgreInitResLocs",               l_OgreInitResLocs);
02013     lua_register(L,"RayAABBQuery",              l_RayAABBQuery);
02014     lua_register(L,"FreeOldUnusedParticleSystems",              l_FreeOldUnusedParticleSystems);
02015     
02016     lua_register(L,"IterateOverMeshTriangles",              l_IterateOverMeshTriangles);
02017     
02018     std::string sOgrePlatform = "unknown";
02019     #if LUGRE_PLATFORM == LUGRE_PLATFORM_APPLE
02020     sOgrePlatform = "apple";
02021     #endif
02022     #if LUGRE_PLATFORM == LUGRE_PLATFORM_LINUX
02023     sOgrePlatform = "linux";
02024     #endif
02025     #if LUGRE_PLATFORM == LUGRE_PLATFORM_WIN32
02026     sOgrePlatform = "win32";
02027     #endif
02028     
02029     lua_pushstring(L,sOgrePlatform.c_str());
02030     lua_setglobal(L,"OGRE_PLATFORM");
02031     lua_pushstring(L,sOgrePlatform.c_str());
02032     lua_setglobal(L,"LUGRE_PLATFORM");
02033 }
02034 
02035 void    RegisterLua_Ogre_Classes            (lua_State* L) {
02036     cCamera::LuaRegister(L);
02037     cViewport::LuaRegister(L);
02038     cRenderTexture::LuaRegister(L);
02039     cBufferedMesh::LuaRegister(L);
02040     Material_LuaRegister(L);
02041     Beam_LuaRegister(L);
02042     cSpriteList::LuaRegister(L);
02043 }
02044 
02045 

Generated on Wed May 23 06:00:15 2012 for cpp by  doxygen 1.5.6