1 //#ident "$Id: Cylinder.cpp,v 1.7 2003/05/12 12:17:58 rzr Exp $"
2 /***************************************************************************
3 Cylinder.cpp - description
4 -------------------
5 begin : Wed Jan 26 2000
6 copyright : (C) 2000 by Henrik Enqvist
7 email : henqvist@excite.com
8 ***************************************************************************/
9
10 #include "Private.h"
11 #include "Cylinder.h"
12 #include "Polygon.h"
13
Cylinder(float fSize,int sides,float fR,float fG,float fB,float fA,bool bTop)14 Cylinder::Cylinder(float fSize, int sides, float fR, float fG, float fB, float fA, bool bTop) : Shape3D(sides+sides, sides+2) {
15 if (sides < 3) sides = 3;
16 Polygon3D * p;
17 // First ring of vertices.
18 { for (float a=0; a<sides; ++a) {
19 this->add(EMath::emSin(a/sides)*fSize/2, (float)fSize/2 , EMath::emCos(a/sides)*fSize/2,
20 fR, fG, fB, fA, 0.0f, 0.0f);
21 } }
22 // Second ring.
23 { for (float a=0; a<sides; ++a) {
24 this->add(EMath::emSin(a/sides)*fSize/2, (float)-fSize/2, EMath::emCos(a/sides)*fSize/2,
25 fR, fG, fB, fA, 0.0f, 0.0f);
26 } }
27 // Add vertices.
28 // The ring of polygons.
29 { for (int a=0; a<sides-1; ++a) {
30 p = new Polygon3D(this, 4);
31 p->add(a);
32 p->add(a+1);
33 p->add(a+sides+1);
34 p->add(a+sides);
35 this->add(p);
36 } }
37
38 p = new Polygon3D(this, 4);
39 p->add(sides-1);
40 p->add(0);
41 p->add(sides);
42 p->add(sides+sides-1);
43 this->add(p);
44 // Top
45 if (bTop) {
46 p = new Polygon3D(this, sides);
47 for (int a=sides-1; a>=0; --a) {
48 p->add(a);
49 }
50 this->add(p);
51 // Bottom
52 p = new Polygon3D(this, sides);
53 { for (int a=sides; a<sides+sides; ++a) {
54 p->add(a);
55 } }
56 this->add(p);
57 }
58
59 this->countNormals();
60 }
61