Panda3D
collisionHandlerPhysical.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file collisionHandlerPhysical.h
10  * @author drose
11  * @date 2002-03-16
12  */
13 
14 #ifndef COLLISIONHANDLERPHYSICAL_H
15 #define COLLISIONHANDLERPHYSICAL_H
16 
17 #include "pandabase.h"
18 
19 #include "collisionHandlerEvent.h"
20 #include "collisionNode.h"
21 
22 #include "driveInterface.h"
23 #include "pointerTo.h"
24 #include "pandaNode.h"
25 
26 /**
27  * The abstract base class for a number of CollisionHandlers that have some
28  * physical effect on their moving bodies: they need to update the nodes'
29  * positions based on the effects of the collision.
30  */
31 class EXPCL_PANDA_COLLIDE CollisionHandlerPhysical : public CollisionHandlerEvent {
32 public:
34  virtual ~CollisionHandlerPhysical();
35 
36  virtual void begin_group();
37  virtual void add_entry(CollisionEntry *entry);
38  virtual bool end_group();
39 
40 PUBLISHED:
41  void add_collider(const NodePath &collider, const NodePath &target);
42  void add_collider(const NodePath &collider, const NodePath &target,
43  DriveInterface *drive_interface);
44  bool remove_collider(const NodePath &collider);
45  bool has_collider(const NodePath &collider) const;
46  void clear_colliders();
47 
48  INLINE void set_center(const NodePath &center);
49  INLINE void clear_center();
50  INLINE const NodePath &get_center() const;
51  INLINE bool has_center() const;
52  INLINE bool has_contact() const;
53 
54 PUBLISHED:
55  MAKE_PROPERTY2(center, has_center, get_center, set_center, clear_center);
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 = nullptr);
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 
77  typedef pvector< PT(CollisionEntry) > Entries;
78  typedef pmap<NodePath, Entries> FromEntries;
79  FromEntries _from_entries;
80 
81  typedef pmap<NodePath, ColliderDef> Colliders;
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 
105 
106 #endif
CollisionHandlerEvent
A specialized kind of CollisionHandler that throws an event for each collision detected.
Definition: collisionHandlerEvent.h:32
pandaNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap< NodePath, Entries >
CollisionEntry
Defines a single collision event.
Definition: collisionEntry.h:42
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
collisionNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionHandlerEvent::add_entry
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
Definition: collisionHandlerEvent.cxx:54
CollisionHandlerEvent::begin_group
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
Definition: collisionHandlerEvent.cxx:40
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
CollisionHandlerEvent::end_group
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal.
Definition: collisionHandlerEvent.cxx:75
DriveInterface
This is a TFormer, similar to Trackball, that moves around a transform matrix in response to mouse in...
Definition: driveInterface.h:31
driveInterface.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionHandlerPhysical
The abstract base class for a number of CollisionHandlers that have some physical effect on their mov...
Definition: collisionHandlerPhysical.h:31
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
collisionHandlerPhysical.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
collisionHandlerEvent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.