Generate Primitives, required.
72 {
73
75
76
77 SoState *state =
action->getState();
78 if (!state)
79 return;
80
81
82
83 SbBool useTexFunction=
84 (SoTextureCoordinateElement::getType(state) ==
85 SoTextureCoordinateElement::FUNCTION);
86
87
88
89
90 const SoTextureCoordinateElement* tce = NULL;
91 SbVec4f texCoord;
92 if (useTexFunction) {
93 tce = SoTextureCoordinateElement::getInstance(state);
94 }
95 else {
96 texCoord[2] = 0.0;
97 texCoord[3] = 1.0;
98 }
99 SbVec3f point, normal;
100
101
103
104#define GEN_VERTEX(pv,x,y,z,s,t,nx,ny,nz) \
105 point.setValue((float)(x),(float)(y),(float)(z)); \
106 normal.setValue((float)(nx),(float)(ny),(float)(nz)); \
107 if (useTexFunction) { \
108 texCoord=tce->get(point,normal); \
109 } else { \
110 texCoord[0]=(float)(s); \
111 texCoord[1]=(float)(t); \
112 } \
113 pv.setPoint(point); \
114 pv.setNormal(normal); \
115 pv.setTextureCoords(texCoord); \
116 shapeVertex(&pv);
117
119
121
123 double rMax=
pRMax.getValue(),rMin=
pRMin.getValue();
124 double zMax=
pDz.getValue(),zMin=-zMax;
125 double cosPhi0=
cos(phi0), sinPhi0=
sin(phi0);
126 double cosPhi1=
cos(phi1), sinPhi1=
sin(phi1);
128 const bool noPhiCutout=fabs(
pDPhi.getValue())==0.F || fabs(fabs(
pDPhi.getValue())-2.0*
M_PI)<0.01;
129 const bool disableLighting(glIsEnabled(GL_LIGHTING));
130 const bool transparencyOn(glIsEnabled(GL_BLEND));
131
132
133
134
136 double sinPhi,cosPhi;
137 beginShape(action,TRIANGLE_STRIP);
138 sinPhi=sinPhi0;
139 cosPhi=cosPhi0;
140 for (i = 0;
i<=NPHI;
i++) {
141 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,cosPhi,sinPhi,0);
142 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,cosPhi,sinPhi,0);
143 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
144 }
145 endShape();
146
147
148
149 if(rMin!=0.F) {
150 beginShape(action,TRIANGLE_STRIP);
151 sinPhi=sinPhi0;
152 cosPhi=cosPhi0;
153 for (i = 0;
i<=NPHI;
i++) {
154 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,-cosPhi,-sinPhi,0);
155 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,1.0,1.0,-cosPhi,-sinPhi,0);
156 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
157 }
158 endShape();
159 }
160
161 if (!noPhiCutout) {
162
163
164
165
166
167
168
169
170 beginShape(action,TRIANGLE_STRIP);
171 sinPhi=sinPhi0;
172 cosPhi=cosPhi0;
173 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,0.0,0.0,sinPhi,-cosPhi,0);
174 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,sinPhi,-cosPhi,0);
175 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,1.0,0.0,sinPhi,-cosPhi,0);
176 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,1.0,sinPhi,-cosPhi,0);
177 endShape();
178
179
180
181 beginShape(action,TRIANGLE_STRIP);
182 sinPhi=sinPhi1;
183 cosPhi=cosPhi1;
184 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMax,0.0,0.0,-sinPhi,+cosPhi,0);
185 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi, zMin,1.0,1.0,-sinPhi,+cosPhi,0);
186 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMax,1.0,0.0,-sinPhi,+cosPhi,0);
187 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi, zMin,0.0,1.0,-sinPhi,+cosPhi,0);
188 endShape();
189
191 if (disableLighting) glDisable(GL_LIGHTING);
192 if (transparencyOn) glDisable(GL_BLEND);
193
194 glBegin(GL_LINES);
195 glVertex3f(rMax*cosPhi0,rMax*sinPhi0, zMax);
196 glVertex3f(rMax*cosPhi0,rMax*sinPhi0, zMin);
197 glVertex3f(rMin*cosPhi0,rMin*sinPhi0, zMax);
198 glVertex3f(rMin*cosPhi0,rMin*sinPhi0, zMin);
199 glVertex3f(rMax*cosPhi1,rMax*sinPhi1, zMax);
200 glVertex3f(rMax*cosPhi1,rMax*sinPhi1, zMin);
201 glVertex3f(rMin*cosPhi1,rMin*sinPhi1, zMax);
202 glVertex3f(rMin*cosPhi1,rMin*sinPhi1, zMin);
203 glEnd();
204 if (disableLighting) glEnable(GL_LIGHTING);
205 if (transparencyOn) glEnable(GL_BLEND);
206 }
207
208 }
209
210
211
212 if(rMin==0.F) {
213 beginShape(action,TRIANGLE_FAN);
214 sinPhi=sinPhi0;
215 cosPhi=cosPhi0;
217 for (i = 0;
i<=NPHI;
i++) {
218 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);
219 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
220 }
221 endShape();
222
223
224
225 beginShape(action,TRIANGLE_FAN);
226 sinPhi=sinPhi0;
227 cosPhi=cosPhi0;
229 for (i = 0;
i<=NPHI;
i++) {
230 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);
231 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
232 }
233 endShape();
234
235
237 if (disableLighting) glDisable(GL_LIGHTING);
238 if (transparencyOn) glDisable(GL_BLEND);
239 glBegin(GL_LINE_STRIP);
240 sinPhi=sinPhi0;
241 cosPhi=cosPhi0;
242 if (!noPhiCutout) glVertex3f(0,0,zMax);
243 for (i = 0;
i<=NPHI;
i++) {
244 glVertex3f(rMax*cosPhi,rMax*sinPhi,zMax);
245 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
246 }
247 if (!noPhiCutout) glVertex3f(0,0,zMax);
248
249 glEnd();
250
251 glBegin(GL_LINE_STRIP);
252 sinPhi=sinPhi0;
253 cosPhi=cosPhi0;
254 if (!noPhiCutout) glVertex3f(0,0,zMin);
255 for (i = 0;
i<=NPHI;
i++) {
256 glVertex3f(rMax*cosPhi,rMax*sinPhi,zMin);
257 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
258 }
259 if (!noPhiCutout) glVertex3f(0,0,zMin);
260
261 glEnd();
262
263 if (disableLighting) glEnable(GL_LIGHTING);
264 if (transparencyOn) glEnable(GL_BLEND);
265 }
266
267 } else {
268 beginShape(action,TRIANGLE_STRIP);
269 sinPhi=sinPhi0;
270 cosPhi=cosPhi0;
271 for (i = 0;
i<=NPHI;
i++) {
272 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMax,0.0,0.0,0,0,1);
273 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMax,1.0,1.0,0,0,1);
274 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
275 }
276 endShape();
277
278
279
280 beginShape(action,TRIANGLE_STRIP);
281 sinPhi=sinPhi0;
282 cosPhi=cosPhi0;
283 for (i = 0;
i<=NPHI;
i++) {
284 GEN_VERTEX(pv,rMin*cosPhi,rMin*sinPhi,zMin,0.0,0.0,0,0,-1);
285 GEN_VERTEX(pv,rMax*cosPhi,rMax*sinPhi,zMin,1.0,1.0,0,0,-1);
286 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
287 }
288 endShape();
289
291 if (disableLighting) glDisable(GL_LIGHTING);
292 if (transparencyOn) glDisable(GL_BLEND);
293 glBegin(GL_LINE_STRIP);
294 sinPhi=sinPhi0;
295 cosPhi=cosPhi0;
296 if (!noPhiCutout) glVertex3f(rMin*cosPhi,rMin*sinPhi,zMax);
297 for (i = 0;
i<=NPHI;
i++) {
298 glVertex3f(rMax*cosPhi,rMax*sinPhi,zMax);
299 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
300 }
301 if (!noPhiCutout) glVertex3f(rMin*cosPhi1,rMin*sinPhi1,zMax);
302 glEnd();
303
304 glBegin(GL_LINE_STRIP);
305 sinPhi=sinPhi0;
306 cosPhi=cosPhi0;
307 for (i = 0;
i<=NPHI;
i++) {
308 glVertex3f(rMin*cosPhi,rMin*sinPhi,zMax);
309 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
310 }
311 glEnd();
312
313 glBegin(GL_LINE_STRIP);
314 sinPhi=sinPhi0;
315 cosPhi=cosPhi0;
316 if (!noPhiCutout) glVertex3f(rMin*cosPhi,rMin*sinPhi,zMin);
317 for (i = 0;
i<=NPHI;
i++) {
318 glVertex3f(rMax*cosPhi,rMax*sinPhi,zMin);
319 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
320 }
321 if (!noPhiCutout) glVertex3f(rMin*cosPhi1,rMin*sinPhi1,zMin);
322 glEnd();
323
324 glBegin(GL_LINE_STRIP);
325 sinPhi=sinPhi0;
326 cosPhi=cosPhi0;
327 for (i = 0;
i<=NPHI;
i++) {
328 glVertex3f(rMin*cosPhi,rMin*sinPhi,zMin);
329 inc(sinPhi, cosPhi, sinDeltaPhi, cosDeltaPhi);
330 }
331 glEnd();
332
333 if (disableLighting) glEnable(GL_LIGHTING);
334 if (transparencyOn) glEnable(GL_BLEND);
335 }
336
337 }
338
339 if (state&&state->isElementEnabled(SoGLCacheContextElement::getClassStackIndex())) {
340
341 SoGLCacheContextElement::shouldAutoCache(state, SoGLCacheContextElement::DO_AUTO_CACHE);
342#if ((COIN_MAJOR_VERSION>=3)||((COIN_MAJOR_VERSION==2)&&(COIN_MINOR_VERSION>=5)))
343 SoGLCacheContextElement::incNumShapes(state);
344#endif
345 }
346}
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
#define GEN_VERTEX(pv, x, y, z, s, t, nx, ny, nz)
static int nphiDivisions(const float &dphi, const float &complexity, int OverrideNPhi=0)
void inc(double &sinPhi, double &cosPhi, double sinDeltaPhi, double cosDeltaPhi) const
help with trigonometry. increments sines an cosines by an angle.