mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2025-01-11 16:29:58 +00:00
117 lines
2.1 KiB
ObjectPascal
117 lines
2.1 KiB
ObjectPascal
program ExampleScene;
|
|
|
|
uses
|
|
FixMath, Graf3D, Graf3DPrimitives;
|
|
|
|
var
|
|
drawingRect: Rect; {A window Size}
|
|
viewWidth, viewHeight, padLeft, padTop: Integer;
|
|
myPort: GrafPort;
|
|
myPort3D: Port3D;
|
|
pa, pb: Point3D;
|
|
hangle, vangle: Longint;
|
|
{cursor}
|
|
cursor, prev: Point;
|
|
isDown: Boolean;
|
|
{scene}
|
|
scene: Scene3D;
|
|
box1, wed1, pyr1: Shape3D;
|
|
|
|
{>>}
|
|
procedure ClearScreen;
|
|
var
|
|
size: Rect;
|
|
begin
|
|
SetRect(size, 0, 0, viewWidth, viewWidth);
|
|
FillRect(size, white);
|
|
end;
|
|
|
|
{>>}
|
|
procedure Redraw;
|
|
var
|
|
i: Integer;
|
|
begin
|
|
ClearScreen;
|
|
LookAt(Long2Fix(-viewWidth), Long2Fix(viewheight), Long2Fix(viewWidth), Long2Fix(-viewHeight));
|
|
ViewAngle(Long2Fix(50));
|
|
Identity;
|
|
Yaw(Long2Fix(hangle));
|
|
Pitch(Long2Fix(vangle)); { roll and pitch the plane }
|
|
DrawScene3D(scene);
|
|
end;
|
|
|
|
{>>}
|
|
procedure WhenDownChanged;
|
|
var
|
|
hoff, voff: Integer;
|
|
begin
|
|
hoff := prev.h - cursor.h;
|
|
hangle := hangle + hoff;
|
|
voff := prev.v - cursor.v;
|
|
vangle := vangle + voff;
|
|
Redraw;
|
|
GetMouse(prev);
|
|
end;
|
|
|
|
{>>}
|
|
procedure WhenDown;
|
|
begin
|
|
GetMouse(cursor);
|
|
if cursor.h <> prev.h then
|
|
if cursor.v <> prev.v then
|
|
WhenDownChanged;
|
|
end;
|
|
|
|
{>>}
|
|
procedure MainLoop;
|
|
begin
|
|
repeat {Until we click outside screen}
|
|
while button do
|
|
begin
|
|
GetMouse(cursor);
|
|
GetMouse(prev);
|
|
repeat {Tight loop until button up}
|
|
WhenDown;
|
|
until not Button;
|
|
end;
|
|
until cursor.h < 0;
|
|
end;
|
|
|
|
procedure InitWindow;
|
|
begin
|
|
viewWidth := 500;
|
|
viewHeight := 342;
|
|
padLeft := 60;
|
|
padTop := 60;
|
|
|
|
SetRect(drawingRect, padLeft, padTop, padLeft + viewWidth, padTop + viewHeight);
|
|
SetDrawingRect(drawingRect);
|
|
ShowDrawing;
|
|
end;
|
|
|
|
begin
|
|
|
|
InitWindow;
|
|
InitGrf3D(nil);
|
|
Open3DPort(@myPort3D);
|
|
ViewPort(thePort^.portRect);
|
|
|
|
{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);
|
|
|
|
AddShape3D(scene, @box1);
|
|
AddShape3D(scene, @wed1);
|
|
AddShape3D(scene, @pyr1);
|
|
|
|
TurnYShape3D(@pyr1);
|
|
MoveShape3D(@pyr1, 100, 0, 0);
|
|
TurnYShape3D(@pyr1);
|
|
|
|
Redraw;
|
|
MainLoop;
|
|
|
|
end. |