-
Notifications
You must be signed in to change notification settings - Fork 18
/
DynamicLines.h
161 lines (132 loc) · 5.35 KB
/
DynamicLines.h
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
155
156
157
158
159
160
161
#ifndef _DYNAMIC_LINES_H_
#define _DYNAMIC_LINES_H_
#include <OgreSimpleRenderable.h>
#include <vector>
/// Abstract base class providing mechanisms for dynamically growing hardware buffers.
class DynamicRenderable : public Ogre::SimpleRenderable
{
public:
/// Constructor
DynamicRenderable();
/// Virtual destructor
virtual ~DynamicRenderable();
/** Initializes the dynamic renderable.
@remarks
This function should only be called once. It initializes the
render operation, and calls the abstract function
createVertexDeclaration().
@param operationType The type of render operation to perform.
@param useIndices Specifies whether to use indices to determine the
vertices to use as input. */
void initialize(Ogre::RenderOperation::OperationType operationType,
bool useIndices);
/// Implementation of Ogre::SimpleRenderable
virtual Ogre::Real getBoundingRadius(void) const;
/// Implementation of Ogre::SimpleRenderable
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
protected:
/// Maximum capacity of the currently allocated vertex buffer.
size_t mVertexBufferCapacity;
/// Maximum capacity of the currently allocated index buffer.
size_t mIndexBufferCapacity;
/** Creates the vertex declaration.
@remarks
Override and set mRenderOp.vertexData->vertexDeclaration here.
mRenderOp.vertexData will be created for you before this method
is called. */
virtual void createVertexDeclaration() = 0;
/** Prepares the hardware buffers for the requested vertex and index counts.
@remarks
This function must be called before locking the buffers in
fillHardwareBuffers(). It guarantees that the hardware buffers
are large enough to hold at least the requested number of
vertices and indices (if using indices). The buffers are
possibly reallocated to achieve this.
@par
The vertex and index count in the render operation are set to
the values of vertexCount and indexCount respectively.
@param vertexCount The number of vertices the buffer must hold.
@param indexCount The number of indices the buffer must hold. This
parameter is ignored if not using indices. */
void prepareHardwareBuffers(size_t vertexCount, size_t indexCount);
/** Fills the hardware vertex and index buffers with data.
@remarks
This function must call prepareHardwareBuffers() before locking
the buffers to ensure the they are large enough for the data to
be written. Afterwards the vertex and index buffers (if using
indices) can be locked, and data can be written to them. */
virtual void fillHardwareBuffers() = 0;
};
class DynamicLines : public DynamicRenderable
{
typedef Ogre::Vector3 Vector3;
typedef Ogre::Quaternion Quaternion;
typedef Ogre::Camera Camera;
typedef Ogre::Real Real;
typedef Ogre::RenderOperation::OperationType OperationType;
public:
/// Constructor - see setOperationType() for description of argument.
DynamicLines(OperationType opType=Ogre::RenderOperation::OT_LINE_STRIP);
virtual ~DynamicLines();
/// Add a point to the point list
void addPoint(const Ogre::Vector3 &p);
/// Add a point to the point list
void addPoint(Real x, Real y, Real z);
/// Change the location of an existing point in the point list
void setPoint(unsigned short index, const Vector3 &value);
/// Return the location of an existing point in the point list
const Vector3& getPoint(unsigned short index) const;
/// Return the total number of points in the point list
unsigned short getNumPoints(void) const;
/// Remove all points from the point list
void clear();
/// Call this to update the hardware buffer after making changes.
void update();
/** Set the type of operation to draw with.
* @param opType Can be one of
* - RenderOperation::OT_LINE_STRIP
* - RenderOperation::OT_LINE_LIST
* - RenderOperation::OT_POINT_LIST
* - RenderOperation::OT_TRIANGLE_LIST
* - RenderOperation::OT_TRIANGLE_STRIP
* - RenderOperation::OT_TRIANGLE_FAN
* The default is OT_LINE_STRIP.
*/
void setOperationType(OperationType opType);
OperationType getOperationType() const;
protected:
/// Implementation DynamicRenderable, creates a simple vertex-only decl
virtual void createVertexDeclaration();
/// Implementation DynamicRenderable, pushes point list out to hardware memory
virtual void fillHardwareBuffers();
std::vector<Vector3> mPoints;
bool mDirty;
};
class GeoCells : public DynamicRenderable {
typedef Ogre::Vector3 Vector3;
typedef Ogre::Quaternion Quaternion;
typedef Ogre::Camera Camera;
typedef Ogre::Real Real;
typedef Ogre::RenderOperation::OperationType OperationType;
public:
GeoCells(float x, float y);
virtual ~GeoCells();
void addCell(uint16_t x, uint16_t y, short height, uint8_t nswe, uint8_t type);
/// Remove all points from the point list
void clear();
/// Call this to update the hardware buffer after making changes.
void update();
protected:
/// Implementation DynamicRenderable, creates a simple vertex-only decl
virtual void createVertexDeclaration();
/// Implementation DynamicRenderable, pushes point list out to hardware memory
virtual void fillHardwareBuffers();
struct GeoCell {
int16_t position[4];
};
float baseX;
float baseY;
std::vector<GeoCell> mCells;
bool mDirty;
};
#endif