Panda3D
 All Classes Functions Variables Enumerations
collisionTube.h
00001 // Filename: collisionTube.h
00002 // Created by:  drose (25Sep03)
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 COLLISIONTUBE_H
00016 #define COLLISIONTUBE_H
00017 
00018 #include "pandabase.h"
00019 #include "collisionSolid.h"
00020 #include "parabola.h"
00021 
00022 ////////////////////////////////////////////////////////////////////
00023 //       Class : CollisionTube
00024 // Description : This implements a solid roughly in cylindrical shape.
00025 //               It's not called a CollisionCylinder because it's not
00026 //               a true cylinder; specifically, it has rounded ends
00027 //               instead of flat ends.  It looks more like a Contac
00028 //               pill.
00029 ////////////////////////////////////////////////////////////////////
00030 class EXPCL_PANDA_COLLIDE CollisionTube : public CollisionSolid {
00031 PUBLISHED:
00032   INLINE CollisionTube(const LPoint3 &a, const LPoint3 &db,
00033                        PN_stdfloat radius);
00034   INLINE CollisionTube(PN_stdfloat ax, PN_stdfloat ay, PN_stdfloat az,
00035                        PN_stdfloat bx, PN_stdfloat by, PN_stdfloat bz,
00036                        PN_stdfloat radius);
00037 
00038   virtual LPoint3 get_collision_origin() const;
00039 
00040 private:
00041   INLINE CollisionTube();
00042 
00043 public:
00044   INLINE CollisionTube(const CollisionTube &copy);
00045   virtual CollisionSolid *make_copy();
00046 
00047   virtual void xform(const LMatrix4 &mat);
00048 
00049   virtual PStatCollector &get_volume_pcollector();
00050   virtual PStatCollector &get_test_pcollector();
00051 
00052   virtual void output(ostream &out) const;
00053 
00054   INLINE static void flush_level();
00055 
00056 PUBLISHED:
00057   INLINE void set_point_a(const LPoint3 &a);
00058   INLINE void set_point_a(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
00059   INLINE const LPoint3 &get_point_a() const;
00060 
00061   INLINE void set_point_b(const LPoint3 &b);
00062   INLINE void set_point_b(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
00063   INLINE const LPoint3 &get_point_b() const;
00064 
00065   INLINE void set_radius(PN_stdfloat radius);
00066   INLINE PN_stdfloat get_radius() const;
00067 
00068 protected:
00069   virtual PT(BoundingVolume) compute_internal_bounds() const;
00070 
00071 protected:
00072   virtual PT(CollisionEntry)
00073   test_intersection_from_sphere(const CollisionEntry &entry) const;
00074   virtual PT(CollisionEntry)
00075   test_intersection_from_line(const CollisionEntry &entry) const;
00076   virtual PT(CollisionEntry)
00077   test_intersection_from_ray(const CollisionEntry &entry) const;
00078   virtual PT(CollisionEntry)
00079   test_intersection_from_segment(const CollisionEntry &entry) const;
00080   virtual PT(CollisionEntry)
00081   test_intersection_from_parabola(const CollisionEntry &entry) const;
00082 
00083   virtual void fill_viz_geom();
00084 
00085 private:
00086   void recalc_internals();
00087 
00088   LVertex calc_sphere1_vertex(int ri, int si, int num_rings, int num_slices);
00089   LVertex calc_sphere2_vertex(int ri, int si, int num_rings, int num_slices,
00090                               PN_stdfloat length);
00091 
00092   bool intersects_line(double &t1, double &t2,
00093                        const LPoint3 &from, const LVector3 &delta,
00094                        PN_stdfloat inflate_radius) const;
00095   bool sphere_intersects_line(double &t1, double &t2, PN_stdfloat center_y,
00096                               const LPoint3 &from, const LVector3 &delta,
00097                               PN_stdfloat inflate_radius) const;
00098   bool intersects_parabola(double &t, const LParabola &parabola,
00099                            double t1, double t2,
00100                            const LPoint3 &p1, const LPoint3 &p2) const;
00101   void calculate_surface_point_and_normal(const LPoint3 &surface_point,
00102                                           double extra_radius,
00103                                           LPoint3 &result_point,
00104                                           LVector3 &result_normal) const;
00105   void set_intersection_point(CollisionEntry *new_entry, 
00106                               const LPoint3 &into_intersection_point, 
00107                               double extra_radius) const;
00108 
00109 private:
00110   LPoint3 _a, _b;
00111   PN_stdfloat _radius;
00112 
00113   // These are derived from the above.
00114   LMatrix4 _mat;
00115   LMatrix4 _inv_mat;
00116   PN_stdfloat _length;
00117 
00118   static PStatCollector _volume_pcollector;
00119   static PStatCollector _test_pcollector;
00120 
00121 public:
00122   static void register_with_read_factory();
00123   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00124 
00125 protected:
00126   static TypedWritable *make_from_bam(const FactoryParams &params);
00127   void fillin(DatagramIterator &scan, BamReader *manager);
00128 
00129 public:
00130   static TypeHandle get_class_type() {
00131     return _type_handle;
00132   }
00133   static void init_type() {
00134     CollisionSolid::init_type();
00135     register_type(_type_handle, "CollisionTube",
00136                   CollisionSolid::get_class_type());
00137   }
00138   virtual TypeHandle get_type() const {
00139     return get_class_type();
00140   }
00141   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00142 
00143 private:
00144   static TypeHandle _type_handle;
00145 };
00146 
00147 #include "collisionTube.I"
00148 
00149 #endif
00150 
00151 
 All Classes Functions Variables Enumerations