[1] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
| 8 | Also see acknowledgements in Readme.html |
---|
| 9 | |
---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 13 | version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
| 18 | |
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
| 23 | |
---|
| 24 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #include "OgreStableHeaders.h" |
---|
| 30 | #include "OgreRectangle2D.h" |
---|
| 31 | |
---|
| 32 | #include "OgreSimpleRenderable.h" |
---|
| 33 | #include "OgreHardwareBufferManager.h" |
---|
| 34 | #include "OgreCamera.h" |
---|
| 35 | |
---|
| 36 | namespace Ogre { |
---|
| 37 | #define POSITION_BINDING 0 |
---|
| 38 | #define TEXCOORD_BINDING 1 |
---|
| 39 | |
---|
| 40 | Rectangle2D::Rectangle2D(bool includeTextureCoords) |
---|
| 41 | { |
---|
| 42 | // use identity projection and view matrices |
---|
| 43 | mUseIdentityProjection = true; |
---|
| 44 | mUseIdentityView = true; |
---|
| 45 | |
---|
| 46 | mRenderOp.vertexData = new VertexData(); |
---|
| 47 | |
---|
| 48 | mRenderOp.indexData = 0; |
---|
| 49 | mRenderOp.vertexData->vertexCount = 4; |
---|
| 50 | mRenderOp.vertexData->vertexStart = 0; |
---|
| 51 | mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP; |
---|
| 52 | mRenderOp.useIndexes = false; |
---|
| 53 | |
---|
| 54 | VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; |
---|
| 55 | VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; |
---|
| 56 | |
---|
| 57 | decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | HardwareVertexBufferSharedPtr vbuf = |
---|
| 61 | HardwareBufferManager::getSingleton().createVertexBuffer( |
---|
| 62 | decl->getVertexSize(POSITION_BINDING), |
---|
| 63 | mRenderOp.vertexData->vertexCount, |
---|
| 64 | HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
| 65 | |
---|
| 66 | // Bind buffer |
---|
| 67 | bind->setBinding(POSITION_BINDING, vbuf); |
---|
| 68 | |
---|
| 69 | if (includeTextureCoords) |
---|
| 70 | { |
---|
| 71 | decl->addElement(TEXCOORD_BINDING, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES); |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | HardwareVertexBufferSharedPtr tvbuf = |
---|
| 75 | HardwareBufferManager::getSingleton().createVertexBuffer( |
---|
| 76 | decl->getVertexSize(TEXCOORD_BINDING), |
---|
| 77 | mRenderOp.vertexData->vertexCount, |
---|
| 78 | HardwareBuffer::HBU_STATIC_WRITE_ONLY); |
---|
| 79 | |
---|
| 80 | // Bind buffer |
---|
| 81 | bind->setBinding(TEXCOORD_BINDING, tvbuf); |
---|
| 82 | |
---|
| 83 | // Set up basic tex coordinates |
---|
| 84 | float* pTex = static_cast<float*>( |
---|
| 85 | tvbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
| 86 | *pTex++ = 0.0f; |
---|
| 87 | *pTex++ = 0.0f; |
---|
| 88 | *pTex++ = 0.0f; |
---|
| 89 | *pTex++ = 1.0f; |
---|
| 90 | *pTex++ = 1.0f; |
---|
| 91 | *pTex++ = 0.0f; |
---|
| 92 | *pTex++ = 1.0f; |
---|
| 93 | *pTex++ = 1.0f; |
---|
| 94 | tvbuf->unlock(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // set basic white material |
---|
| 98 | this->setMaterial("BaseWhiteNoLighting"); |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | Rectangle2D::~Rectangle2D() |
---|
| 105 | { |
---|
| 106 | delete mRenderOp.vertexData; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void Rectangle2D::setCorners(Real left, Real top, Real right, Real bottom) |
---|
| 110 | { |
---|
| 111 | HardwareVertexBufferSharedPtr vbuf = |
---|
| 112 | mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING); |
---|
| 113 | float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); |
---|
| 114 | |
---|
| 115 | *pFloat++ = left; |
---|
| 116 | *pFloat++ = top; |
---|
| 117 | *pFloat++ = -1; |
---|
| 118 | |
---|
| 119 | *pFloat++ = left; |
---|
| 120 | *pFloat++ = bottom; |
---|
| 121 | *pFloat++ = -1; |
---|
| 122 | |
---|
| 123 | *pFloat++ = right; |
---|
| 124 | *pFloat++ = top; |
---|
| 125 | *pFloat++ = -1; |
---|
| 126 | |
---|
| 127 | *pFloat++ = right; |
---|
| 128 | *pFloat++ = bottom; |
---|
| 129 | *pFloat++ = -1; |
---|
| 130 | |
---|
| 131 | vbuf->unlock(); |
---|
| 132 | |
---|
| 133 | mBox.setExtents( |
---|
| 134 | std::min(left, right), std::min(top, bottom), 0, |
---|
| 135 | std::max(left, right), std::max(top, bottom), 0); |
---|
| 136 | |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | // Override this method to prevent parent transforms (rotation,translation,scale) |
---|
| 140 | void Rectangle2D::getWorldTransforms( Matrix4* xform ) const |
---|
| 141 | { |
---|
| 142 | // return identity matrix to prevent parent transforms |
---|
| 143 | *xform = Matrix4::IDENTITY; |
---|
| 144 | } |
---|
| 145 | //----------------------------------------------------------------------- |
---|
| 146 | const Quaternion& Rectangle2D::getWorldOrientation(void) const |
---|
| 147 | { |
---|
| 148 | return Quaternion::IDENTITY; |
---|
| 149 | } |
---|
| 150 | //----------------------------------------------------------------------- |
---|
| 151 | const Vector3& Rectangle2D::getWorldPosition(void) const |
---|
| 152 | { |
---|
| 153 | return Vector3::ZERO; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | } |
---|
| 158 | |
---|