dwss/LogoBox.cc
2010-11-24 16:20:42 -05:00

61 lines
1.5 KiB
C++

/*
* Author: Josh Holtrop
* DornerWorks ScreenSaver
* This module can be used to create "LogoBox" objects
* which consist of a 3D DW logo
*/
#include <GL/gl.h>
#include "WFObj.h"
#include "LogoBox.h"
#include "LoadFile.h"
#include <string.h> /* memcpy() */
#include <iostream>
using namespace std;
static GLuint _logoList = 0;
static GLuint _drawList;
static LoadFile loadFile;
static float _width, _depth, _height;
/*
* 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();
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();
glTranslatef(-c_x, -c_y, -c_z);
glCallList(_logoList);
glPopMatrix();
glEndList();
}
}
m_drawList = _drawList;
m_width = _width;
m_depth = _depth;
m_height = _height;
}