mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2025-08-15 15:27:21 +00:00
Added a basic scene
This commit is contained in:
@@ -14,20 +14,35 @@ interface
|
|||||||
procedure SetCyl3D (var shape: Shape3D; x, y, z, w, h, d, r: 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);
|
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
|
||||||
{parts}
|
{parts}
|
||||||
|
procedure AddVertice3D (var shape: Shape3D; x, y, z: Fixed);
|
||||||
procedure AddLink3D (var shape: Shape3D; a, b: Integer);
|
procedure AddLink3D (var shape: Shape3D; a, b: Integer);
|
||||||
|
procedure AddFace3D (var shape: Shape3D; a, b, c: Integer);
|
||||||
procedure AddTri3D (var shape: Shape3D; x, y, z, w, h: Fixed);
|
procedure AddTri3D (var shape: Shape3D; x, y, z, w, h: Fixed);
|
||||||
procedure AddRect3D (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, r: Fixed);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{privates}
|
procedure AddVertice3D (var shape: Shape3D; x, y, z: Fixed);
|
||||||
|
var
|
||||||
|
voff: Integer; { vertices offset}
|
||||||
|
begin
|
||||||
|
shape.verticesLength := shape.verticesLength + 1;
|
||||||
|
SetPt3D(shape.vertices[shape.verticesLength], Long2Fix(x), Long2Fix(y), Long2Fix(z));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure AddLink3D (var shape: Shape3D; a, b: Integer);
|
procedure AddLink3D (var shape: Shape3D; a, b: Integer);
|
||||||
begin
|
begin
|
||||||
shape.length := shape.length + 1;
|
shape.length := shape.length + 1;
|
||||||
SetLk3D(shape.edges[shape.length], @shape.vertices[a], @shape.vertices[b]);
|
SetLk3D(shape.edges[shape.length], @shape.vertices[a], @shape.vertices[b]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure AddFace3D (var shape: Shape3D; a, b, c: Integer);
|
||||||
|
begin
|
||||||
|
shape.facesLength := shape.facesLength + 1;
|
||||||
|
SetFc3D(shape.faces[shape.facesLength], @shape.vertices[a], @shape.vertices[b], @shape.vertices[c]);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure AddTri3D (var shape: Shape3D; x, y, z, w, h: Fixed);
|
procedure AddTri3D (var shape: Shape3D; x, y, z, w, h: Fixed);
|
||||||
var
|
var
|
||||||
voff, eoff, foff: Integer; { vertices offset}
|
voff, eoff, foff: Integer; { vertices offset}
|
||||||
|
@@ -151,7 +151,7 @@ implementation
|
|||||||
LineTo3D(face.c^.X, face.c^.Y, face.c^.Z);
|
LineTo3D(face.c^.X, face.c^.Y, face.c^.Z);
|
||||||
LineTo3D(face.a^.X, face.a^.Y, face.a^.Z);
|
LineTo3D(face.a^.X, face.a^.Y, face.a^.Z);
|
||||||
CloseRgn(tempRgn);
|
CloseRgn(tempRgn);
|
||||||
FillRgn(tempRgn, ltgray);
|
FillRgn(tempRgn, white);
|
||||||
DisposeRgn(tempRgn);
|
DisposeRgn(tempRgn);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -182,9 +182,9 @@ implementation
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
{ DrawWidget(50); }
|
||||||
for i := 1 to scene.length do
|
for i := 1 to scene.length do
|
||||||
DrawShape3D(scene.shapes[i]);
|
DrawShape3D(scene.shapes[i]);
|
||||||
DrawWidget(50);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ClearScreen;
|
procedure ClearScreen;
|
||||||
|
@@ -5,6 +5,9 @@ interface
|
|||||||
FixMath, Graf3D, Graf3DScene, Graf3DPrimitives;
|
FixMath, Graf3D, Graf3DScene, Graf3DPrimitives;
|
||||||
|
|
||||||
procedure SetStairs3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
procedure SetStairs3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
procedure SetDoorway3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
procedure SetDoorwayWall3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
procedure SetParticles3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@@ -13,12 +16,82 @@ implementation
|
|||||||
hq: Fixed;
|
hq: Fixed;
|
||||||
begin
|
begin
|
||||||
hq := FixDiv(h, 4);
|
hq := FixDiv(h, 4);
|
||||||
|
AddRect3D(shape, x, y - h + FixMul(hq div 2, 5), z + d - FixMul(hq, 2), w, h div 4);
|
||||||
|
AddRect3D(shape, x, y - h + FixMul(hq div 2, 7), z + d - FixMul(hq, 3), w, h div 4);
|
||||||
|
AddRect3D(shape, x, y - h + FixMul(hq div 2, 9), z + d - FixMul(hq, 4), w, h div 4);
|
||||||
|
AddRect3D(shape, x, y - h + FixMul(hq div 2, 11), z + d - FixMul(hq, 5), w, h div 4);
|
||||||
|
AddLink3D(shape, 4, 7);
|
||||||
|
AddLink3D(shape, 1, 6);
|
||||||
|
AddLink3D(shape, 8, 11);
|
||||||
|
AddLink3D(shape, 5, 10);
|
||||||
|
AddLink3D(shape, 12, 15);
|
||||||
|
AddLink3D(shape, 9, 14);
|
||||||
|
{last step}
|
||||||
|
AddVertice3D(shape, x - w div 2, y + h div 2, z - d div 2);
|
||||||
|
AddVertice3D(shape, x + w div 2, y + h div 2, z - d div 2);
|
||||||
|
AddLink3D(shape, 16, 17);
|
||||||
|
AddLink3D(shape, 13, 18);
|
||||||
|
{sides}
|
||||||
|
AddVertice3D(shape, x - w div 2, y - h div 2, z - d div 2);
|
||||||
|
AddVertice3D(shape, x + w div 2, y - h div 2, z - d div 2);
|
||||||
|
AddLink3D(shape, 17, 19);
|
||||||
|
AddLink3D(shape, 18, 20);
|
||||||
|
AddLink3D(shape, 19, 3);
|
||||||
|
AddLink3D(shape, 20, 2);
|
||||||
|
end;
|
||||||
|
|
||||||
AddRect3D(shape, x, y - h div 2, z + d div 4, w, h div 4);
|
procedure SetDoorway3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
AddRect3D(shape, x, y - h div 2 + FixMul(hq, 1), z + d div 4 - FixMul(hq, 1), w, h div 4);
|
begin
|
||||||
AddRect3D(shape, x, y - h div 2 + FixMul(hq, 2), z + d div 4 - FixMul(hq, 2), w, h div 4);
|
{ frame }
|
||||||
AddRect3D(shape, x, y - h div 2 + FixMul(hq, 3), z + d div 4 - FixMul(hq, 3), w, h div 4);
|
AddVertice3D(shape, x - w div 2, y - h div 2, z);
|
||||||
|
AddVertice3D(shape, x - w div 2, y + h div 4, z);
|
||||||
|
AddVertice3D(shape, x, y + h div 2, z);
|
||||||
|
AddVertice3D(shape, x + w div 2, y + h div 4, z);
|
||||||
|
AddVertice3D(shape, x + w div 2, y - h div 2, z);
|
||||||
|
AddLink3D(shape, 1, 2);
|
||||||
|
AddLink3D(shape, 2, 3);
|
||||||
|
AddLink3D(shape, 3, 4);
|
||||||
|
AddLink3D(shape, 4, 5);
|
||||||
|
AddLink3D(shape, 1, 5);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure SetDoorwayWall3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
begin
|
||||||
|
{ frame }
|
||||||
|
AddVertice3D(shape, x - w div 2, y - h, z);
|
||||||
|
AddVertice3D(shape, x - w div 2, y + h div 4, z);
|
||||||
|
AddVertice3D(shape, x, y + h div 2, z);
|
||||||
|
AddVertice3D(shape, x + w div 2, y + h div 4, z);
|
||||||
|
AddVertice3D(shape, x + w div 2, y - h, z);
|
||||||
|
AddVertice3D(shape, x + w * 2, y - h div 2, z);{6}
|
||||||
|
AddVertice3D(shape, x + w * 2, y + h, z);{7}
|
||||||
|
AddVertice3D(shape, x - w * 2, y + h, z);{8}
|
||||||
|
AddVertice3D(shape, x - w * 2, y - h div 2, z);{9}
|
||||||
|
AddFace3D(shape, 4, 5, 6);
|
||||||
|
AddFace3D(shape, 4, 6, 7);
|
||||||
|
AddFace3D(shape, 3, 4, 7);
|
||||||
|
AddFace3D(shape, 3, 7, 8);
|
||||||
|
AddFace3D(shape, 2, 3, 8);
|
||||||
|
AddFace3D(shape, 2, 8, 9);
|
||||||
|
AddFace3D(shape, 1, 2, 9);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure SetParticles3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
rx, ry, rz: Fixed;
|
||||||
|
begin
|
||||||
|
{ frame }
|
||||||
|
|
||||||
|
for i := 1 to 20 do
|
||||||
|
begin
|
||||||
|
rx := FracMul(Fix2Frac(Random), w);
|
||||||
|
ry := FracMul(Fix2Frac(Random), h);
|
||||||
|
rz := FracMul(Fix2Frac(Random), z);
|
||||||
|
AddVertice3D(shape, x + rx, y + ry, z + rz);
|
||||||
|
AddVertice3D(shape, x + rx, y + ry + 2, z + rz);
|
||||||
|
AddLink3D(shape, i * 2 - 1, i * 2);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
@@ -8,9 +8,9 @@ program ExampleScene;
|
|||||||
wed2, box2, cyl2: Shape3D;
|
wed2, box2, cyl2: Shape3D;
|
||||||
|
|
||||||
wed1, box1, cyl1: Shape3D;
|
wed1, box1, cyl1: Shape3D;
|
||||||
tri1, rec1, cir1: Shape3D;
|
rec2, rec1, cir1: Shape3D;
|
||||||
|
|
||||||
sta1: Shape3D;
|
sta1, dwy1, dwy2, dwy3, dww1, prt1: Shape3D;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
@@ -19,13 +19,36 @@ begin
|
|||||||
SetScene3D(scene);
|
SetScene3D(scene);
|
||||||
|
|
||||||
SetWedge3D(wed1, -100, 0, -100, 100, 100, 100);
|
SetWedge3D(wed1, -100, 0, -100, 100, 100, 100);
|
||||||
SetBox3D(box1, 0, 0, -100, 100, 100, 100);
|
SetBox3D(box1, 0, 0, 0, 100, 100, 100);
|
||||||
SetCyl3D(cyl1, 100, 0, -100, 100, 100, 100, 50);
|
SetCyl3D(cyl1, 100, 0, -100, 100, 100, 100, 50);
|
||||||
|
|
||||||
SetStairs3D(sta1, 0, 0, 0, 100, 100, 100);
|
SetStairs3D(sta1, 0, -100, 0, 100, 100, 100);
|
||||||
|
SetDoorway3D(dwy1, 0, 50, -50, 100, 200, 100);
|
||||||
|
SetDoorway3D(dwy2, 0, 50, -150, 100, 200, 100);
|
||||||
|
SetDoorway3D(dwy3, 0, 50, -200, 100, 200, 100);
|
||||||
|
SetDoorwayWall3D(dww1, 0, 50, -50, 100, 200, 100);
|
||||||
|
SetParticles3D(prt1, 0, 0, 100, 600, 300, 300);
|
||||||
|
|
||||||
|
SetRect3D(rec1, 0, -150, -50, 100, 200);
|
||||||
|
SetRect3D(rec2, 0, 200, -150, 100, 300);
|
||||||
|
SetCircle3D(cir1, 0, 75, -50, 30);
|
||||||
|
|
||||||
|
AddShape3D(scene, @rec1);
|
||||||
|
AddShape3D(scene, @dwy3);
|
||||||
|
AddShape3D(scene, @dwy2);
|
||||||
|
|
||||||
|
TurnXShape3D(@rec1);
|
||||||
|
TurnXShape3D(@rec2);
|
||||||
|
|
||||||
|
AddShape3D(scene, @dww1);
|
||||||
|
AddShape3D(scene, @dwy1);
|
||||||
|
AddShape3D(scene, @cir1);
|
||||||
AddShape3D(scene, @sta1);
|
AddShape3D(scene, @sta1);
|
||||||
|
|
||||||
|
AddShape3D(scene, @rec2);
|
||||||
|
|
||||||
|
AddShape3D(scene, @prt1);
|
||||||
|
|
||||||
InitWindow;
|
InitWindow;
|
||||||
|
|
||||||
end.
|
end.
|
Reference in New Issue
Block a user