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 LMatrix4f &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 00051 virtual void output(ostream &out) const; 00052 00053 PUBLISHED: 00054 INLINE void set_collide_mask(CollideMask mask); 00055 void set_from_collide_mask(CollideMask mask); 00056 INLINE void set_into_collide_mask(CollideMask mask); 00057 INLINE CollideMask get_from_collide_mask() const; 00058 INLINE CollideMask get_into_collide_mask() const; 00059 00060 INLINE void clear_solids(); 00061 INLINE int get_num_solids() const; 00062 INLINE CPT(CollisionSolid) get_solid(int n) const; 00063 MAKE_SEQ(get_solids, get_num_solids, get_solid); 00064 INLINE PT(CollisionSolid) modify_solid(int n); 00065 INLINE void set_solid(int n, CollisionSolid *solid); 00066 INLINE void remove_solid(int n); 00067 INLINE int add_solid(const CollisionSolid *solid); 00068 00069 INLINE int get_collider_sort() const; 00070 INLINE void set_collider_sort(int sort); 00071 00072 INLINE static CollideMask get_default_collide_mask(); 00073 00074 protected: 00075 virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds, 00076 int &internal_vertices, 00077 int pipeline_stage, 00078 Thread *current_thread) const; 00079 00080 private: 00081 CPT(RenderState) get_last_pos_state(); 00082 00083 // This data is not cycled, for now. We assume the collision 00084 // traversal will take place in App only. Perhaps we will revisit 00085 // this later. 00086 CollideMask _from_collide_mask; 00087 int _collider_sort; 00088 00089 typedef pvector< COWPT(CollisionSolid) > Solids; 00090 Solids _solids; 00091 00092 public: 00093 static void register_with_read_factory(); 00094 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00095 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00096 00097 protected: 00098 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00099 void fillin(DatagramIterator &scan, BamReader *manager); 00100 00101 public: 00102 static TypeHandle get_class_type() { 00103 return _type_handle; 00104 } 00105 static void init_type() { 00106 PandaNode::init_type(); 00107 register_type(_type_handle, "CollisionNode", 00108 PandaNode::get_class_type()); 00109 } 00110 virtual TypeHandle get_type() const { 00111 return get_class_type(); 00112 } 00113 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00114 00115 private: 00116 static TypeHandle _type_handle; 00117 }; 00118 00119 #include "collisionNode.I" 00120 00121 #endif