Allolib  1.0
C++ Components For Interactive Multimedia
al_Gnomon.hpp
1 #ifndef INCLUDE_AL_GNOMON_HPP
2 #define INCLUDE_AL_GNOMON_HPP
3 
4 #include "al/graphics/al_Font.hpp"
5 #include "al/graphics/al_Graphics.hpp"
6 #include "al/graphics/al_Mesh.hpp"
7 #include "al/graphics/al_Shapes.hpp"
8 #include "al/types/al_Color.hpp"
9 
10 namespace al {
11 
14 struct Gnomon {
15  Mesh gnomonMesh;
16  Mesh arrowMesh;
17 
18  // static Gnomon gnomon;
19 
20  Color colors[3];
21  const char *labels[3];
22 
23  Gnomon();
24 
25  void draw(Graphics &g);
26 
28  void drawFloating(Graphics &g, Pose pose = Pose(), double scale = 1.0);
29 
31  void drawAtPos(Graphics &g, Vec3f pos, Pose cam_pose = Pose(),
32  double scale = 1.0);
33 
34  void drawOrigin(Graphics &g, Pose cam_pose = Pose(), double scale = 1.0);
35 
37  void drawAtPose(Graphics &g, Pose pose, Pose cam_pose = Pose(),
38  double scale = 1.0);
39 
40  void drawArrows(Graphics &g);
41 
42  void drawLabels(Graphics &g, FontRenderer &fontrender, Pose cam_pose,
43  double scale = 1.0, Vec3f offset = Vec3f(0, 0, 0)) {
44  // XYZ labels
45  g.polygonFill();
46  // glEnable(GL_BLEND);
47  // glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
48  // glEnable(GL_ALPHA_TEST);
49  // glAlphaFunc(GL_GREATER, 0.5);
50  g.blending(true);
51  g.blendTrans();
52  for (int i = 0; i < 3; i++) {
53  g.pushMatrix();
54  Vec3f xform = gnomonMesh.vertices()[(i * 2) + 1];
55  Vec3d forward = Vec3d(cam_pose.pos() - xform - offset).normalize();
56  Quatd rot = Quatd::getBillboardRotation(forward, cam_pose.uu());
57 
58  g.translate(xform);
59  g.rotate(rot);
60  g.scale(scale);
61 
62  g.color(colors[i]);
63  fontrender.write(labels[i], 0.1);
64  fontrender.render(g);
65  g.popMatrix();
66  }
67  // glDisable(GL_ALPHA_TEST);
68  // glDisable(GL_BLEND);
69  }
70 };
71 
72 } // namespace al
73 // Gnomon Gnomon::gnomon;
74 
75 #endif
Interface for loading fonts and rendering text.
Definition: al_Graphics.hpp:63
void blending(bool doBlend)
Turn blending on/off.
Definition: al_Graphics.hpp:81
void polygonFill()
Draw filled polygons.
void blendTrans()
Set blend mode to transparent (asymmetric)
Stores buffers related to rendering graphical objects.
Definition: al_Mesh.hpp:62
A local coordinate frame.
Definition: al_Pose.hpp:63
Vec3d uu() const
Get up unit vector.
Definition: al_Pose.hpp:153
Vec3d & pos()
Get "position" vector.
Definition: al_Pose.hpp:100
static Quat getBillboardRotation(const Vec< 3, double > &forward, const Vec< 3, double > &up)
Definition: al_Quat.hpp:1031
void rotate(float angle, float x=0., float y=0., float z=1.)
void scale(float x, float y, float z=1.)
Scale current matrix along each dimension.
void translate(float x, float y, float z=0.)
Translate current matrix.
void popMatrix()
Pop current matrix stack.
void pushMatrix()
Push current matrix stack.
Vec & normalize(T scale=T(1))
Set magnitude to one without changing direction.
Definition: al_Vec.hpp:729
Definition: al_App.hpp:23
Vec< 3, double > Vec3d
double 3-vector
Definition: al_Vec.hpp:60
Vec< 3, float > Vec3f
float 3-vector
Definition: al_Vec.hpp:59
Convenience class to simplify rendering text.
Definition: al_Font.hpp:138
void drawAtPose(Graphics &g, Pose pose, Pose cam_pose=Pose(), double scale=1.0)
Gnomon at any pose.
void drawFloating(Graphics &g, Pose pose=Pose(), double scale=1.0)
floating gnomon in front of camera
void drawAtPos(Graphics &g, Vec3f pos, Pose cam_pose=Pose(), double scale=1.0)
Gnomon at any position.