Some old AMOS code that I recently found. Might help someone learning about 3D.
' Rotating 3D Cube Example.
' Original code by ??? Converted to AMOS by Kev G.
'
' Compile for more speed and/or use Turbo extension fast GFX commands
'
' If you have any questions regarding this code then you can find me
' on the AMOS Factory forums. Bye!
'
'
Screen Open 0,320,200,2,Lowres
Curs Off : Flash Off : Hide
Palette $0,$CCC : Cls 0
Double Buffer : Autoback 0
Degree
'
CX=Screen Width/2 : CY=Screen Height/2
Global CX,CY,X2D,Y2D
'
Dim VERTEX(8,3)
Global VERTEX()
Dim PPOINTS(8,2)
Global PPOINTS()
'
Dim _SIN#(360)
Global _SIN#()
Dim _COS#(360)
Global _COS#()
'
For D=0 To 359 : _SIN#(D)=Sin(D) : _COS#(D)=Cos(D) : Next D
'
'
Restore VERTEX_DATA
I=0
For N=0 To 7
Read A,B,C
VERTEX(I,0)=A : VERTEX(I,1)=B : VERTEX(I,2)=C
Inc I
Next N
'
VERTEX_DATA:
Data -50,-50,-50
Data 50,-50,-50
Data 50,50,-50
Data -50,50,-50
Data -50,-50,50
Data 50,-50,50
Data 50,50,50
Data -50,50,50
'
ANGLEX=0 : ANGLEY=0 : ANGLEZ=0
_ZOOM=150 : DEPTH=200 : SPEED=4
'
Key Speed 1,1
Break Off : Amos Lock : Wait Vbl
CUBE[1]
'
Repeat
If Key State(50) Then Add ANGLEX,SPEED,0 To 359 : Rem 'X' Key
If Key State(21) Then Add ANGLEY,SPEED,0 To 359 : Rem 'Y' Key
If Key State(49) Then Add ANGLEZ,SPEED,0 To 359 : Rem 'Z' key
If Key State(23) Then Add _ZOOM,SPEED,10 To 200 : Rem 'I' key
If Key State(24) Then Add _ZOOM,-SPEED,10 To 200 : Rem 'O' key
'
For N=0 To 7
CALCULATE_2D_POINT[VERTEX(N,0),VERTEX(N,1),VERTEX(N,2),ANGLEX,ANGLEY,ANGLEZ,_ZOOM,DEPTH]
PPOINTS(N,0)=X2D : PPOINTS(N,1)=Y2D
Next N
'
CUBE[1]
Text 0,190,"X,Y,Z,I,O Keys to move. Mouse to quit."
Screen Swap
Wait Vbl
Cls 0
Until Mouse Key=1
'
Key Speed 10,2
Wait Vbl : Amos Unlock : Break On
Screen Close 0
End
'
' **********************************************
'
Procedure CALCULATE_2D_POINT[X3D,Y3D,Z3D,ROTX,ROTY,ROTZ,_ZOOM,DEPTH]
X2#=(X3D*_COS#(ROTZ))-(Y3D*_SIN#(ROTZ))
Y2#=(X3D*_SIN#(ROTZ))+(Y3D*_COS#(ROTZ))
X3#=(X2#*_COS#(ROTY))-(Z3D*_SIN#(ROTY))
Z2#=(X2#*_SIN#(ROTY))+(Z3D*_COS#(ROTY))
Y3#=(Y2#*_COS#(ROTX))-(Z2#*_SIN#(ROTX))
Z3#=(Y2#*_SIN#(ROTX))+(Z2#*_COS#(ROTX))
X2D=Int(_ZOOM*(X3#/(Z3#+DEPTH))+CX)
Y2D=Int(_ZOOM*(Y3#/(Z3#+DEPTH))+CY)
End Proc
'
' **********************************************
'
Procedure CUBE[_MODE]
If _MODE=0
For V=0 To 7
Plot PPOINTS(V,0),PPOINTS(V,1),2
Next V
Else
Draw PPOINTS(0,0),PPOINTS(0,1) To PPOINTS(1,0),PPOINTS(1,1)
Draw PPOINTS(1,0),PPOINTS(1,1) To PPOINTS(2,0),PPOINTS(2,1)
Draw PPOINTS(2,0),PPOINTS(2,1) To PPOINTS(3,0),PPOINTS(3,1)
Draw PPOINTS(3,0),PPOINTS(3,1) To PPOINTS(0,0),PPOINTS(0,1)
'
Draw PPOINTS(4,0),PPOINTS(4,1) To PPOINTS(5,0),PPOINTS(5,1)
Draw PPOINTS(5,0),PPOINTS(5,1) To PPOINTS(6,0),PPOINTS(6,1)
Draw PPOINTS(6,0),PPOINTS(6,1) To PPOINTS(7,0),PPOINTS(7,1)
Draw PPOINTS(7,0),PPOINTS(7,1) To PPOINTS(4,0),PPOINTS(4,1)
'
Draw PPOINTS(0,0),PPOINTS(0,1) To PPOINTS(4,0),PPOINTS(4,1)
Draw PPOINTS(1,0),PPOINTS(1,1) To PPOINTS(5,0),PPOINTS(5,1)
Draw PPOINTS(2,0),PPOINTS(2,1) To PPOINTS(6,0),PPOINTS(6,1)
Draw PPOINTS(3,0),PPOINTS(3,1) To PPOINTS(7,0),PPOINTS(7,1)
End If
End Proc
'
' **********************************************