Panda3D

collisionDSSolid.h

00001 // Filename: CollisionDSSolid.h
00002 // Created by:  Dave Schuyler (05Apr06)
00003 // Based on collision tube by:  drose
00004 //
00005 ////////////////////////////////////////////////////////////////////
00006 //
00007 // PANDA 3D SOFTWARE
00008 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00009 //
00010 // All use of this software is subject to the terms of the revised BSD
00011 // license.  You should have received a copy of this license along
00012 // with this source code in a file named "LICENSE."
00013 //
00014 ////////////////////////////////////////////////////////////////////
00015 
00016 #ifndef COLLISIONDSSOLID_H
00017 #define COLLISIONDSSOLID_H
00018 
00019 #include "pandabase.h"
00020 #include "plane.h"
00021 #include "collisionSolid.h"
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //       Class : CollisionDSSolid
00025 // Description : A collision volume or object made up of the intersection
00026 //               of two spheres (potentially a lens) and two half-spaces
00027 //               (planes).
00028 ////////////////////////////////////////////////////////////////////
00029 class EXPCL_PANDA_COLLIDE CollisionDSSolid: public CollisionSolid {
00030 PUBLISHED:
00031   INLINE CollisionDSSolid(
00032     const LPoint3f &center_a, float radius_a,
00033     const LPoint3f &center_b, float radius_b,
00034     const Planef &plane_a, const Planef &plane_b);
00035   INLINE CollisionDSSolid(
00036     float ax, float ay, float az, float radius_a,
00037     float bx, float by, float bz, float radius_b,
00038     const Planef &plane_a, const Planef &plane_b);
00039 
00040   virtual LPoint3f get_collision_origin() const;
00041 
00042 protected:
00043   INLINE CollisionDSSolid();
00044 
00045 public:
00046   INLINE CollisionDSSolid(const CollisionDSSolid &copy);
00047   virtual CollisionSolid *make_copy();
00048 
00049   virtual PT(CollisionEntry)
00050   test_intersection(const CollisionEntry &entry) const;
00051 
00052   INLINE float get_lens_radius() const;
00053 
00054   virtual void xform(const LMatrix4f &mat);
00055 
00056   virtual PStatCollector &get_volume_pcollector();
00057   virtual PStatCollector &get_test_pcollector();
00058 
00059   virtual void output(ostream &out) const;
00060 
00061 PUBLISHED:
00062   // Sphere a
00063   INLINE void set_center_a(const LPoint3f &center);
00064   INLINE void set_center_a(float x, float y, float z);
00065   INLINE const LPoint3f &get_center_a() const;
00066 
00067   INLINE void set_radius_a(float radius);
00068   INLINE float get_radius_a() const;
00069 
00070   // Sphere b
00071   INLINE void set_center_b(const LPoint3f &center);
00072   INLINE void set_center_b(float x, float y, float z);
00073   INLINE const LPoint3f &get_center_b() const;
00074 
00075   INLINE void set_radius_b(float radius);
00076   INLINE float get_radius_b() const;
00077 
00078   // Plane a
00079   INLINE LVector3f get_normal_a() const;
00080   INLINE float dist_to_plane_a(const LPoint3f &point) const;
00081 
00082   INLINE void set_plane_a(const Planef &plane);
00083   INLINE const Planef &get_plane_a() const;
00084 
00085   // Plane b
00086   INLINE LVector3f get_normal_b() const;
00087   INLINE float dist_to_plane_b(const LPoint3f &point) const;
00088 
00089   INLINE void set_plane_b(const Planef &plane);
00090   INLINE const Planef &get_plane_b() const;
00091 
00092 protected:
00093   virtual PT(BoundingVolume) compute_internal_bounds() const;
00094 
00095   virtual PT(CollisionEntry)
00096   test_intersection_from_sphere(const CollisionEntry &entry) const;
00097 
00098   virtual void fill_viz_geom();
00099 
00100 protected:
00101   void recalc_internals();
00102   Vertexf compute_point(float latitude, float longitude) const;
00103 
00104 private:
00105   LPoint3f _center_a;
00106   float _radius_a;
00107   LPoint3f _center_b;
00108   float _radius_b;
00109   Planef _plane_a;
00110   Planef _plane_b;
00111   
00112   mutable float _lens_radius;
00113 
00114   static PStatCollector _volume_pcollector;
00115   static PStatCollector _test_pcollector;
00116 
00117   void calc_plane(const Planef &plane);
00118   Vertexf calc_sphere1_vertex(
00119       int ri, int si, int num_rings, int num_slices, float length,
00120       float angle);
00121   Vertexf calc_sphere2_vertex(
00122       int ri, int si, int num_rings, int num_slices, float length,
00123       float angle);
00124 
00125 public:
00126   static void register_with_read_factory();
00127   virtual void write_datagram(BamWriter *manager, Datagram &me);
00128 
00129 protected:
00130   static TypedWritable *make_CollisionSphere(const FactoryParams &params);
00131   static TypedWritable *make_from_bam(const FactoryParams &params);
00132   void fillin(DatagramIterator &scan, BamReader *manager);
00133 
00134 public:
00135   static TypeHandle get_class_type() {
00136     return _type_handle;
00137   }
00138   static void init_type() {
00139     CollisionSolid::init_type();
00140     register_type(_type_handle, "CollisionDSSolid",
00141                   CollisionSolid::get_class_type());
00142   }
00143   virtual TypeHandle get_type() const {
00144     return get_class_type();
00145   }
00146   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00147 
00148 private:
00149   static TypeHandle _type_handle;
00150 };
00151 
00152 #include "collisionDSSolid.I"
00153 
00154 #endif
 All Classes Functions Variables Enumerations