mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2024-06-14 05:29:34 +00:00
Started transforms
This commit is contained in:
parent
0418718ec5
commit
0a2c3b1d5e
|
@ -15,7 +15,7 @@ program ExampleScene;
|
|||
isDown: Boolean;
|
||||
{scene}
|
||||
scene: Scene3D;
|
||||
box1, box2, pyr1, pyr2, wed1, wed2: Shape3D;
|
||||
box1, box2, box3, box4: Shape3D;
|
||||
|
||||
{>>}
|
||||
procedure ClearScreen;
|
||||
|
@ -94,15 +94,13 @@ begin
|
|||
{scene}
|
||||
|
||||
SetScene3D(scene);
|
||||
SetBox3D(box1, -300, 0, 0, 100, 100, 100);
|
||||
SetPyramid3D(pyr1, -150, 0, 0, 100, 100, 100);
|
||||
SetWedge3D(wed1, 0, 0, 0, 100, 100, 100, 0);
|
||||
SetWedge3D(wed2, 150, 0, 0, 100, 100, 100, 50);
|
||||
SetBox3D(box1, 0, 0, 0, 100, 100, 100);
|
||||
SetBox3D(box2, 0, 0, 0, 100, 100, 100);
|
||||
|
||||
AddShape3D(scene, @box1);
|
||||
AddShape3D(scene, @pyr1);
|
||||
AddShape3D(scene, @wed1);
|
||||
AddShape3D(scene, @wed2);
|
||||
AddShape3D(scene, @box2);
|
||||
|
||||
MoveShape3D(@box2, 50, 50, 50);
|
||||
|
||||
Redraw;
|
||||
MainLoop;
|
||||
|
|
|
@ -5,19 +5,21 @@ interface
|
|||
FixMath, Graf3D;
|
||||
|
||||
type
|
||||
Point3DPtr = ^Point3D;
|
||||
|
||||
Link3D = record
|
||||
a: Point3D;
|
||||
b: Point3D;
|
||||
a: Point3DPtr;
|
||||
b: Point3DPtr;
|
||||
end;
|
||||
|
||||
Face3D = record
|
||||
a: Point3D;
|
||||
b: Point3D;
|
||||
c: Point3D;
|
||||
a: Point3DPtr;
|
||||
b: Point3DPtr;
|
||||
c: Point3DPtr;
|
||||
end;
|
||||
|
||||
Shape3D = record
|
||||
length, facesLength: Integer;
|
||||
length, verticesLength, facesLength: Integer;
|
||||
vertices: array[1..9] of Point3D;
|
||||
edges: array[1..13] of Link3D;
|
||||
faces: array[1..6] of Face3D;
|
||||
|
@ -33,12 +35,13 @@ interface
|
|||
Scene3DPtr = ^Scene3D;
|
||||
|
||||
procedure AddShape3D (var scene: scene3D; shape: Shape3DPtr);
|
||||
procedure MoveShape3D (shape: Shape3DPtr; x, y, z: Fixed);
|
||||
procedure SetScene3D (var scene: Scene3D);
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3D);
|
||||
procedure SetFc3D (var fc3D: Face3D; a, b, c: Point3D);
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3DPtr);
|
||||
procedure SetFc3D (var fc3D: Face3D; a, b, c: Point3DPtr);
|
||||
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 SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: 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);
|
||||
|
@ -51,13 +54,21 @@ implementation
|
|||
scene.shapes[scene.length] := shape;
|
||||
end;
|
||||
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3D);
|
||||
procedure MoveShape3D (shape: Shape3DPtr; x, y, z: Fixed);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 1 to shape^.verticesLength do
|
||||
SetPt3D(shape^.vertices[i], shape^.vertices[i].x + Long2Fix(x), shape^.vertices[i].y + Long2Fix(y), shape^.vertices[i].z + Long2Fix(z));
|
||||
end;
|
||||
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3DPtr);
|
||||
begin
|
||||
lk3D.a := a;
|
||||
lk3D.b := b;
|
||||
end;
|
||||
|
||||
procedure SetFc3D (var fc3D: Face3D; a, b, c: Point3D);
|
||||
procedure SetFc3D (var fc3D: Face3D; a, b, c: Point3DPtr);
|
||||
begin
|
||||
fc3D.a := a;
|
||||
fc3D.b := b;
|
||||
|
@ -79,20 +90,22 @@ implementation
|
|||
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]);
|
||||
|
||||
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;
|
||||
|
@ -105,17 +118,18 @@ implementation
|
|||
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]);
|
||||
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;
|
||||
|
@ -127,15 +141,16 @@ implementation
|
|||
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]);
|
||||
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;
|
||||
|
@ -155,8 +170,8 @@ implementation
|
|||
|
||||
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);
|
||||
MoveTo3D(link.a^.x, link.a^.y, link.a^.z);
|
||||
LineTo3D(link.b^.x, link.b^.y, link.b^.z);
|
||||
end;
|
||||
|
||||
procedure DrawFace3D (face: Face3D);
|
||||
|
@ -165,10 +180,10 @@ implementation
|
|||
begin
|
||||
tempRgn := NewRgn;
|
||||
OpenRgn;
|
||||
MoveTo3D(face.a.X, face.a.Y, face.a.Z);
|
||||
LineTo3D(face.b.X, face.b.Y, face.b.Z);
|
||||
LineTo3D(face.c.X, face.c.Y, face.c.Z);
|
||||
LineTo3D(face.a.X, face.a.Y, face.a.Z);
|
||||
MoveTo3D(face.a^.X, face.a^.Y, face.a^.Z);
|
||||
LineTo3D(face.b^.X, face.b^.Y, face.b^.Z);
|
||||
LineTo3D(face.c^.X, face.c^.Y, face.c^.Z);
|
||||
LineTo3D(face.a^.X, face.a^.Y, face.a^.Z);
|
||||
CloseRgn(tempRgn);
|
||||
FillRgn(tempRgn, ltgray);
|
||||
DisposeRgn(tempRgn);
|
||||
|
|
Loading…
Reference in New Issue
Block a user