I have been experimenting with ways to use 3D in my programs, without using complicated stuff like OpenGL. Here, I have a simple rotating cube that uses a non-3d method for making cubes.


     option explicit     ' you really don't need this, but I think it helps to stay organized. More compatable with C Lang

  dim common  aa = 10
  dim common red = rgb(255,0,0),blue = rgb(0,0,255),green = rgb(0,255,0),violet = rgb(255,0,255),yellow = rgb(255,255,0),bluegreen = rgb(0,255,255)
  dim common red2 = rgb(255,0,0),blue2 = rgb(255,0,0),green2 = rgb(255,0,0),violet2 = rgb(255,0,0),yellow2 = rgb(255,0,0),bluegreen2 = rgb(255,0,0)
  dim common black = rgb(0,0,0),white = rgb(255,255,255)

  dim common tilt = 0.3                 '0.7
  dim common Pi = 3.14159265 , AngleS = Pi / 180  ' Angle Segment equal to 1.0 degrees
  ' declare array
  dim common  px[10]        '  Point X
  dim common   py[10]       '  Point Y
autoback(-2)
setdisplay( 800,600,32,1)
    ink (rgb(20,60,80))
cls


function DrawSides(radius)
    '   dim Ang1 = aa
       dim x1 = px[1],x2 = px[2],x3 = px[3],x4 = px[4]
       dim x5 = px[1],x6 = px[2],x7 = px[3],x8 = px[4]
       dim y1 = py[1],y2 = py[2],y3 = py[3],y4 = py[4]
       dim y5 = py[1] -radius ,y6 = py[2] -radius ,y7 = py[3] -radius ,y8 = py[4] -radius
     if aa > 45 then
       ink (bluegreen)
       polygon(x8,y8,x5,y5,x1,y1,x4,y4)
     end if
     if aa > 315 or aa < 135 then
           ink (blue)
           polygon(x5,y5,x6,y6,x2,y2,x1,y1)
     end if
     if aa > 225 or aa< 45 then
       ink (green)
       polygon(x6,y6,x7,y7,x3,y3,x2,y2)
     end if
     if aa > 135 and aa < 315 then
       ink (yellow)
       polygon(x7,y7,x8,y8,x4,y4,x3,y3)
     end if
       ink (red)
       polygon(x5,y5,x6,y6,x7,y7,x8,y8)
end function


function DrawQuad( cx,cy,radius, Ang1)
               ' AngleS = number of Radians in 1 Degree
          dim Angle  =  Ang1 * AngleS
          dim Angle2 = (Ang1 + 90 )* AngleS
          dim Angle3 = (Ang1 + 180 )* AngleS
          dim Angle4 = (Ang1 + 270 )* AngleS
             ' calculate the 4 bottom points of the cube.   
             ' point 1
             px[1] = cos(Angle) * radius + cx
             py[1] = .2 * sin(Angle) * radius + cy
             ' point 2
             px[2] = cos(Angle2) * radius + cx
             py[2]  = .2 * sin(Angle2) * radius + cy
             ' point 3
             px[3] = cos(Angle3) * radius + cx
             py[3]  = .2 * sin(Angle3) * radius + cy
              'point 4
             px[4] = cos(Angle4) * radius + cx
             py[4]  = .2 * sin(Angle4) * radius + cy        
         
          DrawSides(radius)
          ink(white)
end function


' Start Program

 
    cls
    ink ( white )
    text ( 0,10,16,"Press Escape Key to exit ")
    text ( 300,10,16,"Angle = ")
 while not key( k_esc )
          ink ( rgb(0,0,0))
          bar ( 0,100,800,600 )
          bar ( 400,0,800,100 )
         ' wait(1)
       
       
         ink ( rgb(255,255,255))
          DrawQuad( 400,400,100,aa )   ' x,y,radius,angle

        aa = aa + 1
        if aa > 359 then
           aa = 0
        end if
       
          text(400,10,16,aa)
 
         screenswap
        wait(1)
      
 wend
 

end

 

Make a free website with Yola