#include "screen/ScreenBox.h" using namespace projection; /** * Constructor. * * @param pScreen Screen data. */ ScreenBox::ScreenBox(Screen* pScreen) : ScreenShape(pScreen) { m_width = 2.0; m_height = 2.0; m_depth = 2.0; m_horResolution = 4; m_vertResolution = 4; m_depthResolution = 4; } /** * Destructor. */ ScreenBox::~ScreenBox() { } /** * Set width of the box screen. * * @param width Width of the box screen. */ void ScreenBox::setWidth(double width) { if (m_width != width) { m_width = width; notifyRedraw(); } } /** * Set height of the box screen. * * @param height Height of the box screen. */ void ScreenBox::setHeight(double height) { if (m_height != height) { m_height = height; notifyRedraw(); } } /** * Set depth of the box screen. * * @param depth Depth of the box screen. */ void ScreenBox::setDepth(double depth) { if (m_depth != depth) { m_depth = depth; notifyRedraw(); } } /** * Set horizontal resolution of the box screen. * * @param resolution Horizontal resolution of the box screen. */ void ScreenBox::setHorResolution(unsigned int resolution) { m_horResolution = resolution; notifyRedraw(); } /** * Set vertical resolution of the box screen. * * @param resolution Vertical resolution of the box screen. */ void ScreenBox::setVertResolution(unsigned int resolution) { m_vertResolution = resolution; notifyRedraw(); } /** * Set depth resolution of the box screen. * * @param resolution Depth resolution of the box screen. */ void ScreenBox::setDepthResolution(unsigned int resolution) { m_depthResolution = resolution; notifyRedraw(); } /** * Retrieve bounding box of the screen shape. * * @param min One corner of the screen shape. * @param max Another corner of the screen shape. */ void ScreenBox::getBoundingBox(gmtl::Vec3f& min, gmtl::Vec3f& max) { min.set((float)-m_width/2.0f, (float)-m_depth/2.0f, (float)-m_height/2.0f); max.set((float)m_width/2.0f, (float)m_depth/2.0f, (float)m_height/2.0f); } /** * Restore the screen shape from XML data. * * @param element Parent XML element of the screen shape data. */ bool ScreenBox::initFromDOMElement(const QDomElement& element) { // don't notify redrawing by each restoring step if (!element.isNull()) { m_width = element.attribute("width").toFloat(); m_height = element.attribute("height").toFloat(); m_depth = element.attribute("depth").toFloat(); m_horResolution = element.attribute("horResolution").toInt(); m_vertResolution = element.attribute("vertResolution").toInt(); m_depthResolution = element.attribute("depthResolution").toInt(); // if change notifyRedraw(); } return true; // todo: secure this function and return false on any critical error } /** * Store the current screen shape as XML data. * * @param name XML node name of the data. * @param doc XML document to store the data. * @return Current screen shape data as XML data. */ QDomElement ScreenBox::domElement(const QString& name, QDomDocument& doc) const { QDomElement de = doc.createElement(name); de.setAttribute("name", getName()); de.setAttribute("width", m_width); de.setAttribute("height", m_height); de.setAttribute("depth", m_depth); de.setAttribute("horResolution", m_horResolution); de.setAttribute("vertResolution", m_vertResolution); de.setAttribute("depthResolution", m_depthResolution); return de; } /** * Draw the shape model in inherited class. * * @param bFrame True to draw a wire frame mesh. False to draw as a polygon model. */ void ScreenBox::drawShape(bool) { glPushAttrib(GL_ENABLE_BIT); glEnable(GL_CULL_FACE); double horDelta = m_width / m_horResolution; double vertDelta = m_height / m_vertResolution; double depthDelta = m_depth / m_depthResolution; unsigned int horCount; unsigned int vertCount; unsigned int depthCount; for (vertCount=0; vertCount