Post by Rod on May 21, 2020 18:07:16 GMT
Ok, still developing the sprite creator. Next task is a perspective transformation that takes say a 64x64 sprite and maps it to a perspective view. Any help much appreciated. Shout if there is confusion, my maths and trig is poor. Discount my solution, throw it away and substitute yours.
Eventually I will be able to take 64x64 flat images and do a perspective transform that will allow them to be used as floor wall or ceiling tiles. Double the size will knit together and produce a 3d view.
Eventually I will be able to take 64x64 flat images and do a perspective transform that will allow them to be used as floor wall or ceiling tiles. Double the size will knit together and produce a 3d view.
nomainwin
WindowWidth = 860
WindowHeight = 500
UpperLeftX = int((DisplayWidth-WindowWidth)/2)
UpperLeftY = 10
graphicbox #1.gb, 35, 30, 386, 386
open "Sprite Creator" for graphics_nsb_nf as #1
#1 "trapclose [quit]"
#1.gb "down ; fill black "
global pix, npix, fcol$, bcol$,frame
pix=6
npix=64
null=color("255 255 0")
dim frame$(npix,npix)
dim back$(npix,npix)
'frame$() is out visible drawing
'back$() is a background copy
'draw a yellow line round the graphicbox
'and store it in frame$() and back$()
for x= 0 to npix-1
null=paint(x,0)
back$(x,0)="255 255 0"
null=paint(x,npix-1)
back$(x,npix-1)="255 255 0"
next
for y= 0 to npix-1
null=paint(0,y)
back$(0,y)="255 255 0"
null=paint(npix-1,y)
back$(npix-1,y)="255 255 0"
next
[perspective]
cursor hourglass
ocol$=fcol$
null=perspective("floor")
nul=color(ocol$)
cursor normal
wait
[quit]
close #1
end
function color(c$)
if c$="" then c$="0 0 0"
fcol$=c$
#1.gb "backcolor ";fcol$;" ; color ";fcol$
end function
function paint(x,y)
'clips and paints pixel square to size, updating frame array
if x>=0 and x<npix and y>=0 and y<npix then
#1.gb "place ";x*pix;" ";y*pix
#1.gb "boxfilled ";x*pix+pix;" ";y*pix+pix
frame$(x,y)=fcol$
end if
end function
'if we take a 64x64 sprite to get a perspective view that will be scaleable
'we need to take the 64x64 image and spread it.
'top line gets mapped to x=16 y= 48 to x=48 y=48
'bottom is mapped just as it is x=0 y=63 to x=63 y=63
function perspective(face$) 'floor,left,right,ceiling
'for the moment we just want the floor perspective
'eventually we will clear the screen before drawing
'the perspective view, for now it just overdraws
sx=npix/4+npix/4
sy=npix/4*3
sd=npix/2/npix
yd=npix/4/npix
xd=npix/2/npix
for y=0 to npix-1
xx=sx
for x=0 to npix-1
'get the color from the background file
tcol$=back$(x,frame*npix+y)
'set the pen to that color
nul=color(tcol$)
'paint the new location
nul=paint(xx,sy)
xx=xx+xd
next
xd=y/npix
sx=sx-sd
sy=sy+yd
next
end function