00001 // Filename: collisionNode.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 COLLISIONNODE_H 00020 #define COLLISIONNODE_H 00021 00022 #include "pandabase.h" 00023 00024 #include "collisionSolid.h" 00025 00026 #include "collideMask.h" 00027 #include "pandaNode.h" 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Class : CollisionNode 00031 // Description : A node in the scene graph that can hold any number of 00032 // CollisionSolids. This may either represent a bit of 00033 // static geometry in the scene that things will collide 00034 // with, or an animated object twirling around in the 00035 // world and running into things. 00036 //////////////////////////////////////////////////////////////////// 00037 class EXPCL_PANDA CollisionNode : public PandaNode { 00038 PUBLISHED: 00039 CollisionNode(const string &name); 00040 00041 protected: 00042 CollisionNode(const CollisionNode ©); 00043 00044 public: 00045 virtual ~CollisionNode(); 00046 virtual PandaNode *make_copy() const; 00047 virtual bool preserve_name() const; 00048 virtual void xform(const LMatrix4f &mat); 00049 virtual PandaNode *combine_with(PandaNode *other); 00050 00051 virtual bool has_cull_callback() const; 00052 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); 00053 00054 virtual void output(ostream &out) const; 00055 00056 PUBLISHED: 00057 INLINE void set_collide_mask(CollideMask mask); 00058 INLINE void set_from_collide_mask(CollideMask mask); 00059 INLINE void set_into_collide_mask(CollideMask mask); 00060 INLINE CollideMask get_from_collide_mask() const; 00061 INLINE CollideMask get_into_collide_mask() const; 00062 00063 INLINE void set_collide_geom(bool flag); 00064 INLINE bool get_collide_geom() const; 00065 00066 INLINE int get_num_solids() const; 00067 INLINE CollisionSolid *get_solid(int n) const; 00068 INLINE void remove_solid(int n); 00069 INLINE int add_solid(CollisionSolid *solid); 00070 00071 virtual void set_velocity(const LVector3f &vel); 00072 INLINE void clear_velocity(); 00073 INLINE bool has_velocity() const; 00074 INLINE const LVector3f &get_velocity() const; 00075 00076 protected: 00077 virtual BoundingVolume *recompute_bound(); 00078 virtual BoundingVolume *recompute_internal_bound(); 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 CollideMask _into_collide_mask; 00088 LVector3f _velocity; 00089 00090 enum Flags { 00091 F_collide_geom = 0x0001, 00092 F_has_velocity = 0x0002, 00093 // Presently only 8 bits are written to the bam file. 00094 }; 00095 int _flags; 00096 00097 typedef pvector< PT(CollisionSolid) > Solids; 00098 Solids _solids; 00099 00100 public: 00101 static void register_with_read_factory(); 00102 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00103 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00104 00105 protected: 00106 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00107 void fillin(DatagramIterator &scan, BamReader *manager); 00108 00109 public: 00110 static TypeHandle get_class_type(void) { 00111 return _type_handle; 00112 } 00113 static void init_type(void) { 00114 PandaNode::init_type(); 00115 register_type(_type_handle, "CollisionNode", 00116 PandaNode::get_class_type()); 00117 } 00118 virtual TypeHandle get_type(void) const { 00119 return get_class_type(); 00120 } 00121 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00122 00123 private: 00124 static TypeHandle _type_handle; 00125 }; 00126 00127 #include "collisionNode.I" 00128 00129 #endif