Panda3D
|
00001 // Filename: CollisionHandlerGravity.h 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CollisionHandlerGravity_H 00016 #define CollisionHandlerGravity_H 00017 00018 #include "pandabase.h" 00019 00020 #include "collisionHandlerPhysical.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : CollisionHandlerGravity 00024 // Description : A specialized kind of CollisionHandler that sets the 00025 // Z height of the collider to a fixed linear offset 00026 // from the highest detected collision point each frame. 00027 // It's intended to implement walking around on a floor 00028 // of varying height by casting a ray down from the 00029 // avatar's head. 00030 //////////////////////////////////////////////////////////////////// 00031 class EXPCL_PANDA_COLLIDE CollisionHandlerGravity : public CollisionHandlerPhysical { 00032 PUBLISHED: 00033 CollisionHandlerGravity(); 00034 virtual ~CollisionHandlerGravity(); 00035 00036 INLINE void set_offset(PN_stdfloat offset); 00037 INLINE PN_stdfloat get_offset() const; 00038 00039 INLINE void set_reach(PN_stdfloat reach); 00040 INLINE PN_stdfloat get_reach() const; 00041 00042 INLINE PN_stdfloat get_airborne_height() const; 00043 INLINE bool is_on_ground() const; 00044 INLINE PN_stdfloat get_impact_velocity() const; 00045 INLINE const LVector3 &get_contact_normal() const; 00046 00047 INLINE void add_velocity(PN_stdfloat velocity); 00048 INLINE void set_velocity(PN_stdfloat velocity); 00049 INLINE PN_stdfloat get_velocity() const; 00050 00051 INLINE void set_gravity(PN_stdfloat gravity); 00052 INLINE PN_stdfloat get_gravity() const; 00053 00054 INLINE void set_max_velocity(PN_stdfloat max_vel); 00055 INLINE PN_stdfloat get_max_velocity() const; 00056 00057 INLINE void set_legacy_mode(bool legacy_mode); 00058 INLINE bool get_legacy_mode() const; 00059 00060 protected: 00061 PN_stdfloat set_highest_collision(const NodePath &target_node_path, const NodePath &from_node_path, const Entries &entries); 00062 virtual bool handle_entries(); 00063 virtual void apply_linear_force(ColliderDef &def, const LVector3 &force); 00064 00065 private: 00066 PN_stdfloat _offset; 00067 PN_stdfloat _reach; 00068 PN_stdfloat _airborne_height; 00069 PN_stdfloat _impact_velocity; 00070 PN_stdfloat _gravity; 00071 PN_stdfloat _current_velocity; 00072 PN_stdfloat _max_velocity; 00073 LVector3 _contact_normal; 00074 bool _legacy_mode; 00075 00076 00077 public: 00078 static TypeHandle get_class_type() { 00079 return _type_handle; 00080 } 00081 static void init_type() { 00082 CollisionHandlerPhysical::init_type(); 00083 register_type(_type_handle, "CollisionHandlerGravity", 00084 CollisionHandlerPhysical::get_class_type()); 00085 } 00086 virtual TypeHandle get_type() const { 00087 return get_class_type(); 00088 } 00089 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00090 00091 private: 00092 static TypeHandle _type_handle; 00093 }; 00094 00095 #include "collisionHandlerGravity.I" 00096 00097 #endif 00098 00099 00100