Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/tools/DynamicLines.cc @ 8383

Last change on this file since 8383 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
RevLine 
[3130]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
[2942]29#include "DynamicLines.h"
[3130]30
[2942]31#include <cassert>
32#include <cmath>
33
[3130]34namespace Ogre
[3089]35{
[3130]36    enum
37    {
38        POSITION_BINDING,
39        TEXCOORD_BINDING
40    };
[2942]41
[3130]42    DynamicLines::DynamicLines(OperationType opType)
43    {
44        initialize(opType,false);
45        setMaterial("BaseWhiteNoLighting");
46        mDirty = true;
47    }
[2942]48
[3130]49    DynamicLines::~DynamicLines()
50    {
51    }
[2942]52
[3130]53    void DynamicLines::setOperationType(OperationType opType)
54    {
55        mRenderOp.operationType = opType;
56    }
[2942]57
[3130]58    RenderOperation::OperationType DynamicLines::getOperationType() const
59    {
60        return mRenderOp.operationType;
61    }
[2942]62
[3130]63    void DynamicLines::addPoint(const Vector3 &p)
64    {
65        mPoints.push_back(p);
66        mDirty = true;
67    }
[2942]68
[3130]69    void DynamicLines::addPoint(Real x, Real y, Real z)
70    {
71        mPoints.push_back(Vector3(x,y,z));
72        mDirty = true;
73    }
[2942]74
[3130]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    }
[2942]80
[3130]81    unsigned short DynamicLines::getNumPoints(void) const
82    {
83        return (unsigned short)mPoints.size();
84    }
[2942]85
[3130]86    void DynamicLines::setPoint(unsigned short index, const Vector3 &value)
87    {
88        assert(index < mPoints.size() && "Point index is out of bounds!!");
[2942]89
[3130]90        mPoints[index] = value;
91        mDirty = true;
92    }
[2942]93
[3130]94    void DynamicLines::clear()
95    {
96        mPoints.clear();
97        mDirty = true;
98    }
[3089]99
[3130]100    void DynamicLines::update()
101    {
102        if (mDirty)
103            fillHardwareBuffers();
104    }
[2942]105
[3130]106    void DynamicLines::createVertexDeclaration()
107    {
108        VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
109        decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
110    }
[2942]111
[3130]112    void DynamicLines::fillHardwareBuffers()
113    {
114        int size = mPoints.size();
[2942]115
[3130]116        prepareHardwareBuffers(size,0);
[2942]117
[3130]118        if (!size)
119        {
120            mBox.setExtents(Vector3::ZERO,Vector3::ZERO);
121            mDirty=false;
122            return;
123        }
[2942]124
[3130]125        Vector3 vaabMin = mPoints[0];
126        Vector3 vaabMax = mPoints[0];
[2942]127
[3130]128        HardwareVertexBufferSharedPtr vbuf =
129            mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);
[2942]130
[3130]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;
[2942]137
[3130]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    */
[2942]178}
Note: See TracBrowser for help on using the repository browser.