113 lines
2.6 KiB
C++
113 lines
2.6 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 <ode/ode.h>
|
|
#include "../wfobj/WFObj.hh"
|
|
#include "LogoBox.h"
|
|
#include "../LoadFile/LoadFile.h"
|
|
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
static GLuint _logoList = 0;
|
|
static float _logoAABB[6];
|
|
static GLuint _drawList;
|
|
|
|
/* 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. If physics are being used
|
|
* (world and space are not NULL), then the constructor
|
|
* initializes an ODE body and geometry for each
|
|
* constructed logo.
|
|
*/
|
|
LogoBox::LogoBox(dWorldID world, dSpaceID space)
|
|
{
|
|
if (_logoList == 0)
|
|
{
|
|
WFObj obj;
|
|
if (obj.load("dwlogo.obj", NULL, &LoadFile))
|
|
{
|
|
_logoList = obj.render();
|
|
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();
|
|
}
|
|
}
|
|
|
|
m_body = 0;
|
|
m_geom = 0;
|
|
|
|
if (world != 0)
|
|
{
|
|
dMass mass;
|
|
|
|
m_body = dBodyCreate(world);
|
|
dMassSetBox(&mass, 1.0, getWidth(), getDepth(), getHeight());
|
|
dBodySetMass(m_body, &mass);
|
|
|
|
if (space != 0)
|
|
{
|
|
m_geom = dCreateBox(space, getWidth(), getDepth(), getHeight());
|
|
dGeomSetBody(m_geom, m_body);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Clean up ODE resources */
|
|
LogoBox::~LogoBox()
|
|
{
|
|
if (m_geom)
|
|
{
|
|
dGeomDestroy(m_geom);
|
|
}
|
|
if (m_body)
|
|
{
|
|
dBodyDestroy(m_body);
|
|
}
|
|
}
|
|
|
|
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];
|
|
}
|
|
|