lugre_ogrewrapper.h

Go to the documentation of this file.
00001 /*
00002 http://www.opensource.org/licenses/mit-license.php  (MIT-License)
00003 
00004 Copyright (c) 2007 Lugre-Team
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022 THE SOFTWARE.
00023 */
00024 #ifndef LUGRE_OGREWRAPPER_H
00025 #define LUGRE_OGREWRAPPER_H
00026 #undef min
00027 #undef max
00028 #include <OgrePrerequisites.h>
00029 #include <OgreVector3.h>
00030 #include <OgreQuaternion.h>
00031 #if OGRE_VERSION < 0x10700
00032 #include <OgreUserDefinedObject.h>
00033 #endif
00035 
00036 namespace Ogre {
00037     class TextAreaOverlayElement;
00038     class Skeleton;
00039     class Bone;
00040 }
00041 namespace OIS {
00042     class InputManager;
00043     class Mouse;
00044     class Keyboard;
00045     class JoyStick;
00046 }
00047 
00048 namespace Lugre {
00049     
00050 #if OGRE_VERSION < 0x10700
00052 class cOgreUserObjectWrapper : public Ogre::UserDefinedObject { public :
00053     Ogre::Entity*   mpEntity;   
00054     int             miType;     
00055     int             miParam[4]; 
00056     
00057     cOgreUserObjectWrapper();
00058     virtual ~cOgreUserObjectWrapper();
00059     virtual long getTypeID(void) const;
00060     virtual const Ogre::String& getTypeName(void) const;
00061 };
00062 #endif
00063 
00064 class cOgreWrapper { public :
00065     Ogre::Root*             mRoot;
00066     Ogre::Camera*           mCamera;
00067     Ogre::Viewport*         mViewport;
00068     Ogre::SceneManager*     mSceneMgr;
00069     Ogre::RenderWindow*     mWindow;
00070     Ogre::SceneNode*        mpCamPosSceneNode;      // only has cam pos, absolute orientation
00071     Ogre::SceneNode*        mpCamHolderSceneNode;   // has cam pos and orientation
00072     
00073     // stores some render stats
00074     std::string msWindowTitle;
00075     float   mfLastFPS;
00076     float   mfAvgFPS;
00077     float   mfBestFPS;
00078     float   mfWorstFPS;
00079     unsigned long   miBestFrameTime;
00080     unsigned long   miWorstFrameTime;
00081     size_t  miTriangleCount;
00082     size_t  miBatchCount;
00083     
00084     //OIS Input devices
00085     OIS::InputManager*  mInputManager;
00086     OIS::Mouse*         mMouse;
00087     OIS::Keyboard*      mKeyboard;
00088     OIS::JoyStick*      mJoy;
00089     
00090     cOgreWrapper();
00091     
00092     // cOgreWrapper::GetSingleton().
00093     inline static cOgreWrapper& GetSingleton () { 
00094         static cOgreWrapper* mSingleton = 0;
00095         if (!mSingleton) mSingleton = new cOgreWrapper();
00096         return *mSingleton;
00097     }
00098     
00099     // utils
00100     Ogre::SceneManager* GetSceneManager (const char* szSceneMgrName="main");
00101     
00102     // config
00103     std::vector<std::string>    ListRenderSystems                   ();
00104     void                        SetRenderSystemByName               (std::string sRenderSysName);
00105     std::vector<std::string>    ListConfigOptionNames               (std::string sRenderSysName);
00106     std::vector<std::string>    ListPossibleValuesForConfigOption   (std::string sRenderSysName,std::string sConfigOptionName);
00107     void                        SetConfigOption                     (std::string sName,std::string sValue);
00108     std::string                 GetConfigOption                     (std::string sName);
00109     
00111     bool    Init                (const char* szWindowTitle,const char* szOgrePluginDir,const char* szOgreBaseDir,bool bAutoCreateWindow=true); 
00112     bool    CreateOgreWindow    (bool bConfigRestoreOrDialog=true); 
00113     void    RenderOneFrame      ();
00114     void    DeInit              ();
00115     void    TakeGridScreenshot  (const int& pGridSize, const Ogre::String& pFileName, const Ogre::String& pFileExtention, const bool& pStitchGridImages);
00116     void    TakeScreenshot      (const char* szPrefix="../screenshots/");
00117     
00118     void    SetSkybox       (const char* szMatName,const bool bFlip=false);
00119     void    AttachCamera    (Ogre::SceneNode* pSceneNode=0);
00120     void    SetCameraPos    (const Ogre::Vector3    vPos=Ogre::Vector3::ZERO);
00121     void    SetCameraRot    (const Ogre::Quaternion qRot=Ogre::Quaternion::IDENTITY);
00122     void    CameraLookAt    (const Ogre::Vector3    vPos=Ogre::Vector3::ZERO);
00123     
00124     // utils
00125     static std::string      GetUniqueName   ();
00126     int     GetViewportHeight   (); 
00127     int     GetViewportWidth    (); 
00128     
00129     // Ray/Intersection Queries
00130     int             GetEntityIndexCount (Ogre::Entity* pEntity);
00131     Ogre::Vector3   GetEntityVertex     (Ogre::Entity* pEntity,const int iIndexIndex);
00132     bool    RayAABBQuery    (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,const Ogre::AxisAlignedBox &aabb,float* pfHitDist=0, int* pfHitFaceNormalX=0, int* pfHitFaceNormalY=0, int* pfHitFaceNormalZ=0);
00133     int     RayEntityQuery  (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,Ogre::Entity* pEntity,float* pfHitDist=0);
00134     int     RayEntityQuery  (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,Ogre::Entity* pEntity,const Ogre::Vector3& vPos,const Ogre::Quaternion& qRot,const Ogre::Vector3& vScale,float* pfHitDist=0);
00135     void    RayEntityQuery  (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,Ogre::Entity* pEntity,std::vector<std::pair<float,int> > &pHitList);
00136     void    RayEntityQuery  (const Ogre::Vector3& vRayPos,const Ogre::Vector3& vRayDir,Ogre::Entity* pEntity,const Ogre::Vector3& vPos,const Ogre::Quaternion& qRot,const Ogre::Vector3& vScale,std::vector<std::pair<float,int> > &pHitList);
00137 
00138     // 3d to 2d projection
00139     bool            ProjectPos          (const Ogre::Vector3& pos,Ogre::Real& x,Ogre::Real& y);
00140     bool            ProjectSizeAndPos   (const Ogre::Vector3& pos,Ogre::Real& x,Ogre::Real& y,const Ogre::Real rad,Ogre::Real& cx,Ogre::Real& cy);
00141     Ogre::Vector3   ProjectSizeAndPosEx (const Ogre::Vector3& pos,const Ogre::Real rad,Ogre::Vector3& vSize);
00142     
00143     static Ogre::Bone*      SearchBoneByName    (Ogre::Skeleton& pSkeleton,const char* szBoneName);
00144     
00145     static void             ImageBlit               (Ogre::Image& pImageS,Ogre::Image& pImageD,const int tx0,const int ty0);
00146     static void             ImageBlitPart           (Ogre::Image& pImageS,Ogre::Image& pImageD,int dst_x,int dst_y,int src_x,int src_y,int w,int h);
00147     static void             ImageColorReplace       (Ogre::Image& pImage,Ogre::ColourValue colSearch,Ogre::ColourValue colReplace);
00148     static void             ImageColorKeyToAlpha    (Ogre::Image& pImage,Ogre::ColourValue colSearch);
00149 };
00150 
00151 };
00152 
00153 #endif

Generated on Wed Feb 8 06:00:12 2012 for cpp by  doxygen 1.5.6