center logobox when drawing

This commit is contained in:
Josh Holtrop 2011-10-12 12:21:13 -04:00
parent 123951d863
commit 2f88a11652

View File

@ -25,6 +25,7 @@ enum Locations {
LOC_NORMAL LOC_NORMAL
}; };
static float _width, _depth, _height; static float _width, _depth, _height;
static float center_xlate[3];
static bool loaded = false; static bool loaded = false;
/* /*
@ -41,9 +42,9 @@ LogoBox::LogoBox()
{ {
const float * aabb = obj.getAABB(); const float * aabb = obj.getAABB();
float c_x = (aabb[0] + aabb[3]) / 2.0f; center_xlate[0] = -(aabb[0] + aabb[3]) / 2.0f;
float c_y = (aabb[1] + aabb[4]) / 2.0f; center_xlate[1] = -(aabb[1] + aabb[4]) / 2.0f;
float c_z = (aabb[2] + aabb[5]) / 2.0f; center_xlate[2] = -(aabb[2] + aabb[5]) / 2.0f;
_width = aabb[3] - aabb[0]; _width = aabb[3] - aabb[0];
_depth = aabb[4] - aabb[1]; _depth = aabb[4] - aabb[1];
@ -125,6 +126,8 @@ void LogoBox::draw()
stride, (GLvoid *) obj.getVertexOffset()); stride, (GLvoid *) obj.getVertexOffset());
glVertexAttribPointer(LOC_NORMAL, 3, GL_FLOAT, GL_FALSE, glVertexAttribPointer(LOC_NORMAL, 3, GL_FLOAT, GL_FALSE,
stride, (GLvoid *) obj.getNormalOffset()); stride, (GLvoid *) obj.getNormalOffset());
glPushMatrix();
glTranslatef(center_xlate[0], center_xlate[1], center_xlate[2]);
for (map<string, WFObj::Material>::iterator it = obj.getMaterials().begin(); for (map<string, WFObj::Material>::iterator it = obj.getMaterials().begin();
it != obj.getMaterials().end(); it != obj.getMaterials().end();
it++) it++)
@ -134,4 +137,5 @@ void LogoBox::draw()
GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT,
(GLvoid *) (sizeof(GLushort) * it->second.first_vertex)); (GLvoid *) (sizeof(GLushort) * it->second.first_vertex));
} }
glPopMatrix();
} }