Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreRectangle2D.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreStableHeaders.h"
    00026 #include "OgreRectangle2D.h"
    00027
    00028 #include "OgreSimpleRenderable.h"
    00029 #include "OgreHardwareBufferManager.h"
    00030 #include "OgreCamera.h"
    00031
    00032 namespace Ogre {
    00033 #define POSITION_BINDING 0
    00034 #define TEXCOORD_BINDING 1
    00035
    00036     Rectangle2D::Rectangle2D(bool includeTextureCoords)
    00037     {
    00038         mRenderOp.vertexData = new VertexData();
    00039
    00040         mRenderOp.indexData = 0;
    00041         mRenderOp.vertexData->vertexCount = 4;
    00042         mRenderOp.vertexData->vertexStart = 0;
    00043         mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP;
    00044         mRenderOp.useIndexes = false;
    00045
    00046         VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
    00047         VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
    00048
    00049         decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
    00050
    00051
    00052         HardwareVertexBufferSharedPtr vbuf =
    00053             HardwareBufferManager::getSingleton().createVertexBuffer(
    00054             decl->getVertexSize(POSITION_BINDING),
    00055             mRenderOp.vertexData->vertexCount,
    00056             HardwareBuffer::HBU_STATIC_WRITE_ONLY);
    00057
    00058         // Bind buffer
    00059         bind->setBinding(POSITION_BINDING, vbuf);
    00060
    00061         if (includeTextureCoords)
    00062         {
    00063             decl->addElement(TEXCOORD_BINDING, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES);
    00064
    00065
    00066             HardwareVertexBufferSharedPtr tvbuf =
    00067                 HardwareBufferManager::getSingleton().createVertexBuffer(
    00068                 decl->getVertexSize(TEXCOORD_BINDING),
    00069                 mRenderOp.vertexData->vertexCount,
    00070                 HardwareBuffer::HBU_STATIC_WRITE_ONLY);
    00071
    00072             // Bind buffer
    00073             bind->setBinding(TEXCOORD_BINDING, tvbuf);
    00074
    00075             // Set up basic tex coordinates
    00076             Real* pTex = static_cast<Real*>(
    00077                 tvbuf->lock(HardwareBuffer::HBL_DISCARD));
    00078             *pTex++ = 0.0f;
    00079             *pTex++ = 0.0f;
    00080             *pTex++ = 0.0f;
    00081             *pTex++ = 1.0f;
    00082             *pTex++ = 1.0f;
    00083             *pTex++ = 0.0f;
    00084             *pTex++ = 1.0f;
    00085             *pTex++ = 1.0f;
    00086             tvbuf->unlock();
    00087         }
    00088
    00089         // set basic white material
    00090         this->setMaterial("BaseWhiteNoLighting");
    00091
    00092
    00093
    00094     }
    00095
    00096     Rectangle2D::~Rectangle2D()
    00097     {
    00098         delete mRenderOp.vertexData;
    00099     }
    00100
    00101     void Rectangle2D::setCorners(Real left, Real top, Real right, Real bottom)
    00102     {
    00103         HardwareVertexBufferSharedPtr vbuf =
    00104             mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);
    00105         Real* pReal = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
    00106
    00107         *pReal++ = left;
    00108         *pReal++ = top;
    00109         *pReal++ = -1;
    00110
    00111         *pReal++ = left;
    00112         *pReal++ = bottom;
    00113         *pReal++ = -1;
    00114
    00115         *pReal++ = right;
    00116         *pReal++ = top;
    00117         *pReal++ = -1;
    00118
    00119         *pReal++ = right;
    00120         *pReal++ = bottom;
    00121         *pReal++ = -1;
    00122
    00123         vbuf->unlock();
    00124
    00125         AxisAlignedBox aabb;
    00126         aabb.setExtents(left, top, 0, right, bottom, 0);
    00127
    00128     }
    00129
    00130     // Override this method to prevent parent transforms (rotation,translation,scale)
    00131     void Rectangle2D::getWorldTransforms( Matrix4* xform ) const
    00132     {
    00133         // return identity matrix to prevent parent transforms
    00134         *xform = Matrix4::IDENTITY;
    00135     }
    00136     //-----------------------------------------------------------------------
    00137     const Quaternion& Rectangle2D::getWorldOrientation(void) const
    00138     {
    00139         return Quaternion::IDENTITY;
    00140     }
    00141     //-----------------------------------------------------------------------
    00142     const Vector3& Rectangle2D::getWorldPosition(void) const
    00143     {
    00144         return Vector3::ZERO;
    00145     }
    00146
    00147
    00148 }
    00149

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:41 2004