37 vi->setViewportPosition(0.7, 0.05, 0.28, 0.28);
38 vi->setCloneView(
"main");
39 vi->setTransparent(
true);
40 vi->getCamera().setAzimuthDegrees(45);
41 vi->getCamera().setElevationDegrees(45);
42 vi->getCamera().setZoomDistance(10);
49 opengl::CGridPlaneXY::Create(-20, 20, -20, 20, 0, 1);
50 obj->setColor(0.4, 0.4, 0.4);
51 theScene->insert(
obj);
57 obj->enableTickMarks();
58 obj->setAxisLimits(-10, -10, -10, 10, 10, 10);
59 theScene->insert(
obj);
64 obj->setWireframe(
false);
65 obj->setColor(1, 0, 0);
66 obj->setLineWidth(3.0);
68 theScene->insert(
obj);
73 obj->setColor(0, 0, 1);
75 obj->setLocation(0, 0, 1);
76 obj->setName(
"ball_1");
77 theScene->insert(
obj);
81 obj->setColor(1, 0, 0);
83 obj->setLocation(-1, -1, 1);
84 obj->setName(
"ball_2");
85 theScene->insert(
obj);
90 obj->setColor(0, 1, 0);
92 obj->setLocation(0, 0, 0);
93 obj->setName(
"USER_MOUSE_PICK");
94 theScene->insert(
obj);
98 win.unlockAccess3DScene();
100 win.captureImagesStart();
103 win.addTextMessage(0.05, 0.05,
"This is a 2D message");
105 win.setCameraElevationDeg(25.0f);
109 cout <<
"Control with mouse or keyboard. Valid keys:" << endl;
110 cout <<
" ESC -> Exit" << endl;
111 cout <<
" Left/right cursor arrow -> Camera azimuth" << endl;
116 while (!
end &&
win.isOpen())
123 obj1->getPoseX() + cos(obj1->getPoseY() / 2) * 0.05,
124 obj1->getPoseY() - sin(obj1->getPoseX() / 2) * 0.09,
125 obj1->getPoseZ() - sin(obj1->getPoseX() / 2) * 0.08);
127 obj1 = theScene->getByName(
"ball_2");
129 obj1->getPoseX() + cos(obj1->getPoseY() / 2) * 0.05,
130 obj1->getPoseY() - sin(obj1->getPoseX() / 2) * 0.09,
131 obj1->getPoseZ() - sin(obj1->getPoseX() / 2) * 0.08);
136 "ball#1 pos: %.02f %.02f %.02f ", obj1->getPoseX(),
137 obj1->getPoseY(), obj1->getPoseZ()),
144 win.unlockAccess3DScene();
148 std::this_thread::sleep_for(10ms);
155 const string s =
format(
"GRAB_%06i.png", ++i);
157 printf(
"Saved frame image to: %s \r",
s.c_str());
168 int key =
win.getPushedKey(&kmods);
170 "Key pushed: %c (%i) - modifiers: 0x%04X\n",
char(key), key,
176 win.setCameraAzimuthDeg(
win.getCameraAzimuthDeg() + 5);
178 win.setCameraAzimuthDeg(
win.getCameraAzimuthDeg() - 5);
194 catch (
const std::exception& e)
201 printf(
"Untyped exception!!");
GLsizei GLsizei GLuint * obj
std::shared_ptr< CImage > Ptr
mrpt::gui::CDisplayWindow3D::Ptr win
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A RGB color - floats in the range [0,1].
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
The namespace for 3D scene representation and rendering.
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
GLenum GLsizei GLenum format
Classes for creating GUI windows for 2D and 3D visualization.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.