Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/map/src/orxonox/tools/DynamicLines.cpp @ 3010

Last change on this file since 3010 was 2942, checked in by Naaduun, 16 years ago

=added dynamic libs to orxonox/tools. changed humancontroller to use mouseview

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