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 _PRIMITIVE_H 00008 #define _PRIMITIVE_H 00009 00010 #include <map> 00011 #include <vector> 00012 #include <boost/shared_ptr.hpp> 00013 #include <Physsim/Base.h> 00014 #include <Physsim/Matrix3.h> 00015 #include <Physsim/Triangle.h> 00016 00017 class SoNode; 00018 class SoSeparator; 00019 class SoTransform; 00020 00021 namespace Physsim { 00022 00024 00030 class Primitive : public Base 00031 { 00032 public: 00033 Primitive(); 00034 Primitive(const Matrix4& T); 00035 virtual ~Primitive(); 00036 virtual Matrix3 calc_inertia(); 00037 virtual Vector3 calc_com(); 00038 virtual Real calc_mass(); 00039 virtual void load_from_xml(XMLTreeConstPtr node, std::map<std::string, BasePtr>& id_map); 00040 virtual void save_to_xml(XMLTreePtr node, std::list<BaseConstPtr>& shared_objects) const; 00041 virtual void center(); 00042 virtual SoNode* create_visualization(); 00043 void update_visualization(); 00044 SoSeparator* get_visualization(); 00045 TriangleArrayConstPtr get_tris() const { return _tris; } 00046 void set_transform(const Matrix4& T); 00047 std::list<Vector3ConstPtr> get_vertices() const; 00048 static void transform_inertia(Real mass, const Matrix3& J_in, const Vector3& com_in, const Matrix4& T, Matrix3& J_out, Vector3& com_out); 00049 void set_max_tri_area(Real max_tri_area); 00050 Real get_max_tri_area() const { return _max_tri_area; } 00051 00053 const Matrix4& get_transform() const { return _T; } 00054 00055 std::vector<Real> det_indexed_mesh_vertices() const; 00056 std::vector<int> det_indexed_mesh_indices(bool term) const; 00057 // const std::map<Vector3ConstPtr, unsigned>& get_vertices(); 00058 // SoNode* get_visualization(); 00059 00061 void set_mass(Real mass) { _mass = mass; } 00062 00064 void set_density(Real density) { _density = density; } 00065 00066 00067 protected: 00068 void transform_mesh(); 00069 void subdivide(); 00070 00072 Matrix4 _T; 00073 00075 Real _mass; 00076 00078 Real _density; 00079 00081 00084 TriangleArrayConstPtr _tris; 00085 00086 private: 00087 00088 // void set_mesh(const std::vector<TriangleConstPtr>& mesh); 00089 // void det_vertices_from_mesh(const std::vector<TriangleConstPtr>& mesh); 00090 00092 Real _max_tri_area; 00093 00095 SoSeparator* _viz; 00096 00098 SoTransform* _vtransform; 00099 }; 00100 00101 } 00102 00103 #endif
1.5.1