MeshKit  1.0
3D.h
Go to the documentation of this file.
00001 #ifndef GFXGEOM_3D_INCLUDED // -*- C++ -*-
00002 #define GFXGEOM_3D_INCLUDED
00003 
00004 #include "Vec3.h"
00005 #include "Vec4.h"
00006 #include "Array.h"
00007 
00008 class Bounds
00009 {
00010 public:
00011 
00012     Vec3 min, max;
00013     Vec3 center;
00014     double radius;
00015     unsigned int points;
00016 
00017     Bounds() { reset(); }
00018 
00019     void reset();
00020     void addPoint(const Vec3&);
00021     void complete();
00022 };
00023 
00024 class Plane
00025 {
00026     //
00027     // A plane is defined by the equation:  n*p + d = 0
00028     Vec3 n;
00029     double d;
00030 
00031 public:
00032 
00033     Plane() : n(0,0,1) { d=0; } // -- this will define the XY plane
00034     Plane(const Vec3& p, const Vec3& q, const Vec3& r) { calcFrom(p,q,r); }
00035     Plane(const array<Vec3>& verts) { calcFrom(verts); }
00036     Plane(const Plane& p) { n=p.n; d=p.d; }
00037 
00038     void calcFrom(const Vec3& p, const Vec3& q, const Vec3& r);
00039     void calcFrom(const array<Vec3>&);
00040 
00041     bool isValid() const { return n[X]!=0.0 || n[Y]!=0.0 || n[Z]!= 0.0; }
00042     void markInvalid() { n[X] = n[Y] = n[Z] = 0.0; }
00043 
00044     double distTo(const Vec3& p) const { return n*p + d; }
00045     const Vec3& normal() const { return n; }
00046 
00047     void coeffs(double *a, double *b, double *c, double *dd) const {
00048         *a=n[X]; *b=n[Y]; *c=n[Z]; *dd=d;
00049     }
00050     Vec4 coeffs() const { return Vec4(n,d); }
00051 };
00052 
00053 // GFXGEOM_3D_INCLUDED
00054 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines