Textured 3d cube routine

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

Textured 3d cube routine

Post by DrChip »

rem Textured 3d cube routine
rem I'M BUILDING A GRAPHIC DATA BUILDER
rem I'LL POST IT WHEN I'M DONE!
rem enjoy...
rem iPhone 6 Plus / 8.3 b2

gosub setup

loop:
refresh off
graphics clear
gosub drawcube
gosub rotate
refresh on
goto loop

drawcube:
for i=1 to 6
c1=ac1(i)!c2=ac2(i)
c3=ac3(i)!c4=ac4(i)
gosub cp
if cp<0 then goto skip2
gosub fillface
skip2:
next i
return

fillface:
ax2=(xx(c2)-xx(c3))/sprx
ay2=(yy(c2)-yy(c3))/spry
ax3=(xx(c4)-xx(c1))/sprx
ay3=(yy(c4)-yy(c1))/spry

for a=0 to sprx
ta3=(ax3*a)+xx(c1)
tb3=(ay3*a)+yy(c1)
ta2=(ax2*a)+xx(c3)
tb2=(ay2*a)+yy(c3)

tx=(ta3-ta2)/sprx
ty=(tb3-tb2)/spry

for b=0 to spry
gx(a,b)=(tx*b)+ta2
gy(a,b)=(ty*b)+tb2
next b
next a

for b=0 to spry-1
for a=0 to sprx-1
if texture(a,b)>0 then

CB = and(texture(a,b),16711680)/65536
CG = (and(texture(a,b),65280)/256%256)
CR = (texture(a,b)%256)
fill color CR/255,CG/255,CB/255

'fill triangle gx(a,b),gy(a,b) to gx(a+1,b),gy(a+1,b) to gx(a,b+1),gy(a,b+1)
trix(0)=gx(a,b)
triy(0)=gy(a,b)
trix(1)=gx(a+1,b)
triy(1)=gy(a+1,b)
trix(2)=gx(a,b+1)
triy(2)=gy(a,b+1)
fill poly trix,triy count 3
'fill triangle gx(a+1,b+1),gy(a+1,b+1) to gx(a+1,b),gy(a+1,b) to gx(a,b+1),gy(a,b+1)
trix(0)=gx(a+1,b+1)
triy(0)=gy(a+1,b+1)
trix(1)=gx(a+1,b)
triy(1)=gy(a+1,b)
trix(2)=gx(a,b+1)
triy(2)=gy(a,b+1)
fill poly trix,triy count 3
end if
next a
next b
return

cp:
cp=(xx(c1)-xx(c2))*(yy(c3)-yy(c2))-(xx(c3)-xx(c2))*(yy(c1)-yy(c2))
return

rotate:
xr=xr+1
if xr>360 then xr=xr-360
yr=yr+2
if yr>360 then yr=yr-360
zr=zr+1
if zr>360 then zr=zr-360
s=s+1
if s>360 then s=s-360
sz=sine(s)

for a=1 to points
x1=x(a)
y1=y(a)
z1=z(a)
txx=x1
tyy=y1*cosi(xr)+z1*sine(xr)
tzz=z1*cosi(xr)-y1*sine(xr)
y1=tyy
x1=txx*cosi(yr)-tzz*sine(yr)
z1=txx*sine(yr)+tzz*cosi(yr)
tzz=z1
txx=x1*cosi(zr)-y1*sine(zr)
tyy=x1*sine(zr)+y1*cosi(zr)
dx(a)=txx
dy(a)=tyy
dz(a)=tzz
xx(a)=sz*((dx(a)/((dz(a)/focus)+1)))+cx
yy(a)=sz*((dy(a)/((dz(a)/focus)+1)))+cy
next a
return


setup:
graphics
sw=screen_width()
sh=screen_height()
pi=3.1415

points=8! focus=500! cx=sw/2! cy=sh/2
dim sine(362),cosi(362)
dim x(points+1),y(points+1),z(points+1),xx(points+1),yy(points+1)
dim dx(points+1),dy(points+1),dz(points+1)

for a=0 to 361
cosi(a)=cos(a*(pi/180))
sine(a)=sin(a*(pi/180))
next a

for a=1 to points
read x(a)
read y(a)
read z(a)
next a

dim ac1(7),ac2(7),ac3(7),ac4(7)
for a=1 to 6
read ac1(a),ac2(a),ac3(a),ac4(a)
next a

