/* 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 #ifndef WITHOUT_ODE #include #endif #include "../wfobj/WFObj.h" #include "LogoBox.h" #include "../LoadFile/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. If physics are being used * (world and space are not NULL), then the constructor * initializes an ODE body and geometry for each * constructed logo. */ #ifndef WITHOUT_ODE LogoBox::LogoBox(dWorldID world, dSpaceID space) #else LogoBox::LogoBox() #endif { 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(); } } #ifndef WITHOUT_ODE 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); } } #endif } /* Clean up ODE resources */ LogoBox::~LogoBox() { #ifndef WITHOUT_ODE if (m_geom) { dGeomDestroy(m_geom); } if (m_body) { dBodyDestroy(m_body); } #endif } 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]; }