Panda3D
|
00001 // Filename: collisionSolid.h 00002 // Created by: drose (24Apr00) 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 COLLISIONSOLID_H 00016 #define COLLISIONSOLID_H 00017 00018 #include "pandabase.h" 00019 00020 #include "config_collide.h" 00021 #include "copyOnWriteObject.h" 00022 #include "luse.h" 00023 #include "pointerTo.h" 00024 #include "renderState.h" 00025 #include "geomNode.h" 00026 #include "lightMutex.h" 00027 #include "lightMutexHolder.h" 00028 #include "pStatCollector.h" 00029 00030 class CollisionHandler; 00031 class CollisionEntry; 00032 class CollisionSphere; 00033 class GeomNode; 00034 class CollisionNode; 00035 class CullTraverserData; 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Class : CollisionSolid 00039 // Description : The abstract base class for all things that can 00040 // collide with other things in the world, and all the 00041 // things they can collide with (except geometry). 00042 // 00043 // This class and its derivatives really work very 00044 // similarly to the way BoundingVolume and all of its 00045 // derivatives work. There's a different subclass for 00046 // each basic shape of solid, and double-dispatch 00047 // function calls handle the subset of the N*N 00048 // intersection tests that we care about. 00049 //////////////////////////////////////////////////////////////////// 00050 class EXPCL_PANDA_COLLIDE CollisionSolid : public CopyOnWriteObject { 00051 public: 00052 CollisionSolid(); 00053 CollisionSolid(const CollisionSolid ©); 00054 virtual ~CollisionSolid(); 00055 00056 virtual CollisionSolid *make_copy()=0; 00057 protected: 00058 virtual PT(CopyOnWriteObject) make_cow_copy(); 00059 00060 PUBLISHED: 00061 virtual LPoint3 get_collision_origin() const=0; 00062 00063 INLINE void set_tangible(bool tangible); 00064 INLINE bool is_tangible() const; 00065 00066 INLINE void set_effective_normal(const LVector3 &effective_normal); 00067 INLINE void clear_effective_normal(); 00068 INLINE bool has_effective_normal() const; 00069 INLINE const LVector3 &get_effective_normal() const; 00070 00071 INLINE void set_respect_effective_normal(bool respect_effective_normal); 00072 INLINE bool get_respect_effective_normal() const; 00073 00074 CPT(BoundingVolume) get_bounds() const; 00075 void set_bounds(const BoundingVolume &bounding_volume); 00076 00077 public: 00078 virtual PT(CollisionEntry) 00079 test_intersection(const CollisionEntry &entry) const; 00080 00081 virtual void xform(const LMatrix4 &mat); 00082 00083 virtual PT(PandaNode) get_viz(const CullTraverser *trav, 00084 const CullTraverserData &data, 00085 bool bounds_only) const; 00086 00087 virtual PStatCollector &get_volume_pcollector(); 00088 virtual PStatCollector &get_test_pcollector(); 00089 00090 PUBLISHED: 00091 virtual void output(ostream &out) const; 00092 virtual void write(ostream &out, int indent_level = 0) const; 00093 00094 protected: 00095 INLINE bool do_is_tangible() const; 00096 INLINE bool do_has_effective_normal() const; 00097 00098 INLINE void mark_internal_bounds_stale(); 00099 virtual PT(BoundingVolume) compute_internal_bounds() const; 00100 00101 virtual PT(CollisionEntry) 00102 test_intersection_from_sphere(const CollisionEntry &entry) const; 00103 virtual PT(CollisionEntry) 00104 test_intersection_from_line(const CollisionEntry &entry) const; 00105 virtual PT(CollisionEntry) 00106 test_intersection_from_ray(const CollisionEntry &entry) const; 00107 virtual PT(CollisionEntry) 00108 test_intersection_from_segment(const CollisionEntry &entry) const; 00109 virtual PT(CollisionEntry) 00110 test_intersection_from_parabola(const CollisionEntry &entry) const; 00111 virtual PT(CollisionEntry) 00112 test_intersection_from_box(const CollisionEntry &entry) const; 00113 00114 static void report_undefined_intersection_test(TypeHandle from_type, 00115 TypeHandle into_type); 00116 static void report_undefined_from_intersection(TypeHandle from_type); 00117 00118 INLINE void mark_viz_stale(); 00119 virtual void fill_viz_geom(); 00120 00121 CPT(RenderState) get_solid_viz_state(); 00122 CPT(RenderState) get_wireframe_viz_state(); 00123 CPT(RenderState) get_other_viz_state(); 00124 CPT(RenderState) get_solid_bounds_viz_state(); 00125 CPT(RenderState) get_wireframe_bounds_viz_state(); 00126 CPT(RenderState) get_other_bounds_viz_state(); 00127 00128 PT(GeomNode) _viz_geom; 00129 PT(GeomNode) _bounds_viz_geom; 00130 00131 private: 00132 LVector3 _effective_normal; 00133 PT(BoundingVolume) _internal_bounds; 00134 00135 // Be careful reordering these bits, since they are written to a bam 00136 // file. 00137 enum Flags { 00138 F_tangible = 0x01, 00139 F_effective_normal = 0x02, 00140 F_viz_geom_stale = 0x04, 00141 F_ignore_effective_normal = 0x08, 00142 F_internal_bounds_stale = 0x10, 00143 }; 00144 int _flags; 00145 00146 LightMutex _lock; 00147 00148 static PStatCollector _volume_pcollector; 00149 static PStatCollector _test_pcollector; 00150 00151 public: 00152 virtual void write_datagram(BamWriter* manager, Datagram &me); 00153 00154 protected: 00155 void fillin(DatagramIterator& scan, BamReader* manager); 00156 00157 public: 00158 static TypeHandle get_class_type() { 00159 return _type_handle; 00160 } 00161 static void init_type() { 00162 CopyOnWriteObject::init_type(); 00163 register_type(_type_handle, "CollisionSolid", 00164 CopyOnWriteObject::get_class_type()); 00165 } 00166 virtual TypeHandle get_type() const { 00167 return get_class_type(); 00168 } 00169 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00170 00171 private: 00172 static TypeHandle _type_handle; 00173 00174 friend class CollisionSphere; 00175 friend class CollisionLine; 00176 friend class CollisionRay; 00177 friend class CollisionSegment; 00178 friend class CollisionParabola; 00179 friend class CollisionHandlerFluidPusher; 00180 friend class CollisionBox; 00181 }; 00182 00183 INLINE ostream &operator << (ostream &out, const CollisionSolid &cs) { 00184 cs.output(out); 00185 return out; 00186 } 00187 00188 #include "collisionSolid.I" 00189 00190 #endif 00191