1 //#ident "$Id: Cone.cpp,v 1.8 2003/05/12 12:17:58 rzr Exp $"
2 /***************************************************************************
3 Cone.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 "Cone.h"
12 #include "Polygon.h"
13
Cone(float fSize,int sides,float fR,float fG,float fB,float fA)14 Cone::Cone(float fSize, int sides, float fR, float fG, float fB, float fA) : Shape3D(8+1, 8+1) {
15 if (sides < 3) sides = 3;
16 Polygon3D* p;
17 // Top vertex.
18 this->add(0, fSize/2, 0);
19 // Ring of vertices.
20 for (float a=0; a<sides; ++a) {
21 this->add( EMath::emSin(a/sides)*fSize/2, -fSize/2 , EMath::emCos(a/sides)*fSize/2,
22 fR, fG, fB, fA, 0.0f, 0.0f);
23 }
24 // The ring of polygons.
25 { for (int a=1; a<sides; ++a) {
26 p = new Polygon3D(this, 3);
27 p->add(0);
28 p->add(a+1);
29 p->add(a);
30 this->add(p);
31 } }
32 // the last one
33 p = new Polygon3D(this, 3);
34 p->add(0);
35 p->add(1);
36 p->add(sides);
37 this->add(p);
38 // The bottom of the cone.
39 p = new Polygon3D(this, sides);
40 { for (int a=0; a<sides; ++a) {
41 p->add(a+1);
42 } }
43 this->add(p);
44
45 this->countNormals();
46 }
47