AGX Dynamics  2.35.0.1
agxSDK/PickHandler.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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:
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 
74 
76 
77 
80 
83 
84 
85  bool isActive() const;
86 
87  protected:
88  virtual ~PickHandler();
89 
91  bool validate(agx::RigidBody *body);
92 
95 
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 
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Derive from this class to implement a listener for simulation GuiEvents.
agx::MaterialRef m_particleMaterial
agx::RigidBody * getRigidBody()
virtual void removeNotification()
Called when this listener is removed from the simulation.
virtual void reset()
Will detach constraints and reset picked body/geometry.
agx::ConstraintRef m_constraint
virtual void addNotification()
Called when this listener is added to the simulation.
virtual ~PickHandler()
void calculateComplianceAndDamping(agx::LockJoint *constraint, agx::RigidBody *rb)
void calculateComplianceAndDamping(agx::BallJoint *constraint, agx::RigidBody *rb)
bool validate(agx::RigidBody *body)
agx::Vec3 getCurrentWorldMousePoint() const
agxCollide::Geometry * getAttachedGeometry()
agx::Vec3 getWorldAttachmentPoint() const
agx::Vector< PickedParticle > m_particleSet
void calculateComplianceAndDamping(agx::DistanceJoint *constraint, agx::RigidBody *rb)
agxCollide::GeometryRef m_geometry
agx::Physics::ParticlePtr m_particle
virtual PickResult pick(float, float)
agx::RigidBodyRef m_rigidBody
virtual bool updateAttachment(const agx::Vec3 &mousePositionWorld)
Update the attachment point with the mousePositionWorld which is the point of the mouse in world coor...
bool playbackMode() const
bool attachGeometry(const agx::Vec3 &worldPoint, agxCollide::Geometry *geometry, bool useLock=false)
bool isActive() const
virtual bool attachBody(const agx::Vec3 &worldPoint, agx::RigidBody *body, bool useLock=false, bool updateRotation=false)
Attaches a constraint to the specified body.
agx::Vec3 getLocalAttachmentPoint() const
Constraint that removes the three translation DOF between two bodies (or one and the world).
Definition: BallJoint.h:48
This joint will preserve the initial distance between a body and a point in world coordinate or betwe...
Definition: DistanceJoint.h:28
Constraint that removes all 6 DOF between two bodies, or one body and the world.
Definition: LockJoint.h:29
Pointer to a entity instance of type Physics.Material.
Pointer to a entity instance of type Physics.Particle.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
Templated vector class.
Definition: agx/Vector.h:53
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
agx::ref_ptr< PickHandler > PickHandlerRef
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
PickedParticle(agx::Physics::ParticlePtr p)
agx::Physics::MaterialPtr material
agx::Physics::ParticlePtr particle