home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
graphics
/
b109_1
/
!3D_Utils
/
Demo
(
.txt
)
< prev
next >
Wrap
RISC OS BBC BASIC V Source
|
1994-01-15
|
7KB
|
259 lines
demo of 3d_utils by Michel Grimminck
vdu 16,time(10)
init3Dswinames :
Put names of swi's in variables
"TD_GetInfo"
info :
Get info on screenmode, etc.
info!4:
"TD_CurrentScreen" :
always necessary !
640,512 :
Set OS origin to quandrangle module's origin
@StartCount=info!44 :
read quadrangle counter
initbankswap
points
rotatequad
Statistics:
"TD_GetInfo"
info
"There were ";info!44-StartCount;" quadrangles drawn"
"There were ";info!44;" quadrangles drawn since module startup"
"There were ";info!56;" SWI's called since module startup"
"TD_ClrScreen",255 :
Clear the screen, dithering white and black
data 40000 :
Space for quadrangles
X%=(T%-128)/128*640
X1%=(T%-124)/128*640
3
"TD_RGBto16bit",255-T%,255-T%,255-T%
@
"TD_Quadrangle",X%,-1000,X1%,-1000,X1%,1000,X%,1000,C%
I=100:C=4
T=I
-1
AD=data+36*(I-T)
$1AD!0=-C*T:AD!4=-C*T :
Set x,y positions
AD!8=C*T:AD!12=-C*T
AD!16=C*T:AD!20=C*T
AD!24=-C*T:AD!28=C*T
(%AD!32=T*257 :
Color
"TD_QuadrangleList",data,I+1 :
Draw the quadrangles
points
place points at random positions with random colors
T%=0
25000:
TD_Point%,
(1280)-640,
(1024)-512,257*
(255):
rotatequad
"TD_ClrScreen",1
X0(3),Y0(3),X(3),Y(3)
"Basic routine:";
40,0);"Quadrangle routine:"
"Each routine gets an equal fraction of the processor time"
ALFA=.02:C=1:C0=1
X(0)=-200:Y(0)=-200
X(1)=200 :Y(1)=-200
X(2)=200 :Y(2)= 200
X(3)=-200:Y(3)= 200
X0()=X():Y0()=Y()
(ALFA):CA=
(ALFA)
U%=1
TD_Quadrangle%,X0(0)+300,Y0(0),X0(1)+300,Y0(1),X0(2)+300,Y0(2),X0(3)+300,Y0(3),C0*257 :
Draw a quadrangle
C; X=X0(I%)*CA-Y0(I%)*SA :
Rotate corner points
Y=X0(I%)*SA+Y0(I%)*CA
X0(I%)=X:Y0(I%)=Y
C0=(C0+1)
C/4
64*(C
X(0)-300,Y(0):
X(1)-300,Y(1)
85,X(3)-300,Y(3):
85,X(2)-300,Y(2)
X=X(I%)*CA-Y(I%)*SA
Y=X(I%)*SA+Y(I%)*CA
X(I%)=X:Y(I%)=Y
C=(C+1)
initbackground
"TD_ClrScreen",&8A8B:Tcount=0
steps%=24
Object 2*12*steps%,XYZ% 2*12*steps%,Matrix 9*4,quad 6*2*steps%
Make a cilinder
T%=0
steps%-1
A=(T%/steps%)*2*
`& X=1024*
(A):Y=1024*
(A):Z=1024
a> Object!(12*T%)=X:Object!(12*T%+4)=Y:Object!(12*T%+8)=Z
bZ Object!(12*(T%+steps%))=X:Object!(12*(T%+steps%)+4)=Y:Object!(12*(T%+steps%)+8)=-Z
Set the quadrangles, first the inside, than the outside of the object
steps%-1
f5 T1%=(T%+1)
steps%:
T%>=steps%
T1%+=steps%
T2%=T%+steps%
h :
inside
j :
kO AD=quad+6*T% :
address of current quad.
l< AD?0=T%:AD?1=T2%:AD?2=(T2%+1)
steps%+steps%:AD?3=T1%
J%=
*T%/steps%)*64
nG
"TD_RGBto16bit",J%+64,J%+64,J%+64
C% :
calc a nice colour
o; AD?4=C% >>8:AD?5=C%
255 :
Colour
p :
q*
outside:corners in reverse order
r :
AD2=AD+6*steps%
t3 AD2?0=AD?3:AD2?1=AD?2:AD2?2=AD?1:AD2?3=AD?0
J%=
*T%/steps%)*80
v5
"TD_RGBto16bit",2*J%+118,J%+118,J%+118
w" AD2?4=C% >>8:AD2?5=C%
y9RX=3:RY=1:RZ=1:S=0 :
RX,RY,RZ = rotation angle
bankswap
makematrix(RX,RY,RZ,1000,500) :
create a rotation matrix
"TD_QuadrangleList",background,back :
draw background
0,1);"Framerate:";
(1000/(
-time(Tcount))+.5):time(Tcount)=
:Tcount=(Tcount+1)
"TD_Rotate",Object,XYZ%,Matrix,steps%*2,12 :
rotate the points in space
>300
0,0)"And now a little perspective ..."
>300
"TD_Perspective",XYZ%,steps%*2,21,300*
(S),300*
(1.3*S+1) :
Add perspective and move over the screen.
<600
!
draw wireframe in basic
T%=0
2*steps%-1
9 T1%=(T%+1)
steps%:
T%>=steps%
T1%+=steps%
T2%=T%+steps%
U
TD_Line%,XYZ%!(12*T%),XYZ%!(12*T%+4),XYZ%!(12*T1%),XYZ%!(12*T1%+4),255
b
T%<steps% :
TD_Line%,XYZ%!(12*T%),XYZ%!(12*T%+4),XYZ%!(12*T2%),XYZ%!(12*T2%+4),255
C
draw solid object, note this is faster than the wireframe
,
"TD_DrawSimple",XYZ%,quad,steps%*2
8RY+=.05:RX+=.025:RZ-=.01:S+=.05 :
increase angles
>1600
initbackground
Set up a list of quadrangles, to be used as background.
background 32*36
back=0
Y%=(T%-128)/128*512
Y1%=(T%-120)/128*512
(
"TD_RGBto16bit",T%,T%,255
ad=background+36*back
ad!0=-1000:ad!4=Y%
ad!8=1000:ad!12=Y%
ad!16=1000:ad!20=Y1%
ad!24=-1000:ad!28=Y1%
ad!32=C%
back+=1
makematrix(RX,RY,RZ,SCA,SCZ)
SCA is scaling in x and y direction, SCZ is scaling in z direction
RX:SD=
RX:CC=
RY:SC=
RY:CG=
RY:SG=
UMatrix!0=(CD*CC-SD*SG*SC)*SCA :Matrix!4=(SD*SG*CC+CD*SC)*SCA :Matrix!8=-SD*CG*SCA
UMatrix!12=(SD*CC+CD*SG*SC)*SCA:Matrix!16=(SD*SC-CD*SG*CC)*SCA:Matrix!20=CD*CG*SCA
RMatrix!24=-(CG*SC)*SCZ :Matrix!28=CC*CG*SCZ :Matrix!32=SG*SCZ
init3Dswinames
Defines variables for use in basic for fast access to the SWI's
TD_ScreenAddress%=&0CCB40
TD_QuadrangleList%=&0CCB41
TD_Rotate%=&0CCB42
TD_ClrScreen%=&0CCB43
TD_Quadrangle%=&0CCB44
TD_Point%=&0CCB45
TD_Perspective%=&0CCB46
TD_DrawSimple%=&0CCB47
TD_CurrentScreen%=&0CCB48
TD_GetInfo%=&0CCB49
TD_PointList%=&0CCB4A
TD_RGBto16bit%=&0CCB4B
TD_Decompress%=&0CCB4C
TD_DrawSorted%=&0CCB4D
TD_SetWindow%=&0CCB4E
TD_Line%=&0CCB4F
bankswap
bankswapper for 1, 2 or 3 banks. If using 3 banks, there is no need for
the WAIT statement, saving 10 millisecs on average.
BankMax%=1
:
just one bank
BankMax%<3
:
just two banks
8NB%=bank%+1:
NB%>BankMax%
NB%=1 :
next bank
6,112,NB%:
6,113,bank%
"TD_ScreenAddress",StartScreen%+ScrMem%*(NB%-1)
bank%=NB%
initbankswap
vdu!0=149:vdu!4=-1
"OS_ReadVduVariables",vdu,vdu+8
StartScreen%=vdu!8
.ScrMem%=info!32 :
screensize
count the amount of screenmemory.
(There must be a swi for it, but I don't know it)
*ScrMax%=0:CH%=&2000:AD%=&2000000-CH%:
"OS_ValidateAddress",AD%,AD%
;C%:C%=C%
2:AD%-=CH%
C%=0
ScrMax%+=CH%
C%=2
Now takes as many banks as possible
6BankMax%=ScrMax%/ScrMem%:
BankMax%>3
BankMax%=3
bank%=1