AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
agxOSG/PickHandler.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
20#include <osgText/Text>
21#include <osg/Geometry>
22#include <osgViewer/Viewer>
23#include <agx/PopDisableWarnings.h> // End of disabled warnings.
24
25#include <agxOSG/GeometryNode.h>
26
27#include <agx/RigidBody.h>
28#include <agxSDK/PickHandler.h>
29
30namespace agxOSG
31{
32 class AGXOSG_EXPORT Panel : public osg::Geode
33 {
34 public:
36 Panel( const agx::Vec2& position, const agx::Vec2& size, const agx::Vec4& color );
37
38 void setPosition( const agx::Vec2& position );
39 const agx::Vec2& getPosition() const { return m_position; }
40
41 void setSize( const agx::Vec2& size );
42 const agx::Vec2& getSize() const { return m_size; }
43
44 void setColor( const agx::Vec4& color );
46
47 virtual void uninitialize( osg::Group* sceneData ) = 0;
48 virtual bool isValid() const = 0;
49 virtual void update() = 0;
50 virtual bool match( const void* obj ) const = 0;
51
52 protected:
53 virtual ~Panel() {}
54 void initialize();
55
56 protected:
59
60 osg::ref_ptr<osg::Geometry> m_geometry;
61 osg::ref_ptr<osg::Vec3Array> m_vertices;
62 osg::ref_ptr<osg::DrawElementsUInt> m_indices;
63 osg::ref_ptr<osg::Vec4Array> m_color;
64 osg::ref_ptr<osg::Vec3Array> m_normals;
65 };
66
67 typedef osg::ref_ptr< Panel > PanelRef;
68
70
71 // class to handle events with a pick
72
73 // Testclass for the new design of PickHandler
76 {
77 public:
79
80 PickHandler( osgViewer::Viewer *viewer, osg::Group *scene=nullptr);
81
82
84 void reset();
85
87 void setActivateModKeyMask(unsigned int modKey );
88
90 void setActivateMouseButton(unsigned int mouse);
91
93 unsigned int getActivateModKeyMask() const;
94
96 unsigned int getActivateMouseButton() const;
97
100 agxSDK::PickResult intersect(float screenX, float screenY, bool onlyDynamics);
101
103 void getNearFarPoints(const osg::Camera* camera, agx::Vec3& near, agx::Vec3& far, float x, float y, bool useOldMatrix = false) const;
104
106 const osg::Camera *getCamera() const;
107
108 virtual bool keyboard(int key, unsigned int modKeyMask, float x, float y, bool keydown);
109
115 virtual bool mouse(MouseButtonMask button, MouseState state, float x, float y);
116 virtual bool mouseDragged(MouseButtonMask buttonMask, float x, float y);
117 virtual void update(float x, float y);
118
119 protected:
120
121
122 virtual ~PickHandler();
123
124 private:
125
126 unsigned int m_modKeyMask;
127 unsigned int m_key;
128 osg::Matrix m_cameraMatrix;
129 osg::observer_ptr< osgViewer::Viewer > m_viewer;
130 osg::observer_ptr< osg::Group > m_scene;
131 osg::observer_ptr< osg::Camera > m_camera;
132
133 unsigned int m_activateModKeyMask;
134 unsigned int m_activateMouseKey;
135
136
137 public: // Old interface
138 virtual agxSDK::PickResult pick( float screenX, float screenY );
139
140
141 void createMouseSpringRendering(float scale);
144 void setCamera(osg::Camera *camera);
145
146 private:
147 void init();
148
149 bool isInitialized() const { return m_initialized; }
150 void updateClickedGeometry(MouseState state, float x, float y);
151
152 // void createConstraint( const agx::Vec3& worldPoint );
153 bool intersect( float screenX, float screenY, const osg::Camera* camera, agxCollide::LocalGeometryContactVector& result ) const;
154 void startPick(float x, float y);
155 void updatePanels(float x, float y);
156 void updateUnphysical(agx::Vec3 direction, agx::Vec3 currentMousePoint);
157
158
159 void traverseParticles();
160
161 // Internal helper methods for mouse handling.
162 bool mouseDown(MouseButtonMask button, float x, float y);
163 bool mouseDownLeftButton(float x, float y);
164 bool mouseDownMiddleButton(float x, float y);
165 bool mouseDownRightButton(float x, float y);
166
167
168
169 private: // Old interface
170
171 agx::RigidBodyRef m_mousePickBody;
172
173 bool m_initialized;
174 bool m_useLock;
175 bool m_moveUnphysically;
176 bool m_inDragging;
177
178 agx::Vec3 m_rotationFromStart;
179 agx::Quat m_oldBodyRotation;
180 agx::Vec3 m_oldBodyCMOffset;
181 agx::Vec3 m_localPoint;
182 agx::Real m_distance;
183
184
185
186 osg::PositionAttitudeTransform *m_mouseAttachTransform;
187 osg::PositionAttitudeTransform *m_mousePositionTransform;
188 osg::Geometry *m_mouseSpringLine;
189 osg::observer_ptr< osg::Switch > m_mouseMarkerSwitch;
190 PanelContainer m_panels;
191
192 osg::observer_ptr< osg::Switch > m_sphereSwitch;
193
194 float m_mousePickingGraphicsScale;
195
196 };
197}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXOSG_EXPORT
#define m_size
Definition: agx/Vector.h:429
void setColor(const agx::Vec4 &color)
osg::ref_ptr< osg::Vec4Array > m_color
void setPosition(const agx::Vec2 &position)
virtual void update()=0
virtual void uninitialize(osg::Group *sceneData)=0
const agx::Vec2 & getPosition() const
virtual bool match(const void *obj) const =0
const agx::Vec2 & getSize() const
agx::Vec2 m_position
osg::ref_ptr< osg::Vec3Array > m_normals
virtual bool isValid() const =0
osg::ref_ptr< osg::Vec3Array > m_vertices
void setSize(const agx::Vec2 &size)
Panel(const agx::Vec2 &position, const agx::Vec2 &size, const agx::Vec4 &color)
osg::ref_ptr< osg::Geometry > m_geometry
agx::Vec4 getColor() const
osg::ref_ptr< osg::DrawElementsUInt > m_indices
void initialize()
unsigned int getActivateMouseButton() const
void setCamera(osg::Camera *camera)
void setActivateMouseButton(unsigned int mouse)
Specify the mousekey that will activate the PickHandler, for example RIGHT_MOUSE_BUTTON.
virtual agxSDK::PickResult pick(float screenX, float screenY)
virtual ~PickHandler()
unsigned int getActivateModKeyMask() const
void setActivateModKeyMask(unsigned int modKey)
Specify the modkeymask that will activate the PickHandler, for example MODKEY_LEFT_SHIFT.
virtual bool mouseDragged(MouseButtonMask buttonMask, float x, float y)
Called when one or more mouse buttons are pressed and moved.
void getNearFarPoints(const osg::Camera *camera, agx::Vec3 &near, agx::Vec3 &far, float x, float y, bool useOldMatrix=false) const
Get the near and far points based on the current camera pose.
virtual bool keyboard(int key, unsigned int modKeyMask, float x, float y, bool keydown)
virtual bool mouse(MouseButtonMask button, MouseState state, float x, float y)
const osg::Camera * getCamera() const
virtual void update(float x, float y)
Called once per simulation frame.
void createMouseSpringRendering(float scale)
void setSimulation(agxSDK::Simulation *simulation)
agxSDK::PickHandler base
agxSDK::PickResult intersect(float screenX, float screenY, bool onlyDynamics)
PickHandler(osgViewer::Viewer *viewer, osg::Group *scene=nullptr)
void reset()
Will detach any constrained rigidbody.
void setSimulation(Simulation *simulation)
Set the associated simulation for this EventListener.
agxSDK::PickResult intersect(const agx::Vec3 &start, const agx::Vec3 &end, bool onlyDynamics)
Shoot a ray from start to end into the space and calculate the closest geometry.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
agx::Vector< PanelRef > PanelContainer
osg::ref_ptr< Panel > PanelRef
double Real
Definition: Real.h:41