Improved rotation

This commit is contained in:
neauoire 2020-05-14 09:01:11 +09:00
parent e03fc53695
commit 8a8366f39d
3 changed files with 39 additions and 23 deletions

View File

@ -9,8 +9,8 @@ interface
procedure SetRect3D (var shape: Shape3D; x, y, z, w, d: Fixed);
procedure SetCircle3D (var shape: Shape3D; x, y, z, r: Fixed);
{3d}
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: Fixed);
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: 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);
@ -69,8 +69,7 @@ implementation
voff, eoff, foff: Integer; { vertices offset}
i, segs: Integer;
offx, offy: Fixed;
pi, radians: Fixed;
arc, angle: Fixed;
radians, arc: Fixed;
begin
voff := shape.verticesLength;
foff := shape.facesLength;
@ -79,8 +78,7 @@ implementation
arc := FracDiv(360, Long2Fix(segs));
for i := 1 to segs do
begin
angle := FixMul(arc, Long2Fix(i));
radians := FracMul(angle, FixDiv(205887, 180));
radians := FracMul(FixMul(arc, Long2Fix(i)), FixDiv(205887, 180));
offx := FracMul(Long2Fix(r), FracCos(radians));
offy := FracMul(Long2Fix(r), FracSin(radians));
SetPt3D(shape.vertices[voff + i], round(Long2Fix(x) + offx), round(Long2Fix(y) + offy), round(Long2Fix(z)));
@ -109,7 +107,7 @@ implementation
AddCircle3D(shape, x, y, z, r);
end;
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d, ax, az: Fixed);
procedure SetBox3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
var
i: Integer;
begin
@ -120,7 +118,7 @@ implementation
AddLink3D(shape, i, i + 4);
end;
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d, a: Fixed);
procedure SetWedge3D (var shape: Shape3D; x, y, z, w, h, d: Fixed);
var
i: Integer;
begin

View File

@ -21,8 +21,8 @@ interface
Shape3D = record
origin: Point3D;
length, verticesLength, facesLength: Integer;
vertices: array[1..10] of Point3D;
edges: array[1..13] of Link3D;
vertices: array[1..64] of Point3D;
edges: array[1..64] of Link3D;
faces: array[1..6] of Face3D;
end;
@ -30,7 +30,7 @@ interface
Scene3D = record
length: Integer;
shapes: array[1..20] of Shape3DPtr;
shapes: array[1..10] of Shape3DPtr;
end;
Scene3DPtr = ^Scene3D;
@ -96,16 +96,15 @@ implementation
begin
SetPt3D(shape^.origin, shape^.origin.x, shape^.origin.z, shape^.origin.y);
for i := 1 to shape^.verticesLength do
SetPt3D(shape^.vertices[i], shape^.vertices[i].x, shape^.vertices[i].z, shape^.vertices[i].y);
SetPt3D(shape^.vertices[i], shape^.vertices[i].x, shape^.vertices[i].z - shape^.origin.y, shape^.vertices[i].y + shape^.origin.y);
end;
procedure TurnYShape3D (shape: Shape3DPtr);
var
i: Integer;
begin
SetPt3D(shape^.origin, shape^.origin.z, shape^.origin.y, shape^.origin.x);
for i := 1 to shape^.verticesLength do
SetPt3D(shape^.vertices[i], shape^.vertices[i].z, shape^.vertices[i].y, shape^.vertices[i].x - shape^.origin.x);
SetPt3D(shape^.vertices[i], shape^.origin.z - shape^.vertices[i].z + shape^.origin.x, shape^.vertices[i].y, shape^.vertices[i].x - shape^.origin.x + shape^.origin.z);
end;
procedure TurnZShape3D (shape: Shape3DPtr);

View File

@ -4,6 +4,9 @@ program ExampleScene;
FixMath, Graf3D, Graf3DScene, Graf3DPrimitives, Graf3DStructures;
var
wed3, box3, cyl3: Shape3D;
wed2, box2, cyl2: Shape3D;
wed1, box1, cyl1: Shape3D;
tri1, rec1, cir1: Shape3D;
@ -13,21 +16,37 @@ begin
SetScene3D(scene);
SetWedge3D(wed1, -100, 0, 100, 100, 100, 100, 0);
SetBox3D(box1, 0, 0, 100, 100, 100, 100, 0, 0);
SetCyl3D(cyl1, 100, 0, 100, 100, 100, 100, 50);
SetWedge3D(wed2, -100, 0, -200, 100, 100, 100);
SetBox3D(box2, 0, 0, -200, 100, 100, 100);
SetCyl3D(cyl2, 100, 0, -200, 100, 100, 100, 50);
SetTri3D(tri1, -100, -0, 300, 100, 100);
SetRect3D(rec1, 0, 0, 300, 100, 100);
SetCircle3D(cir1, 100, 0, 300, 50);
SetWedge3D(wed1, -100, 0, 0, 100, 100, 100);
SetBox3D(box1, 0, 0, 0, 100, 100, 100);
SetCyl3D(cyl1, 100, 0, 0, 100, 100, 100, 50);
SetWedge3D(wed3, -100, 0, 200, 100, 100, 100);
SetBox3D(box3, 0, 0, 200, 100, 100, 100);
SetCyl3D(cyl3, 100, 0, 200, 100, 100, 100, 50);
AddShape3D(scene, @wed2);
AddShape3D(scene, @box2);
AddShape3D(scene, @cyl2);
AddShape3D(scene, @wed1);
AddShape3D(scene, @box1);
AddShape3D(scene, @cyl1);
AddShape3D(scene, @tri1);
AddShape3D(scene, @rec1);
AddShape3D(scene, @cir1);
AddShape3D(scene, @wed3);
AddShape3D(scene, @box3);
AddShape3D(scene, @cyl3);
TurnXShape3D(@wed2);
TurnXShape3D(@box2);
TurnXShape3D(@cyl2);
TurnYShape3D(@wed3);
TurnYShape3D(@box3);
TurnYShape3D(@cyl3);
InitWindow;