1 | type
|
---|
2 |
|
---|
3 | { TBGRASphere3D }
|
---|
4 |
|
---|
5 | TBGRASphere3D = class(TBGRAObject3D)
|
---|
6 | constructor Create(AScene: TBGRAScene3D; ARadius: single; HorizPrecision: integer = 8; VerticalPrecision : integer = 6; HalfSphere: boolean = false);
|
---|
7 | end;
|
---|
8 |
|
---|
9 | { TBGRASphere3D }
|
---|
10 |
|
---|
11 | constructor TBGRASphere3D.Create(AScene: TBGRAScene3D; ARadius: single; HorizPrecision: integer; VerticalPrecision : integer; HalfSphere: boolean);
|
---|
12 | var prevAlpha,prevBeta,alpha,beta,NbAlpha,NbBeta: integer;
|
---|
13 | sinBeta,cosBeta: single;
|
---|
14 | sinAlpha,cosAlpha: single;
|
---|
15 | v: IBGRAPart3D;
|
---|
16 | vTop,vBottom: IBGRAVertex3D;
|
---|
17 | alphaFactor: single;
|
---|
18 | startAlpha: integer;
|
---|
19 | begin
|
---|
20 | inherited Create(AScene);
|
---|
21 | NbAlpha := HorizPrecision;
|
---|
22 | if NbAlpha < 4 then NbAlpha := 4;
|
---|
23 | NbBeta := VerticalPrecision-1;
|
---|
24 | if NbBeta < 2 then NbBeta := 2;
|
---|
25 | v := GetMainPart;
|
---|
26 |
|
---|
27 |
|
---|
28 | if halfSphere then
|
---|
29 | alphaFactor := Pi/(NbAlpha-1)
|
---|
30 | else
|
---|
31 | alphaFactor := (2*Pi)/NbAlpha;
|
---|
32 |
|
---|
33 | for beta := 1 to NbBeta-1 do
|
---|
34 | begin
|
---|
35 | sinBeta := sin(beta*Pi/NbBeta);
|
---|
36 | cosBeta := -cos(beta*Pi/NbBeta);
|
---|
37 | for alpha := 0 to NbAlpha-1 do
|
---|
38 | begin
|
---|
39 | sinAlpha := -sin(alpha*alphaFactor);
|
---|
40 | cosAlpha := -cos(alpha*alphaFactor);
|
---|
41 | v.Add( cosAlpha*sinBeta*ARadius, cosBeta*ARadius, sinAlpha*sinBeta*ARadius );
|
---|
42 | end;
|
---|
43 | end;
|
---|
44 |
|
---|
45 | if halfSphere then
|
---|
46 | startAlpha := 1
|
---|
47 | else
|
---|
48 | startAlpha := 0;
|
---|
49 |
|
---|
50 | vTop := v.Add(0,-ARadius,0);
|
---|
51 | prevAlpha := (startAlpha+NbAlpha-1) mod NbAlpha;
|
---|
52 | for alpha := startAlpha to NbAlpha-1 do
|
---|
53 | begin
|
---|
54 | AddFace( [v.Vertex[prevAlpha], vTop, v.Vertex[alpha]], HalfSphere );
|
---|
55 | prevAlpha := alpha;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | prevBeta := 0;
|
---|
59 | for beta := 1 to NbBeta-2 do
|
---|
60 | begin
|
---|
61 | prevAlpha := (startAlpha+NbAlpha-1) mod NbAlpha;
|
---|
62 | for alpha := startAlpha to NbAlpha-1 do
|
---|
63 | begin
|
---|
64 | AddFace( [v.Vertex[prevAlpha + prevBeta*NbAlpha], v.Vertex[alpha + prevBeta*NbAlpha],
|
---|
65 | v.Vertex[alpha + beta*NbAlpha], v.Vertex[prevAlpha + beta*NbAlpha]], HalfSphere );
|
---|
66 | prevAlpha := alpha;
|
---|
67 | end;
|
---|
68 | prevBeta := beta;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | vBottom := v.Add(0,ARadius,0);
|
---|
72 | prevAlpha := (startAlpha+NbAlpha-1) mod NbAlpha;
|
---|
73 | for alpha := startAlpha to NbAlpha-1 do
|
---|
74 | begin
|
---|
75 | AddFace( [v.Vertex[prevAlpha + prevBeta*NbAlpha], v.Vertex[alpha + prevBeta*NbAlpha], vBottom], HalfSphere );
|
---|
76 | prevAlpha := alpha;
|
---|
77 | end;
|
---|
78 | end;
|
---|