3#include <cgv/gui/mouse_event.h>
4#include <cgv/math/ftransform.h>
5#include <cgv/math/intersection.h>
19 if(_geometry_out_of_date) {
21 _geometry_out_of_date =
false;
24 if(keep_screen_size_constant) {
27 if(lock_size_during_interaction) {
28 if(!_captured_mouse || _size < 0.0f)
29 _size = adjusted_size;
31 _size = adjusted_size;
41 if(_orientation == GizmoOrientation::kLocal)
71 vec2 viewport_size =
vec2(viewport.
z(), viewport.
w());
75 static_cast<int>(me.
get_x()),
76 viewport_size.
y() -
static_cast<int>(me.
get_y()) - 1
87 bool was_hovered = _hovered;
88 InteractionFeature last_feature = _interaction_feature;
89 AxisId last_axis_id = _interaction_axis_id;
93 ray_object.origin -= _position;
94 ray_object.origin /= _size;
96 if(_orientation == GizmoOrientation::kLocal) {
101 _hovered = intersect_bounding_box(ray_object) && intersect(ray_object);
103 if(was_hovered != _hovered || last_feature != _interaction_feature || last_axis_id != _interaction_axis_id) {
104 set_geometry_out_of_date();
111 if(_hovered && _interaction_feature != InteractionFeature::kNone) {
112 if(start_drag(ray)) {
113 _drag_start_ray = ray;
114 _captured_mouse =
true;
121 if(_captured_mouse) {
123 _captured_mouse =
false;
124 _interaction_feature = InteractionFeature::kNone;
125 set_geometry_out_of_date();
130 if(_captured_mouse && drag(ray))
140GizmoOrientation gizmo::get_orientation()
const {
144void gizmo::set_orientation(GizmoOrientation orientation) {
145 _orientation = orientation;
149vec3 gizmo::get_position()
const {
153void gizmo::set_position(
const vec3& position) {
154 _position = position;
158quat gizmo::get_rotation()
const {
162void gizmo::set_rotation(
const quat& rotation) {
163 _rotation = rotation;
167float gizmo::get_size()
const {
175void gizmo::set_geometry_out_of_date() {
176 _geometry_out_of_date =
true;
179bool gizmo::captured_mouse()
const {
180 return _captured_mouse;
183bool gizmo::is_hovered()
const {
187vec3 gizmo::get_axis(
int index)
const {
188 assert(index >= 0 && index < 3);
194vec3 gizmo::get_axis_mask(InteractionFeature feature, AxisId axis_id)
const {
196 case InteractionFeature::kAxis:
197 return get_axis(axis_id_to_index(axis_id));
198 case InteractionFeature::kPlane:
199 return vec3(1.0f) - get_axis(axis_id_to_index(axis_id));
200 case InteractionFeature::kCenter:
207int gizmo::axis_id_to_index(AxisId axis)
const {
208 return static_cast<int>(axis);
211gizmo::AxisId gizmo::index_to_axis_id(
int idx)
const {
212 assert(idx >= 0 && idx < 3);
213 return static_cast<AxisId
>(idx);
void finish_frame(cgv::render::context &) override
this method is called in one pass over all drawables after drawing
bool handle(cgv::gui::event &e) override
overload and implement this method to handle events
bool get_active() const
return whether the current node is active
unsigned get_kind() const
return, what kind of event this is, typically a value from the EventId enum
class to represent all possible mouse events with the EID_MOUSE
short get_y() const
current mouse y position (origin is top-left of window)
MouseAction get_action() const
return the mouse action
short get_x() const
current mouse x position (origin is top-left of window)
void inverse_rotate(vec_type &image) const
rotate vector according to the inverse quaternion
hmat_type get_homogeneous_matrix() const
return equivalent 4x4 rotation matrix
This class defines a template for n-dimensional rays with arbitrary data type defined by origin and d...
base class for all drawables, which is independent of the used rendering API.
void set_blend_func_back_to_front()
set the default blend function for back to front blending
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
void push_depth_test_state()
push a copy of the current depth test state onto the stack saved attributes: depth test enablement,...
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
virtual void disable_depth_test()
disable the depth test
void pop_blend_state()
pop the top of the current culling state from the stack
void pop_depth_test_state()
pop the top of the current depth test state from the stack
virtual dmat4 get_projection_matrix() const =0
return homogeneous 4x4 projection matrix, which transforms from eye to clip space
const std::vector< window_transformation > & get_window_transformation_array() const
return the current window transformation array
virtual void enable_blending()
enable blending
virtual dmat4 get_modelview_matrix() const =0
return homogeneous 4x4 viewing matrix, which transforms from world to eye space
void pop_modelview_matrix()
see push_V for an explanation
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
context * get_context() const
access the current context. The context will be available latestly in the init method but not in the ...
view * find_view_as_node(size_t view_idx=0) const
convenience function to find the view control in the current hierarchy
void post_redraw()
posts a redraw event to the current context if one is available
defines a symmetric view with the following quantities:
const dvec3 get_eye() const
query the eye point, which is computed from focus, view dir, y extent at focus and y view angle
const dvec3 & get_view_dir() const
query current view direction
double get_tan_of_half_of_fovy(bool ensure_non_zero) const
compute tan of half of y view angle, if ensure_non_zero is true, replace y view angles < 0....
@ MA_PRESS
mouse button pressed
@ MA_MOVE
mouse pointer moved
@ MA_DRAG
mouse drag action
@ MA_RELEASE
mouse button released
@ EID_MOUSE
id for mouse event
namespace for api independent GPU programming
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors