From 467e701d27b88bae7a6bd4acffb434630f1f09be Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 24 Nov 2010 14:18:07 -0500 Subject: [PATCH] imported LogoBox --- LogoBox.cc | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ LogoBox.h | 25 ++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 LogoBox.cc create mode 100644 LogoBox.h diff --git a/LogoBox.cc b/LogoBox.cc new file mode 100644 index 0000000..14db5c4 --- /dev/null +++ b/LogoBox.cc @@ -0,0 +1,84 @@ + +/* 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 + */ + +#include +#include "WFObj.h" +#include "LogoBox.h" +#include "LoadFile.h" +#include /* memcpy() */ + +#include +using namespace std; + +static GLuint _logoList = 0; +static float _logoAABB[6]; +static GLuint _drawList; +static LoadFile loadFile; + +/* 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. + */ +LogoBox::LogoBox() +{ + if (_logoList == 0) + { + WFObj obj(loadFile); + if (obj.load(FileLoader::Path("", "dwlogo.obj"))) + { + _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; + _drawList = glGenLists(1); + glNewList(_drawList, GL_COMPILE); + glPushMatrix(); + glTranslatef(-c_x, -c_y, -c_z); + glCallList(_logoList); + glPopMatrix(); + glEndList(); + } + } + +} + +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 new file mode 100644 index 0000000..950df3d --- /dev/null +++ b/LogoBox.h @@ -0,0 +1,25 @@ + +/* + * Author: Josh Holtrop + * DornerWorks screensaver + * The LogoBox class + */ + +#ifndef LOGOBOX_H +#define LOGOBOX_H + +#include + +class LogoBox +{ +public: + LogoBox(); + ~LogoBox(); + void draw(); + const float * const getAABB() const; + float getWidth() const; + float getHeight() const; + float getDepth() const; +}; + +#endif