00001 // Filename: collisionHandlerPhysical.h 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef COLLISIONHANDLERPHYSICAL_H 00020 #define COLLISIONHANDLERPHYSICAL_H 00021 00022 #include "pandabase.h" 00023 00024 #include "collisionHandlerEvent.h" 00025 #include "collisionNode.h" 00026 00027 #include "driveInterface.h" 00028 #include "pointerTo.h" 00029 #include "pandaNode.h" 00030 00031 /////////////////////////////////////////////////////////////////// 00032 // Class : CollisionHandlerPhysical 00033 // Description : The abstract base class for a number of 00034 // CollisionHandlers that have some physical effect on 00035 // their moving bodies: they need to update the nodes' 00036 // positions based on the effects of the collision. 00037 //////////////////////////////////////////////////////////////////// 00038 class EXPCL_PANDA CollisionHandlerPhysical : public CollisionHandlerEvent { 00039 public: 00040 CollisionHandlerPhysical(); 00041 virtual ~CollisionHandlerPhysical(); 00042 00043 virtual void begin_group(); 00044 virtual void add_entry(CollisionEntry *entry); 00045 virtual bool end_group(); 00046 00047 PUBLISHED: 00048 void add_collider_drive(CollisionNode *node, DriveInterface *drive_interface); 00049 void add_collider_node(CollisionNode *node, PandaNode *target); 00050 bool remove_collider(CollisionNode *node); 00051 bool has_collider(CollisionNode *node) const; 00052 void clear_colliders(); 00053 00054 protected: 00055 virtual bool handle_entries()=0; 00056 00057 protected: 00058 typedef pvector< PT(CollisionEntry) > Entries; 00059 typedef pmap<PT(CollisionNode), Entries> FromEntries; 00060 FromEntries _from_entries; 00061 00062 class ColliderDef { 00063 public: 00064 INLINE void set_drive_interface(DriveInterface *drive_interface); 00065 INLINE void set_node(PandaNode *node); 00066 INLINE bool is_valid() const; 00067 00068 void get_mat(LMatrix4f &mat) const; 00069 void set_mat(const LMatrix4f &mat); 00070 00071 PT(DriveInterface) _drive_interface; 00072 PT(PandaNode) _node; 00073 }; 00074 00075 typedef pmap<PT(CollisionNode), ColliderDef> Colliders; 00076 Colliders _colliders; 00077 00078 00079 public: 00080 static TypeHandle get_class_type() { 00081 return _type_handle; 00082 } 00083 static void init_type() { 00084 CollisionHandlerEvent::init_type(); 00085 register_type(_type_handle, "CollisionHandlerPhysical", 00086 CollisionHandlerEvent::get_class_type()); 00087 } 00088 virtual TypeHandle get_type() const { 00089 return get_class_type(); 00090 } 00091 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00092 00093 private: 00094 static TypeHandle _type_handle; 00095 }; 00096 00097 #include "collisionHandlerPhysical.I" 00098 00099 #endif 00100 00101 00102