Sdl3dBoard

 I hope to be able to expand on the ideas that I got while making this. The main idea is; 3d without openGL or other complex code.


        option explicit

  dim scnt = 100 , num = 100 , v1 = 11
 
  dim cnt = 0 , count , m1
  dim common tilt = 0.7

  ' declare array
 dim common YSlope[9000]
 dim common XSlope[9000]
 dim common flip[9000]              
 dim common var[900]
directScreen
autoback(-2)
'screenswap
setdisplay( 800,600,32,1)
 
   for count = 1 to 9000  
       XSlope[count] = 1
       YSlope[count] = 1
       flip[count] = 1
   next
   for count = 1 to 900 
      var[count] = 1
   next
    ink (rgb(20,60,80))
cls

function Zprint()
   dim count
   for count = 1 to 20 
       text ( 1150,count * 20,16,var[count] )
   next
end function


function SetConversion( )
      dim  cnt = 0
       dim x1 = 1 , y1 = 1
        for cnt = 0 to 7000
             XSlope[cnt] = x1
             YSlope[cnt] = y1     '  * tilt
             x1 = x1 * .9997
             y1 = y1 * .9997
             flip[cnt] = 550 - cnt   ' Reverse Z coordinates and add offset
            
        next    
      
end function
function Point3d( x,z )
       dim slope = YSlope[round(z)] , x2
       dim slopex = XSlope[round(z)]
        x2 = 600 - x
        x = slopex * x2 + 400
        z = z * slope
        z =  flip[round(z)]  ' 1 = bottom  higher numbers of z get
end function


function Line3d(x1,z1,x2,z2)
       dim x10,z10,x20,z20
        x10=x1:x20=x2:z10 = z1 : z20 = z2
       Point3d( x10,z10 )
       Point3d( x20,z20 )
       line(x10,z10,x20,z20)
end function



function quad(x1,z1,x2,z2,x3,z3,x4,z4)

         Line(x1,z1,x2,z2)  ' x1 = bottom left   x2 = bottom right   x3 = top right   x4 = top left
         Line(x2,z2,x3,z3)
         Line(x3,z3,x4,z4)
         Line(x1,z1,x4,z4)
        
end function

function LineQuad(x1,z1,x2,z2,x3,z3,x4,z4)
    dim x10,z10,x20,z20,x30,z30,x40,z40
     x10=x1:z10=z1:x20=x2:z20=z2:x30=x3:z30=z3:x40=x4:z40=z4
    Point3d(x10,z10)
    Point3d(x20,z20)
    Point3d(x30,z30)
    Point3d(x40,z40)
    polyline(x10,z10,x20,z20,x30,z30,x40,z40)
    

end function
function SolidQuad(x1,z1,x2,z2,x3,z3,x4,z4)
    dim x10,z10,x20,z20,x30,z30,x40,z40
     x10=x1:z10=z1:x20=x2:z20=z2:x30=x3:z30=z3:x40=x4:z40=z4
    Point3d(x10,z10)
    Point3d(x20,z20)
    Point3d(x30,z30)
    Point3d(x40,z40)
    polygon(x10,z10,x20,z20,x30,z30,x40,z40)
    

end function


function Zboard()
   dim lngth = 100 , start = 300
   Dim x1 = start , x2 = start - lngth  ,x3 = start - lngth ,x4 = start ,z1 = 1 ,z2 = 1 ,z3 = lngth * tilt,z4 = lngth * tilt ,clr = 2
   Dim row = 1 , column
     while row < 9
         clr = clr + 1
         if clr > 2  then
            clr = 1
         end if
         for column = 1 to 8
            if clr = 1  then
                ink ( rgb(0,230,230))
                clr = 2
                else                                 
                ink( rgb(200,255,255) )
                clr = 1
            end if
             SolidQuad(x1,z1,x2,z2,x3,z3,x4,z4)
             ink ( rgb(0,0,255) )
             LineQuad(x1,z1,x2,z2,x3,z3,x4,z4)
 
             x1 = x1 + lngth
             x2 = x2 + lngth
             x3 = x3 + lngth
             x4 = x4 + lngth
         next
         x1 = start : x2 = start - lngth : x3 = start - lngth  : x4 = start
         z1 = z1 + lngth * tilt
         z2 = z2 + lngth * tilt
         z3 = z3 + lngth * tilt
         z4 = z4 + lngth * tilt
        row = row + 1
     wend
       
end function



SetConversion()
    ink ( rgb(255,255,255) )
   ' cnt = 0
 while not key( k_esc )
        cls
          wait(20)
          Zboard()

          Zprint()
          ink ( rgb(255,255,255))
          text ( 0,0,16,"Press Escape Key to exit ")
          text(20,40,16,mouseX)
          text(20,60,16,mouseY)
         
       
        m1 = mouseY
        if  m1<1  then
            m1 = 1
        end if
           text ( 20,80,16,flip[m1] )
         'Squad(200,200,400,200,400,200,200,400)
         screenswap
        wait(20)
      
 wend
 

end
 


 

 

Make a free website with Yola