Files
macintosh_cookbook/examples/3d.scene.pas
2020-05-11 07:30:17 +09:00

111 lines
1.9 KiB
ObjectPascal

program ExampleScene;
uses
FixMath, Graf3D, Graf3DPrimitives;
var
w: WindowPtr; {A window to draw in}
r: Rect; {A window Size}
myPort: GrafPort;
myPort3D: Port3D;
pa, pb: Point3D;
hangle, vangle: Longint;
{cursor}
cursor, prev: Point;
isDown: Boolean;
{scene}
scene: Scene3D;
box1, box2, pyr1: Shape3D;
{>>}
procedure WindowInit;
begin
SetRect(r, 100, 50, 300, 250);
w := NewWindow(nil, r, 'Graf3DPrimitives', true, zoomDocProc, WindowPtr(-1), false, 0);
SetPort(w);
end;
{>>}
procedure ClearScreen;
var
size: Rect;
begin
SetRect(size, 0, 0, 200, 200);
FillRect(size, white);
end;
{>>}
procedure Redraw;
var
i: Integer;
begin
ClearScreen;
LookAt(Long2Fix(-200), Long2Fix(200), Long2Fix(200), Long2Fix(-200));
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;
begin
WindowInit;
InitGrf3D(nil);
Open3DPort(@myPort3D);
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;
end.