Panda3D
collisionTube.h
1 // Filename: collisionTube.h
2 // Created by: drose (25Sep03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef COLLISIONTUBE_H
16 #define COLLISIONTUBE_H
17 
18 #include "pandabase.h"
19 #include "collisionSolid.h"
20 #include "parabola.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : CollisionTube
24 // Description : This implements a solid roughly in cylindrical shape.
25 // It's not called a CollisionCylinder because it's not
26 // a true cylinder; specifically, it has rounded ends
27 // instead of flat ends. It looks more like a Contac
28 // pill.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_COLLIDE CollisionTube : public CollisionSolid {
31 PUBLISHED:
32  INLINE CollisionTube(const LPoint3 &a, const LPoint3 &db,
33  PN_stdfloat radius);
34  INLINE CollisionTube(PN_stdfloat ax, PN_stdfloat ay, PN_stdfloat az,
35  PN_stdfloat bx, PN_stdfloat by, PN_stdfloat bz,
36  PN_stdfloat radius);
37 
38  virtual LPoint3 get_collision_origin() const;
39 
40 private:
41  INLINE CollisionTube();
42 
43 public:
44  INLINE CollisionTube(const CollisionTube &copy);
45  virtual CollisionSolid *make_copy();
46 
47  virtual void xform(const LMatrix4 &mat);
48 
49  virtual PStatCollector &get_volume_pcollector();
51 
52  virtual void output(ostream &out) const;
53 
54  INLINE static void flush_level();
55 
56 PUBLISHED:
57  INLINE void set_point_a(const LPoint3 &a);
58  INLINE void set_point_a(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
59  INLINE const LPoint3 &get_point_a() const;
60 
61  INLINE void set_point_b(const LPoint3 &b);
62  INLINE void set_point_b(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
63  INLINE const LPoint3 &get_point_b() const;
64 
65  INLINE void set_radius(PN_stdfloat radius);
66  INLINE PN_stdfloat get_radius() const;
67 
68 protected:
69  virtual PT(BoundingVolume) compute_internal_bounds() const;
70 
71 protected:
72  virtual PT(CollisionEntry)
73  test_intersection_from_sphere(const CollisionEntry &entry) const;
74  virtual PT(CollisionEntry)
75  test_intersection_from_line(const CollisionEntry &entry) const;
76  virtual PT(CollisionEntry)
77  test_intersection_from_ray(const CollisionEntry &entry) const;
78  virtual PT(CollisionEntry)
79  test_intersection_from_segment(const CollisionEntry &entry) const;
80  virtual PT(CollisionEntry)
81  test_intersection_from_parabola(const CollisionEntry &entry) const;
82 
83  virtual void fill_viz_geom();
84 
85 private:
86  void recalc_internals();
87 
88  LVertex calc_sphere1_vertex(int ri, int si, int num_rings, int num_slices);
89  LVertex calc_sphere2_vertex(int ri, int si, int num_rings, int num_slices,
90  PN_stdfloat length);
91 
92  bool intersects_line(double &t1, double &t2,
93  const LPoint3 &from, const LVector3 &delta,
94  PN_stdfloat inflate_radius) const;
95  bool sphere_intersects_line(double &t1, double &t2, PN_stdfloat center_y,
96  const LPoint3 &from, const LVector3 &delta,
97  PN_stdfloat inflate_radius) const;
98  bool intersects_parabola(double &t, const LParabola &parabola,
99  double t1, double t2,
100  const LPoint3 &p1, const LPoint3 &p2) const;
101  void calculate_surface_point_and_normal(const LPoint3 &surface_point,
102  double extra_radius,
103  LPoint3 &result_point,
104  LVector3 &result_normal) const;
105  void set_intersection_point(CollisionEntry *new_entry,
106  const LPoint3 &into_intersection_point,
107  double extra_radius) const;
108 
109 private:
110  LPoint3 _a, _b;
111  PN_stdfloat _radius;
112 
113  // These are derived from the above.
114  LMatrix4 _mat;
115  LMatrix4 _inv_mat;
116  PN_stdfloat _length;
117 
118  static PStatCollector _volume_pcollector;
119  static PStatCollector _test_pcollector;
120 
121 public:
122  static void register_with_read_factory();
123  virtual void write_datagram(BamWriter *manager, Datagram &dg);
124 
125 protected:
126  static TypedWritable *make_from_bam(const FactoryParams &params);
127  void fillin(DatagramIterator &scan, BamReader *manager);
128 
129 public:
130  static TypeHandle get_class_type() {
131  return _type_handle;
132  }
133  static void init_type() {
134  CollisionSolid::init_type();
135  register_type(_type_handle, "CollisionTube",
136  CollisionSolid::get_class_type());
137  }
138  virtual TypeHandle get_type() const {
139  return get_class_type();
140  }
141  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
142 
143 private:
144  static TypeHandle _type_handle;
145 };
146 
147 #include "collisionTube.I"
148 
149 #endif
150 
151 
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A lightweight class that represents a single element that may be timed and/or counted via stats...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
Defines a single collision event.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual PStatCollector & get_test_pcollector()
Returns a PStatCollector that is used to count the number of intersection tests made against a solid ...
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This implements a solid roughly in cylindrical shape.
Definition: collisionTube.h:30
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43