source: projectionDesigner/trunk/projdesigner/src/screen/ScreenPlane.cpp @ 413

Last change on this file since 413 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 3.8 KB
Line 
1#include "screen/ScreenPlane.h"
2
3using namespace projection;
4
5/**
6 * Constructor.
7 *
8 * @param pScreen Screen data.
9 */
10ScreenPlane::ScreenPlane(Screen* pScreen) : ScreenShape(pScreen)
11{
12    m_width = 2.0;
13    m_height = 2.0;
14    m_horResolution = 4;
15    m_vertResolution = 4;
16}
17
18/**
19 * Destructor.
20 */
21ScreenPlane::~ScreenPlane()
22{
23}
24
25/**
26 * Set width of the plane screen.
27 *
28 * @param width Width of the plane screen.
29 */
30void ScreenPlane::setWidth(double width)
31{
32    if (m_width != width)
33    {
34        m_width = width;
35        notifyRedraw();
36    }
37}
38
39/**
40 * Set height of the plane screen.
41 *
42 * @param height Height of the plane screen.
43 */
44void ScreenPlane::setHeight(double height)
45{
46    if (m_height != height)
47    {
48        m_height = height;
49        notifyRedraw();
50    }
51}
52
53/**
54 * Set horizontal resolution of the plane screen.
55 *
56 * @param resolution Horizontal resolution of the plane screen.
57 */
58void ScreenPlane::setHorResolution(unsigned int resolution)
59{
60    m_horResolution = resolution;
61    notifyRedraw();
62}
63
64/**
65 * Set vertical resolution of the plane screen.
66 *
67 * @param resolution Vertical resolution of the plane screen.
68 */
69void ScreenPlane::setVertResolution(unsigned int resolution)
70{
71    m_vertResolution = resolution;
72    notifyRedraw();
73}
74
75/**
76 * Retrieve bounding box of the screen shape.
77 *
78 * @param min One corner of the screen shape.
79 * @param max Another corner of the screen shape.
80 */
81void ScreenPlane::getBoundingBox(gmtl::Vec3f& min, gmtl::Vec3f& max)
82{
83    min.set((float)-m_width/2.0f, (float)-m_height/2.0f, 0.0f);
84    max.set((float)m_width/2.0f, (float)m_height/2.0f, 0.0f);
85}
86
87/**
88 * Restore the screen shape from XML data.
89 *
90 * @param element Parent XML element of the screen shape data.
91 */
92bool ScreenPlane::initFromDOMElement(const QDomElement& element)
93{
94    if (!element.isNull())
95    {
96        m_width = element.attribute("width").toFloat();
97        m_height = element.attribute("height").toFloat();
98        m_horResolution = element.attribute("horResolution").toInt();
99        m_vertResolution = element.attribute("vertResolution").toInt();
100        // if change
101        notifyRedraw();
102    }
103
104        return true;    // todo: secure this function and return false on any critical error
105}
106
107/**
108 * Store the current screen shape as XML data.
109 *
110 * @param name XML node name of the data.
111 * @param doc XML document to store the data.
112 * @return Current screen shape data as XML data.
113 */
114QDomElement ScreenPlane::domElement(const QString& name, QDomDocument& doc) const
115{
116    QDomElement de = doc.createElement(name);
117    de.setAttribute("name", getName());
118    de.setAttribute("width", m_width);
119    de.setAttribute("height", m_height);
120    de.setAttribute("horResolution", m_horResolution);
121    de.setAttribute("vertResolution", m_vertResolution);
122
123    return de;
124}
125
126/**
127 * Draw the shape model in inherited class.
128 *
129 * @param bFrame True to draw a wire frame mesh. False to draw as a polygon model.
130 */
131void ScreenPlane::drawShape(bool)
132{
133    double horDelta = m_width / m_horResolution;
134    double vertDelta = m_height / m_vertResolution;
135
136    for (unsigned int vertCount=0; vertCount<m_vertResolution; ++vertCount)
137    {
138        glBegin(GL_QUAD_STRIP);
139        for (unsigned int horCount=0; horCount<=m_horResolution; ++horCount)
140        {
141            glNormal3d(0, 0, 1);
142            glVertex3d(m_width/2.0 - horDelta*horCount,
143                       -m_height/2.0 + vertDelta*vertCount,
144                       0.0);
145            glNormal3d(0, 0, 1);
146            glVertex3d(m_width/2.0 - horDelta*(horCount),
147                       -m_height/2.0 + vertDelta*(vertCount+1),
148                       0.0);
149        }
150        glEnd();
151    }
152}
Note: See TracBrowser for help on using the repository browser.