85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
|
|
/* 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 <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 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];
|
|
}
|
|
|