-
Notifications
You must be signed in to change notification settings - Fork 31
/
visual.cpp
72 lines (63 loc) · 2.67 KB
/
visual.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
/*
* An example morph::Visual scene, containing a HexGrid.
*/
#include <iostream>
#include <vector>
#include <cmath>
#include <morph/vec.h>
#include <morph/Visual.h>
#include <morph/VisualDataModel.h>
#include <morph/HexGridVisual.h>
#include <morph/HexGrid.h>
int main()
{
// Contructor args are width, height, title, coordinate arrows offset, cooridnate
// arrows lengths, coord arrow thickness, coord arrow label font size (0.0f means no labels)
morph::Visual v(1600, 1000, "morph::Visual", {-0.8,-0.8}, {.05,.05,.05}, 2.0f, 0.0f);
// You can set a field of view (in degrees)
v.fov = 15;
// Should the scene be 'locked' so that movements and rotations are prevented?
v.sceneLocked = false;
// Various methods to set the 'scene translation'. Try pressing 'z' in the app window to see what the current sceneTrans is
v.setSceneTransXY (0.0f, 0.0f);
v.setSceneTransZ (-6.0f);
v.setSceneTrans (morph::vec<float, 3>{0.0f, 0.0f, -6.0f});
// Make this larger to "scroll in and out of the image" faster
v.scenetrans_stepsize = 0.5;
// The coordinate arrows can be hidden
v.showCoordArrows = true;
// The title can be hidden
v.showTitle = true;
// The coord arrows can be displayed within the scene (rather than in, say, the corner)
v.coordArrowsInScene = false;
// You can set the background (white, black, or any other colour)
v.backgroundWhite();
// You can switch on the "lighting shader" which puts diffuse light into the scene
v.lightingEffects();
// Add some text labels to the scene
v.addLabel ("Each object is derived from morph::VisualModel", {0.005f, -0.02f, 0.0f});
v.addLabel ("This is a morph::CoordArrows object", {0.03f, -0.23f, 0.0f});
v.addLabel ("This is a\nmorph::HexGridVisual\nobject", {0.26f, -0.16f, 0.0f});
// Create a HexGrid to show in the scene
morph::HexGrid hg(0.01, 3, 0);
hg.setCircularBoundary (0.3);
std::cout << "Number of hexes in grid:" << hg.num() << std::endl;
// Make some dummy data (a sine wave) to make an interesting surface
std::vector<float> data(hg.num(), 0.0);
for (unsigned int hi=0; hi<hg.num(); ++hi) {
data[hi] = 0.05 + 0.05*std::sin(10*hg.d_x[hi]); // Range 0->1
}
// Add a HexGridVisual to display the HexGrid within the morph::Visual scene
morph::vec<float, 3> offset = { 0.0, -0.05, 0.0 };
auto hgv = std::make_unique<morph::HexGridVisual<float>>(&hg, offset);
v.bindmodel (hgv);
hgv->setScalarData (&data);
hgv->finalize();
v.addVisualModel (hgv);
while (v.readyToFinish == false) {
v.waitevents (0.018);
v.render();
}
v.savegltf("./visual.gltf");
return 0;
}