Panda3D
Public Member Functions | Static Public Member Functions | Protected Member Functions

CollisionHandlerGravity Class Reference

A specialized kind of CollisionHandler that sets the Z height of the collider to a fixed linear offset from the highest detected collision point each frame. More...

#include "collisionHandlerGravity.h"

Inheritance diagram for CollisionHandlerGravity:
CollisionHandlerPhysical CollisionHandlerEvent CollisionHandler TypedReferenceCount TypedObject ReferenceCount MemoryBase MemoryBase

List of all members.

Public Member Functions

void add_velocity (PN_stdfloat velocity)
 Adds the sepcified amount to the current velocity.
virtual TypeHandle force_init_type ()
PN_stdfloat get_airborne_height () const
 Return the height of the object from the ground.
const LVector3get_contact_normal () const
PN_stdfloat get_gravity () const
 Gets the linear gravity force (always plumb).
PN_stdfloat get_impact_velocity () const
 How hard did the object hit the ground.
bool get_legacy_mode () const
 returns true if legacy mode is enabled
PN_stdfloat get_max_velocity () const
 Retrieves the maximum speed at which the object will be allowed to descend towards a floor below it, in units per second.
PN_stdfloat get_offset () const
 Returns the linear offset to add to (or subtract from) the highest detected collision point to determine the actual height at which to set the collider.
PN_stdfloat get_reach () const
 Returns the reach to add to (or subtract from) the highest collision point.
virtual TypeHandle get_type () const
PN_stdfloat get_velocity () const
 Gets the current vertical velocity.
bool is_on_ground () const
 Is the object at rest?
void set_gravity (PN_stdfloat gravity)
 Sets the linear gravity force (always plumb).
void set_legacy_mode (bool legacy_mode)
 Enables old behavior required by Toontown (Sellbot Factory lava room is good test case, lava and conveyor belt specifically).
void set_max_velocity (PN_stdfloat max_vel)
 Sets the maximum speed at which the object will be allowed to descend towards a floor below it, in units per second.
void set_offset (PN_stdfloat offset)
 Sets the linear offset to add to (or subtract from) the highest detected collision point to determine the actual height at which to set the collider.
void set_reach (PN_stdfloat reach)
 Sets the reach to add to (or subtract from) the highest collision point.
void set_velocity (PN_stdfloat velocity)
 Sets the current vertical velocity.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.

Protected Member Functions

virtual void apply_linear_force (ColliderDef &def, const LVector3 &force)
virtual bool handle_entries ()
 Called by the parent class after all collisions have been detected, this manages the various collisions and moves around the nodes as necessary.
PN_stdfloat set_highest_collision (const NodePath &target_node_path, const NodePath &from_node_path, const Entries &entries)

Detailed Description

A specialized kind of CollisionHandler that sets the Z height of the collider to a fixed linear offset from the highest detected collision point each frame.

It's intended to implement walking around on a floor of varying height by casting a ray down from the avatar's head.

Definition at line 31 of file collisionHandlerGravity.h.


Member Function Documentation

void CollisionHandlerGravity::add_velocity ( PN_stdfloat  velocity) [inline]

Adds the sepcified amount to the current velocity.

This is mostly here allow this common operation to be faster for scripting, but it's also more concise even in cpp.

Definition at line 125 of file collisionHandlerGravity.I.

PN_stdfloat CollisionHandlerGravity::get_airborne_height ( ) const [inline]

Return the height of the object from the ground.

The object might not necessarily be at rest. Use is_on_ground() if you want to know whether the object is on the ground and at rest.

See Also: is_in_outer_space()

Definition at line 74 of file collisionHandlerGravity.I.

Referenced by is_on_ground().

PN_stdfloat CollisionHandlerGravity::get_gravity ( ) const [inline]

Gets the linear gravity force (always plumb).

Definition at line 175 of file collisionHandlerGravity.I.

PN_stdfloat CollisionHandlerGravity::get_impact_velocity ( ) const [inline]

How hard did the object hit the ground.

This value is set on impact with the ground. You may want to watch (poll) on is_on_groun() and when that is true, call get_impact_velocity(). Normally I avoid polling, but we are calling is_on_ground() frequently anyway.

