Panda3D
collisionSphere.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 collisionSphere.h
10  * @author drose
11  * @date 2000-04-24
12  */
13 
14 #ifndef COLLISIONSPHERE_H
15 #define COLLISIONSPHERE_H
16 
17 #include "pandabase.h"
18 #include "collisionSolid.h"
19 #include "parabola.h"
20 #include "collisionBox.h"
21 
22 /**
23  * A spherical collision volume or object.
24  */
25 class EXPCL_PANDA_COLLIDE CollisionSphere : public CollisionSolid {
26 PUBLISHED:
27  INLINE explicit CollisionSphere(const LPoint3 &center, PN_stdfloat radius);
28  INLINE explicit CollisionSphere(PN_stdfloat cx, PN_stdfloat cy, PN_stdfloat cz, PN_stdfloat radius);
29 
30  virtual LPoint3 get_collision_origin() const;
31 
32 protected:
33  INLINE CollisionSphere();
34 
35 public:
36  INLINE CollisionSphere(const CollisionSphere &copy);
37  virtual CollisionSolid *make_copy();
38 
39  virtual PT(CollisionEntry)
40  test_intersection(const CollisionEntry &entry) const;
41 
42  virtual void xform(const LMatrix4 &mat);
43 
44  virtual PStatCollector &get_volume_pcollector();
46 
47  virtual void output(std::ostream &out) const;
48 
49  INLINE static void flush_level();
50 
51 PUBLISHED:
52  INLINE void set_center(const LPoint3 &center);
53  INLINE void set_center(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
54  INLINE const LPoint3 &get_center() const;
55 
56  INLINE void set_radius(PN_stdfloat radius);
57  INLINE PN_stdfloat get_radius() const;
58 
59 PUBLISHED:
60  MAKE_PROPERTY(center, get_center, set_center);
61  MAKE_PROPERTY(radius, get_radius, set_radius);
62 
63 protected:
64  virtual PT(BoundingVolume) compute_internal_bounds() const;
65 
66  virtual PT(CollisionEntry)
67  test_intersection_from_sphere(const CollisionEntry &entry) const;
68  virtual PT(CollisionEntry)
69  test_intersection_from_line(const CollisionEntry &entry) const;
70  virtual PT(CollisionEntry)
71  test_intersection_from_ray(const CollisionEntry &entry) const;
72  virtual PT(CollisionEntry)
73  test_intersection_from_segment(const CollisionEntry &entry) const;
74  virtual PT(CollisionEntry)
75  test_intersection_from_capsule(const CollisionEntry &entry) const;
76  virtual PT(CollisionEntry)
77  test_intersection_from_parabola(const CollisionEntry &entry) const;
78  virtual PT(CollisionEntry)
79  test_intersection_from_box(const CollisionEntry &entry) const;
80 
81  virtual void fill_viz_geom();
82 
83 protected:
84  bool intersects_line(double &t1, double &t2,
85  const LPoint3 &from, const LVector3 &delta,
86  PN_stdfloat inflate_radius) const;
87  bool intersects_parabola(double &t, const LParabola &parabola,
88  double t1, double t2,
89  const LPoint3 &p1, const LPoint3 &p2) const;
90  LVertex compute_point(PN_stdfloat latitude, PN_stdfloat longitude) const;
91 
92 private:
93  LPoint3 _center;
94  PN_stdfloat _radius;
95 
96  static PStatCollector _volume_pcollector;
97  static PStatCollector _test_pcollector;
98 
99 public:
100  static void register_with_read_factory();
101  virtual void write_datagram(BamWriter *manager, Datagram &me);
102 
103 protected:
104  static TypedWritable *make_CollisionSphere(const FactoryParams &params);
105  void fillin(DatagramIterator &scan, BamReader *manager);
106 
107 public:
108  static TypeHandle get_class_type() {
109  return _type_handle;
110  }
111  static void init_type() {
112  CollisionSolid::init_type();
113  register_type(_type_handle, "CollisionSphere",
114  CollisionSolid::get_class_type());
115  }
116  virtual TypeHandle get_type() const {
117  return get_class_type();
118  }
119  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
120 
121 private:
122  static TypeHandle _type_handle;
123 };
124 
125 #include "collisionSphere.I"
126 
127 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
The abstract base class for all things that can collide with other things in the world,...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
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.
Defines a single collision event.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
virtual PStatCollector & get_test_pcollector()
Returns a PStatCollector that is used to count the number of intersection tests made against a solid ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38