Panda3D
|
00001 // Filename: collisionHandlerPhysical.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 COLLISIONHANDLERPHYSICAL_H 00016 #define COLLISIONHANDLERPHYSICAL_H 00017 00018 #include "pandabase.h" 00019 00020 #include "collisionHandlerEvent.h" 00021 #include "collisionNode.h" 00022 00023 #include "driveInterface.h" 00024 #include "pointerTo.h" 00025 #include "pandaNode.h" 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : CollisionHandlerPhysical 00029 // Description : The abstract base class for a number of 00030 // CollisionHandlers that have some physical effect on 00031 // their moving bodies: they need to update the nodes' 00032 // positions based on the effects of the collision. 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_PANDA_COLLIDE CollisionHandlerPhysical : public CollisionHandlerEvent { 00035 public: 00036 CollisionHandlerPhysical(); 00037 virtual ~CollisionHandlerPhysical(); 00038 00039 virtual void begin_group(); 00040 virtual void add_entry(CollisionEntry *entry); 00041 virtual bool end_group(); 00042 00043 PUBLISHED: 00044 void add_collider(const NodePath &collider, const NodePath &target); 00045 void add_collider(const NodePath &collider, const NodePath &target, 00046 DriveInterface *drive_interface); 00047 bool remove_collider(const NodePath &collider); 00048 bool has_collider(const NodePath &collider) const; 00049 void clear_colliders(); 00050 00051 INLINE void set_center(const NodePath ¢er); 00052 INLINE void clear_center(); 00053 INLINE const NodePath &get_center() const; 00054 INLINE bool has_center() const; 00055 INLINE bool has_contact() const; 00056 00057 protected: 00058 bool _has_contact; // Are we in contact with anything? 00059 00060 00061 protected: 00062 class ColliderDef { 00063 public: 00064 INLINE void set_target(const NodePath &target, 00065 DriveInterface *drive_interface = NULL); 00066 INLINE void updated_transform(); 00067 00068 NodePath _target; 00069 PT(DriveInterface) _drive_interface; 00070 }; 00071 00072 virtual bool handle_entries()=0; 00073 virtual void apply_linear_force(ColliderDef &def, const LVector3 &force)=0; 00074 00075 virtual bool validate_target(const NodePath &target); 00076 00077 typedef pvector< PT(CollisionEntry) > Entries; 00078 typedef pmap<NodePath, Entries> FromEntries; 00079 FromEntries _from_entries; 00080 00081 typedef pmap<NodePath, ColliderDef> Colliders; 00082 Colliders _colliders; 00083 00084 NodePath _center; 00085 00086 public: 00087 static TypeHandle get_class_type() { 00088 return _type_handle; 00089 } 00090 static void init_type() { 00091 CollisionHandlerEvent::init_type(); 00092 register_type(_type_handle, "CollisionHandlerPhysical", 00093 CollisionHandlerEvent::get_class_type()); 00094 } 00095 virtual TypeHandle get_type() const { 00096 return get_class_type(); 00097 } 00098 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00099 00100 private: 00101 static TypeHandle _type_handle; 00102 }; 00103 00104 #include "collisionHandlerPhysical.I" 00105 00106 #endif 00107 00108 00109