Migrated cir

This commit is contained in:
neauoire 2020-05-15 20:12:56 +09:00
parent 96a0102d6f
commit 75d3045f31

View File

@ -4,6 +4,9 @@ interface
uses
FixMath, Graf3D, Graf3DScene;
const
CIR_VERTICES = 12;
{parts}
procedure AddTri3D (var shape: Shape3D; x, y, z, w, h: Longint);
procedure AddRec3D (var shape: Shape3D; x, y, z, w, h: Longint);
@ -36,7 +39,7 @@ implementation
AddVertice3D(shape, x + w div 2, y - h div 2, z);
AddVertice3D(shape, x - w div 2, y - h div 2, z);
AddVertice3D(shape, x - w div 2, y + h div 2, z);
AddEdge3D(shape, shape.verticesLength , shape.verticesLength - 1);
AddEdge3D(shape, shape.verticesLength, shape.verticesLength - 1);
AddEdge3D(shape, shape.verticesLength - 1, shape.verticesLength - 2);
AddEdge3D(shape, shape.verticesLength - 2, shape.verticesLength - 3);
AddEdge3D(shape, shape.verticesLength - 3, shape.verticesLength);
@ -46,29 +49,20 @@ implementation
procedure AddCir3D (var shape: Shape3D; x, y, z, d: Longint);
var
voff, eoff, foff: Integer; { vertices offset}
i, segs: Integer;
offx, offy: Fixed;
i: Integer;
radians, arc: Fixed;
begin
voff := shape.verticesLength;
foff := shape.facesLength;
eoff := shape.edgesLength;
segs := 12;
arc := FracDiv(360, Long2Fix(segs));
for i := 1 to segs do
arc := FracDiv(360, Long2Fix(CIR_VERTICES));
for i := 1 to CIR_VERTICES do
begin
radians := FracMul(FixMul(arc, Long2Fix(i)), FixDiv(205887, 180));
offx := FracMul(Long2Fix(d div 2), FracCos(radians));
offy := FracMul(Long2Fix(d div 2), FracSin(radians));
SetPt3D(shape.vertices[voff + i], round(Long2Fix(x) + offx), round(Long2Fix(y) + offy), round(Long2Fix(z)));
if i <> segs then
SetLk3D(shape.edges[eoff + i], @shape.vertices[voff + i], @shape.vertices[voff + i + 1]);
AddVertice3D(shape, Fix2Long(Long2Fix(x) + FracMul(Long2Fix(d div 2), FracCos(radians))), Fix2Long(Long2Fix(y) + FracMul(Long2Fix(d div 2), FracSin(radians))), z);
end;
SetLk3D(shape.edges[eoff + segs], @shape.vertices[voff + segs], @shape.vertices[voff + 1]);
shape.verticesLength := voff + segs;
shape.facesLength := foff + 0;
shape.edgesLength := eoff + segs;
for i := 1 to CIR_VERTICES - 1 do
begin
AddEdge3D(shape, shape.verticesLength - CIR_VERTICES + i, shape.verticesLength - CIR_VERTICES + i + 1);
end;
AddEdge3D(shape, shape.verticesLength - CIR_VERTICES + 1, shape.verticesLength);
end;
{publics}
@ -116,8 +110,8 @@ implementation
SetPt3D(shape.origin, Long2Fix(x), Long2Fix(y), Long2Fix(z));
AddCir3D(shape, x, y, z + d div 2, r);
AddCir3D(shape, x, y, z - d div 2, r);
for i := 1 to 12 do
AddEdge3D(shape, i, i + 12);
for i := 1 to CIR_VERTICES do
AddEdge3D(shape, i, i + CIR_VERTICES);
end;
end.