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  EXTENSION(PyObject *__reduce__(PyObject *self) const);
58  EXTENSION(void __setstate__(PyObject *self, vector_uchar data, PyObject *nodepaths));
59 
60 protected:
61  bool _has_contact; // Are we in contact with anything?
62 
63 
64 protected:
65  class ColliderDef {
66  public:
67  INLINE void set_target(const NodePath &target,
68  DriveInterface *drive_interface = nullptr);
69  INLINE void updated_transform();
70 
71  NodePath _target;
72  PT(DriveInterface) _drive_interface;
73  };
74 
75  virtual bool handle_entries()=0;
76  virtual void apply_linear_force(ColliderDef &def, const LVector3 &force)=0;
77 
78  virtual bool validate_target(const NodePath &target);
79 
80  typedef pvector< PT(CollisionEntry) > Entries;
81  typedef pmap<NodePath, Entries> FromEntries;
82  FromEntries _from_entries;
83 
84  typedef pmap<NodePath, ColliderDef> Colliders;
85  Colliders _colliders;
86 
87  NodePath _center;
88 
89  friend class Extension<CollisionHandlerPhysical>;
90 
91 public:
92  static TypeHandle get_class_type() {
93  return _type_handle;
94  }
95  static void init_type() {
96  CollisionHandlerEvent::init_type();
97  register_type(_type_handle, "CollisionHandlerPhysical",
98  CollisionHandlerEvent::get_class_type());
99  }
100  virtual TypeHandle get_type() const {
101  return get_class_type();
102  }
103  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
104 
105 private:
106  static TypeHandle _type_handle;
107 };
108 
110 
111 #endif
Defines a single collision event.
A specialized kind of CollisionHandler that throws an event for each collision detected.
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
virtual void add_entry(CollisionEntry *entry)
Called between a begin_group() .
virtual bool end_group()
Called by the CollisionTraverser at the completion of all collision detections for this traversal.
The abstract base class for a number of CollisionHandlers that have some physical effect on their mov...
This is a TFormer, similar to Trackball, that moves around a transform matrix in response to mouse in...
The default class template does not define any methods.
Definition: extension.h:34
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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