read sprx
read spry
read filter
dim gx(sprx+2,spry+2),gy(sprx+2,spry+2)
dim texture(sprx+1,spry+1)

for b=0 to spry rem -1
for a=0 to sprx rem -1
read texture(a,b)
next a
next b
return

data 100, 100, 100,-100, 100, 100,-100, 100,-100
data 100, 100,-100, 100,-100, 100,-100,-100, 100
data -100,-100,-100, 100,-100,-100, 1,3,2,4,1,8,4,5
data 8,6,7,5,6,3,7,2,3,8,7,4,1,6,5,2


REM - COLOR AND TEXTURE CODE:


data 27,27,10
data 2621440,2630888,2621440,2630888,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2630888,2621440
data 2621440,2630888,2630888,2630888,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2630888,2630888,2621440
data 2621440,2630888,58600,2630888,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2630888,58600,2630888,2630888
data 2621440,2621440,2630888,58600,2630888,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2106440,5262416,5262416,5262416,5262416,2106440,2621440,2621440,2621440,2621440,2621440,2630888,2630888,58600,2630888,2621440
data 2621440,2621440,58600,58600,2621440,2621440,2621440,2621440,2621440,2621440,2106440,2106440,5262416,7367792,8946824,8946824,7367792,5262416,2106440,2106440,2621440,2621440,2621440,2621440,58600,2630888,2621440,2621440
data 5262416,5262416,7367792,13157608,7367792,5262416,2621440,2621440,2621440,5262416,7367792,5262416,5262416,7367792,7367792,7367792,7367792,5262416,7367792,5262416,5262416,2621440,5262416,5262416,7367792,13157608,7367792,5262416
data 2621440,2621440,7367792,8946824,2621440,2621440,2621440,2621440,2106440,7367792,8946824,5262416,2106440,5262416,5262416,5262416,5262416,2106440,7367792,8946824,5262416,2106440,2621440,2621440,7367792,8946824,2621440,2621440
data 2621440,2621440,7367792,8946824,7367792,2621440,2621440,5262416,7367792,2106440,5262416,2106440,2621440,2106440,2106440,2106440,2106440,2106440,5262416,7367792,5262416,2106440,2621440,5262416,7367792,8946824,2621440,2621440
data 2621440,2621440,7367792,8946824,5262416,7367792,2106440,7367792,8946824,7367792,2106440,2106440,2621440,2621440,2621440,2621440,2621440,2106440,2106440,5262416,5262416,2106440,5262416,7367792,7367792,8946824,2621440,2621440
data 2621440,2621440,5262416,7367792,2621440,5262416,2106440,7367792,7367792,5262416,2106440,2621440,2621440,2621440,2621440,2621440,2621440,2621440,2106440,2106440,2106440,2106440,7367792,2621440,5262416,7367792,2621440,2621440
data 2621440,2621440,2621440,2621440,2621440,2106440,2106440,5262416,2106440,2106440,2621440,2621440,5262416,15221832,15221832,15221832,15221832,2621440,2621440,2621440,5262416,5262416,5262416,2106440,2621440,2621440,2621440,2621440
data 2621440,2621440,2621440,2621440,2621440,2106440,7367792,13157608,7367792,2621440,2621440,5262416,15221832,15221832,15221832,15221832,15221832,15221832,2621440,2106440,7367792,8946824,7367792,5262416,2621440,2621440,2621440,2621440
data 2621440,2621440,2621440,2621440,2106440,5262416,7367792,7367792,7367792,2106440,2621440,15221832,15221832,15221832,15221832,15221832,15221832,17424,2621440,2106440,5262416,5262416,5262416,5262416,2621440,2621440,2621440,2621440
data 2621440,2621440,2621440,2621440,2106440,5262416,5262416,7367792,5262416,2106440,2621440,15221832,15221832,15221832,15221832,17424,17424,2124872,2621440,2621440,2106440,2106440,5262416,2106440,2106440,2621440,2621440,2621440
data 2621440,2621440,2621440,2621440,2106440,2106440,5262416,5262416,2106440,2621440,2621440,15221832,15221832,15221832,17424,2124872,2124872,17424,2621440,2621440,2106440,5262416,7367792,7367792,5262416,2106440,2621440,2621440
data 2621440,2621440,2621440,2621440,2106440,2106440,2106440,2106440,2621440,2621440,2621440,15221832,17424,2124872,2124872,2124872,17424,17424,2621440,2621440,2106440,7367792,8946824,8946824,7367792,5262416,2621440,2621440
data 2621440,2621440,2621440,2106440,5262416,7367792,7367792,5262416,2106440,2621440,2621440,17424,2124872,2124872,2124872,17424,17424,17424,2621440,2621440,2106440,5262416,5262416,5262416,5262416,2106440,2621440,2621440
data 2621440,2621440,2621440,5262416,7367792,13157608,7367792,7367792,2106440,2106440,2621440,2124872,2106440,2106440,2106440,2106440,2106440,17424,2621440,2621440,2621440,2106440,5262416,5262416,2106440,2106440,2621440,2621440
data 2621440,2621440,2621440,5262416,7367792,7367792,7367792,5262416,2106440,2106440,2621440,2621440,3163264,3163264,3163264,2106440,2106440,2106440,2621440,2621440,2621440,2106440,7367792,7367792,7367792,5262416,2106440,2621440
data 2621440,2621440,2621440,2106440,5262416,5262416,5262416,5262416,5262416,2106440,2621440,3163264,3163264,3163264,3163264,3163264,2106440,2106440,2621440,2621440,5262416,2106440,7367792,8946824,13157608,8946824,2106440,2621440
data 2621440,2621440,2106440,2106440,2106440,5262416,5262416,2106440,2106440,2621440,2621440,3163264,4224160,4224160,3163264,3163264,3163264,2106440,2106440,2621440,2106440,2106440,5262416,7367792,7367792,5262416,2106440,2621440
data 2621440,2621440,5262416,5262416,7367792,7367792,13157608,7367792,2106440,2621440,3163264,6329536,6329536,4224160,4224160,4224160,3163264,3163264,2106440,2621440,2106440,5262416,5262416,2106440,2106440,2106440,2106440,2621440
data 2621440,2621440,5262416,5262416,5262416,7367792,7367792,7367792,2621440,2621440,6329536,6329536,6329536,6329536,6329536,4224160,4224160,3163264,3163264,2106440,5262416,7367792,8946824,5262416,5262416,8946824,5262416,2106440
data 17424,4224160,3163264,5262416,5262416,5262416,5262416,2106440,2621440,4224160,3163264,4224160,4224160,4224160,4224160,6329536,6329536,4224160,3163264,2106440,2106440,5262416,17424,2106440,7367792,7367792,5262416,2106440
data 17424,4224160,4224160,2106440,2106440,3163264,3163264,3163264,2106440,3163264,4224160,4224160,3163264,4224160,4224160,4224160,4224160,4224160,2106440,4224160,2106440,2124872,17424,2124872,17424,5262416,17424,2124872
data 4224160,4224160,2106440,3163264,2106440,2106440,2106440,2106440,2106440,4224160,3163264,4224160,4224160,4224160,3163264,4224160,4224160,4224160,4224160,4224160,4224160,17424,17424,2124872,17424,2124872,2124872,2124872
data 4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160
data 4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,4224160,422416000
Attachments
image.jpg
image.jpg (206.88 KiB) Viewed 2817 times
image.jpg
image.jpg (239.02 KiB) Viewed 2817 times
image.jpg
image.jpg (155.22 KiB) Viewed 2817 times
image.jpg
image.jpg (115.4 KiB) Viewed 2817 times
image.jpg
image.jpg (81.78 KiB) Viewed 2817 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Textured 3d cube routine

Post by Mr. Kibernetik »

So much great work!
Texture image is very complex...

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

Re: Textured 3d cube routine

Post by DrChip »

Thank you, I think! Smart Basic was the only iOS basic fast enough to run my sloppy routines. :)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Textured 3d cube routine

Post by Mr. Kibernetik »

If you use 4-points polygons instead of 3-points, it would be faster.

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

Re: Textured 3d cube routine

Post by DrChip »

I'm old school programmer, the days when demos and intros were placed before cracked games. I'll try my next project with 4 instead of 3. I'm working on a filled, spinning tunnel game. I'll try it there. Thanks for the tip! If you have any others, that would be great!

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Textured 3d cube routine

Post by Mr. Kibernetik »

DrChip wrote:I'm old school programmer, the days when demos and intros were placed before cracked games. I'll try my next project with 4 instead of 3. I'm working on a filled, spinning tunnel game. I'll try it there. Thanks for the tip! If you have any others, that would be great!
Next version 4.8 will offer direct quad draw/fill command, which will not need prior storing data in array before using them.

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

Re: Textured 3d cube routine

Post by DrChip »

Awesome!

Post Reply