Panda3D
collisionSphere.h
1 // Filename: collisionSphere.h
2 // Created by: drose (24Apr00)
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 COLLISIONSPHERE_H
16 #define COLLISIONSPHERE_H
17 
18 #include "pandabase.h"
19 #include "collisionSolid.h"
20 #include "parabola.h"
21 #include "collisionBox.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : CollisionSphere
25 // Description : A spherical collision volume or object.
26 ////////////////////////////////////////////////////////////////////
27 class EXPCL_PANDA_COLLIDE CollisionSphere : public CollisionSolid {
28 PUBLISHED:
29  INLINE CollisionSphere(const LPoint3 &center, PN_stdfloat radius);
30  INLINE CollisionSphere(PN_stdfloat cx, PN_stdfloat cy, PN_stdfloat cz, PN_stdfloat radius);
31 
32  virtual LPoint3 get_collision_origin() const;
33 
34 protected:
35  INLINE CollisionSphere();
36 
37 public:
38  INLINE CollisionSphere(const CollisionSphere &copy);
39  virtual CollisionSolid *make_copy();
40 
41  virtual PT(CollisionEntry)
42  test_intersection(const CollisionEntry &entry) const;
43 
44  virtual void xform(const LMatrix4 &mat);
45 
46  virtual PStatCollector &get_volume_pcollector();
48 
49  virtual void output(ostream &out) const;
50 
51  INLINE static void flush_level();
52 
53 PUBLISHED:
54  INLINE void set_center(const LPoint3 &center);
55  INLINE void set_center(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
56  INLINE const LPoint3 &get_center() const;
57 
58  INLINE void set_radius(PN_stdfloat radius);
59  INLINE PN_stdfloat get_radius() const;
60 
61 protected:
62  virtual PT(BoundingVolume) compute_internal_bounds() const;
63 
64  virtual PT(CollisionEntry)
65  test_intersection_from_sphere(const CollisionEntry &entry) const;
66  virtual PT(CollisionEntry)
67  test_intersection_from_line(const CollisionEntry &entry) const;
68  virtual PT(CollisionEntry)
69  test_intersection_from_ray(const CollisionEntry &entry) const;
70  virtual PT(CollisionEntry)
71  test_intersection_from_segment(const CollisionEntry &entry) const;
72  virtual PT(CollisionEntry)
73  test_intersection_from_parabola(const CollisionEntry &entry) const;
74  virtual PT(CollisionEntry)
75  test_intersection_from_box(const CollisionEntry &entry) const;
76 
77  virtual void fill_viz_geom();
78 
79 protected:
80  bool intersects_line(double &t1, double &t2,
81  const LPoint3 &from, const LVector3 &delta,
82  PN_stdfloat inflate_radius) const;
83  bool intersects_parabola(double &t, const LParabola &parabola,
84  double t1, double t2,
85  const LPoint3 &p1, const LPoint3 &p2) const;
86  LVertex compute_point(PN_stdfloat latitude, PN_stdfloat longitude) const;
87 
88 private:
89  LPoint3 _center;
90  PN_stdfloat _radius;
91 
92  static PStatCollector _volume_pcollector;
93  static PStatCollector _test_pcollector;
94 
95 public:
96  static void register_with_read_factory();
97  virtual void write_datagram(BamWriter *manager, Datagram &me);
98 
99 protected:
100  static TypedWritable *make_CollisionSphere(const FactoryParams &params);
101  void fillin(DatagramIterator &scan, BamReader *manager);
102 
103 public:
104  static TypeHandle get_class_type() {
105  return _type_handle;
106  }
107  static void init_type() {
108  CollisionSolid::init_type();
109  register_type(_type_handle, "CollisionSphere",
110  CollisionSolid::get_class_type());
111  }
112  virtual TypeHandle get_type() const {
113  return get_class_type();
114  }
115  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
116 
117 private:
118  static TypeHandle _type_handle;
119 };
120 
121 #include "collisionSphere.I"
122 
123 #endif
124 
125 
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
A spherical collision volume or object.
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43