Panda3D
|
00001 // Filename: collisionFloorMesh.h 00002 // Created by: zpavlov (28Jun07) 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 COLLISIONFLOORMESH_H 00016 #define COLLISIONFLOORMESH_H 00017 00018 #include "pandabase.h" 00019 00020 #include "collisionPlane.h" 00021 #include "clipPlaneAttrib.h" 00022 #include "look_at.h" 00023 #include "pvector.h" 00024 00025 class GeomNode; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : CollisionFloorMesh 00029 // Description : This object represents a solid made entirely of triangles, which 00030 // will only be tested again z axis aligned rays 00031 //////////////////////////////////////////////////////////////////// 00032 class EXPCL_PANDA_COLLIDE CollisionFloorMesh : public CollisionSolid { 00033 public: 00034 typedef struct { 00035 unsigned int p1; 00036 unsigned int p2; 00037 unsigned int p3; 00038 PN_stdfloat min_x; 00039 PN_stdfloat max_x; 00040 PN_stdfloat min_y; 00041 PN_stdfloat max_y; 00042 } TriangleIndices; 00043 00044 00045 PUBLISHED: 00046 00047 INLINE CollisionFloorMesh(); 00048 00049 INLINE void add_vertex(const LPoint3 &vert); 00050 void add_triangle(unsigned int pointA, unsigned int pointB, unsigned int pointC); 00051 00052 INLINE const unsigned int get_num_vertices() const; 00053 INLINE const LPoint3 get_vertex(unsigned int index) const; 00054 MAKE_SEQ(get_vertices, get_num_vertices, get_vertex); 00055 INLINE const unsigned int get_num_triangles() const; 00056 INLINE const LPoint3d get_triangle(unsigned int index) const; 00057 MAKE_SEQ(get_triangles, get_num_triangles, get_triangle); 00058 00059 virtual LPoint3 get_collision_origin() const; 00060 00061 public: 00062 CollisionFloorMesh(const CollisionFloorMesh ©); 00063 virtual CollisionSolid *make_copy(); 00064 00065 public: 00066 00067 virtual void xform(const LMatrix4 &mat); 00068 00069 virtual PStatCollector &get_volume_pcollector(); 00070 virtual PStatCollector &get_test_pcollector(); 00071 00072 virtual void output(ostream &out) const; 00073 virtual void write(ostream &out, int indent_level = 0) const; 00074 00075 INLINE static void flush_level(); 00076 00077 protected: 00078 virtual PT(BoundingVolume) compute_internal_bounds() const; 00079 00080 virtual PT(CollisionEntry) 00081 test_intersection_from_ray(const CollisionEntry &entry) const; 00082 virtual PT(CollisionEntry) 00083 test_intersection_from_sphere(const CollisionEntry &entry) const; 00084 00085 virtual void fill_viz_geom(); 00086 00087 private: 00088 typedef pvector<LPoint3> Vertices; 00089 typedef pvector<TriangleIndices> Triangles; 00090 00091 Vertices _vertices; 00092 Triangles _triangles; 00093 00094 static PStatCollector _volume_pcollector; 00095 static PStatCollector _test_pcollector; 00096 00097 protected: 00098 void fillin(DatagramIterator& scan, BamReader* manager); 00099 00100 public: 00101 static void register_with_read_factory(); 00102 virtual void write_datagram(BamWriter* manager, Datagram &me); 00103 00104 static TypedWritable *make_CollisionFloorMesh(const FactoryParams ¶ms); 00105 static TypeHandle get_class_type() { 00106 return _type_handle; 00107 } 00108 static void init_type() { 00109 CollisionSolid::init_type(); 00110 register_type(_type_handle, "CollisionFloorMesh", 00111 CollisionSolid::get_class_type()); 00112 } 00113 virtual TypeHandle get_type() const { 00114 return get_class_type(); 00115 } 00116 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00117 00118 private: 00119 static TypeHandle _type_handle; 00120 }; 00121 00122 #include "collisionFloorMesh.I" 00123 00124 #endif 00125 00126