00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _GFX_QUAD3_
00026 #define _GFX_QUAD3_
00027
00028 #include <gfx/gfx>
00029 #include <base/Point3>
00030 #include <base/Vector3>
00031 #include <gfx/Segment3>
00032 #include <gfx/Triangle3>
00033
00034 #include <iostream>
00035
00036
00037 namespace gfx {
00038
00039
00040 class Quad3
00041 {
00042
00043 public:
00044 Quad3() {}
00045 Quad3(const Quad3& q)
00046 : c1(q.c1), c2(q.c2), c3(q.c3), c4(q.c4) {}
00047 Quad3(const Point3& c1, const Point3& c2, const Point3& c3, const Point3& c4);
00048 ~Quad3() {}
00049
00050 const Point3& operator[](Int i) const { return (i==1)?c1:((i==2)?c2:((i==3)?c3:c4)); }
00051 Point3& operator[](Int i) { return (i==1)?c1:((i==2)?c2:((i==3)?c3:c4)); }
00052
00053
00054 Quad3& operator*=(Real s) { c1*=s; c2*=s; c3*=s; c4*=s; return *this; }
00055 Quad3& operator/=(Real s) { c1/=s; c2/=s; c3/=s; c4/=s; return *this; }
00056
00057 void transform(const base::Transform& t)
00058 {
00059 c1=t*c1;
00060 c2=t*c2;
00061 c3=t*c3;
00062 c4=t*c4;
00063 }
00064
00065
00066 Real distanceTo(const Point3& p) const;
00067
00068
00069 Point3 pointClosestTo(const Point3& p) const;
00070
00071
00072 Segment3 shortestSegmentBetween(const Segment3& s) const;
00073
00074
00075 Segment3 shortestSegmentBetween(const Triangle3& t) const;
00076
00077
00078 Segment3 shortestSegmentBetween(const Quad3& q) const;
00079
00080
00081 Real distanceTo(const Segment3& s) const;
00082
00083
00084 Real distanceTo(const Triangle3& t) const;
00085
00086
00087 Real distanceTo(const Quad3& q) const;
00088
00089
00090 Point3 c1, c2, c3, c4;
00091 };
00092
00093
00094
00095
00096 inline Quad3 operator*(const Quad3& q, Real s)
00097 { Quad3 r(q); r*=s; return r; }
00098
00099 inline Quad3 operator*(Real s, const Quad3& q)
00100 { Quad3 r(q); r*=s; return r; }
00101
00102 inline Quad3 operator/(const Quad3& q, Real s)
00103 { Quad3 r(q); r/=s; return r; }
00104
00105
00106 inline std::ostream& operator<<(std::ostream& out, const Quad3& q)
00107 { return out << "[" << q.c1 << "-" << q.c2 << "-" << q.c3 << "-" << q.c4 << "]"; }
00108
00109
00110 }
00111
00112 #endif