1 | #include "screen/ScreenDome.h" |
---|
2 | |
---|
3 | using namespace projection; |
---|
4 | using namespace gmtl; |
---|
5 | |
---|
6 | /** |
---|
7 | * Constructor. |
---|
8 | * |
---|
9 | * @param pScreen Screen data. |
---|
10 | */ |
---|
11 | ScreenDome::ScreenDome(Screen* pScreen) : ScreenShape(pScreen) |
---|
12 | { |
---|
13 | m_radius = 1.0; |
---|
14 | m_elevResolution = 16; |
---|
15 | m_azimResolution = 16; |
---|
16 | m_subdiv = 4; |
---|
17 | m_bFullDome = false; |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | * Destructor. |
---|
22 | */ |
---|
23 | ScreenDome::~ScreenDome() |
---|
24 | { |
---|
25 | } |
---|
26 | |
---|
27 | /** |
---|
28 | * Set radius of the dome screen. |
---|
29 | * |
---|
30 | * @param radius Radius of the dome screen. |
---|
31 | */ |
---|
32 | void ScreenDome::setRadius(double radius) |
---|
33 | { |
---|
34 | if (m_radius != radius) |
---|
35 | { |
---|
36 | m_radius = radius; |
---|
37 | notifyRedraw(); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * Set elevation resolution of the dome screen. |
---|
43 | * |
---|
44 | * @param resolution Elevation resolution of the dome screen. |
---|
45 | */ |
---|
46 | void ScreenDome::setElevResolution(unsigned int resolution) |
---|
47 | { |
---|
48 | m_elevResolution = resolution; |
---|
49 | notifyRedraw(); |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * Set azimuth resolution of the dome screen. |
---|
54 | * |
---|
55 | * @param resolution Azimuth resolution of the dome screen. |
---|
56 | */ |
---|
57 | void ScreenDome::setAzimResolution(unsigned int resolution) |
---|
58 | { |
---|
59 | m_azimResolution = resolution; |
---|
60 | notifyRedraw(); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Retrieve azimuth resolution of the dome screen. |
---|
65 | * |
---|
66 | * @return Azimuth resolution of the dome screen. |
---|
67 | */ |
---|
68 | void ScreenDome::setSubdivision(unsigned int subdiv) |
---|
69 | { |
---|
70 | m_subdiv = subdiv; |
---|
71 | notifyRedraw(); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * Select full dome or half dome. |
---|
76 | * |
---|
77 | * @param bFullDome True to select a full dome, False to select a half dome. |
---|
78 | */ |
---|
79 | void ScreenDome::setFullDome(bool bFullDome) |
---|
80 | { |
---|
81 | m_bFullDome = bFullDome; |
---|
82 | notifyRedraw(); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * Retrieve bounding box of the screen shape. |
---|
87 | * |
---|
88 | * @param min One corner of the screen shape. |
---|
89 | * @param max Another corner of the screen shape. |
---|
90 | */ |
---|
91 | void ScreenDome::getBoundingBox(gmtl::Vec3f& min, gmtl::Vec3f& max) |
---|
92 | { |
---|
93 | min.set(-m_radius, -m_radius, 0.0); |
---|
94 | max.set(m_radius, m_radius, m_radius); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * Restore the screen shape from XML data. |
---|
99 | * |
---|
100 | * @param element Parent XML element of the screen shape data. |
---|
101 | */ |
---|
102 | bool ScreenDome::initFromDOMElement(const QDomElement& element) |
---|
103 | { |
---|
104 | // don't notify redrawing by each restoring step |
---|
105 | if (!element.isNull()) |
---|
106 | { |
---|
107 | m_radius = element.attribute("radius").toFloat(); |
---|
108 | m_elevResolution = element.attribute("elevResolution").toInt(); |
---|
109 | m_azimResolution = element.attribute("azimResolution").toInt(); |
---|
110 | m_subdiv = element.attribute("subdivision").toInt(); |
---|
111 | m_bFullDome= element.attribute("fullDome")=="true"; |
---|
112 | // if change |
---|
113 | notifyRedraw(); |
---|
114 | } |
---|
115 | |
---|
116 | return true; // todo: secure this function and return false on any critical error |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * Store the current screen shape as XML data. |
---|
121 | * |
---|
122 | * @param name XML node name of the data. |
---|
123 | * @param doc XML document to store the data. |
---|
124 | * @return Current screen shape data as XML data. |
---|
125 | */ |
---|
126 | QDomElement ScreenDome::domElement(const QString& name, QDomDocument& doc) const |
---|
127 | { |
---|
128 | QDomElement de = doc.createElement(name); |
---|
129 | de.setAttribute("name", getName()); |
---|
130 | de.setAttribute("radius", m_radius); |
---|
131 | de.setAttribute("elevResolution", m_elevResolution); |
---|
132 | de.setAttribute("azimResolution", m_azimResolution); |
---|
133 | de.setAttribute("subdivision", m_subdiv); |
---|
134 | de.setAttribute("fullDome", m_bFullDome?"true":"false"); |
---|
135 | |
---|
136 | return de; |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * Draw the shape model in inherited class. |
---|
141 | * |
---|
142 | * @param bFrame True to draw a wire frame mesh. False to draw as a polygon model. |
---|
143 | */ |
---|
144 | void ScreenDome::drawShape(bool bFrame) |
---|
145 | { |
---|
146 | if (!bFrame) |
---|
147 | { |
---|
148 | // draw as a polygon model |
---|
149 | double azimDelta = Math::PI / m_azimResolution / m_subdiv; |
---|
150 | double elevDelta = Math::PI / 2.0 / m_elevResolution / m_subdiv; |
---|
151 | if (m_bFullDome) azimDelta *= 2.0; |
---|
152 | for (unsigned int elevCount=0; elevCount<m_elevResolution*m_subdiv; ++elevCount) |
---|
153 | { |
---|
154 | glBegin(GL_QUAD_STRIP); |
---|
155 | for (unsigned int azimCount=0; azimCount<=m_azimResolution*m_subdiv; ++azimCount) |
---|
156 | { |
---|
157 | double nx, ny, nz; |
---|
158 | nx = cos(-azimDelta*azimCount) * cos(elevDelta*elevCount); |
---|
159 | ny = sin(elevDelta*elevCount); |
---|
160 | nz = sin(-azimDelta*azimCount) * cos(elevDelta*elevCount); |
---|
161 | glNormal3d(-nx, -ny, -nz); |
---|
162 | glVertex3d(m_radius * nx, m_radius * ny, m_radius * nz); |
---|
163 | nx = cos(-azimDelta*azimCount) * cos(elevDelta*(elevCount+1)); |
---|
164 | ny = sin(elevDelta*(elevCount+1)); |
---|
165 | nz = sin(-azimDelta*azimCount) * cos(elevDelta*(elevCount+1)); |
---|
166 | glNormal3d(-nx, -ny, -nz); |
---|
167 | glVertex3d(m_radius * nx, m_radius * ny, m_radius * nz); |
---|
168 | } |
---|
169 | glEnd(); |
---|
170 | } |
---|
171 | } |
---|
172 | else |
---|
173 | { |
---|
174 | // draw as a wire frame model |
---|
175 | |
---|
176 | double azimDelta = Math::PI / m_azimResolution / m_subdiv; |
---|
177 | double elevDelta = Math::PI / 2.0 / m_elevResolution / m_subdiv; |
---|
178 | if (m_bFullDome) azimDelta *= 2.0; |
---|
179 | for (unsigned int elevCount=0; elevCount<m_elevResolution; ++elevCount) |
---|
180 | { |
---|
181 | for (unsigned int azimCount=0; azimCount<m_azimResolution; ++azimCount) |
---|
182 | { |
---|
183 | int subElevCount, subAzimCount; |
---|
184 | glBegin(GL_POLYGON); |
---|
185 | for (subElevCount=0; subElevCount<m_subdiv; ++subElevCount) { |
---|
186 | double nx, ny, nz; |
---|
187 | nx = cos(-azimDelta*azimCount*m_subdiv) * cos(elevDelta*(elevCount*m_subdiv+subElevCount)); |
---|
188 | ny = sin(elevDelta*(elevCount*m_subdiv+subElevCount)); |
---|
189 | nz = sin(-azimDelta*azimCount*m_subdiv) * cos(elevDelta*(elevCount*m_subdiv+subElevCount)); |
---|
190 | glNormal3d(-nx, -ny, -nz); |
---|
191 | glVertex3d(m_radius * nx, m_radius * ny, m_radius * nz); |
---|
192 | } |
---|
193 | for (subAzimCount=0; subAzimCount<m_subdiv; ++subAzimCount) { |
---|
194 | double nx, ny, nz; |
---|
195 | nx = cos(-azimDelta*(azimCount*m_subdiv+subAzimCount)) * cos(elevDelta*(elevCount+1)*m_subdiv); |
---|
196 | ny = sin(elevDelta*(elevCount+1)*m_subdiv); |
---|
197 | nz = sin(-azimDelta*(azimCount*m_subdiv+subAzimCount)) * cos(elevDelta*(elevCount+1)*m_subdiv); |
---|
198 | glNormal3d(-nx, -ny, -nz); |
---|
199 | glVertex3d(m_radius * nx, m_radius * ny, m_radius * nz); |
---|
200 | } |
---|
201 | for (subElevCount=0; subElevCount<m_subdiv; ++subElevCount) { |
---|
202 | double nx, ny, nz; |
---|
203 | nx = cos(-azimDelta*(azimCount+1)*m_subdiv) * cos(elevDelta*((elevCount+1)*m_subdiv-subElevCount)); |
---|
204 | ny = sin(elevDelta*((elevCount+1)*m_subdiv-subElevCount)); |
---|
205 | nz = sin(-azimDelta*(azimCount+1)*m_subdiv) * cos(elevDelta*((elevCount+1)*m_subdiv-subElevCount)); |
---|
206 | glNormal3d(-nx, -ny, -nz); |
---|
207 | glVertex3d(m_radius * nx, m_radius * ny, m_radius * nz); |
---|
208 | } |
---|
209 | for (subAzimCount=0; subAzimCount<m_subdiv; ++subAzimCount) { |
---|
210 | double nx, ny, nz; |
---|
211 | nx = cos(-azimDelta*((azimCount+1)*m_subdiv-subAzimCount)) * cos(elevDelta*elevCount*m_subdiv); |
---|
212 | ny = sin(elevDelta*elevCount*m_subdiv); |
---|
213 | nz = sin(-azimDelta*((azimCount+1)*m_subdiv-subAzimCount)) * cos(elevDelta*elevCount*m_subdiv); |
---|
214 | glNormal3d(-nx, -ny, -nz); |
---|
215 | glVertex3d(m_radius * nx, m_radius * ny, m_radius * nz); |
---|
216 | } |
---|
217 | glEnd(); |
---|
218 | } |
---|
219 | } |
---|
220 | } |
---|
221 | } |
---|