Definition at line 102 of file collisionHandlerGravity.I.

bool CollisionHandlerGravity::get_legacy_mode ( ) const [inline]

returns true if legacy mode is enabled

Definition at line 224 of file collisionHandlerGravity.I.

PN_stdfloat CollisionHandlerGravity::get_max_velocity ( ) const [inline]

Retrieves the maximum speed at which the object will be allowed to descend towards a floor below it, in units per second.

See set_max_velocity().

Definition at line 200 of file collisionHandlerGravity.I.

PN_stdfloat CollisionHandlerGravity::get_offset ( ) const [inline]

Returns the linear offset to add to (or subtract from) the highest detected collision point to determine the actual height at which to set the collider.

Definition at line 36 of file collisionHandlerGravity.I.

PN_stdfloat CollisionHandlerGravity::get_reach ( ) const [inline]

Returns the reach to add to (or subtract from) the highest collision point.

Definition at line 58 of file collisionHandlerGravity.I.

PN_stdfloat CollisionHandlerGravity::get_velocity ( ) const [inline]

Gets the current vertical velocity.

Generally, negative values mean the object is in free fall; while postive values mean the object has vertical thrust.

A zero value does not necessarily mean the object on the ground, it may also be weightless and/or at the apex of its jump.

See Also: is_on_ground() and get_gravity()

Definition at line 155 of file collisionHandlerGravity.I.

bool CollisionHandlerGravity::handle_entries ( ) [protected, virtual]

Called by the parent class after all collisions have been detected, this manages the various collisions and moves around the nodes as necessary.

The return value is normally true, but it may be false to indicate the CollisionTraverser should disable this handler from being called in the future.

Implements CollisionHandlerPhysical.

Definition at line 228 of file collisionHandlerGravity.cxx.

References ClockObject::get_dt(), ClockObject::get_global_clock(), NodePath::get_transform(), NodePath::set_transform(), and CollisionHandlerPhysical::ColliderDef::updated_transform().

static void CollisionHandlerGravity::init_type ( ) [inline, static]

This function is declared non-inline to work around a compiler bug in g++ 2.96.

Making it inline seems to cause problems in the optimizer.

Reimplemented from CollisionHandlerPhysical.

Definition at line 81 of file collisionHandlerGravity.h.

References CollisionHandlerPhysical::init_type().

bool CollisionHandlerGravity::is_on_ground ( ) const [inline]

Is the object at rest?

Definition at line 84 of file collisionHandlerGravity.I.

References get_airborne_height().

void CollisionHandlerGravity::set_gravity ( PN_stdfloat  gravity) [inline]

Sets the linear gravity force (always plumb).

Definition at line 165 of file collisionHandlerGravity.I.

void CollisionHandlerGravity::set_legacy_mode ( bool  legacy_mode) [inline]

Enables old behavior required by Toontown (Sellbot Factory lava room is good test case, lava and conveyor belt specifically).

Behavior is to throw enter/exit events only for floor that the toon is in contact with

Definition at line 214 of file collisionHandlerGravity.I.

void CollisionHandlerGravity::set_max_velocity ( PN_stdfloat  max_velocity) [inline]

Sets the maximum speed at which the object will be allowed to descend towards a floor below it, in units per second.

Set this to zero to allow it to instantly teleport any distance.

Definition at line 188 of file collisionHandlerGravity.I.

void CollisionHandlerGravity::set_offset ( PN_stdfloat  offset) [inline]

Sets the linear offset to add to (or subtract from) the highest detected collision point to determine the actual height at which to set the collider.

Definition at line 24 of file collisionHandlerGravity.I.

void CollisionHandlerGravity::set_reach ( PN_stdfloat  reach) [inline]

Sets the reach to add to (or subtract from) the highest collision point.

Definition at line 47 of file collisionHandlerGravity.I.

void CollisionHandlerGravity::set_velocity ( PN_stdfloat  velocity) [inline]

Sets the current vertical velocity.

Definition at line 135 of file collisionHandlerGravity.I.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations