mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2025-08-15 15:27:21 +00:00
Drawing a circle for the first time
This commit is contained in:
@@ -4,19 +4,20 @@ interface
|
|||||||
uses
|
uses
|
||||||
FixMath, Graf3D, Graf3DScene;
|
FixMath, Graf3D, Graf3DScene;
|
||||||
|
|
||||||
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
procedure SetArc3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
|
||||||
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: Fixed);
|
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: Fixed);
|
||||||
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
|
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
|
||||||
begin
|
begin
|
||||||
SetPt3D(shape.origin, Long2Fix(x), Long2Fix(y), Long2Fix(z));
|
SetPt3D(shape.origin, Long2Fix(x), Long2Fix(y), Long2Fix(z));
|
||||||
SetPt3D(shape.vertices[1], Long2Fix(x + w div 2), Long2Fix(y + h div 2), Long2Fix(z + d div 2));
|
SetPt3D(shape.vertices[1], Long2Fix(x + w div 2 - ax), Long2Fix(y + h div 2), Long2Fix(z + d div 2 - az));
|
||||||
SetPt3D(shape.vertices[2], Long2Fix(x + w div 2), Long2Fix(y + h div 2), Long2Fix(z - d div 2));
|
SetPt3D(shape.vertices[2], Long2Fix(x + w div 2 - ax), Long2Fix(y + h div 2), Long2Fix(z - d div 2 + ax));
|
||||||
SetPt3D(shape.vertices[3], Long2Fix(x - w div 2), Long2Fix(y + h div 2), Long2Fix(z - d div 2));
|
SetPt3D(shape.vertices[3], Long2Fix(x - w div 2 + ax), Long2Fix(y + h div 2), Long2Fix(z - d div 2 + az));
|
||||||
SetPt3D(shape.vertices[4], Long2Fix(x - w div 2), Long2Fix(y + h div 2), Long2Fix(z + d div 2));
|
SetPt3D(shape.vertices[4], Long2Fix(x - w div 2 + ax), Long2Fix(y + h div 2), Long2Fix(z + d div 2 - az));
|
||||||
SetPt3D(shape.vertices[5], 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));
|
||||||
SetPt3D(shape.vertices[6], Long2Fix(x + w div 2), Long2Fix(y - h div 2), Long2Fix(z - d div 2));
|
SetPt3D(shape.vertices[6], Long2Fix(x + w div 2), Long2Fix(y - h div 2), Long2Fix(z - d div 2));
|
||||||
SetPt3D(shape.vertices[7], Long2Fix(x - w div 2), Long2Fix(y - h div 2), Long2Fix(z - d div 2));
|
SetPt3D(shape.vertices[7], Long2Fix(x - w div 2), Long2Fix(y - h div 2), Long2Fix(z - d div 2));
|
||||||
@@ -87,4 +88,44 @@ implementation
|
|||||||
shape.length := 8;
|
shape.length := 8;
|
||||||
end;
|
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.
|
end.
|
@@ -4,24 +4,33 @@ program ExampleScene;
|
|||||||
FixMath, Graf3D, Graf3DScene, Graf3DPrimitives, Graf3DStructures;
|
FixMath, Graf3D, Graf3DScene, Graf3DPrimitives, Graf3DStructures;
|
||||||
|
|
||||||
var
|
var
|
||||||
box1, wed1, pyr1: Shape3D;
|
arc1, box1, wed1, pyr1: Shape3D;
|
||||||
|
arc2, box2, wed2, pyr2: Shape3D;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
{scene}
|
{scene}
|
||||||
|
|
||||||
SetScene3D(scene);
|
SetScene3D(scene);
|
||||||
SetBox3D(box1, -100, 0, 0, 100, 100, 100);
|
|
||||||
SetWedge3D(wed1, 0, 0, 0, 100, 100, 100, 50);
|
|
||||||
SetPyramid3D(pyr1, 100, 0, 0, 100, 100, 100, 50, 50);
|
|
||||||
|
|
||||||
|
SetArc3D(arc1, -100, 0, 100, 100, 100, 100);
|
||||||
|
SetBox3D(box1, -100, 0, 100, 100, 100, 100, 0, 0);
|
||||||
|
SetWedge3D(wed1, 0, 0, 100, 100, 100, 100, 0);
|
||||||
|
SetPyramid3D(pyr1, 100, 0, 100, 100, 100, 100, 0, 0);
|
||||||
|
|
||||||
|
SetBox3D(box2, -100, 0, -100, 100, 100, 100, 25, 25);
|
||||||
|
SetWedge3D(wed2, 0, 0, -100, 100, 100, 100, 50);
|
||||||
|
SetPyramid3D(pyr2, 100, 0, -100, 100, 100, 100, 50, 50);
|
||||||
|
|
||||||
|
AddShape3D(scene, @arc1);
|
||||||
|
AddShape3D(scene, @arc2);
|
||||||
AddShape3D(scene, @box1);
|
AddShape3D(scene, @box1);
|
||||||
AddShape3D(scene, @wed1);
|
AddShape3D(scene, @wed1);
|
||||||
AddShape3D(scene, @pyr1);
|
AddShape3D(scene, @pyr1);
|
||||||
|
|
||||||
TurnYShape3D(@pyr1);
|
AddShape3D(scene, @box2);
|
||||||
MoveShape3D(@pyr1, 100, 0, 0);
|
AddShape3D(scene, @wed2);
|
||||||
TurnYShape3D(@pyr1);
|
AddShape3D(scene, @pyr2);
|
||||||
|
|
||||||
InitWindow;
|
InitWindow;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user