Panda3D
 All Classes Functions Variables Enumerations
collisionHandlerGravity.h
1 // Filename: CollisionHandlerGravity.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 CollisionHandlerGravity_H
16 #define CollisionHandlerGravity_H
17 
18 #include "pandabase.h"
19 
20 #include "collisionHandlerPhysical.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : CollisionHandlerGravity
24 // Description : A specialized kind of CollisionHandler that sets the
25 // Z height of the collider to a fixed linear offset
26 // from the highest detected collision point each frame.
27 // It's intended to implement walking around on a floor
28 // of varying height by casting a ray down from the
29 // avatar's head.
30 ////////////////////////////////////////////////////////////////////
31 class EXPCL_PANDA_COLLIDE CollisionHandlerGravity : public CollisionHandlerPhysical {
32 PUBLISHED:
34  virtual ~CollisionHandlerGravity();
35 
36  INLINE void set_offset(PN_stdfloat offset);
37  INLINE PN_stdfloat get_offset() const;
38 
39  INLINE void set_reach(PN_stdfloat reach);
40  INLINE PN_stdfloat get_reach() const;
41 
42  INLINE PN_stdfloat get_airborne_height() const;
43  INLINE bool is_on_ground() const;
44  INLINE PN_stdfloat get_impact_velocity() const;
45  INLINE const LVector3 &get_contact_normal() const;
46 
47  INLINE void add_velocity(PN_stdfloat velocity);
48  INLINE void set_velocity(PN_stdfloat velocity);
49  INLINE PN_stdfloat get_velocity() const;
50 
51  INLINE void set_gravity(PN_stdfloat gravity);
52  INLINE PN_stdfloat get_gravity() const;
53 
54  INLINE void set_max_velocity(PN_stdfloat max_vel);
55  INLINE PN_stdfloat get_max_velocity() const;
56 
57  INLINE void set_legacy_mode(bool legacy_mode);
58  INLINE bool get_legacy_mode() const;
59 
60 protected:
61  PN_stdfloat set_highest_collision(const NodePath &target_node_path, const NodePath &from_node_path, const Entries &entries);
62  virtual bool handle_entries();
63  virtual void apply_linear_force(ColliderDef &def, const LVector3 &force);
64 
65 private:
66  PN_stdfloat _offset;
67  PN_stdfloat _reach;
68  PN_stdfloat _airborne_height;
69  PN_stdfloat _impact_velocity;
70  PN_stdfloat _gravity;
71  PN_stdfloat _current_velocity;
72  PN_stdfloat _max_velocity;
73  LVector3 _contact_normal;
74  bool _legacy_mode;
75 
76 
77 public:
78  static TypeHandle get_class_type() {
79  return _type_handle;
80  }
81  static void init_type() {
82  CollisionHandlerPhysical::init_type();
83  register_type(_type_handle, "CollisionHandlerGravity",
84  CollisionHandlerPhysical::get_class_type());
85  }
86  virtual TypeHandle get_type() const {
87  return get_class_type();
88  }
89  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
90 
91 private:
92  static TypeHandle _type_handle;
93 };
94 
95 #include "collisionHandlerGravity.I"
96 
97 #endif
98 
99 
100 
A specialized kind of CollisionHandler that sets the Z height of the collider to a fixed linear offse...
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...
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