Panda3D

collisionFloorMesh.h

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