Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spaceraceTwo/src/libraries/tools/DynamicLines.cc @ 9110

Last change on this file since 9110 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Baxissimo, Emmeran, DWORD, EtherDrive (OGRE Wiki)
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "DynamicLines.h"
30
31#include <cassert>
32#include <cmath>
33
34namespace Ogre
35{
36    enum
37    {
38        POSITION_BINDING,
39        TEXCOORD_BINDING
40    };
41
42    DynamicLines::DynamicLines(OperationType opType)
43    {
44        initialize(opType,false);
45        setMaterial("BaseWhiteNoLighting");
46        mDirty = true;
47    }
48
49    DynamicLines::~DynamicLines()
50    {
51    }
52
53    void DynamicLines::setOperationType(OperationType opType)
54    {
55        mRenderOp.operationType = opType;
56    }
57
58    RenderOperation::OperationType DynamicLines::getOperationType() const
59    {
60        return mRenderOp.operationType;
61    }
62
63    void DynamicLines::addPoint(const Vector3 &p)
64    {
65        mPoints.push_back(p);
66        mDirty = true;
67    }
68
69    void DynamicLines::addPoint(Real x, Real y, Real z)
70    {
71        mPoints.push_back(Vector3(x,y,z));
72        mDirty = true;
73    }
74
75    const Vector3& DynamicLines::getPoint(unsigned short index) const
76    {
77        assert(index < mPoints.size() && "Point index is out of bounds!!");
78        return mPoints[index];
79    }
80
81    unsigned short DynamicLines::getNumPoints(void) const
82    {
83        return (unsigned short)mPoints.size();
84    }
85
86    void DynamicLines::setPoint(unsigned short index, const Vector3 &value)
87    {
88        assert(index < mPoints.size() && "Point index is out of bounds!!");
89
90        mPoints[index] = value;
91        mDirty = true;
92    }
93
94    void DynamicLines::clear()
95    {
96        mPoints.clear();
97        mDirty = true;
98    }
99
100    void DynamicLines::update()
101    {
102        if (mDirty)
103            fillHardwareBuffers();
104    }
105
106    void DynamicLines::createVertexDeclaration()
107    {
108        VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
109        decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
110    }
111
112    void DynamicLines::fillHardwareBuffers()
113    {
114        int size = mPoints.size();
115
116        prepareHardwareBuffers(size,0);
117
118        if (!size)
119        {
120            mBox.setExtents(Vector3::ZERO,Vector3::ZERO);
121            mDirty=false;
122            return;
123        }
124
125        Vector3 vaabMin = mPoints[0];
126        Vector3 vaabMax = mPoints[0];
127
128        HardwareVertexBufferSharedPtr vbuf =
129            mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);
130
131        Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
132        for (int i = 0; i < size; i++)
133        {
134            *prPos++ = mPoints[i].x;
135            *prPos++ = mPoints[i].y;
136            *prPos++ = mPoints[i].z;
137
138            if (mPoints[i].x < vaabMin.x)
139                vaabMin.x = mPoints[i].x;
140            if (mPoints[i].y < vaabMin.y)
141                vaabMin.y = mPoints[i].y;
142            if (mPoints[i].z < vaabMin.z)
143                vaabMin.z = mPoints[i].z;
144
145            if (mPoints[i].x > vaabMax.x)
146                vaabMax.x = mPoints[i].x;
147            if (mPoints[i].y > vaabMax.y)
148                vaabMax.y = mPoints[i].y;
149            if (mPoints[i].z > vaabMax.z)
150                vaabMax.z = mPoints[i].z;
151        }
152        vbuf->unlock();
153
154        mBox.setExtents(vaabMin, vaabMax);
155
156        mDirty = false;
157    }
158
159    /*
160    void DynamicLines::getWorldTransforms(Matrix4 *xform) const
161    {
162        // return identity matrix to prevent parent transforms
163        *xform = Matrix4::IDENTITY;
164    }
165    */
166
167    /*
168    const Quaternion &DynamicLines::getWorldOrientation(void) const
169    {
170        return Quaternion::IDENTITY;
171    }
172
173    const Vector3 &DynamicLines::getWorldPosition(void) const
174    {
175        return Vector3::ZERO;
176    }
177    */
178}
Note: See TracBrowser for help on using the repository browser.