3d rotating Mac (still working on it)

Post Reply
DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

3d rotating Mac (still working on it)

Post by DrChip »

REM Rotating 3d Mac SE
REM iPhone 6+ / iOS 8.2 b3
REM enjoy...
graphics
pi=3.1415
GOSUB setup

loop:
graphics clear 0,0,0
refresh off
snn=snn+5
IF snn>359 THEN
snn=1
END IF
GOSUB rotate
GOSUB draw
GOSUB scroll
refresh on
GOTO loop

rotate:
'rotation
rx=rx+1
IF rx>359 THEN
rx=rx-359
END IF
ry=ry+2
IF ry>359 THEN
ry=ry-359
END IF

' move object
zpos=30+sn(snn)*5

'apply rotation to the vertices
c1=cs(rx)
c2=cs(ry)
s1=sn(rx)
s2=sn(ry)
FOR p=1 TO points
xx=vx(p)
yy=vy(p)
zz=vz(p)
ny=c1*yy+s1*zz
nz=c1*zz-s1*yy
nx=c2*xx+s2*nz
nz=c2*nz-s2*xx
nz=nz+zpos

'add perspective
tx(p)=fov*(nx/nz)+xpos
ty(p)=fov*(ny/nz)+ypos
col(p)=255-nz*6
NEXT p
RETURN

draw:
' draw wire frame
FOR f=1 TO faces
col1=col(vrtx(f,1))
col2=col(vrtx(f,2))
col3=col(vrtx(f,3))
fill COLOR col1/255,col1/255,col1*.7/255

IF f>16 AND f<19 THEN
fill COLOR col1*.7/255,col1*.7/255,col1*.7/255
END IF

fx1=tx(vrtx(f,1))
fx2=tx(vrtx(f,2))
fx3=tx(vrtx(f,3))
fy1=ty(vrtx(f,1))
fy2=ty(vrtx(f,2))
fy3=ty(vrtx(f,3))
IF (fx1-fx2)*(fy3-fy2)-(fx3-fx2)*(fy1-fy2)<0 THEN
'TRIANGLE fx1,fy1, fx2,fy2, fx3,fy3
trix(0)=fx1
triy(0)=fy1
trix(1)=fx2
triy(1)=fy2
trix(2)=fx3
triy(2)=fy3
fill poly trix,triy count 3
END IF
NEXT f
RETURN

scroll:

'move letters
sx=sx-5
IF sx<0 THEN
ll=len(l$)
FOR l=0 TO 65
letter$(l)=letter$(l+1)
NEXT l
letter$(65)=substr$(scroll$,0,1)
o=o+1
IF o>LEN(scroll$) THEN
o=0
END IF
sx=1
END IF

' display scroll
draw COLOR 1,1,0
lx=sx
FOR l=1 TO 65
ly=sinus(lx+10)
DRAW TEXT letter$(l) at lx,ly
lx=lx+10
NEXT l
RETURN

setup:
'setup variables
points=30
faces=56
xpos=Screen_Width()/2
ypos=Screen_Height()/2
zpos=30
fov=700

'dimension arrays
DIM vx(points+1),vy(points+1),vz(points+1)
DIM tx(points+1),ty(points+1)
DIM vrtx(faces+1,4),col(points+2)
DIM sn(360),cs(360)
DIM letter$(67),sinus(656)
DIM trix(4),triy(4)

' setup vertices
FOR p=1 TO points
READ vx(p),vy(p),vz(p)
NEXT p

FOR f=1 TO faces
READ vrtx(f,1),vrtx(f,2),vrtx(f,3)
NEXT f

' setup sin/cos-LUT
FOR a=1 TO 359
sn(a)=SIN(a*PI/180)
cs(a)=COS(a*PI/180)
NEXT a
'setup scroll text
scroll$="PLAY > "
scroll$=scroll$&"Hello everyone! This is DrChip "
scroll$=scroll$&"here with a classic 3D-model "
scroll$=scroll$&"of a Macintosh SE. I didn't do "
scroll$=scroll$&"any proper z-sorting 'cause I'm a lazy bum. "
scroll$=scroll$&"There are no major overlaps anyway, and the "
scroll$=scroll$&"sorting would have caused serious speed issues"
scroll$=scroll$&". I think it's slow enough as it is, and it's "
scroll$=scroll$&"this scroll that slows it down... anyways.."
scroll$=scroll$&" Greetings to everyone on this"
scroll$=scroll$&" basic forum.... "
scroll$=scroll$&"enjoy this 3D-business..."
scroll$=scroll$&" << REWIND"
scroll$=scroll$&" "

