AGX Dynamics  2.37.3.2
agxSDK/PickHandler.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/agxPhysics_export.h>
21 
22 #include <agxCollide/Geometry.h>
23 #include <agx/Constraint.h>
25 
26 namespace agx
27 {
28  class DistanceJoint;
29  class BallJoint;
30  class LockJoint;
31 }
32 
33 namespace agxSDK
34 {
35  // class to handle events with a pick
37  {
38  public:
39  // Old interface
40  virtual PickResult pick( float /*screenX*/, float /*screenY*/ ) { return PickResult(); };
41 
42  public:
43  PickHandler();
44 
45  virtual void addNotification();
46  virtual void removeNotification();
47 
56  virtual bool attachBody(const agx::Vec3& worldPoint, agx::RigidBody *body, bool useLock = false, bool updateRotation = false);
57 
58  bool attachGeometry(const agx::Vec3& worldPoint, agxCollide::Geometry *geometry, bool useLock = false);
59 
64  virtual bool updateAttachment(const agx::Vec3& mousePositionWorld);
65 
67  bool playbackMode() const;
68 
70  virtual void reset();
71 
73  agx::RigidBody *getRigidBody();
74 
75  agxCollide::Geometry *getAttachedGeometry();
76 
77 
79  agx::Vec3 getCurrentWorldMousePoint() const;
80 
82  agx::Vec3 getWorldAttachmentPoint() const;
83 
84 
85  bool isActive() const;
86 
87  protected:
88  virtual ~PickHandler();
89 
91  bool validate(agx::RigidBody *body);
92 
94  agx::Vec3 getLocalAttachmentPoint() const;
95 
96  void calculateComplianceAndDamping( agx::DistanceJoint* constraint, agx::RigidBody* rb );
97  void calculateComplianceAndDamping( agx::BallJoint* constraint, agx::RigidBody* rb );
98  void calculateComplianceAndDamping( agx::LockJoint* constraint, agx::RigidBody* rb );
99 
100  protected:
101 
105 
107 
108 
110  {
112  PickedParticle(agx::Physics::ParticlePtr p) : particle(p), material(p.material()), color(p.color()) {}
113 
117  };
119 
122 
123  private:
124 
125 
126  agx::Vec3 m_initialMousePointWorld;
127  agx::Vec3 m_currentMousePointWorld;
128  agx::Vec3 m_worldAttachmentPoint;
129  agx::Vec3 m_localAttachmentPoint;
130  agx::Quat m_oldBodyRotation;
131 
132  agx::FrameRef m_constraintWorldFrame;
133  agx::FrameRef m_constraintBodyFrame;
134 
135  agx::ComponentRef m_mouseComponent;
136  agxData::ValueRef m_pickAttachmentPoint;
137  agxData::ValueRef m_pickHandlePoint;
138  agxData::ValueRef m_isPicking;
139  };
140 
142 
143 }
144 
agx::ConstraintRef m_constraint
Pointer to a entity instance of type Physics.Material.
This joint will preserve the initial distance between a body and a point in world coordinate or betwe...
Definition: DistanceJoint.h:27
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
agxCollide::GeometryRef m_geometry
PickedParticle(agx::Physics::ParticlePtr p)
#define AGXPHYSICS_EXPORT
agx::Physics::ParticlePtr m_particle
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::Physics::ParticlePtr particle
Templated vector class.
Definition: Vector.h:52
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:28
Constraint that removes the three translation DOF between two bodies (or one and the world)...
Definition: BallJoint.h:47
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Derive from this class to implement a listener for simulation GuiEvents.
virtual PickResult pick(float, float)
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agx::Physics::MaterialPtr material
agx::MaterialRef m_particleMaterial
agx::Vector< PickedParticle > m_particleSet
Pointer to a entity instance of type Physics.Particle.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agx::ref_ptr< PickHandler > PickHandlerRef
agx::RigidBodyRef m_rigidBody