41 vi->setViewportPosition(0.7, 0.05, 0.28, 0.28);
42 vi->setCloneView(
"main");
43 vi->setTransparent(
true);
44 vi->getCamera().setAzimuthDegrees(45);
45 vi->getCamera().setElevationDegrees(45);
46 vi->getCamera().setZoomDistance(10);
52 vi->setViewportPosition(
56 vi->setCloneView(
"main");
57 vi->setTransparent(
false);
58 vi->getCamera().setAzimuthDegrees(-95);
59 vi->getCamera().setElevationDegrees(30);
60 vi->getCamera().setZoomDistance(8);
67 mrpt::make_aligned_shared<mrpt::opengl::CText>();
69 vi->setViewportPosition(0, 0, 0.3, 0.3);
70 vi->setTransparent(
true);
72 vi->getCamera().setAzimuthDegrees(0);
73 vi->getCamera().setElevationDegrees(90);
74 vi->getCamera().setZoomDistance(5);
75 vi->getCamera().setOrthogonal(
true);
84 mrpt::make_aligned_shared<opengl::CGridPlaneXY>(
85 -20, 20, -20, 20, 0, 1);
86 obj->setColor(0.8, 0.8, 0.8);
87 theScene->insert(
obj);
93 obj->enableTickMarks();
94 obj->setAxisLimits(-10, -10, -10, 10, 10, 10);
95 theScene->insert(
obj);
100 obj->setWireframe(
false);
101 obj->setColor(1, 0, 0);
102 obj->setLineWidth(3.0);
103 obj->setPose(
TPose3D(10, 0, 0, 0.2, 0.3, 0.1));
104 theScene->insert(
obj);
109 obj->setColor(0, 0, 1);
111 obj->setLocation(0, 0, 1);
112 obj->setName(
"ball_1");
113 theScene->insert(
obj);
117 obj->setColor(1, 0, 0);
119 obj->setLocation(-1, -1, 1);
120 obj->setName(
"ball_2");
121 theScene->insert(
obj);
126 obj->setColor(0, 1, 0);
128 obj->setLocation(0, 0, 0);
129 obj->setName(
"USER_MOUSE_PICK");
130 theScene->insert(
obj);
134 win.unlockAccess3DScene();
138 0.01, 0.85,
"This is a 2D message",
TColorf(1, 1, 1),
"sans", 11,
141 win.setCameraElevationDeg(25.0f);
145 cout <<
"Control with mouse or keyboard. Valid keys:" << endl;
146 cout <<
" ESC -> Exit" << endl;
147 cout <<
" Left/right cursor arrow -> Camera azimuth" << endl;
148 cout <<
" P -> Enable / disable 'place object' " 154 bool placeMode =
false;
159 while (!
end &&
win.isOpen())
161 const double t = timer.
Tac();
167 const double W1 = 5.0, Q1 = 3.3;
170 R1 * cos(W1 *
t) * sin(Q1 *
t), R1 * sin(W1 *
t),
171 R1 * cos(W1 *
t) * cos(Q1 *
t));
174 const double W2 = 1.3, Q2 = 7.2;
177 R2 * cos(W2 *
t) * sin(Q2 *
t), R2 * sin(W2 *
t),
178 R2 * cos(W2 *
t) * cos(Q2 *
t));
181 0.01, 0.85,
"This is a 2D message",
TColorf(1, 0, 0),
"sans", 8,
188 "ball#1 pos: %.02f %.02f %.02f ", obj1->getPoseX(),
189 obj1->getPoseY(), obj1->getPoseZ()),
190 TColorf(.8, .8, .8),
"sans", 14,
211 int mouse_x, mouse_y;
213 win.getLastMousePosition(
218 theScene->getViewport(
"main")->get3DRayForPixelCoord(
219 mouse_x, mouse_y, ray);
236 theScene->getByName(
"USER_MOUSE_PICK")
237 ->setLocation(inters_pt.
x, inters_pt.
y, inters_pt.
z);
242 win.unlockAccess3DScene();
246 std::this_thread::sleep_for(20ms);
252 int key =
win.getPushedKey(&kmods);
254 "Key pushed: %c (%i) - modifiers: 0x%04X\n",
char(key), key,
260 win.setCameraAzimuthDeg(
win.getCameraAzimuthDeg() + 5);
262 win.setCameraAzimuthDeg(
win.getCameraAzimuthDeg() - 5);
264 if (key ==
'p' || key ==
'P')
266 placeMode = !placeMode;
267 win.setCursorCross(placeMode);
284 catch (std::exception& e)
286 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
291 printf(
"Untyped exception!!");
double Tac() noexcept
Stops the stopwatch.
A high-performance stopwatch, with typical resolution of nanoseconds.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Standard object for storing any 3D lightweight object.
GLsizei GLsizei GLuint * obj
This base provides a set of functions for maths stuff.
3D Plane, represented by its equation
double x
X,Y,Z coordinates.
mrpt::gui::CDisplayWindow3D::Ptr win
bool getPoint(TPoint3D &p) const
Gets the content as a point, returning false if the type is not adequate.
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).
renders glyphs filled with antialiased outlines
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.
GLenum GLsizei GLenum format
Classes for creating GUI windows for 2D and 3D visualization.
void Tic() noexcept
Starts the stopwatch.
std::string dateTimeLocalToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
renders glyphs as filled polygons
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
3D line, represented by a base point and a director vector.