source: OGRE/trunk/ogrenew/OgreMain/src/OgreRectangle2D.cpp @ 692

Revision 692, 4.8 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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