Panda3D
collisionFloorMesh.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file collisionFloorMesh.h
10  * @author zpavlov
11  * @date 2007-06-28
12  */
13 
14 #ifndef COLLISIONFLOORMESH_H
15 #define COLLISIONFLOORMESH_H
16 
17 #include "pandabase.h"
18 
19 #include "collisionPlane.h"
20 #include "clipPlaneAttrib.h"
21 #include "look_at.h"
22 #include "pvector.h"
23 
24 class GeomNode;
25 
26 /**
27  * This object represents a solid made entirely of triangles, which will only
28  * be tested again z axis aligned rays
29  */
30 class EXPCL_PANDA_COLLIDE CollisionFloorMesh : public CollisionSolid {
31 public:
32  typedef struct {
33  unsigned int p1;
34  unsigned int p2;
35  unsigned int p3;
36  PN_stdfloat min_x;
37  PN_stdfloat max_x;
38  PN_stdfloat min_y;
39  PN_stdfloat max_y;
40  } TriangleIndices;
41 
42 PUBLISHED:
43  INLINE CollisionFloorMesh();
44 
45  INLINE void add_vertex(const LPoint3 &vert);
46  void add_triangle(unsigned int pointA, unsigned int pointB, unsigned int pointC);
47 
48  INLINE unsigned int get_num_vertices() const;
49  INLINE const LPoint3 &get_vertex(unsigned int index) const;
50  MAKE_SEQ(get_vertices, get_num_vertices, get_vertex);
51  INLINE unsigned int get_num_triangles() const;
52  INLINE LPoint3i get_triangle(unsigned int index) const;
53  MAKE_SEQ(get_triangles, get_num_triangles, get_triangle);
54 
55  virtual LPoint3 get_collision_origin() const;
56 
57 PUBLISHED:
58  MAKE_SEQ_PROPERTY(vertices, get_num_vertices, get_vertex);
59  MAKE_SEQ_PROPERTY(triangles, get_num_triangles, get_triangle);
60 
61 public:
63  virtual CollisionSolid *make_copy();
64 
65 public:
66 
67  virtual void xform(const LMatrix4 &mat);
68 
69  virtual PStatCollector &get_volume_pcollector();
71 
72  virtual void output(std::ostream &out) const;
73  virtual void write(std::ostream &out, int indent_level = 0) const;
74 
75  INLINE static void flush_level();
76 
77 protected:
78  virtual PT(BoundingVolume) compute_internal_bounds() const;
79 
80  virtual PT(CollisionEntry)
81  test_intersection_from_ray(const CollisionEntry &entry) const;
82  virtual PT(CollisionEntry)
83  test_intersection_from_sphere(const CollisionEntry &entry) const;
84 
85  virtual void fill_viz_geom();
86 
87 private:
88  typedef pvector<LPoint3> Vertices;
90 
91  Vertices _vertices;
92  Triangles _triangles;
93 
94  static PStatCollector _volume_pcollector;
95  static PStatCollector _test_pcollector;
96 
97 protected:
98  void fillin(DatagramIterator& scan, BamReader* manager);
99 
100 public:
101  static void register_with_read_factory();
102  virtual void write_datagram(BamWriter* manager, Datagram &me);
103 
104  static TypedWritable *make_CollisionFloorMesh(const FactoryParams &params);
105  static TypeHandle get_class_type() {
106  return _type_handle;
107  }
108  static void init_type() {
109  CollisionSolid::init_type();
110  register_type(_type_handle, "CollisionFloorMesh",
111  CollisionSolid::get_class_type());
112  }
113  virtual TypeHandle get_type() const {
114  return get_class_type();
115  }
116  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
117 
118 private:
119  static TypeHandle _type_handle;
120 };
121 
122 #include "collisionFloorMesh.I"
123 
124 #endif
clipPlaneAttrib.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector< LPoint3 >
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
CollisionEntry
Defines a single collision event.
Definition: collisionEntry.h:42
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
CollisionSolid::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
Definition: collisionSolid.cxx:345
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
collisionFloorMesh.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
GeomNode
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:34
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
CollisionSolid::get_test_pcollector
virtual PStatCollector & get_test_pcollector()
Returns a PStatCollector that is used to count the number of intersection tests made against a solid ...
Definition: collisionSolid.cxx:169
PStatCollector
A lightweight class that represents a single element that may be timed and/or counted via stats.
Definition: pStatCollector.h:43
CollisionSolid
The abstract base class for all things that can collide with other things in the world,...
Definition: collisionSolid.h:45
BoundingVolume
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
Definition: boundingVolume.h:41
look_at.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
collisionPlane.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CollisionFloorMesh
This object represents a solid made entirely of triangles, which will only be tested again z axis ali...
Definition: collisionFloorMesh.h:30