macintosh_cookbook/units/Graf3DScene/Graf3DPrimitives.pas
2020-05-12 21:14:52 +09:00

90 lines
5.1 KiB
ObjectPascal

unit Graf3DPrimitives;
interface
uses
FixMath, Graf3D, Graf3DScene;
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: 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);
implementation
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
begin
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[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));
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[8], 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[2], @shape.vertices[3]);
SetLk3D(shape.edges[3], @shape.vertices[3], @shape.vertices[4]);
SetLk3D(shape.edges[4], @shape.vertices[4], @shape.vertices[1]);
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[5]);
SetLk3D(shape.edges[9], @shape.vertices[1], @shape.vertices[5]);
SetLk3D(shape.edges[10], @shape.vertices[2], @shape.vertices[6]);
SetLk3D(shape.edges[11], @shape.vertices[3], @shape.vertices[7]);
SetLk3D(shape.edges[12], @shape.vertices[4], @shape.vertices[8]);
SetFc3D(shape.faces[1], @shape.vertices[1], @shape.vertices[2], @shape.vertices[5]);
SetFc3D(shape.faces[2], @shape.vertices[2], @shape.vertices[5], @shape.vertices[6]);
shape.verticesLength := 8;
shape.facesLength := 2;
shape.length := 12;
end;
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: Fixed);
begin
SetPt3D(shape.origin, Long2Fix(x), Long2Fix(y), Long2Fix(z));
SetPt3D(shape.vertices[1], Long2Fix(x + a), Long2Fix(y + h div 2), Long2Fix(z - d div 2));
SetPt3D(shape.vertices[2], Long2Fix(x + a), 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));
SetPt3D(shape.vertices[6], 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[4]);
SetLk3D(shape.edges[3], @shape.vertices[1], @shape.vertices[5]);
SetLk3D(shape.edges[4], @shape.vertices[2], @shape.vertices[3]);
SetLk3D(shape.edges[5], @shape.vertices[2], @shape.vertices[6]);
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[6]);
SetLk3D(shape.edges[9], @shape.vertices[6], @shape.vertices[3]);
SetFc3D(shape.faces[1], @shape.vertices[1], @shape.vertices[2], @shape.vertices[3]);
SetFc3D(shape.faces[2], @shape.vertices[1], @shape.vertices[3], @shape.vertices[4]);
shape.verticesLength := 6;
shape.facesLength := 2;
shape.length := 9;
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;
end.