lugre_CompassOverlay.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include "lugre_CompassOverlay.h"
00003 #include <OgreOverlayElementFactory.h>
00004 #include <OgreOverlayManager.h>
00005 #include <math.h>
00006 
00007 
00008 using namespace Ogre;
00009 
00010 
00011 namespace Lugre {
00012     
00013 String cCompassOverlay::msTypeName = "Compass";
00014 
00015 
00016 
00017 // ***** ***** ***** ***** ***** Factory
00018 
00019 
00020 
00022 class /*_OgreExport*/ cCompassOverlayElementFactory: public OverlayElementFactory { public:
00024     OverlayElement* createOverlayElement(const String& instanceName) {
00025         return new cCompassOverlay(instanceName);
00026     }
00028     const String& getTypeName(void) const {
00029         return cCompassOverlay::msTypeName;
00030     }
00031 };
00032 
00033 //SiENcE
00034 void    cCompassOverlay::RegisterFactory () {
00035     OverlayManager::getSingleton().addOverlayElementFactory(new cCompassOverlayElementFactory());
00036 }
00037 
00038 
00039 // ***** ***** ***** ***** ***** cCompassOverlay
00040 
00041 cCompassOverlay::cCompassOverlay(const Ogre::String& name) : 
00042     cRobRenderOp(&mRenderOp), OverlayContainer(name), mTransparent(false),
00043     mfMidU(0.5), mfMidV(0.5), mfRadU(0.5), mfRadV(0.5), mfAngBias(0)
00044 {
00045     // default to pixel coords
00046     setMetricsMode(GMM_PIXELS);
00047 }
00048     
00049 cCompassOverlay::~cCompassOverlay() {
00050     delete mRenderOp.vertexData; mRenderOp.vertexData = 0;
00051     delete mRenderOp.indexData; mRenderOp.indexData = 0;
00052 }
00053     
00055 void cCompassOverlay::initialise(void) {
00056     OverlayContainer::initialise();
00057     mInitialised = true;
00058 }
00059 
00060 //---------------------------------------------------------------------
00061 void cCompassOverlay::setTransparent(bool isTransparent)
00062 {
00063     mTransparent = isTransparent;
00064 }
00065 
00066 //---------------------------------------------------------------------
00067 bool cCompassOverlay::isTransparent(void) const
00068 {
00069     return mTransparent;
00070 }
00071 
00073 const String& cCompassOverlay::getTypeName(void) const {
00074     return msTypeName;
00075 }
00076 
00078 void cCompassOverlay::getRenderOperation(RenderOperation& op) {
00079     op = mRenderOp;
00080 }
00081 
00083 void cCompassOverlay::setMaterialName(const String& matName) {
00084     OverlayContainer::setMaterialName(matName);
00085 }
00086 
00088 void cCompassOverlay::_updateRenderQueue(RenderQueue* queue) {
00089     if (mVisible)
00090     {
00091 
00092         if (!mTransparent && !mpMaterial.isNull())
00093         {
00094             OverlayElement::_updateRenderQueue(queue);
00095         }
00096 
00097         // Also add children
00098         ChildIterator it = getChildIterator();
00099         while (it.hasMoreElements())
00100         {
00101             // Give children ZOrder 1 higher than this
00102             it.getNext()->_updateRenderQueue(queue);
00103         }
00104     }
00105 }
00106 
00107 
00108 void    cCompassOverlay::SetUVMid   (const float fMidU,const float fMidV) { mfMidU = fMidU; mfMidV = fMidV; mGeomPositionsOutOfDate = true; }
00109 void    cCompassOverlay::SetUVRad   (const float fRadU,const float fRadV) { mfRadU = fRadU; mfRadV = fRadV; mGeomPositionsOutOfDate = true; }
00110 void    cCompassOverlay::SetAngBias (const float fAngBias) { mfAngBias = fAngBias; mGeomPositionsOutOfDate = true; }
00111 
00113 void cCompassOverlay::updatePositionGeometry(void) {
00114     /*
00115     // init clip to fullscreen
00116     if (!mbClipInitialized) {
00117         mbClipInitialized = true;
00118         mClip.left = 0;
00119         mClip.top = 0;
00120         if (mMetricsMode != GMM_RELATIVE) {
00121             mClip.right = mClip.left+cOgreWrapper::GetSingleton().GetViewportWidth();
00122             mClip.bottom = mClip.top+cOgreWrapper::GetSingleton().GetViewportHeight();
00123         } else {
00124             mClip.right = mClip.left+1.0;
00125             mClip.bottom = mClip.top+1.0;
00126         }
00127     }
00128     */
00129     
00130     //mForm.SetLTWH(_getDerivedLeft(),_getDerivedTop(),mWidth,mHeight);
00131     
00132         
00133     // clear z buffer under overlay
00134     Real maxz   = GetMaxZ();
00135     
00136     // construct geometry
00137     int iSteps = 21;
00138     Begin(2+iSteps,3*iSteps,true,false,Ogre::RenderOperation::OT_TRIANGLE_LIST);
00139     float radx = (mWidth / 2.0) * 2.0;
00140     float rady = (mHeight / 2.0) * 2.0;
00141     float midx = (_getDerivedLeft()) * 2.0 - 1.0 + radx;
00142     float midy = - (_getDerivedTop() * 2.0 - 1.0 + rady);
00143     float ang;
00144     float partang = 2.0 * 3.1415 / float(iSteps);
00145 
00146     Vertex(Vector3(midx,midy,maxz),mfMidU,mfMidV);
00147     for (int i=0;i<=iSteps;++i) {
00148         ang = float((i==iSteps)?0:i) * partang;
00149         Vertex(Vector3(midx-radx*sin(ang),midy+rady*cos(ang),maxz),mfMidU+mfRadU*sin(ang+mfAngBias),mfMidV+mfRadV*cos(ang+mfAngBias));
00150         if (i>0) {
00151             Index(0);
00152             Index(i+1);
00153             Index(i);
00154         }
00155     }
00156     //clipped.DrawStrip(this,maxz);
00157     End();
00158     //pRobRenderOp->Vertex(Vector3(x * 2.0 - 1.0,-(y * 2.0 - 1.0),z),u,v,col);
00159 }
00160 
00162 void cCompassOverlay::updateTextureGeometry(void) {}
00163 
00165 void cCompassOverlay::addBaseParameters(void) { OverlayContainer::addBaseParameters(); }
00166 
00167 };

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