LogoBox: cleaned up and optimized

This commit is contained in:
Josh Holtrop 2010-11-24 16:20:42 -05:00
parent f2aa2ff908
commit bb3dad0809
2 changed files with 26 additions and 49 deletions

View File

@ -1,10 +1,9 @@
/* Author: Josh Holtrop
* DornerWorks screensaver
/*
* Author: Josh Holtrop
* DornerWorks ScreenSaver
* This module can be used to create "LogoBox" objects
* which consist of a 3D DW logo and possibly have a
* mass and boundary associated with them if physics
* is being used
* which consist of a 3D DW logo
*/
#include <GL/gl.h>
@ -17,11 +16,12 @@
using namespace std;
static GLuint _logoList = 0;
static float _logoAABB[6];
static GLuint _drawList;
static LoadFile loadFile;
static float _width, _depth, _height;
/* construct a LogoBox object
/*
* construct a LogoBox object
* The first time the constructor is called it loads the
* Alias Wavefront object model. Subsequent calls will
* reuse the same module.
@ -35,11 +35,15 @@ LogoBox::LogoBox()
{
_logoList = obj.render(false);
const float * aabb = obj.getAABB();
memcpy(_logoAABB, aabb, sizeof(_logoAABB));
float c_x = (_logoAABB[0] + _logoAABB[3]) / 2.0f;
float c_y = (_logoAABB[1] + _logoAABB[4]) / 2.0f;
float c_z = (_logoAABB[2] + _logoAABB[5]) / 2.0f;
float c_x = (aabb[0] + aabb[3]) / 2.0f;
float c_y = (aabb[1] + aabb[4]) / 2.0f;
float c_z = (aabb[2] + aabb[5]) / 2.0f;
_width = aabb[3] - aabb[0];
_depth = aabb[4] - aabb[1];
_height = aabb[5] - aabb[2];
_drawList = glGenLists(1);
glNewList(_drawList, GL_COMPILE);
glPushMatrix();
@ -49,36 +53,8 @@ LogoBox::LogoBox()
glEndList();
}
}
m_drawList = _drawList;
m_width = _width;
m_depth = _depth;
m_height = _height;
}
LogoBox::~LogoBox()
{
}
void LogoBox::draw()
{
glCallList(_drawList);
}
/* return a pointer to the axis-aligned bounding box for a DW logo */
const float * const LogoBox::getAABB() const
{
return _logoAABB;
}
float LogoBox::getWidth() const
{
return _logoAABB[3] - _logoAABB[0];
}
float LogoBox::getHeight() const
{
return _logoAABB[5] - _logoAABB[2];
}
float LogoBox::getDepth() const
{
return _logoAABB[4] - _logoAABB[1];
}

View File

@ -14,12 +14,13 @@ class LogoBox
{
public:
LogoBox();
~LogoBox();
void draw();
const float * const getAABB() const;
float getWidth() const;
float getHeight() const;
float getDepth() const;
void draw() { glCallList(m_drawList); }
float getWidth() const { return m_width; }
float getDepth() const { return m_depth; }
float getHeight() const { return m_height; }
protected:
GLuint m_drawList;
float m_width, m_depth, m_height;
};
#endif