mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2025-01-03 09:30:21 +00:00
Trying to rotate a point
This commit is contained in:
parent
0a2c3b1d5e
commit
8c301f7d10
@ -96,11 +96,17 @@ begin
|
||||
SetScene3D(scene);
|
||||
SetBox3D(box1, 0, 0, 0, 100, 100, 100);
|
||||
SetBox3D(box2, 0, 0, 0, 100, 100, 100);
|
||||
SetBox3D(box3, 0, 0, 0, 100, 100, 100);
|
||||
SetBox3D(box4, 0, 0, 0, 100, 100, 100);
|
||||
|
||||
AddShape3D(scene, @box1);
|
||||
AddShape3D(scene, @box2);
|
||||
AddShape3D(scene, @box3);
|
||||
AddShape3D(scene, @box4);
|
||||
|
||||
MoveShape3D(@box2, 50, 50, 50);
|
||||
MoveShape3D(@box2, 100, 0, 0);
|
||||
MoveShape3D(@box3, 0, 100, 0);
|
||||
MoveShape3D(@box4, 0, 0, 100);
|
||||
|
||||
Redraw;
|
||||
MainLoop;
|
||||
|
77
units/Graf2D.pas
Normal file
77
units/Graf2D.pas
Normal file
@ -0,0 +1,77 @@
|
||||
program ExampleRotate;
|
||||
|
||||
uses
|
||||
FixMath;
|
||||
|
||||
const
|
||||
PI = 3.141592654;
|
||||
RADDEG = 0.017453292; { PI/180 }
|
||||
DEGRAD = 57.29577951; { 180/PI }
|
||||
|
||||
type
|
||||
Point2D = record
|
||||
x: Fixed;
|
||||
y: Fixed;
|
||||
end;
|
||||
|
||||
var
|
||||
origin, target: Point2D;
|
||||
|
||||
procedure SetPoint2D (var point: Point2D; x, y: Fixed);
|
||||
begin
|
||||
point.x := Long2Fix(x);
|
||||
point.y := Long2Fix(y);
|
||||
end;
|
||||
|
||||
function Distance2D (a, b: Point2D): Fixed;
|
||||
var
|
||||
val: Fixed;
|
||||
begin
|
||||
val := FracMul((b.x - a.x), (b.x - a.x)) + FracMul((b.y - a.y), (b.y - a.y));
|
||||
Distance2D := Frac2Fix(FracSqrt(val));
|
||||
end;
|
||||
|
||||
procedure RotatePoint2D (var target, origin: Point2D; angle: Fixed);
|
||||
var
|
||||
radians, cos, sin, x, y, r: Fixed;
|
||||
begin
|
||||
radians := FixRatio(angle, 314);
|
||||
r := Distance2D(target, origin);
|
||||
target.x := origin.x + FixMul(r, FracCos(radians));
|
||||
target.y := origin.y + FixMul(r, FracSin(radians));
|
||||
end;
|
||||
|
||||
procedure DrawPoint2D (point: Point2D);
|
||||
var
|
||||
dotRect: Rect;
|
||||
radius: Integer;
|
||||
begin
|
||||
SetRect(dotRect, Fix2Long(point.x), Fix2Long(point.y), Fix2Long(point.x) + 5, Fix2Long(point.y) + 5);
|
||||
PaintOval(dotRect);
|
||||
end;
|
||||
|
||||
begin
|
||||
|
||||
ShowDrawing;
|
||||
|
||||
{ origin }
|
||||
SetPoint2D(origin, 100, 100);
|
||||
DrawPoint2D(origin);
|
||||
|
||||
{ origin }
|
||||
SetPoint2D(target, 150, 100);
|
||||
RotatePoint2D(target, origin, 0);
|
||||
DrawPoint2D(target);
|
||||
SetPoint2D(target, 150, 100);
|
||||
RotatePoint2D(target, origin, 90);
|
||||
DrawPoint2D(target);
|
||||
SetPoint2D(target, 150, 100);
|
||||
RotatePoint2D(target, origin, 180);
|
||||
DrawPoint2D(target);
|
||||
SetPoint2D(target, 150, 100);
|
||||
RotatePoint2D(target, origin, 270);
|
||||
DrawPoint2D(target);
|
||||
|
||||
end.
|
||||
|
||||
{ note: This project requires the FixMath library. }
|
@ -19,6 +19,7 @@ interface
|
||||
end;
|
||||
|
||||
Shape3D = record
|
||||
origin: Point3D;
|
||||
length, verticesLength, facesLength: Integer;
|
||||
vertices: array[1..9] of Point3D;
|
||||
edges: array[1..13] of Link3D;
|
||||
@ -36,6 +37,7 @@ interface
|
||||
|
||||
procedure AddShape3D (var scene: scene3D; shape: Shape3DPtr);
|
||||
procedure MoveShape3D (shape: Shape3DPtr; x, y, z: Fixed);
|
||||
procedure TurnShape3D (shape: Shape3DPtr; x, y, z: Fixed);
|
||||
procedure SetScene3D (var scene: Scene3D);
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3DPtr);
|
||||
procedure SetFc3D (var fc3D: Face3D; a, b, c: Point3DPtr);
|
||||
@ -62,6 +64,16 @@ implementation
|
||||
SetPt3D(shape^.vertices[i], shape^.vertices[i].x + Long2Fix(x), shape^.vertices[i].y + Long2Fix(y), shape^.vertices[i].z + Long2Fix(z));
|
||||
end;
|
||||
|
||||
procedure TurnShape3D (shape: Shape3DPtr; x, y, z: Fixed);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 1 to shape^.verticesLength do
|
||||
begin
|
||||
{ DO IT }
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure SetLk3D (var lk3D: Link3D; a, b: Point3DPtr);
|
||||
begin
|
||||
lk3D.a := a;
|
||||
@ -82,6 +94,7 @@ implementation
|
||||
|
||||
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||
begin
|
||||
SetPt3D(shape.origin, x,y,z);
|
||||
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));
|
||||
SetPt3D(shape.vertices[3], Long2Fix(x - w div 2), Long2Fix(y + h div 2), Long2Fix(z - d div 2));
|
||||
@ -90,7 +103,6 @@ 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]);
|
||||
@ -112,6 +124,7 @@ implementation
|
||||
|
||||
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: Fixed);
|
||||
begin
|
||||
SetPt3D(shape.origin, x,y,z);
|
||||
SetPt3D(shape.vertices[1], Long2Fix(x + a), Long2Fix(y + h div 2), Long2Fix(z - d div 2));
|
||||
SetPt3D(shape.vertices[2], Long2Fix(x + a), 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));
|
||||
@ -136,6 +149,7 @@ implementation
|
||||
|
||||
procedure SetPyramid3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
|
||||
begin
|
||||
SetPt3D(shape.origin, x,y,z);
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user