MRPT / mrpt

:zap: The Mobile Robot Programming Toolkit (MRPT)
https://docs.mrpt.org/reference/latest/
BSD 3-Clause "New" or "Revised" License
1.94k stars 628 forks source link

Incorrect rendering of 3D objects #93

Closed phocoena-sinus closed 9 years ago

phocoena-sinus commented 9 years ago

I am trying to figure out some unexpected effects when rendering OpenGL objects. For instance, when rendering a CornerXYZ object, the tips of the arrows sometimes appear shifted away from the lines--even though the 3 lines are perfectly aligned to each other.

file:///home/lnavarro/Desktop/Screenshot-Sample%20CornerXYZ.png

This happens with mrpt-1.2.2, running on Ubuntu 10.04LTS 32bits and Ubuntu 12.04 32bits.

The relevant sample test code is

mrpt::gui::CDisplayWindow3D *win3D = new mrpt::gui::CDisplayWindow3D("Sample CornerXYZ", 600, 500); win3D->setCameraZoom(70); win3D->setCameraAzimuthDeg(-90); win3D->setCameraElevationDeg(90);

mrpt::opengl::COpenGLScenePtr scene = mrpt::opengl::COpenGLScene::Create(); mrpt::opengl::COpenGLViewportPtr view = scene -> getViewport( "main" );

  mrpt::poses::CPose3D  jeepPose; // x y z yaw pitch roll
   {
     mrpt::opengl::CSetOfObjectsPtr obj = mrpt::opengl::stock_objects::CornerXYZ(1.0);
     obj  -> setPose( jeepPose );
     view -> insert( obj );
   }

   // Show 3D?
   if (win3D) {
     mrpt::opengl::COpenGLScenePtr &ptrScene = win3D -> get3DSceneAndLock();
     ptrScene = scene;
     // Move camera:
     win3D -> setCameraPointingToPoint( jeepPose.x(), jeepPose.y(),  jeepPose.z() );
     win3D -> unlockAccess3DScene();

     // Update:
     win3D -> forceRepaint();
     win3D -> waitForKey();

   }
mlopezantequera commented 9 years ago

Can't see the screenshot

phocoena-sinus commented 9 years ago

A sample screenshot is shown in https://app.box.com/s/2coug8kymqr2q3q6dq2w

mlopezantequera commented 9 years ago

I ran your code on Ubuntu 14.04 64bit (mrpt 1.0.2 and 1.2.2) but the arrows look ok to me. Maybe post a full working example? where you fill out the pose of the arrows also.

phocoena-sinus commented 9 years ago

Thanks for looking into this. Your question made me think of something else, and I think that's what's causing the incorrect rendering I see. Test your code using the values 4428236.059665, 585360.461802, 0 for jeepPose.x(), jeepPose.y() and jeepPose.z() respectively. These values come from the UTM coordinates I was using in my test. If I use local coordinates instead (i.e. much smaller values), everything is rendered correctly.

jlblancoc commented 9 years ago

Hum! Interesting, so it was a cause of floating number accuracy :-) Thanks for writing back for the records.

Perhaps you can still use UTM coordinates if placing stuff inside a CSetOfObjects in local coordinates, then moving that object to UTM coords. It will be up to the graphic card accuracy then...

(Marking as closed)

phocoena-sinus commented 9 years ago

Thank you!