Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_DRAW_BODY_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_DRAW_BODY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl_util.h>
00013
00014 #include <OpenTissue/collision/sdf/sdf.h>
00015 #include <OpenTissue/core/geometry/geometry_sphere.h>
00016 #include <OpenTissue/core/geometry/geometry_plane.h>
00017 #include <OpenTissue/core/geometry/geometry_obb.h>
00018
00019
00020 namespace OpenTissue
00021 {
00022 namespace mbd
00023 {
00024
00025 template<typename body_type>
00026 void draw_body(body_type const & body, bool wireframe)
00027 {
00028 typedef typename body_type::math_policy math_policy;
00029
00030 typedef typename body_type::value_traits value_traits;
00031 typedef typename body_type::node_traits node_traits;
00032
00033 typedef typename math_policy::real_type real_type;
00034 typedef typename math_policy::vector3_type vector3_type;
00035 typedef typename math_policy::matrix3x3_type matrix3x3_type;
00036 typedef typename math_policy::quaternion_type quaternion_type;
00037
00038 typedef OpenTissue::geometry::Sphere<math_policy> sphere_type;
00039 typedef OpenTissue::geometry::Plane<math_policy> plane_type;
00040 typedef OpenTissue::geometry::OBB<math_policy> box_type;
00041 typedef OpenTissue::polymesh::PolyMesh<math_policy> mesh_type;
00042 typedef OpenTissue::grid::Grid<float,math_policy> grid_type;
00043 typedef OpenTissue::sdf::Geometry<mesh_type,grid_type> sdf_geometry_type;
00044
00045 static real_type const one_third = value_traits::one() / 3;
00046 static real_type const two_third = value_traits::two()*one_third;
00047
00048 if(body.is_fixed())
00049 gl::ColorPicker(one_third,one_third,one_third);
00050 else if (body.is_sleepy())
00051 gl::ColorPicker(value_traits::zero(),value_traits::zero(),two_third);
00052 else
00053 gl::ColorPicker(two_third,two_third,two_third);
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 glPushMatrix();
00071 vector3_type r;
00072 quaternion_type Q;
00073 body.get_position(r);
00074 body.get_orientation(Q);
00075 gl::Transform(r,Q);
00076
00077
00078
00079
00080
00081 if(body.get_geometry()->class_id() == sdf_geometry_type::id() )
00082 {
00083 sdf_geometry_type * sdf = static_cast<sdf_geometry_type*>(body.get_geometry());
00084 if(wireframe)
00085 gl::DrawMesh(sdf->m_mesh,GL_LINE_LOOP);
00086 else
00087 gl::DrawMesh(sdf->m_mesh,GL_POLYGON);
00088 gl::ColorPicker(value_traits::one(),value_traits::zero(),value_traits::zero());
00089 gl::DrawGridAABB(sdf->m_phi);
00090 }
00091 else if(body.get_geometry()->class_id() == box_type::id() )
00092 {
00093 gl::DrawOBB( *(static_cast<box_type*>(body.get_geometry() )), wireframe);
00094 }
00095 else if(body.get_geometry()->class_id() == sphere_type::id() )
00096 {
00097 gl::DrawSphere( *(static_cast<sphere_type*>(body.get_geometry() )), wireframe);
00098 }
00099 else if(body.get_geometry()->class_id() == plane_type::id() )
00100 {
00101 gl::DrawPlane( *(static_cast<plane_type*>(body.get_geometry() )), wireframe );
00102 }
00103 else
00104 {
00105 assert(!"draw_body(): not handled");
00106 }
00107 glPopMatrix();
00108 if(wireframe)
00109 {
00110 vector3_type u;
00111 body.get_velocity(u);
00112 gl::ColorPicker(value_traits::one(),value_traits::zero(),value_traits::one());
00113 gl::DrawVector(r,u);
00114 gl::ColorPicker(value_traits::one(),value_traits::one(),value_traits::zero());
00115 body.get_spin(u);
00116 gl::DrawVector(r,u);
00117 }
00118 }
00119
00120 template<bool wireframe>
00121 class DrawBodyFunctor
00122 {
00123 public:
00124 template<typename body_type>
00125 void operator()(body_type const & body) const
00126 {
00127 draw_body(body,false);
00128 }
00129 };
00130
00131 template<>
00132 class DrawBodyFunctor<true>
00133 {
00134 public:
00135 template<typename body_type>
00136 void operator()(body_type const & body) const
00137 {
00138 draw_body(body,true);
00139 }
00140 };
00141
00142
00143 }
00144 }
00145
00146 #endif