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