From bb3dad08099a771d50ec2a91f3cd4341b6f7320a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 24 Nov 2010 16:20:42 -0500 Subject: [PATCH] LogoBox: cleaned up and optimized --- LogoBox.cc | 62 +++++++++++++++++------------------------------------- LogoBox.h | 13 ++++++------ 2 files changed, 26 insertions(+), 49 deletions(-) diff --git a/LogoBox.cc b/LogoBox.cc index 14db5c4..872cb81 100644 --- a/LogoBox.cc +++ b/LogoBox.cc @@ -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 @@ -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]; -} - diff --git a/LogoBox.h b/LogoBox.h index 950df3d..66fc056 100644 --- a/LogoBox.h +++ b/LogoBox.h @@ -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