Skip to content

Commit

Permalink
Neo6502 - sample/cube refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zbyti committed Sep 1, 2024
1 parent 4a705c6 commit 1ce0eb3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 115 deletions.
165 changes: 50 additions & 115 deletions samples/neo6502/demoeffects/cube.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,145 +7,80 @@
//------------------------------------------------------------------------------

const
sz : byte = 50;
cx : byte = 160;
cy : byte = 120;
scale : byte = 65;
originX : byte = 160;
originY : byte = 120;

//------------------------------------------------------------------------------

var
angle : shortreal = 0.0;

pts : array[0..7, 0..2] of shortint;
rzp : array[0..7, 0..3] of shortreal;
ryp : array[0..7, 0..3] of shortreal;
rxp : array[0..7, 0..3] of shortreal;

X1, X2, Y1, Y2 : byte;
vertecs : array[0..7, 0..2] of shortint;
cube : array[0..7, 0..2] of word;
angle : single = 0.0;

//------------------------------------------------------------------------------

procedure init_points;
procedure initPoints;
begin
pts[0,0] := -1; pts[0,1] := -1; pts[0,2] := -1;
pts[1,0] := 1; pts[1,1] := -1; pts[1,2] := -1;
pts[2,0] := 1; pts[2,1] := 1; pts[2,2] := -1;
pts[3,0] := -1; pts[3,1] := 1; pts[3,2] := -1;
pts[4,0] := -1; pts[4,1] := -1; pts[4,2] := 1;
pts[5,0] := 1; pts[5,1] := -1; pts[5,2] := 1;
pts[6,0] := 1; pts[6,1] := 1; pts[6,2] := 1;
pts[7,0] := -1; pts[7,1] := 1; pts[7,2] := 1;
// v,x v,y v,z bottom
vertecs[0,0] := -1; vertecs[0,1] := -1; vertecs[0,2] := -1;
vertecs[1,0] := 1; vertecs[1,1] := -1; vertecs[1,2] := -1;
vertecs[2,0] := 1; vertecs[2,1] := 1; vertecs[2,2] := -1;
vertecs[3,0] := -1; vertecs[3,1] := 1; vertecs[3,2] := -1;
// v,x v,y v,z top
vertecs[4,0] := -1; vertecs[4,1] := -1; vertecs[4,2] := 1;
vertecs[5,0] := 1; vertecs[5,1] := -1; vertecs[5,2] := 1;
vertecs[6,0] := 1; vertecs[6,1] := 1; vertecs[6,2] := 1;
vertecs[7,0] := -1; vertecs[7,1] := 1; vertecs[7,2] := 1;
end;

procedure rotate_points;
//--------------------------------------

{*
RotationMatrix (Gimbal Lock effect)
*}
procedure rotatePoints;
var
n: byte;
sn, cs: shortreal;
n : byte;
s, c : single;
tmp1, tmp2 : single;
begin
sn := sin(angle);
cs := cos(angle);
s := sin(angle);
c := cos(angle);

for n := 0 To 7 do begin
rzp[n,0] := -cs * pts[n,0] + sn * pts[n,1];
rzp[n,1] := sn * pts[n,0] + cs * pts[n,1];
rzp[n,2] := pts[n,2];

ryp[n,0] := cs * rzp[n,0] + sn * rzp[n,2];
ryp[n,1] := rzp[n,1];
ryp[n,2] := -sn * rzp[n,0] + cs * rzp[n,2];

rxp[n,0] := ryp[n,0];
rxp[n,1] := cs * ryp[n,1] - sn * ryp[n,2];
rxp[n,2] := sn * ryp[n,1] + cs * ryp[n,2];
tmp1 := s * vertecs[n,0] + c * vertecs[n,1];
tmp2 := s * c * vertecs[n,0] - s * s * vertecs[n,1] + c * vertecs[n,2];
cube[n,0] := Trunc((- c * c * vertecs[n,0] + c * s * vertecs[n,1] + s * vertecs[n,2]) * scale + originX);
cube[n,1] := Trunc((c * tmp1 - s * tmp2) * scale + originY);
cube[n,2] := Trunc((s * tmp1 + c * tmp2) * scale);
end;
end;

