Panda3D
|
00001 // Filename: collisionNode.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 COLLISIONNODE_H 00016 #define COLLISIONNODE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "collisionSolid.h" 00021 00022 #include "collideMask.h" 00023 #include "pandaNode.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : CollisionNode 00027 // Description : A node in the scene graph that can hold any number of 00028 // CollisionSolids. This may either represent a bit of 00029 // static geometry in the scene that things will collide 00030 // with, or an animated object twirling around in the 00031 // world and running into things. 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_PANDA_COLLIDE CollisionNode : public PandaNode { 00034 PUBLISHED: 00035 CollisionNode(const string &name); 00036 00037 protected: 00038 CollisionNode(const CollisionNode ©); 00039 00040 public: 00041 virtual ~CollisionNode(); 00042 virtual PandaNode *make_copy() const; 00043 virtual bool preserve_name() const; 00044 virtual void xform(const LMatrix4 &mat); 00045 virtual PandaNode *combine_with(PandaNode *other); 00046 virtual CollideMask get_legal_collide_mask() const; 00047 00048 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); 00049 virtual bool is_renderable() const; 00050 virtual bool is_collision_node() const; 00051 00052 virtual void output(ostream &out) const; 00053 00054 PUBLISHED: 00055 INLINE void set_collide_mask(CollideMask mask); 00056 void set_from_collide_mask(CollideMask mask); 00057 INLINE void set_into_collide_mask(CollideMask mask); 00058 INLINE CollideMask get_from_collide_mask() const; 00059 INLINE CollideMask get_into_collide_mask() const; 00060 00061 INLINE void clear_solids(); 00062 INLINE int get_num_solids() const; 00063 INLINE CPT(CollisionSolid) get_solid(int n) const; 00064 MAKE_SEQ(get_solids, get_num_solids, get_solid); 00065 INLINE PT(CollisionSolid) modify_solid(int n); 00066 INLINE void set_solid(int n, CollisionSolid *solid); 00067 INLINE void remove_solid(int n); 00068 INLINE int add_solid(const CollisionSolid *solid); 00069 00070 INLINE int get_collider_sort() const; 00071 INLINE void set_collider_sort(int sort); 00072 00073 INLINE static CollideMask get_default_collide_mask(); 00074 00075 protected: 00076 virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds, 00077 int &internal_vertices, 00078 int pipeline_stage, 00079 Thread *current_thread) const; 00080 00081 private: 00082 CPT(RenderState) get_last_pos_state(); 00083 00084 // This data is not cycled, for now. We assume the collision 00085 // traversal will take place in App only. Perhaps we will revisit 00086 // this later. 00087 CollideMask _from_collide_mask; 00088 int _collider_sort; 00089 00090 typedef pvector< COWPT(CollisionSolid) > Solids; 00091 Solids _solids; 00092 00093 public: 00094 static void register_with_read_factory(); 00095 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00096 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00097 00098 protected: 00099 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00100 void fillin(DatagramIterator &scan, BamReader *manager); 00101 00102 public: 00103 static TypeHandle get_class_type() { 00104 return _type_handle; 00105 } 00106 static void init_type() { 00107 PandaNode::init_type(); 00108 register_type(_type_handle, "CollisionNode", 00109 PandaNode::get_class_type()); 00110 } 00111 virtual TypeHandle get_type() const { 00112 return get_class_type(); 00113 } 00114 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00115 00116 private: 00117 static TypeHandle _type_handle; 00118 }; 00119 00120 #include "collisionNode.I" 00121 00122 #endif