Panda3D
Loading...
Searching...
No Matches
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
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 */
31class EXPCL_PANDA_COLLIDE CollisionHandlerPhysical : public CollisionHandlerEvent {
32public:
33 CollisionHandlerPhysical();
34 virtual ~CollisionHandlerPhysical();
35
36 virtual void begin_group();
37 virtual void add_entry(CollisionEntry *entry);
38 virtual bool end_group();
39
40PUBLISHED:
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
54PUBLISHED:
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
60protected:
61 bool _has_contact; // Are we in contact with anything?
62
63
64protected:
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
90
91public:
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
105private:
106 static TypeHandle _type_handle;
107};
108
110
111#endif
Defines a single collision event.
virtual void begin_group()
Will be called by the CollisionTraverser before a new traversal is begun.
CollisionHandlerEvent()
The default CollisionHandlerEvent will throw no events.
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...
bool has_contact() const
Did the handler make any contacts with anything on the last collision pass?
has_center
Returns true if a NodePath has been specified with set_center(), false otherwise.
clear_center
Clears the center NodePath specified with set_center.
void add_collider(const NodePath &collider, const NodePath &target)
Adds a new collider to the list with a NodePath that will be updated with the collider's new position...
bool remove_collider(const NodePath &collider)
Removes the collider from the list of colliders that this handler knows about.
void clear_colliders()
Completely empties the list of colliders this handler knows about.
bool has_collider(const NodePath &collider) const
Returns true if the handler knows about the indicated collider, false otherwise.
set_center
Specifies an arbitrary NodePath that the handler is always considered to be facing.
get_center
Returns the NodePath specified with set_center, or the empty NodePath if nothing has been specified.
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
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(),...