-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.cc
89 lines (61 loc) · 2.43 KB
/
object.cc
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "object.h"
#include "point_based_renderer.h"
Object::~Object() {
glDeleteLists(pointsDisplayList, 1);
}
/**
* Render object using designed rendering system.
**/
void Object::render ( void ) const{
glCallList(pointsDisplayList);
/// for rendering directly without display-lists uncomment the code below and comment line above
/// but performance drops drastically in many cases, for the asian dragon it is around 4 times slower for example
// glBegin(GL_POINTS);
// for (surfelVectorIterConst it = surfels.begin(); it != surfels.end(); ++it) {
// glColor4f((GLfloat)(it->Color()[0] / 255.0), (GLfloat)(it->Color()[1] / 255.0), (GLfloat)(it->Color()[2] / 255.0), (GLfloat)(1.0));
// glNormal3f((GLfloat)it->Normal()[0], (GLfloat)it->Normal()[1], (GLfloat)it->Normal()[2]);
// glVertex4f((GLfloat)it->Center()[0], (GLfloat)it->Center()[1], (GLfloat)it->Center()[2], (GLfloat)it->Radius());
// }
// glEnd();
check_for_ogl_error("Primitives render");
}
/**
* Changes the renderer type.
* @param rtype Given renderer type.
**/
void Object::setRendererType ( int rtype ) {
renderer_type = rtype;
if (rtype == PYRAMID_POINTS) {
setPyramidPointsDisplayList();
}
else if (rtype == PYRAMID_POINTS_COLOR) {
setPyramidPointsColorDisplayList();
}
}
void Object::setPyramidPointsDisplayList ( void ) {
pointsDisplayList = glGenLists(1);
glNewList(pointsDisplayList, GL_COMPILE);
glPointSize(1.0);
glBegin(GL_POINTS);
for (surfelVectorIter it = surfels.begin(); it != surfels.end(); ++it) {
glNormal3f((GLfloat)it->Normal()[0], (GLfloat)it->Normal()[1], (GLfloat)it->Normal()[2]);
glVertex4f((GLfloat)it->Center()[0], (GLfloat)it->Center()[1], (GLfloat)it->Center()[2], (GLfloat)it->Radius());
}
glEnd();
glEndList();
}
void Object::setPyramidPointsColorDisplayList ( void ) {
pointsDisplayList = glGenLists(1);
glNewList(pointsDisplayList, GL_COMPILE);
glBegin(GL_POINTS);
for (surfelVectorIter it = surfels.begin(); it != surfels.end(); ++it) {
glColor4f((GLfloat)(it->Color()[0] / 255.0), (GLfloat)(it->Color()[1] / 255.0), (GLfloat)(it->Color()[2] / 255.0), (GLfloat)(1.0));
glNormal3f((GLfloat)it->Normal()[0], (GLfloat)it->Normal()[1], (GLfloat)it->Normal()[2]);
glVertex4f((GLfloat)it->Center()[0], (GLfloat)it->Center()[1], (GLfloat)it->Center()[2], (GLfloat)it->Radius());
}
glEnd();
glEndList();
}
void Object::clearSurfels ( void ) {
surfels.clear();
}