mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2025-01-03 09:30:21 +00:00
Progress on Graf3DPrimitives
This commit is contained in:
parent
50554147a2
commit
4323d18443
@ -14,28 +14,14 @@ program ExampleScene;
|
||||
cursor, prev: Point;
|
||||
isDown: Boolean;
|
||||
{scene}
|
||||
box1: Box3D;
|
||||
|
||||
{>>}
|
||||
procedure PaintAxis (size: Integer);
|
||||
begin
|
||||
PenPat(black);
|
||||
MoveTo3D(0, 0, 0);
|
||||
LineTo3D(Long2Fix(size), 0, 0);
|
||||
WriteDraw('x');
|
||||
MoveTo3D(0, 0, 0);
|
||||
LineTo3D(0, Long2Fix(size), 0);
|
||||
WriteDraw('y');
|
||||
MoveTo3D(0, 0, 0);
|
||||
LineTo3D(0, 0, Long2Fix(size));
|
||||
WriteDraw('z');
|
||||
end;
|
||||
scene: Scene3D;
|
||||
box1, box2, pyr1: Shape3D;
|
||||
|
||||
{>>}
|
||||
procedure WindowInit;
|
||||
begin
|
||||
SetRect(r, 100, 50, 300, 250);
|
||||
w := NewWindow(nil, r, 'Study', true, zoomDocProc, WindowPtr(-1), false, 0);
|
||||
w := NewWindow(nil, r, 'Graf3DPrimitives', true, zoomDocProc, WindowPtr(-1), false, 0);
|
||||
SetPort(w);
|
||||
end;
|
||||
|
||||
@ -57,14 +43,11 @@ program ExampleScene;
|
||||
LookAt(Long2Fix(-200), Long2Fix(200), Long2Fix(200), Long2Fix(-200));
|
||||
ViewAngle(Long2Fix(50));
|
||||
Identity;
|
||||
Roll(Long2Fix(hangle));
|
||||
Yaw(Long2Fix(hangle));
|
||||
Pitch(Long2Fix(vangle)); { roll and pitch the plane }
|
||||
|
||||
for i := 1 to 12 do
|
||||
begin
|
||||
MoveTo3D(box1.edges[i].a.x, box1.edges[i].a.y, box1.edges[i].a.z);
|
||||
LineTo3D(box1.edges[i].b.x, box1.edges[i].b.y, box1.edges[i].b.z);
|
||||
end;
|
||||
DrawScene3D(scene);
|
||||
|
||||
end;
|
||||
|
||||
{>>}
|
||||
@ -112,7 +95,15 @@ begin
|
||||
ViewPort(thePort^.portRect);
|
||||
|
||||
{scene}
|
||||
|
||||
SetScene3D(scene);
|
||||
SetBox3D(box1, 0, 0, 0, 100, 100, 100);
|
||||
SetBox3D(box2, 0, 0, 150, 100, 40, 100);
|
||||
SetPyramid3D(pyr1, 0, 100, 0, 100, 100, 100);
|
||||
|
||||
AddShape3D(scene, @box1);
|
||||
AddShape3D(scene, @box2);
|
||||
AddShape3D(scene, @pyr1);
|
||||
|
||||
Redraw;
|
||||
MainLoop;
|
||||
|
@ -10,24 +10,50 @@ interface
|
||||
b: Point3D;
|
||||
end;
|
||||
|
||||
type
|
||||
Box3D = record
|
||||
Shape3D = record
|
||||
length: Integer;
|
||||
vertices: array[1..9] of Point3D;
|
||||
edges: array[1..13] of Link3D;
|
||||
end;
|
||||
|
||||
Shape3DPtr = ^Shape3D;
|
||||
|
||||
Scene3D = record
|
||||
length: Integer;
|
||||
shapes: array[1..20] of Shape3DPtr;
|
||||
end;
|
||||
|
||||
Scene3DPtr = ^Scene3D;
|
||||
|
||||
procedure AddShape3D (var scene: scene3D; shape: Shape3DPtr);
|
||||
procedure SetScene3D (var scene: Scene3D);
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3D);
|
||||
procedure SetBox3D (var shape: Box3D; x, y, z, w, h, d: Fixed);
|
||||
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||
procedure DrawLink3D (link: Link3D);
|
||||
procedure DrawShape3D (shape: Shape3DPtr);
|
||||
procedure DrawScene3D (scene: Scene3D);
|
||||
|
||||
implementation
|
||||
|
||||
procedure AddShape3D (var scene: scene3D; shape: Shape3DPtr);
|
||||
begin
|
||||
scene.length := scene.length + 1;
|
||||
scene.shapes[scene.length] := shape;
|
||||
end;
|
||||
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3D);
|
||||
begin
|
||||
lk3D.a := a;
|
||||
lk3D.b := b;
|
||||
end;
|
||||
|
||||
procedure SetBox3D (var shape: Box3D; x, y, z, w, h, d: Fixed);
|
||||
procedure SetScene3D (var scene: Scene3D);
|
||||
begin
|
||||
scene.length := 0;
|
||||
end;
|
||||
|
||||
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||
begin
|
||||
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));
|
||||
@ -49,6 +75,61 @@ implementation
|
||||
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]);
|
||||
shape.length := 12;
|
||||
end;
|
||||
|
||||
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||
begin
|
||||
SetPt3D(shape.vertices[1], Long2Fix(x), Long2Fix(y + h div 2), Long2Fix(z));
|
||||
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[1]);
|
||||
shape.length := 8;
|
||||
end;
|
||||
|
||||
procedure DrawWidget (size: Integer);
|
||||
begin
|
||||
PenPat(black);
|
||||
MoveTo3D(Long2Fix(size), 0, 0);
|
||||
WriteDraw('x');
|
||||
LineTo3D(0, 0, 0);
|
||||
LineTo3D(0, Long2Fix(size), 0);
|
||||
WriteDraw('y');
|
||||
MoveTo3D(0, 0, 0);
|
||||
LineTo3D(0, 0, Long2Fix(size));
|
||||
WriteDraw('z');
|
||||
end;
|
||||
|
||||
procedure DrawLink3D (link: Link3D);
|
||||
begin
|
||||
MoveTo3D(link.a.x, link.a.y, link.a.z);
|
||||
LineTo3D(link.b.x, link.b.y, link.b.z);
|
||||
end;
|
||||
|
||||
procedure DrawShape3D (shape: Shape3DPtr);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 1 to shape^.length do
|
||||
DrawLink3D(shape^.edges[i]);
|
||||
end;
|
||||
|
||||
procedure DrawScene3D (scene: Scene3D);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 1 to scene.length do
|
||||
DrawShape3D(scene.shapes[i]);
|
||||
DrawWidget(50);
|
||||
end;
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user