Minor cleanup

This commit is contained in:
neauoire 2020-05-15 12:09:12 +09:00
parent a8ac67d685
commit 4d988a292c
3 changed files with 40 additions and 69 deletions

View File

@ -12,11 +12,10 @@ interface
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
procedure SetCyl3D (var shape: Shape3D; x, y, z, w, h, d, r: Fixed);
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
{parts}
procedure AddTri3D (var shape: Shape3D; x, y, z, w, h: Fixed);
procedure AddRect3D (var shape: Shape3D; x, y, z, w, h: Fixed);
procedure AddCircle3D (var shape: Shape3D; x, y, z, r: Fixed);
procedure AddCircle3D (var shape: Shape3D; x, y, z, d: Fixed);
implementation
@ -61,7 +60,7 @@ implementation
shape.length := eoff + 4;
end;
procedure AddCircle3D (var shape: Shape3D; x, y, z, r: Fixed);
procedure AddCircle3D (var shape: Shape3D; x, y, z, d: Fixed);
var
voff, eoff, foff: Integer; { vertices offset}
i, segs: Integer;
@ -71,13 +70,13 @@ implementation
voff := shape.verticesLength;
foff := shape.facesLength;
eoff := shape.length;
segs := 16;
segs := 12;
arc := FracDiv(360, Long2Fix(segs));
for i := 1 to segs do
begin
radians := FracMul(FixMul(arc, Long2Fix(i)), FixDiv(205887, 180));
offx := FracMul(Long2Fix(r), FracCos(radians));
offy := FracMul(Long2Fix(r), FracSin(radians));
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]);
@ -137,66 +136,4 @@ implementation
AddLink3D(shape, i, i + 16);
end;
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
begin
SetPt3D(shape.origin, Long2Fix(x), Long2Fix(y), Long2Fix(z));
SetPt3D(shape.vertices[1], Long2Fix(x + ax), Long2Fix(y + h div 2), Long2Fix(z + az));
SetPt3D(shape.vertices[2], Long2Fix(x + w div 2), Long2Fix(y - h div 2), Long2Fix(z + d div 2));
SetPt3D(shape.vertices[3], Long2Fix(x + w div 2), Long2Fix(y - h div 2), Long2Fix(z - d div 2));
SetPt3D(shape.vertices[4], Long2Fix(x - w div 2), Long2Fix(y - h div 2), Long2Fix(z - d div 2));
SetPt3D(shape.vertices[5], Long2Fix(x - w div 2), Long2Fix(y - h div 2), Long2Fix(z + d div 2));
SetLk3D(shape.edges[1], @shape.vertices[1], @shape.vertices[2]);
SetLk3D(shape.edges[2], @shape.vertices[1], @shape.vertices[3]);
SetLk3D(shape.edges[3], @shape.vertices[1], @shape.vertices[4]);
SetLk3D(shape.edges[4], @shape.vertices[1], @shape.vertices[5]);
SetLk3D(shape.edges[5], @shape.vertices[2], @shape.vertices[3]);
SetLk3D(shape.edges[6], @shape.vertices[3], @shape.vertices[4]);
SetLk3D(shape.edges[7], @shape.vertices[4], @shape.vertices[5]);
SetLk3D(shape.edges[8], @shape.vertices[5], @shape.vertices[2]);
SetFc3D(shape.faces[1], @shape.vertices[1], @shape.vertices[2], @shape.vertices[3]);
shape.verticesLength := 5;
shape.facesLength := 1;
shape.length := 8;
end;
procedure SetArc3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
var
i: Integer;
slope: Fixed;
offx, offy: Fixed;
pi, radians, r: Fixed;
begin
SetPt3D(shape.origin, Long2Fix(x), Long2Fix(y), Long2Fix(z));
r := Long2Fix(w div 2);
pi := 205887;
for i := 1 to 10 do
begin
slope := FixDiv(Long2Fix(i), pi);
offx := FixMul(slope, r);
offy := FixDiv(r, slope);
radians := FracMul(Long2Fix(i * 10), FixDiv(pi, 180));
offx := FracMul(r, FracCos(radians));
offy := FracMul(r, FracSin(radians));
SetPt3D(shape.vertices[i], Long2Fix(x) + offx, Long2Fix(y) + offy, Long2Fix(z + d div 2));
end;
SetLk3D(shape.edges[1], @shape.vertices[1], @shape.vertices[2]);
SetLk3D(shape.edges[2], @shape.vertices[2], @shape.vertices[3]);
SetLk3D(shape.edges[3], @shape.vertices[3], @shape.vertices[4]);
SetLk3D(shape.edges[4], @shape.vertices[4], @shape.vertices[5]);
SetLk3D(shape.edges[5], @shape.vertices[5], @shape.vertices[6]);
SetLk3D(shape.edges[6], @shape.vertices[6], @shape.vertices[7]);
SetLk3D(shape.edges[7], @shape.vertices[7], @shape.vertices[8]);
SetLk3D(shape.edges[8], @shape.vertices[8], @shape.vertices[9]);
SetLk3D(shape.edges[9], @shape.vertices[9], @shape.vertices[10]);
shape.verticesLength := 9;
shape.facesLength := 0;
shape.length := 9;
end;
end.

View File

@ -6,7 +6,7 @@ interface
const
LIMIT_VERTICES = 32;
LIMIT_EDGES = 32;
LIMIT_EDGES = 40;
LIMIT_FACES = 8;
type

View File

@ -0,0 +1,34 @@
program ExampleScene;
uses
FixMath, Graf3D, Graf3DScene, Graf3DPrimitives, Graf3DStructures;
var
tri1, rec1, cir1: Shape3D; {2d}
wed1, box1, cyl1: Shape3D; {3d}
begin
{scene}
SetScene3D(scene);
SetTri3D(tri1, -100, 0, 150, 100, 100);
SetRect3D(rec1, 0, 0, 150, 100, 100);
SetCircle3D(cir1, 100, 0, 150, 100);
SetWedge3D(wed1, -100, 0, 0, 100, 100, 100);
SetBox3D(box1, 0, 0, 0, 100, 100, 100);
SetCyl3D(cyl1, 100, 0, 0, 100, 100, 100, 100);
AddShape3D(scene, @wed1);
AddShape3D(scene, @box1);
AddShape3D(scene, @cir1);
AddShape3D(scene, @tri1);
AddShape3D(scene, @rec1);
AddShape3D(scene, @cyl1);
InitWindow;
end.