Triangle.h

00001 /****************************************************************************
00002  * Copyright 2005 Evan Drumwright
00003  * This library is distributed under the terms of the GNU General Public 
00004  * License (found in COPYING).
00005  ****************************************************************************/
00006 
00007 #ifndef _TRIANGLE_H
00008 #define _TRIANGLE_H
00009 
00010 #include <ostream>
00011 #include <boost/shared_ptr.hpp>
00012 #include <Physsim/Base.h>
00013 #include <Physsim/Vector3.h>
00014 #include <Physsim/Matrix4.h>
00015 
00016 namespace Physsim {
00017 
00019 class Triangle : public Base
00020 {
00021         public:
00022                 Triangle(Vector3ConstPtr a, Vector3ConstPtr b, Vector3ConstPtr c);
00023                 Triangle(const Vector3& a, const Vector3& b, const Vector3& c);
00024                 Triangle() {}
00025                 ~Triangle();
00026                 Triangle(const Triangle& t) : Base() { operator=(t); }
00027                 void operator=(const Triangle& t);
00028                 static bool intersects(const Triangle& t1, const Triangle& t2);
00029                 static Triangle transform(const Triangle& t, const Matrix4& m);
00030                 Vector3ConstPtr get_vertex(unsigned i) const;
00031                 const Vector3& normal() const { return _normal; }
00032                 bool on_vertex(const Vector3& x) const;
00033                 bool on_edge(const Vector3& x) const;
00034                 bool inside(const Vector3& x) const;
00035                 bool strictly_inside(const Vector3& x) const;
00036                 void to_VRML(std::ostream& o, bool wireframe) const;
00037                 void set_a(Vector3ConstPtr a);
00038                 void set_b(Vector3ConstPtr b);
00039                 void set_c(Vector3ConstPtr c);
00040                 void set_a(const Vector3& a) { set_a(Vector3ConstPtr(new Vector3(a))); }
00041                 void set_b(const Vector3& b) { set_b(Vector3ConstPtr(new Vector3(b))); }
00042                 void set_c(const Vector3& c) { set_c(Vector3ConstPtr(new Vector3(c))); }
00043                 Real get_area() const { return _area; }
00044                 void force_normal_update();
00045                 Real calc_distance(const Vector3& point, Vector3& closest_point) const;
00046 
00048                 Real get_d() const { return _d; }
00049 
00050 //              void transform(const Matrix4& m);
00051                 
00053                 Vector3ConstPtr a() const { return _a; }
00054                 
00056                 Vector3ConstPtr b() const { return _b; }
00057                 
00059                 Vector3ConstPtr c() const { return _c; }
00060 
00061         private:
00062                 Real _area;
00063                 Vector3 _normal;
00064                 Vector3ConstPtr _a, _b, _c;
00065                 Real _d;
00066 
00067                 void calc_area();
00068                 void det_params(const Vector3& x, Real& s, Real& t) const;
00069                 static bool project6(const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vector3&, const Vector3&);
00070 }; // end class
00071 
00072 std::ostream& operator<<(std::ostream& o, const Triangle& t);
00073 
00074 } // end namespace Physsim
00075 
00076 #endif

Generated on Wed Oct 24 14:54:22 2007 for Physsim by  doxygen 1.5.1