18 #include <SOIL/SOIL.h>
23 static GLuint textureWheel;
24 static GLuint textureRobot;
38 std::vector<float> distances;
40 for(
const auto& [angle, distance] : obstacleData)
42 float radianAngle = ((angle + 1) *
PI) / 180.0;
48 distances.push_back(distance);
51 float min = *std::min_element(std::begin(distances), std::end(distances));
52 float max = *std::max_element(std::begin(distances), std::end(distances));
54 for(
const auto& distance : distances)
56 float color = (distance - min) / (max - min) * 255.0;
75 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
76 glEnable(GL_TEXTURE_2D);
79 glClearColor(0.5, 0.5, 0.5, 1);
94 restoreStateFromFile();
96 GLfloat lightPosition[] = {1.0, 1.0, 1.0, 0.0};
97 glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
99 glEnable(GL_LIGHTING);
101 glEnable(GL_DEPTH_TEST);
103 glEnable(GL_TEXTURE_2D);
111 QString text(
"<h2>S i m p l e V i e w e r</h2>");
112 text +=
"Use the mouse to move the camera around the object. ";
113 text +=
"You can respectively revolve around, zoom and translate with the three mouse buttons. ";
114 text +=
"Left and middle buttons pressed together rotate around the camera view direction axis<br><br>";
115 text +=
"Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
116 text +=
"Simply press the function key again to restore it. Several keyFrames define a ";
117 text +=
"camera path. Paths are saved when you quit the application and restored at next start.<br><br>";
118 text +=
"Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
119 text +=
"<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. ";
120 text +=
"See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>";
121 text +=
"Double clicks automates single click actions: A left button double click aligns the closer axis with the "
122 "camera (if close enough). ";
124 "A middle button double click fits the zoom of the camera and the right button re-centers the scene.<br><br>";
125 text +=
"A left button double click while holding right button pressed defines the camera <i>Revolve Around "
127 text +=
"See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>";
128 text +=
"Press <b>Escape</b> to exit the viewer.";
134 glEnable(GL_TEXTURE_2D);
135 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
136 glGenTextures(1, texture);
137 glBindTexture(GL_TEXTURE_2D, *texture);
139 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
141 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
147 unsigned char* image = SOIL_load_image(path.c_str(), &width, &height, 0, SOIL_LOAD_RGB);
149 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
160 glRotatef(90, 0, 1, 0);
167 glRotatef(-90, 0, 1, 0);
172 angle = std::fmod(angle, 360.0);
180 glTranslatef(x, y, z);
192 glVertex3f(size, -size, size);
193 glVertex3f(size, size, size);
194 glVertex3f(-size, size, size);
195 glVertex3f(-size, -size, size);
200 glVertex3f(size, -size, -size);
201 glVertex3f(size, size, -size);
202 glVertex3f(size, size, size);
203 glVertex3f(size, -size, size);
208 glVertex3f(-size, -size, size);
209 glVertex3f(-size, size, size);
210 glVertex3f(-size, size, -size);
211 glVertex3f(-size, -size, -size);
216 glVertex3f(size, size, size);
217 glVertex3f(size, size, -size);
218 glVertex3f(-size, size, -size);
219 glVertex3f(-size, size, size);
224 glVertex3f(size, -size, -size);
225 glVertex3f(size, -size, size);
226 glVertex3f(-size, -size, size);
227 glVertex3f(-size, -size, -size);
235 glEnable(GL_TEXTURE_2D);
236 glBindTexture(GL_TEXTURE_2D, texture);
238 double i, resolution = 0.001;
241 glRotatef(90, 1, 0, 0);
244 glBegin(GL_TRIANGLE_FAN);
245 glTexCoord2f(0.5, 0.5);
246 glVertex3f(0, height, 0);
250 glTexCoord2f(0.5f * cos(i) + 0.5f, 0.5f * sin(i) + 0.5f);
251 glVertex3f(radius * cos(i), height, radius * sin(i));
254 glTexCoord2f(0.5, 0.5);
255 glVertex3f(radius, height, 0);
258 glDisable(GL_TEXTURE_2D);
262 glBegin(GL_TRIANGLE_FAN);
269 glVertex3f(radius * cos(i), 0, radius * sin(i));
276 glBegin(GL_QUAD_STRIP);
282 glVertex3f(radius * cos(i), 0, radius * sin(i));
284 glVertex3f(radius * cos(i), height, radius * sin(i));
288 glVertex3f(radius, 0, 0);
290 glVertex3f(radius, height, 0);