'setup SIN table FOR scroll
FOR x=1 TO 650
sinus(x)=(Screen_Height()-25)+SIN(x/20)*10 '500
NEXT x

' setup scroll start
FOR l=1 TO 65
letter$(l)=" "
NEXT l
RETURN

' vertex coord data
DATA -5,-6,-5
REM front (1,2,3,4)
DATA 5,-6,-5
REM ---------------
DATA 5, 4,-5.5
DATA -5, 4,-5.5
DATA -5, 4,-4
REM front/bottom (5,6,7,8)
DATA 5, 4,-4
REM ----------------------
DATA 5, 7,-4
DATA -5, 7,-4
DATA -5,-4, 5
REM back (9,10,11,12)
DATA 5,-4, 5
REM -----------------
DATA 5, 7, 5.2
DATA -5, 7, 5.2
DATA -5,-5.5, 4
REM back/top (13,14,15)
DATA -2,-5.5, 4
REM ----------
DATA -2,-4, 5
DATA 5,-5.5, 4
REM back/top (16,17,18)
DATA 2,-5.5, 4
REM -------------------
DATA 2,-4, 5
DATA -2,-5.8, 0
REM back/top indent(19,20,21,22)
DATA 2,-5.8, 0
REM ----------------------------
DATA 2,-4, 0
DATA -2,-4, 0
DATA -4,-5,-5
REM screen frame (23,24,25,26)
DATA 4,-5,-5
REM --------------------------
DATA 4, 1,-5.3
DATA -4, 1,-5.3
DATA -3.5,-4.5,-4.5
REM screen surface (27,28,29,30)
DATA 3.5,-4.5,-4.5
REM ----------------------------
DATA 3.5, .5,-4.5
DATA -3.5, .5,-4.5

' face connection data
DATA 20,19,22
REM back/top faces
DATA 22,21,20
REM ----------
DATA 17,20,21
DATA 21,18,17
DATA 19,14,15
DATA 15,22,19
DATA 21,22,15
DATA 15,18,21
DATA 23,24,28
REM screen faces
DATA 28,27,23
REM ------------
DATA 28,24,25
DATA 25,29,28
DATA 30,29,25
DATA 25,26,30
DATA 23,27,30
DATA 30,26,23
DATA 27,28,29
DATA 29,30,27
DATA 4,3,6
REM front/bottom
DATA 6,5,4
REM -----------
DATA 5,6,7
DATA 7,8,5
DATA 1,2,24
REM front faces
DATA 24,23,1
REM -----------
DATA 24,2,3
DATA 3,25,24
DATA 26,25,3
DATA 3,4,26
DATA 1,23,26
DATA 26,4,1
DATA 19,20,2
REM top faces
DATA 2,1,19
REM ---------
DATA 13,14,19
DATA 19,1,13
DATA 17,16,2
DATA 2,20,17
DATA 16,17,18
REM back faces
DATA 18,10,16
REM ----------
DATA 14,13,9
DATA 9,15,14
DATA 10,18,11
DATA 18,15,11
DATA 15,12,11
DATA 15,9,12
DATA 13,1,4
REM left faces
DATA 4,5,13
REM ----------
DATA 9,13,5
DATA 12,5,8
DATA 5,12,9
DATA 2,16,3
REM right faces
DATA 16,10,3
REM -----------
DATA 3,10,6
DATA 6,10,11
DATA 6,11,7
DATA 8,7,11
REM bottom faces
DATA 11,12,8
Attachments
image.jpg
image.jpg (135.38 KiB) Viewed 1796 times
image.jpg
image.jpg (150.66 KiB) Viewed 1796 times
image.jpg
image.jpg (148.04 KiB) Viewed 1796 times

Post Reply