lugre_beam.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_BEAM_H
00025 #define LUGRE_BEAM_H
00026 
00027 #include "lugre_robrenderable.h"
00028 #include <OgrePrerequisites.h>
00029 #include <OgreVector3.h>
00030 #include <deque>
00031 
00032 
00033 namespace Lugre {
00034     
00035 class cBeamFilter;
00036 class cBeam;
00037 class cBeamPoint;
00038     
00039 class cBeamFilter { public:
00040     cBeamFilter();
00041     virtual ~cBeamFilter();
00042     virtual cBeamPoint& CurPoint    (cBeamPoint& p,const int iLine,const int iPoint);
00043     virtual cBeamPoint& NextPoint   (cBeamPoint& p,const int iLine,const int iPoint);
00044     virtual cBeamPoint& PrevPoint   (cBeamPoint& p,const int iLine,const int iPoint);
00045     static cBeamFilter IDENTITY;
00046 };
00047 
00048 class cBeamPoint { public:
00049     Ogre::Vector3       pos; 
00050     float               h1,h2; 
00051     float               u1,u2; 
00052     float               v1,v2; 
00053     Ogre::ColourValue   col1,col2; 
00054     cBeamPoint  () : pos(0,0,0), col1(Ogre::ColourValue::White), col2(Ogre::ColourValue::White), h1(1), h2(1), u1(0), u2(0), v1(0), v2(1) {}
00055     cBeamPoint  (   const Ogre::Vector3& pos,
00056                     const float h1,const float h2,
00057                     const float u1,const float u2, 
00058                     const float v1,const float v2, 
00059                     const Ogre::ColourValue& col1 = Ogre::ColourValue::White,
00060                     const Ogre::ColourValue& col2 = Ogre::ColourValue::White
00061         ) : pos(pos), col1(col1), col2(col2), h1(h1), h2(h2), u1(u1), u2(u2), v1(v1), v2(v2) {}
00062 };
00063 
00066 class cBeam { public:
00067     bool mbBoundsDirty;
00068     std::deque<std::deque<cBeamPoint>*> mlBeamLines;
00069     
00070     cBeam ();
00071     virtual ~cBeam ();
00072     
00073     int     CountLines  () { return mlBeamLines.size(); }
00074     void    ClearLines  () { mbBoundsDirty = true; mlBeamLines.clear(); }
00075     int     AddLine     () { mlBeamLines.push_back(new std::deque<cBeamPoint>()); return mlBeamLines.size()-1;  }
00076     void    DeleteLine  (const int iLine) {
00077         mbBoundsDirty = true; 
00078         if (iLine >= 0 && iLine < mlBeamLines.size()) {
00079             std::deque<std::deque<cBeamPoint>*>::iterator itor = mlBeamLines.begin()+iLine;
00080             if (*itor) delete *itor;
00081             mlBeamLines.erase(itor);
00082         }
00083     }
00084     
00085     // point manipulation
00086     void        AddPoint    (const int iLine,const cBeamPoint& p) { mbBoundsDirty = true; if (iLine >= 0 && iLine < mlBeamLines.size()) mlBeamLines[iLine]->push_back(p); }
00087     void        ClearLine   (const int iLine) { mbBoundsDirty = true; if (iLine >= 0 && iLine < mlBeamLines.size()) mlBeamLines[iLine]->clear(); }
00088     int     CountLinePoints (const int iLine) { return (iLine >= 0 && iLine < mlBeamLines.size()) ? mlBeamLines[iLine]->size() : 0; }
00089     void        PopFront    (const int iLine) { mbBoundsDirty = true; if (iLine >= 0 && iLine < mlBeamLines.size()) mlBeamLines[iLine]->pop_front(); }
00090     void        PopBack     (const int iLine) { mbBoundsDirty = true; if (iLine >= 0 && iLine < mlBeamLines.size()) mlBeamLines[iLine]->pop_back(); }
00091     cBeamPoint* GetPoint    (const int iLine,const int iPoint) {
00092         return (iLine  >= 0 && iLine  < mlBeamLines.size() && 
00093                 iPoint >= 0 && iPoint < mlBeamLines[iLine]->size()) ? &(*mlBeamLines[iLine])[iPoint] : 0; 
00094     }
00095     
00096     void    UpdateBeamBounds    (cRobRenderOp& pRobRenderOp);
00097     
00099     void    Draw    (cRobRenderOp& pRobRenderOp,Ogre::Vector3 vEyePos,const bool bUseVertexColour,cBeamFilter &filter=cBeamFilter::IDENTITY);
00100     void    Draw    (cRobRenderOp& pRobRenderOp,Ogre::Camera& pCam,Ogre::SceneNode& pBeamSceneNode,const bool bUseVertexColour,cBeamFilter &filter=cBeamFilter::IDENTITY);
00101 
00102     static  Ogre::Vector3   CalcEyePos  (Ogre::Camera& pCam,Ogre::SceneNode& pBeamSceneNode);
00103 };
00104 
00105 class cSimpleBeam : public cBeam, public cRobSimpleRenderable { public :
00106     cBeamFilter* pFilter;
00107     bool    mbUseVertexColour;
00108     cSimpleBeam(const bool mbUseVertexColour);
00109     virtual ~cSimpleBeam();
00110     void    UpdateBounds    ();
00111     virtual const Ogre::AxisAlignedBox& getBoundingBox(void) const;
00112     virtual Ogre::Real getBoundingRadius(void) const;
00113     virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
00114     virtual void _notifyCurrentCamera (Ogre::Camera* cam);
00115 };
00116 
00117 };
00118 
00119 #endif

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