Panda3D
collisionHandlerPhysical.h
1 // Filename: collisionHandlerPhysical.h
2 // Created by: drose (16Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef COLLISIONHANDLERPHYSICAL_H
16 #define COLLISIONHANDLERPHYSICAL_H
17 
18 #include "pandabase.h"
19 
20 #include "collisionHandlerEvent.h"
21 #include "collisionNode.h"
22 
23 #include "driveInterface.h"
24 #include "pointerTo.h"
25 #include "pandaNode.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : CollisionHandlerPhysical
29 // Description : The abstract base class for a number of
30 // CollisionHandlers that have some physical effect on
31 // their moving bodies: they need to update the nodes'
32 // positions based on the effects of the collision.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_COLLIDE CollisionHandlerPhysical : public CollisionHandlerEvent {
35 public:
37  virtual ~CollisionHandlerPhysical();
38 
39  virtual void begin_group();
40  virtual void add_entry(CollisionEntry *entry);
41  virtual bool end_group();
42 
43 PUBLISHED:
44  void add_collider(const NodePath &collider, const NodePath &target);
45  void add_collider(const NodePath &collider, const NodePath &target,
46  DriveInterface *drive_interface);
47  bool remove_collider(const NodePath &collider);
48  bool has_collider(const NodePath &collider) const;
49  void clear_colliders();
50 
51  INLINE void set_center(const NodePath &center);
52  INLINE void clear_center();
53  INLINE const NodePath &get_center() const;
54  INLINE bool has_center() const;
55  INLINE bool has_contact() const;
56 
57 protected:
58  bool _has_contact; // Are we in contact with anything?
59 
60 
61 protected:
62  class ColliderDef {
63  public:
64  INLINE void set_target(const NodePath &target,
65  DriveInterface *drive_interface = NULL);
66  INLINE void updated_transform();
67 
68  NodePath _target;
69  PT(DriveInterface) _drive_interface;
70  };
71 
72  virtual bool handle_entries()=0;
73  virtual void apply_linear_force(ColliderDef &def, const LVector3 &force)=0;
74 
75  virtual bool validate_target(const NodePath &target);
76 
79  FromEntries _from_entries;
80 
82  Colliders _colliders;
83 
84  NodePath _center;
85 
86 public:
87  static TypeHandle get_class_type() {
88  return _type_handle;
89  }
90  static void init_type() {
91  CollisionHandlerEvent::init_type();
92  register_type(_type_handle, "CollisionHandlerPhysical",
93  CollisionHandlerEvent::get_class_type());
94  }
95  virtual TypeHandle get_type() const {
96  return get_class_type();
97  }
98  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
99 
100 private:
101  static TypeHandle _type_handle;
102 };
103 
104 #include "collisionHandlerPhysical.I"
105 
106 #endif
107 
108 
109 
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal...
This is a TFormer, similar to Trackball, that moves around a transform matrix in response to mouse in...
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
The abstract base class for a number of CollisionHandlers that have some physical effect on their mov...
Defines a single collision event.
A specialized kind of CollisionHandler that throws an event for each collision detected.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .