-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathvectorvis.cpp
More file actions
71 lines (57 loc) · 1.72 KB
/
Copy pathvectorvis.cpp
File metadata and controls
71 lines (57 loc) · 1.72 KB
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
/*
* Visualize a single vector
*/
#include <iostream>
#include <array>
#include <stdexcept>
#include <string>
#include <memory>
import sm.vec;
import sm.quaternion;
import sm.mat;
import mplot.visual;
import mplot.colour;
import mplot.colourmap;
import mplot.textfeatures;
import mplot.vectorvisual;
int main()
{
mplot::Visual v(1024, 768, "mplot::VectorVisual");
v.lightingEffects();
v.showCoordArrows (true);
v.coordArrowsInScene (true);
sm::vec<float> offset = {1,0,0};
auto vvm = std::make_unique<mplot::VectorVisual<float, 3>>(offset);
vvm->set_parent (v.get_id());
vvm->thevec = {1,1,1};
vvm->fixed_colour = true;
vvm->single_colour = mplot::colour::crimson;
vvm->addLabel ("Rotn by quaternion", {-0.8, -0.5, 0}, mplot::TextFeatures(0.1f));
vvm->finalize();
auto ptr = v.addVisualModel (vvm);
vvm = std::make_unique<mplot::VectorVisual<float, 3>>(-offset);
vvm->set_parent (v.get_id());
vvm->thevec = {1,1,1};
vvm->fixed_colour = true;
vvm->single_colour = mplot::colour::royalblue;
vvm->addLabel ("Rotn by 4x4 mat", {-0.8, -0.5, 0}, mplot::TextFeatures(0.1f));
vvm->finalize();
auto ptr2 = v.addVisualModel (vvm);
float angle_per_frame = 0.05f;
sm::vec<float> axis = {0,1,0.4};
// quaternion way
// Also demo quaternion rotation.
// Set up a rotation about the z axis
sm::quaternion<float> qr (axis, angle_per_frame);
sm::mat<float, 4, 4> tf;
tf.rotate (axis, angle_per_frame);
while (!v.readyToFinish()) {
v.render();
v.wait (0.01);
ptr->thevec = (qr * ptr->thevec);
ptr2->thevec = (tf * ptr2->thevec).less_one_dim();
ptr->reinit();
ptr2->reinit();
}
return 0;
}