rotating one cube with madpascal.

All aspects of programming on the Commander X16.
Post Reply
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

rotating one cube with madpascal.

Post by funkheld »

Here is a demo with a rotating cube using MadPascal. X16 with "-mhz 24" from MADRAFi.

X16 release 47

cube1.prg
load "cube1.prg",8

greeting
Attachments
cube1.prg
(4.29 KiB) Downloaded 101 times
cube.jpg
cube.jpg (14.5 KiB) Viewed 1424 times
User avatar
MADRAFi
Posts: 4
Joined: Thu Apr 13, 2023 9:10 am

Re: rotating one cube with madpascal.

Post by MADRAFi »

Thanks for checking this one. I think if you wish to make it prettier you would need to use frame buffer to hide flickering.
a8 examples have implementations using such buffering.
ATARI
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: rotating one cube with madpascal.

Post by funkheld »

Thanks for the info.

I did it without a buffer.
I just did a quick clss in asm.
I'm not familiar with the buffers yet.

greeting

Code: Select all

program cube;

uses  x16_vera, x16, crt,graph;

const Linien      =12;
      Ecken        =8;
      distanz      =2000.0;
      sinphi        =0.195090322016;
      cosphi       =0.980785280411;

var   start,
      Ende         : array [0..Linien] of smallint;
      x, y, z      : array [0..Ecken]  of real;
      x2d, y2d   : array [0..Ecken]  of smallint;
      Alt           : array [0..Linien*4] of smallint;
      Laenge     : real;
      Add_X , Add_Y : word ;
      d: cardinal;
      f:byte;
      tempX, tempY, tempZ: real;
	  
procedure clss;
begin
  asm 
    lda #0
    sta $9f20
    lda #0
    sta $9f21
    lda #$10
    sta $9f22
	
    lda #1
    ldx #0
loop1:
    ldy #150
loop:
    sta $9f23
    sta $9f23
    dey
    bne loop
    dex
    bne loop1
  end;
end;	  

procedure XRotation;
var i: byte;
begin
    for i := 0 to Ecken-1 do
      begin
        tempY:=y[i];
        tempZ:=z[i];
        y[i] :=tempY*cosphi - tempZ*sinphi;
        z[i] :=tempZ*cosphi + tempY*sinphi;
      end;
      pause(1);
end;

procedure YRotation;
var i: byte;
begin
    for i := 0 to Ecken-1 do
      begin
        tempX:=x[i];
        tempZ:=z[i];
        x[i] :=tempX*cosphi - tempZ*sinphi;
        z[i] :=tempZ*cosphi + tempX*sinphi;
      end;
end;

procedure ZRotation;
var i: byte;
begin
    for i := 0 to Ecken-1 do
      begin
        tempX:=x[i];
        tempY:=y[i];
        x[i] :=tempX*cosphi - tempY*sinphi;
        y[i] :=tempY*cosphi + tempX*sinphi;
      end;
      clss;
end;

procedure Zeichne_Wuerfel;
var i,x : byte;
begin
    for i := 0 to Linien-1 do
      begin
	    x:=i shl 2;

           Alt[x]:=x2d[start[i]];
           Alt[x+1]:=y2d[start[i]];
           Alt[x+2]:=x2d[Ende[i]];
           Alt[x+3]:=y2d[Ende[i]];

           MoveTo (Alt[x],Alt[x+1]);
           LineTo (Alt[x+2],Alt[x+3]);
      end;
end;

procedure Wandle_3D_2D;
var i:byte;
    f:real;
begin
    for i := 0 to Ecken-1 do
      begin
         f := 1000.0 / (distanz-z[i]);
         x2d[i]:=TRUNC(x[i]*f) + Add_X;
         y2d[i]:=TRUNC(y[i]*f) + Add_Y;
      end;
end;

procedure SetzePunkte;
begin
    x[0]:=-Laenge;
    y[0]:= Laenge;
    z[0]:= Laenge;
    x[1]:= Laenge;
    y[1]:= Laenge;
    z[1]:= Laenge;
    x[2]:= Laenge;
    y[2]:=-Laenge;
    z[2]:= Laenge;
    x[3]:=-Laenge;
    y[3]:=-Laenge;
    z[3]:= Laenge;
    x[4]:=-Laenge;
    y[4]:= Laenge;
    z[4]:=-Laenge;
    x[5]:= Laenge;
    y[5]:= Laenge;
    z[5]:=-Laenge;
    x[6]:= Laenge;
    y[6]:=-Laenge;
    z[6]:=-Laenge;
    x[7]:=-Laenge;
    y[7]:=-Laenge;
    z[7]:=-Laenge;
end;

procedure SetzeLinien;
begin
    start[ 0]:=0;  Ende[ 0]:=1;
    start[ 1]:=1;  Ende[ 1]:=2;
    start[ 2]:=2;  Ende[ 2]:=3;
    start[ 3]:=3;  Ende[ 3]:=0;
    start[ 4]:=0;  Ende[ 4]:=4;
    start[ 5]:=1;  Ende[ 5]:=5;
    start[ 6]:=2;  Ende[ 6]:=6;
    start[ 7]:=3;  Ende[ 7]:=7;
    start[ 8]:=4;  Ende[ 8]:=5;
    start[ 9]:=5;  Ende[ 9]:=6;
    start[10]:=6;  Ende[10]:=7;
    start[11]:=7;  Ende[11]:=4;
end;

begin

  InitGraph(X16_MODE_320x240); 
  
  Poke($9f25,0);
  
  Laenge:=ScreenHeight shr 1 - 10;
  Add_X :=ScreenWidth shr 1;
  Add_Y :=ScreenHeight shr 1;

  fillchar(Alt, sizeof(Alt), 0);

  SetzePunkte;
  SetzeLinien;

  YRotation;
  ZRotation;

  repeat
   XRotation;
   //YRotation;
   //ZRotation;
 
   Wandle_3D_2D;
   clss;
   Zeichne_Wuerfel;
  until keypressed;
end.
Post Reply