procedure draw_lines;
begin
X1 := Trunc(rxp[0,0] * sz + cx);
Y1 := Trunc(rxp[0,1] * sz + cy);
X2 := Trunc(rxp[1,0] * sz + cx);
Y2 := Trunc(rxp[1,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[1,0] * sz + cx);
Y1 := Trunc(rxp[1,1] * sz + cy);
X2 := Trunc(rxp[2,0] * sz + cx);
Y2 := Trunc(rxp[2,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[2,0] * sz + cx);
Y1 := Trunc(rxp[2,1] * sz + cy);
X2 := Trunc(rxp[3,0] * sz + cx);
Y2 := Trunc(rxp[3,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[3,0] * sz + cx);
Y1 := Trunc(rxp[3,1] * sz + cy);
X2 := Trunc(rxp[0,0] * sz + cx);
Y2 := Trunc(rxp[0,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[4,0] * sz + cx);
Y1 := Trunc(rxp[4,1] * sz + cy);
X2 := Trunc(rxp[5,0] * sz + cx);
Y2 := Trunc(rxp[5,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[5,0] * sz + cx);
Y1 := Trunc(rxp[5,1] * sz + cy);
X2 := Trunc(rxp[6,0] * sz + cx);
Y2 := Trunc(rxp[6,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[6,0] * sz + cx);
Y1 := Trunc(rxp[6,1] * sz + cy);
X2 := Trunc(rxp[7,0] * sz + cx);
Y2 := Trunc(rxp[7,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[7,0] * sz + cx);
Y1 := Trunc(rxp[7,1] * sz + cy);
X2 := Trunc(rxp[4,0] * sz + cx);
Y2 := Trunc(rxp[4,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[0,0] * sz + cx);
Y1 := Trunc(rxp[0,1] * sz + cy);
X2 := Trunc(rxp[4,0] * sz + cx);
Y2 := Trunc(rxp[4,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[1,0] * sz + cx);
Y1 := Trunc(rxp[1,1] * sz + cy);
X2 := Trunc(rxp[5,0] * sz + cx);
Y2 := Trunc(rxp[5,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[2,0] * sz + cx);
Y1 := Trunc(rxp[2,1] * sz + cy);
X2 := Trunc(rxp[6,0] * sz + cx);
Y2 := Trunc(rxp[6,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);

X1 := Trunc(rxp[3,0] * sz + cx);
Y1 := Trunc(rxp[3,1] * sz + cy);
X2 := Trunc(rxp[7,0] * sz + cx);
Y2 := Trunc(rxp[7,1] * sz + cy);
NeoDrawLine(X1,Y1,X2,Y2);
end;

//------------------------------------------------------------------------------

begin
init_points;
initPoints;

repeat
NeoWaitForVblank;
clrscr;

rotate_points;
draw_lines;
angle := angle + 0.02;
rotatePoints;

NeoDrawLine(cube[0,0],cube[0,1],cube[1,0],cube[1,1]);
NeoDrawLine(cube[1,0],cube[1,1],cube[2,0],cube[2,1]);
NeoDrawLine(cube[2,0],cube[2,1],cube[3,0],cube[3,1]);
NeoDrawLine(cube[3,0],cube[3,1],cube[0,0],cube[0,1]);
NeoDrawLine(cube[4,0],cube[4,1],cube[5,0],cube[5,1]);
NeoDrawLine(cube[5,0],cube[5,1],cube[6,0],cube[6,1]);
NeoDrawLine(cube[6,0],cube[6,1],cube[7,0],cube[7,1]);
NeoDrawLine(cube[7,0],cube[7,1],cube[4,0],cube[4,1]);
NeoDrawLine(cube[0,0],cube[0,1],cube[4,0],cube[4,1]);
NeoDrawLine(cube[1,0],cube[1,1],cube[5,0],cube[5,1]);
NeoDrawLine(cube[2,0],cube[2,1],cube[6,0],cube[6,1]);
NeoDrawLine(cube[3,0],cube[3,1],cube[7,0],cube[7,1]);

angle := angle + 0.02;
until false;
end.
Binary file modified samples/neo6502/demoeffects/cube_0x1000.bin
Binary file not shown.

0 comments on commit 1ce0eb3

Please sign in to comment.