Panda3D

Loading...
Searching...
No Matches
collisionHandlerGravity.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 collisionHandlerGravity.h
10 * @author drose
11 * @date 2002-03-16
12 */
13
14#ifndef CollisionHandlerGravity_H
15#define CollisionHandlerGravity_H
16
17#include "pandabase.h"
18
19#include "collisionHandlerPhysical.h"
20
21/**
22 * A specialized kind of CollisionHandler that sets the Z height of the
23 * collider to a fixed linear offset from the highest detected collision point
24 * each frame. It's intended to implement walking around on a floor of
25 * varying height by casting a ray down from the avatar's head.
26 */
27 class EXPCL_PANDA_COLLIDE CollisionHandlerGravity : public CollisionHandlerPhysical {
28PUBLISHED:
29 CollisionHandlerGravity();
30 virtual ~CollisionHandlerGravity();
31
32 INLINE void set_offset(PN_stdfloat offset);
33 INLINE PN_stdfloat get_offset() const;
34
35 INLINE void set_reach(PN_stdfloat reach);
36 INLINE PN_stdfloat get_reach() const;
37
38 INLINE PN_stdfloat get_airborne_height() const;
39 INLINE bool is_on_ground() const;
40 INLINE PN_stdfloat get_impact_velocity() const;
41 INLINE const LVector3 &get_contact_normal() const;
42
43 INLINE void add_velocity(PN_stdfloat velocity);
44 INLINE void set_velocity(PN_stdfloat velocity);
45 INLINE PN_stdfloat get_velocity() const;
46
47 INLINE void set_gravity(PN_stdfloat gravity);
48 INLINE PN_stdfloat get_gravity() const;
49
50 INLINE void set_max_velocity(PN_stdfloat max_vel);
51 INLINE PN_stdfloat get_max_velocity() const;
52
53 INLINE void set_legacy_mode(bool legacy_mode);
54 INLINE bool get_legacy_mode() const;
55
56PUBLISHED:
57 MAKE_PROPERTY(offset, get_offset, set_offset);
58 MAKE_PROPERTY(reach, get_reach, set_reach);
59 MAKE_PROPERTY(airborne_height, get_airborne_height);
60 MAKE_PROPERTY(on_ground, is_on_ground);
61 MAKE_PROPERTY(impact_velocity, get_impact_velocity);
62 MAKE_PROPERTY(contact_normal, get_contact_normal);
63 MAKE_PROPERTY(velocity, get_velocity, set_velocity);
64 MAKE_PROPERTY(gravity, get_gravity, set_gravity);
65 MAKE_PROPERTY(max_velocity, get_max_velocity, set_max_velocity);
66
67 void write_datagram(Datagram &destination) const;
68 void read_datagram(DatagramIterator &source);
69
70 protected:
71 PN_stdfloat set_highest_collision(const NodePath &target_node_path, const NodePath &from_node_path, const Entries &entries);
72 virtual bool handle_entries();
73 virtual void apply_linear_force(ColliderDef &def, const LVector3 &force);
74
75 private:
76 PN_stdfloat _offset;
77 PN_stdfloat _reach;
78 PN_stdfloat _airborne_height;
79 PN_stdfloat _impact_velocity;
80 PN_stdfloat _gravity;
81 PN_stdfloat _current_velocity;
82 PN_stdfloat _max_velocity;
83 LVector3 _contact_normal;
84 bool _legacy_mode;
85
86
87 public:
88 static TypeHandle get_class_type() {
89 return _type_handle;
90 }
91 static void init_type() {
92 CollisionHandlerPhysical::init_type();
93 register_type(_type_handle, "CollisionHandlerGravity",
94 CollisionHandlerPhysical::get_class_type());
95 }
96 virtual TypeHandle get_type() const {
97 return get_class_type();
98 }
99 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
100
101 private:
102 static TypeHandle _type_handle;
103};
104
105#include "collisionHandlerGravity.I"
106
107#endif
CollisionHandlerEvent::read_datagram
void read_datagram(DatagramIterator &source)
Restores the object state from the given datagram, previously obtained using __getstate__.
Definition collisionHandlerEvent.cxx:182
CollisionHandlerEvent::write_datagram
void write_datagram(Datagram &destination) const
Serializes this object, to implement pickle support.
Definition collisionHandlerEvent.cxx:160
CollisionHandlerGravity::set_velocity
set_velocity
Sets the current vertical velocity.
Definition collisionHandlerGravity.h:63
CollisionHandlerGravity::get_max_velocity
get_max_velocity
Retrieves the maximum speed at which the object will be allowed to descend towards a floor below it,...
Definition collisionHandlerGravity.h:65
CollisionHandlerGravity::set_max_velocity
set_max_velocity
Sets the maximum speed at which the object will be allowed to descend towards a floor below it,...
Definition collisionHandlerGravity.h:65
CollisionHandlerGravity::get_impact_velocity
get_impact_velocity
How hard did the object hit the ground.
Definition collisionHandlerGravity.h:61
CollisionHandlerGravity::is_on_ground
is_on_ground
Is the object at rest?
Definition collisionHandlerGravity.h:60
CollisionHandlerGravity::get_legacy_mode
bool get_legacy_mode() const
returns true if legacy mode is enabled
Definition collisionHandlerGravity.I:174
CollisionHandlerGravity::get_airborne_height
get_airborne_height
Return the height of the object from the ground.
Definition collisionHandlerGravity.h:59
CollisionHandlerGravity::get_reach
get_reach
Returns the reach to add to (or subtract from) the highest collision point.
Definition collisionHandlerGravity.h:58
CollisionHandlerGravity::get_offset
get_offset
Returns the linear offset to add to (or subtract from) the highest detected collision point to determ...
Definition collisionHandlerGravity.h:57
CollisionHandlerGravity::set_legacy_mode
void set_legacy_mode(bool legacy_mode)
Enables old behavior required by Toontown (Sellbot Factory lava room is good test case,...
Definition collisionHandlerGravity.I:166
CollisionHandlerGravity::set_reach
set_reach
Sets the reach to add to (or subtract from) the highest collision point.
Definition collisionHandlerGravity.h:58
CollisionHandlerGravity::set_gravity
set_gravity
Sets the linear gravity force (always plumb).
Definition collisionHandlerGravity.h:64
CollisionHandlerGravity::set_offset
set_offset
Sets the linear offset to add to (or subtract from) the highest detected collision point to determine...
Definition collisionHandlerGravity.h:57
CollisionHandlerGravity::get_gravity
get_gravity
Gets the linear gravity force (always plumb).
Definition collisionHandlerGravity.h:64
CollisionHandlerGravity::add_velocity
void add_velocity(PN_stdfloat velocity)
Adds the sepcified amount to the current velocity.
Definition collisionHandlerGravity.I:97
CollisionHandlerGravity::get_velocity
get_velocity
Gets the current vertical velocity.
Definition collisionHandlerGravity.h:63
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
collisionHandlerGravity.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
collisionHandlerPhysical.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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