Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/tools/DynamicLines.cpp @ 3154

Last change on this file since 3154 was 3089, checked in by landauf, 16 years ago

merged map branch back to trunk

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1#include "DynamicLines.h"
2#include <Ogre.h>
3#include <cassert>
4#include <cmath>
5
6using namespace Ogre;
7
8namespace orxonox
9{
10enum {
11  POSITION_BINDING,
12  TEXCOORD_BINDING
13};
14
15DynamicLines::DynamicLines(OperationType opType)
16{
17  initialize(opType,false);
18  setMaterial("BaseWhiteNoLighting");
19  mDirty = true;
20}
21
22DynamicLines::~DynamicLines()
23{
24}
25
26void DynamicLines::setOperationType(OperationType opType)
27{
28  mRenderOp.operationType = opType;
29}
30
31RenderOperation::OperationType DynamicLines::getOperationType() const
32{
33  return mRenderOp.operationType;
34}
35
36void DynamicLines::addPoint(const Vector3 &p)
37{
38   mPoints.push_back(p);
39   mDirty = true;
40}
41void DynamicLines::addPoint(Real x, Real y, Real z)
42{
43   mPoints.push_back(Vector3(x,y,z));
44   mDirty = true;
45}
46const Vector3& DynamicLines::getPoint(unsigned short index) const
47{
48   assert(index < mPoints.size() && "Point index is out of bounds!!");
49   return mPoints[index];
50}
51unsigned short DynamicLines::getNumPoints(void) const
52{
53  return (unsigned short)mPoints.size();
54}
55void DynamicLines::setPoint(unsigned short index, const Vector3 &value)
56{
57  assert(index < mPoints.size() && "Point index is out of bounds!!");
58
59  mPoints[index] = value;
60  mDirty = true;
61}
62void DynamicLines::clear()
63{
64  mPoints.clear();
65  mDirty = true;
66}
67
68void DynamicLines::update()
69{
70  if (mDirty) fillHardwareBuffers();
71}
72
73void DynamicLines::createVertexDeclaration()
74{
75  VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
76  decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
77}
78
79void DynamicLines::fillHardwareBuffers()
80{
81  int size = mPoints.size();
82
83  prepareHardwareBuffers(size,0);
84
85  if (!size) {
86    mBox.setExtents(Vector3::ZERO,Vector3::ZERO);
87    mDirty=false;
88    return;
89  }
90
91  Vector3 vaabMin = mPoints[0];
92  Vector3 vaabMax = mPoints[0];
93
94  HardwareVertexBufferSharedPtr vbuf =
95    mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);
96
97  Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
98  {
99   for(int i = 0; i < size; i++)
100   {
101      *prPos++ = mPoints[i].x;
102      *prPos++ = mPoints[i].y;
103      *prPos++ = mPoints[i].z;
104
105      if(mPoints[i].x < vaabMin.x)
106         vaabMin.x = mPoints[i].x;
107      if(mPoints[i].y < vaabMin.y)
108         vaabMin.y = mPoints[i].y;
109      if(mPoints[i].z < vaabMin.z)
110         vaabMin.z = mPoints[i].z;
111
112      if(mPoints[i].x > vaabMax.x)
113         vaabMax.x = mPoints[i].x;
114      if(mPoints[i].y > vaabMax.y)
115         vaabMax.y = mPoints[i].y;
116      if(mPoints[i].z > vaabMax.z)
117         vaabMax.z = mPoints[i].z;
118   }
119  }
120  vbuf->unlock();
121
122  mBox.setExtents(vaabMin, vaabMax);
123
124  mDirty = false;
125}
126
127/*
128void DynamicLines::getWorldTransforms(Matrix4 *xform) const
129{
130   // return identity matrix to prevent parent transforms
131   *xform = Matrix4::IDENTITY;
132}
133*/
134/*
135const Quaternion &DynamicLines::getWorldOrientation(void) const
136{
137   return Quaternion::IDENTITY;
138}
139
140const Vector3 &DynamicLines::getWorldPosition(void) const
141{
142   return Vector3::ZERO;
143}
144*/
145}
Note: See TracBrowser for help on using the repository browser.