9 Sphere(float radius
= 0.5f
, unsigned int slices
= 20,
10 unsigned int stacks
= 20, bool hasCulling
= true)
15 m_hasCulling
= hasCulling
;
20 void setRadius(float radius
) { m_radius
= radius
; }
21 void setSlices(unsigned int slices
) { m_slices
= slices
; }
22 void setStacks(unsigned int stacks
) { m_stacks
= stacks
; }
23 void setCulling(bool hasCulling
) { m_hasCulling
= hasCulling
; }
26 float getRadius(void) const { return m_radius
; }
27 unsigned int getSlices(void) const { return m_slices
; }
28 unsigned int getStacks(void) const { return m_stacks
; }
29 bool getCulling(void) const { return m_hasCulling
; }
34 GLfloat theta
, phi
, r
, x
, y
, z
, stepTheta
, stepPhi
;
36 qDebug("Sphere::draw()");
37 qDebug("Stacks = %u\tSlices = %u\tr = %f", m_stacks
, m_slices
, m_radius
);
40 glEnable(GL_CULL_FACE
);
42 glDisable(GL_CULL_FACE
);
44 stepTheta
= M_PI
/ m_stacks
;
45 stepPhi
= 2 * M_PI
/ m_slices
;
48 for (theta
= 0; theta
<= M_PI
; theta
+= stepTheta
) {
49 glBegin(GL_QUAD_STRIP
);
50 for (phi
= 0; phi
<= 2.0 * M_PI
+ 0.1; phi
+= stepPhi
) {
51 x
= r
* sin(theta
) * cos(phi
);
52 y
= r
* sin(theta
) * sin(phi
);
56 x
= r
* sin(theta
+ stepTheta
) * cos(phi
);
57 y
= r
* sin(theta
+ stepTheta
) * sin(phi
);
58 z
= r
* cos(theta
+ stepTheta
);
64 // The boundary edges of the polygon are drawn as line segments.
65 glPolygonMode(GL_FRONT_AND_BACK
, GL_LINE
);
70 unsigned int m_slices
;
71 unsigned int m_stacks
;