-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvectorfield_main.cpp
171 lines (140 loc) · 4.45 KB
/
vectorfield_main.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <omega.h>
#include <omegaGl.h>
#include <iostream>
#include <vector>
#include "VectorField.h"
using namespace std;
using namespace omega;
///////////////////////////////////////////////////////////////////////////////
class VectorFieldRenderModule : public EngineModule
{
public:
VectorFieldRenderModule() :
EngineModule("VectorFieldRenderModule"), visible(true)
{
vectorfield = new vectorfield::VectorField();
}
virtual void initializeRenderer(Renderer* r);
virtual void update(const UpdateContext& context)
{
// After a frame all render passes had a chance to update their
// textures. reset the raster update flag.
}
virtual void dispose()
{
if(vectorfield)
delete vectorfield;
}
void init( const float min_x, const float min_z,
const float max_x, const float max_z,
const float cell_size, const float height )
{
vectorfield->init(min_x, min_z, max_x, max_z, cell_size, height);
}
void addControlPoint(const float px, const float pz,
const float vx, const float vz)
{
vectorfield->addControlPoint(px, pz, vx, vz);
}
void updateVectorField()
{
vectorfield->update();
}
void setVisible(bool v)
{
visible = v;
}
void toggleVisible()
{
visible = !visible;
}
void setPointScale(float ps)
{
vectorfield->setPointScale(ps);
}
void setArrowScale(float as)
{
vectorfield->setArrowScale(as);
}
void nextParticleType()
{
if(vectorfield->getParticleType() == TYPE_POINT)
vectorfield->setParticleType(TYPE_ARROW);
else
vectorfield->setParticleType(TYPE_POINT);
}
void loadElevationFromFile(string txtfile)
{
vectorfield->loadElevationFromFile(txtfile);
}
void setElevationScale(float es)
{
vectorfield->setElevationScale(es);
}
vectorfield::VectorField* vectorfield;
bool visible;
};
///////////////////////////////////////////////////////////////////////////////
class VectorFieldRenderPass : public RenderPass
{
public:
VectorFieldRenderPass(Renderer* client, VectorFieldRenderModule* prm) :
RenderPass(client, "VectorFieldRenderPass"),
module(prm) {}
virtual void initialize()
{
RenderPass::initialize();
}
virtual void render(Renderer* client, const DrawContext& context)
{
if(context.task == DrawContext::SceneDrawTask)
{
glPushAttrib(GL_TEXTURE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
client->getRenderer()->beginDraw3D(context);
if(module->visible)
{
float* MV = context.modelview.cast<float>().data();
float* P = context.projection.cast<float>().data();
module->vectorfield->render(MV, P);
if(oglError) return;
}
client->getRenderer()->endDraw();
glPopAttrib();
}
}
private:
VectorFieldRenderModule* module;
};
///////////////////////////////////////////////////////////////////////////////
void VectorFieldRenderModule::initializeRenderer(Renderer* r)
{
r->addRenderPass(new VectorFieldRenderPass(r, this));
}
///////////////////////////////////////////////////////////////////////////////
VectorFieldRenderModule* initialize()
{
VectorFieldRenderModule* prm = new VectorFieldRenderModule();
ModuleServices::addModule(prm);
prm->doInitialize(Engine::instance());
return prm;
}
///////////////////////////////////////////////////////////////////////////////
// Python API
#include "omega/PythonInterpreterWrapper.h"
BOOST_PYTHON_MODULE(vectorfield)
{
//
PYAPI_REF_BASE_CLASS(VectorFieldRenderModule)
PYAPI_METHOD(VectorFieldRenderModule, init)
PYAPI_METHOD(VectorFieldRenderModule, addControlPoint)
PYAPI_METHOD(VectorFieldRenderModule, updateVectorField)
PYAPI_METHOD(VectorFieldRenderModule, setVisible)
PYAPI_METHOD(VectorFieldRenderModule, toggleVisible)
PYAPI_METHOD(VectorFieldRenderModule, setPointScale)
PYAPI_METHOD(VectorFieldRenderModule, setArrowScale)
PYAPI_METHOD(VectorFieldRenderModule, nextParticleType)
PYAPI_METHOD(VectorFieldRenderModule, loadElevationFromFile)
PYAPI_METHOD(VectorFieldRenderModule, setElevationScale)
;
def("initialize", initialize, PYAPI_RETURN_REF);
}