1 #ifndef __PICKABLE_HPP__
2 #define __PICKABLE_HPP__
6 #include "al/graphics/al_Graphics.hpp"
7 #include "al/math/al_Ray.hpp"
8 #include "al/ui/al_BoundingBox.hpp"
9 #include "al/ui/al_Parameter.hpp"
10 #include "al/ui/al_ParameterBundle.hpp"
39 PickEvent(PickEventType t,
Rayd r,
float v) : type(t), ray(r), amount(v) {}
41 PickEvent(PickEventType t,
float v) : type(t), amount(v) {}
53 Hit(
bool h,
Rayd r,
double tt,
Pickable *pp) : hit(h), ray(r), t(tt), p(pp) {}
54 Vec3d operator()() {
return hit ? ray(t) :
Vec3d(); }
62 ParameterBool hover{
"hover", name}, selected{
"selected", name};
65 Parameter scale{
"scale", name, 1.0f,
"", 0.0f, 10.0f};
69 std::vector<Pickable *> children;
70 bool testChildren =
true;
71 bool containChildren =
false;
72 bool containedChild =
false;
77 Vec3f scale0, prevScale;
93 void clearSelection();
96 bool intersectsChild(
Rayd &r);
101 void addChild(
Pickable *p) { addChild(*p); }
116 void foreach (std::function<
void(Pickable &p)> pre,
117 std::function<
void(Pickable &p)> post = [](Pickable & ) {
120 for (
auto *c : children) c->foreach (pre, post);
146 Pickable::name = name_;
Interface for loading fonts and rendering text.
Stores buffers related to rendering graphical objects.
std::string name() const
get the name for this bundle
virtual ParameterType get()
get the parameter's value
A local coordinate frame.
Vec3d & pos()
Get "position" vector.
Quatd & quat()
Get quaternion component (represents orientation)
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< 3, double > Vec3d
double 3-vector
void setCenter(Vec3f &pos)
set the pickable's center position
void setQuat(Quatf &q)
set pickable's orientation maintaining same center position
float intersectBoundingSphere(Rayd ray)
intersect ray with bounding sphere
Hit intersect(Rayd r)
override base methods
double intersectAABB(Rayd ray)
intersect ray with pickable AxisAlignedBoundingBox
void set(Mesh &m)
initialize bounding box;
bool onEvent(PickEvent e, Hit h)
override callback
double intersectBB(Rayd localRay)
intersect ray with pickable BoundingBox
void popMatrix(Graphics &g)
pop matrix.
void pushMatrix(Graphics &g)
apply pickable pose transforms
virtual Hit intersect(Rayd r)=0
intersection test must be implemented
Vec3f transformVecLocal(const Vec3f &v, float w=1)
transfrom a vector in world space to local space
Rayd transformRayLocal(const Rayd &ray)
transform a ray in world space to local space
Vec3f transformVecWorld(const Vec3f &v, float w=1)
transfrom a vector in local space to world space
virtual bool onEvent(PickEvent e, Hit hit)
override callback
virtual bool event(PickEvent e)
do interaction on self and children, call onEvent callbacks