-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewer.cpp
More file actions
64 lines (56 loc) · 2.97 KB
/
Viewer.cpp
File metadata and controls
64 lines (56 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// \file Viewer.cpp
#include "Viewer.h"
using namespace std;
// Draws a tetrahedron with 4 colors.
void Viewer::draw() {
float colorBronzeDiff[4] = { 0.8, 0.6, 0.0, 1.0 };
float colorBronzeSpec[4] = { 1.0, 1.0, 0.4, 1.0 };
float colorNull [4] = { 0.0, 0.0, 0.0, 1.0 };
// OpenGL met en place par défaut le modèle de Phong d'illumination.
glBegin(GL_TRIANGLES);
glEnable(GL_COLOR_MATERIAL); // le materiau peut changer à chaque triangle.
// Si vous les écrivez là, ces couleurs/réglages seront partagés par tous
// les triangles.
glColor4fv(colorBronzeDiff);
glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBronzeDiff);
glMaterialfv(GL_FRONT, GL_SPECULAR, colorBronzeSpec);
glMaterialf(GL_FRONT, GL_SHININESS, 20.0f );
for (auto triangle : ptrSoup->triangles) {
Vecteur n = triangle.normal();
glNormal3f( n[ 0 ], n[ 1 ], n[ 2 ] );
glVertex3f(triangle.v1[0], triangle.v1[1], triangle.v1[2]);
glVertex3f(triangle.v2[0], triangle.v2[1], triangle.v2[2]);
glVertex3f(triangle.v3[0], triangle.v3[1], triangle.v3[2]);
}
glDisable(GL_COLOR_MATERIAL);
glEnd();
}
void Viewer::init() {
// Restore previous viewer state.
restoreStateFromFile();
Vecteur v1;
Vecteur v2;
ptrSoup->boundingBox(v1, v2);
camera()->setSceneBoundingBox(qglviewer::Vec(v1[0], v1[1], v1[2]), qglviewer::Vec(v2[0], v2[1], v2[2]));
camera()->showEntireScene();
// Opens help window
help();
}
QString Viewer::helpString() const {
QString text("<h2>S i m p l e V i e w e r</h2>");
text += "Use the mouse to move the camera around the object. ";
text += "You can respectively revolve around, zoom and translate with the three mouse buttons. ";
text += "Left and middle buttons pressed together rotate around the camera view direction axis<br><br>";
text += "Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
text += "Simply press the function key again to restore it. Several keyFrames define a ";
text += "camera path. Paths are saved when you quit the application and restored at next start.<br><br>";
text += "Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
text += "<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. ";
text += "See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>";
text += "Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). ";
text += "A middle button double click fits the zoom of the camera and the right button re-centers the scene.<br><br>";
text += "A left button double click while holding right button pressed defines the camera <i>Revolve Around Point</i>. ";
text += "See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>";
text += "Press <b>Escape</b> to exit the viewer.";
return text;
}