Commit c9849a44 authored by Timothee Habra's avatar Timothee Habra

correct simbody visualization

parent 12e4a768
......@@ -31,7 +31,7 @@ void* prepare_simbody(SimbodyBodiesStruct *simbodyBodies){
#ifdef VIZ
p_simbodyVariables->p_system->setUpDirection(+ZAxis); // that is for visualization only. The default direction is +X
Visualizer viz(system);
p_simbodyVariables->p_viz = new Visualizer(*(p_simbodyVariables->p_system));
#endif
//it is "system" commands. We cannot avoid them.
......@@ -43,10 +43,6 @@ void* prepare_simbody(SimbodyBodiesStruct *simbodyBodies){
//it is "system" command. We cannot avoid them.
p_simbodyVariables->p_system->realizeModel(*p_simbodyVariables->p_state);
#ifdef VIZ
p_simbodyVariables->p_viz = &viz;
#endif
return (void*) p_simbodyVariables;
}
......@@ -70,7 +66,7 @@ int loop_Simbody (SimbodyStruct *simbodyStruct)
Visualizer *p_viz = p_simbodyVariables->p_viz;
#endif
// stage 1: to update all the cinematic variables for all the bodies in the system
// stage 1: to update all the kinematic variables for all the bodies in the system
for(i=0;i<NB_CONTACT_BODIES;i++)
{
......@@ -178,6 +174,10 @@ void free_Simbody(void* p_simbodyVariables_void)
delete(p_simbodyVariables->p_matter);
delete(p_simbodyVariables->p_tracker);
delete(p_simbodyVariables->p_contactForces);
#ifdef VIZ
p_simbodyVariables->p_viz->shutdown(); // close window
delete(p_simbodyVariables->p_viz);
#endif
delete(p_simbodyVariables->p_system);
delete(p_simbodyVariables);
......@@ -211,8 +211,8 @@ try
if (GrContProp->Geometry == 1)
{
std::ifstream meshFileGr;
PolygonalMesh GroundMesh;
char FileName[FILENAME_MAX];
PolygonalMesh GroundMesh;
printf("1. Open mesh-file %s ...",GrContProp->FileName);
sprintf(FileName,"%s%s%s",BODIES_OBJ_PATH"/",GrContProp->FileName);
meshFileGr.open(FileName);
......@@ -245,19 +245,26 @@ try
ContactMaterial(GrContProp->k,GrContProp->c,GrContProp->us,GrContProp->ud,GrContProp->uv),
GrContProp->thickness)
);
#ifdef VIZ
DecorativeMesh showGround = DecorativeMesh(GroundMesh);
p_matter->updGround().addBodyDecoration(Transform(Vec3(0, 0, 0)), showGround);
#endif
printf(" succeed! \n\n");//*/
}
else
else //Half space (horizontal plane)
{
const Rotation R_zdown(Pi/2.,YAxis);
p_matter->Ground().updBody().addContactSurface(Transform(R_zdown, Vec3(0,0,0)),
ContactSurface(ContactGeometry::HalfSpace(),
ContactMaterial(GrContProp->k,GrContProp->c,GrContProp->us,GrContProp->ud,GrContProp->uv)));
#ifdef VIZ
p_matter->Ground().updBody().addDecoration(Transform(),
DecorativeBrick(Vec3(10.0, 10.0, 0.001)).setColor(Gray).setOpacity(.1));
#endif
}
#ifdef VIZ
DecorativeMesh showGround = DecorativeMesh(GroundMesh);
p_matter->updGround().addBodyDecoration(Transform(Vec3(0,0,0)),showGround);
#endif
const Vec3 comLoc(0, 0, 0); // Location of the center of mass
// set the mass-inertial properties of the body. These parameters might be arbitrary
......@@ -315,15 +322,25 @@ try
ContactMaterial(CurBodyContProp->k,CurBodyContProp->c,CurBodyContProp->us,CurBodyContProp->ud,CurBodyContProp->uv),
CurBodyContProp->thickness)
);
// it is only for visualization. Doesn't work under Linux
#ifdef VIZ
DecorativeMesh showBox = DecorativeMesh(BodyMesh);
Body.addDecoration(Transform(), showBox.setColor(Red).setOpacity(1).setRepresentation(SimTK::DecorativeGeometry::Representation(0)));
#endif // VIZ
printf(" succeed! \n\n");
}
else if (CurBodyContProp->Geometry == 2) // box
{
Body.addContactSurface(Transform(Vec3(0,0,0)),
Body.addContactSurface(Transform(Vec3(0,0,0.2)),
ContactSurface(ContactGeometry::Brick(Vec3(0.075,0.075,0.075)),
ContactMaterial(CurBodyContProp->k,CurBodyContProp->c,CurBodyContProp->us,CurBodyContProp->ud,CurBodyContProp->uv),
CurBodyContProp->thickness)
);
#ifdef VIZ
Body.addDecoration( Transform(),
DecorativeBrick(Vec3(0.075, 0.075, 0.075)).setColor(Red).setOpacity(1));
#endif
}
else if (CurBodyContProp->Geometry == 3) // sphere
{
......@@ -332,15 +349,12 @@ try
ContactMaterial(CurBodyContProp->k,CurBodyContProp->c,CurBodyContProp->us,CurBodyContProp->ud,CurBodyContProp->uv),
CurBodyContProp->thickness)
);
#ifdef VIZ
Body.addDecoration(Transform(),
DecorativeSphere(0.02).setColor(Orange).setOpacity(1));
#endif
}
// it is only for visualization. Doesn't work under Linux
#ifdef VIZ
//DecorativeMesh showGround = DecorativeMesh(GroundMesh);
//Ground.addBodyDecoration(showGround);
DecorativeMesh showBox = DecorativeMesh(WheelMesh);
WheelBody.addDecoration(Transform(), showBox.setColor(Red).setOpacity(1).setRepresentation(SimTK::DecorativeGeometry::Representation(0)));
#endif // VIZ
MobilizedBody::Free MobBody(p_matter->Ground(), Transform(Vec3(0)),
Body, Transform(Vec3(0)));
......
......@@ -8,6 +8,8 @@
//#include "simu_def.h"
//#define VIZ
// path to the .obj mesh files
#define BODIES_OBJ_PATH PROJECT_ABS_PATH,"/src/project/simulation_files/Simbody/mesh_obj"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment