The Temple In OpenGl

'Written in FreeBasic.023 for windows

'to get latest version:
'Version 0.23 released - freebasic.net

'For a real easy to use Integrated Development Enviroment. FBIDE
'FBIde - #1 editor for FreeBASIC

'=================================
'Begin code
'=================================
#include once “GL/gl.bi”
#include once “GL/glu.bi”

'console printed instructioins.
screen 0
cls
print “Press Esc to EXIT”
print “-----------------------------------------”
print
print “Press Space-bar to stop all motion "
print
print “-----------------------------------------”
print “Left , Right Arrows to rotate on X - Axis”
print
print " Up , Down Arrows to rotate on Y - Axis”
print
print " R_Shft to reset U/D , L/R rotate values "
print “-----------------------------------------”
print
print " (+) , (-) , (Enter) to control spin "
print
print " (Q) , (W) , (E) to control zoom level "
print
print " (A) , (S) , (D) to control U/D shift "
print
print " (Z) , (X) , (C) to control L/R shift "
print
print " (R) , (T) to control RED LEVEL "
print " (F) , (G) to control GREEN LEVEL "
print " (V) , (B) to control BLUE LEVEL "
print “-----------------------------------------”;

'for general trig looping and values
'======================================
dim as double r1 = atn(1)/45
dim as double d1
dim as double deg1_start = 0
dim as double deg1_end = 360
dim as double deg1_inc = 1
'======================================
dim as double r2 = atn(1)/45
dim as double d2
dim as double deg2_start = 0
dim as double deg2_end = 360
dim as double deg2_inc = .5
'======================================
dim as double c1
dim as double c2
dim as double s1
dim as double s2

dim as double out_x
dim as double out_y
dim as double out_z

dim as integer xres,yres
screen 19
screeninfo xres,yres
Screenres xres,yres,32,1,2
windowtitle “The Temple”

’ create and compile a OpenGL list
dim as integer glList = glGenLists(1)
glNewList(glList, GL_COMPILE)
glBegin GL_POINTS

For d1 = deg1_start To deg1_end Step deg1_inc

    c1=cos(d1*r1)
    s1=sin(d1*r1)

    For d2 = deg2_start To deg2_end Step deg2_inc
  
        c2=cos(d2*r2)
        s2=sin(d2*r2)
  
        dim as single x : x = atan2( tan(c2+c2) , tan(c1+c1)/2 )*2
                
        dim as single y : y = atan2( tan(s2+s2) , tan(s1+s1)/2 )*2
                
        dim as single z : z = (cos(c1+s1)*5)
                
        glvertex3f x , y , z

    Next d2

Next d1    

glEnd
glEndList()

'===============================================================================
'===============================================================================
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 75 , xres/yres , .1, 500
glMatrixMode GL_MODELVIEW
glLoadIdentity
glBlendfunc GL_SRC_ALPHA, GL_ONE
glPointsize 1
glEnable gl_blend

'for OpenGl transition,rotation
dim as single xt, yt, zt=-15 'transition variables
dim as single xr, yr, zr ‘rotation variables
dim as single xrs=.5,yrs=.5,zrs=0’ transitions of camera
dim as ubyte red= 150, green=75, blue=25

dim as ubyte status=1
DO WHILE status=1

glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
glloadidentity

gltranslatef xt, yt, zt
glrotatef xr, 1, 0, 0
glrotatef yr, 0, 1, 0
glrotatef zr, 0, 0, 1

’ draw the list
glColor3ub red,green,blue
glCallList glList

'screensync
glFlush
flip

'check for keys being pressed
if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

if multikey(&h50) then xrs-=.25
if multikey(&h48) then xrs+=.25
if multikey(&h4D) then yrs-=.25
if multikey(&h4B) then yrs+=.25
if multikey(&h0C) then zrs-=.25
if multikey(&h4E) then zrs+=.25
           
xr = xr - xrs
yr = yr - yrs
zr = zr - zrs
           
if multikey(&h2C) then xt-=.1
if multikey(&h2D) then xt+=.1
if multikey(&h1E) then yt+=.1
if multikey(&h1F) then yt-=.1
if multikey(&h10) then zt+=.1
if multikey(&h11) then zt-=.1
       
if multikey(&h39) then xrs=0 : yrs=0 : zrs=0  ' SPACE-BAR = stop all transitions
if multikey(&h1C) then  xr=0 :  yr=0 : zr=0   ' "Enter Key" reset spin to zero
if multikey(&h36) then                        'right_shift key, to reset GL_X,GL_Y rotation values
        xrs=0:yrs=0
        xr =0:yr =0
end if
           
if multikey(&h12) then zt=-15 ' "E key" reset zoom level
if multikey(&h20) then yt=  0  ' "D key" reset UP/DOWN    position to center
if multikey(&h2E) then xt=  0  ' "C key" reset Left/Right position to center

red   = red   +((multikey(&h13)) - (multikey(&h14))) ' r , t adjust red level
green = green +((multikey(&h21)) - (multikey(&h22))) ' f , g adjust green level
blue  = blue  +((multikey(&h2f)) - (multikey(&h30))) ' v , b adjust blue level

Loop

END

Heres A COOL!! one Kinda spitirtual or something…

'Written in FreeBasic.023 for windows

'to get latest version:
'Version 0.23 released - freebasic.net

'For a real easy to use Integrated Development Enviroment. FBIDE
'FBIde - #1 editor for FreeBASIC

'=================================
'Begin code
'=================================
#include once “GL/gl.bi”
#include once “GL/glu.bi”

'console printed instructioins.
screen 0
cls
print “Press Esc to EXIT”
print “-----------------------------------------”
print
print “Press Space-bar to stop all motion "
print
print “-----------------------------------------”
print “Left , Right Arrows to rotate on X - Axis”
print
print " Up , Down Arrows to rotate on Y - Axis”
print
print " R_Shft to reset U/D , L/R rotate values "
print “-----------------------------------------”
print
print " (+) , (-) , (Enter) to control spin "
print
print " (Q) , (W) , (E) to control zoom level "
print
print " (A) , (S) , (D) to control U/D shift "
print
print " (Z) , (X) , (C) to control L/R shift "
print
print " (R) , (T) to control RED LEVEL "
print " (F) , (G) to control GREEN LEVEL "
print " (V) , (B) to control BLUE LEVEL "
print “-----------------------------------------”;

'for general trig looping and values
'======================================
dim as double r1 = atn(1)/45
dim as double d1
dim as double deg1_start = 0
dim as double deg1_end = 360
dim as double deg1_inc = 1
'======================================
dim as double r2 = atn(1)/45
dim as double d2
dim as double deg2_start = 0
dim as double deg2_end = 360
dim as double deg2_inc = 1
'======================================
dim as double c1
dim as double c2
dim as double s1
dim as double s2

dim as double out_x
dim as double out_y
dim as double out_z

dim as integer xres,yres
screen 19
screeninfo xres,yres
Screenres xres,yres,32,1,2
windowtitle “The Temple”

’ create and compile a OpenGL list
dim as integer glList = glGenLists(1)
glNewList(glList, GL_COMPILE)
glBegin GL_POINTS

For d1 = deg1_start To deg1_end Step deg1_inc

    c1=cos(d1*r1)
    s1=sin(d1*r1)

    For d2 = deg2_start To deg2_end Step deg2_inc
  
        c2=cos(d2*r2)
        s2=sin(d2*r2)
        
        dim as single x 
            x = c1
            x+=(   c1*cos(cos(d2*r2)*s2/c1)*cos(d2*r2*(c1*c2)/s1)*cos(s1*d2*r2)*c2*s1*2.7)
            x+=(.1*c1*cos(cos(d2*r2)*s2/c1)*cos(d2*r2*(c1*c2)/s1)*cos(s1*d2*r2)*c2*s1*2.7)/1.5
            x=-x
        dim as single y
            y = s1
            y+=(   s1*sin(sin(d2*r2)*c2/s1)*sin(d2*r2*(s1*s2)/c1)*sin(c1*d2*r2)*c2*s1*2.7)
            y+=(.1*s1*sin(sin(d2*r2)*c2/s1)*sin(d2*r2*(s1*s2)/c1)*sin(c1*d2*r2)*c2*s1*2.7)/1.5
            y=-y
        dim as single z = c2+s2
                
        glvertex3f x , y , z

    Next d2

Next d1    

glEnd
glEndList()

'===============================================================================
'===============================================================================
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 22.5 , xres/yres , .1, 500
glMatrixMode GL_MODELVIEW
glLoadIdentity
glBlendfunc GL_SRC_ALPHA, GL_ONE
glPointsize 1
glEnable gl_blend

'for OpenGl transition,rotation
dim as single xt, yt, zt=-15 'transition variables
dim as single xr, yr, zr ‘rotation variables
dim as single xrs=0,yrs=.25,zrs=0’ transitions of camera
dim as ubyte red= 150, green=75, blue=25

dim as ubyte status=1
DO WHILE status=1

glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
glloadidentity

gltranslatef xt, yt, zt
glrotatef xr, 1, 0, 0
glrotatef yr, 0, 1, 0
glrotatef zr, 0, 0, 1

’ draw the list
glColor3ub red,green,blue
glCallList glList

'screensync
glFlush
flip

'check for keys being pressed
if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

if multikey(&h50) then xrs-=.25
if multikey(&h48) then xrs+=.25
if multikey(&h4D) then yrs-=.25
if multikey(&h4B) then yrs+=.25
if multikey(&h0C) then zrs-=.25
if multikey(&h4E) then zrs+=.25
           
xr = xr - xrs
yr = yr - yrs
zr = zr - zrs
           
if multikey(&h2C) then xt-=.1
if multikey(&h2D) then xt+=.1
if multikey(&h1E) then yt+=.1
if multikey(&h1F) then yt-=.1
if multikey(&h10) then zt+=.1
if multikey(&h11) then zt-=.1
       
if multikey(&h39) then xrs=0 : yrs=0 : zrs=0  ' SPACE-BAR = stop all transitions
if multikey(&h1C) then  xr=0 :  yr=0 : zr=0   ' "Enter Key" reset spin to zero
if multikey(&h36) then                        'right_shift key, to reset GL_X,GL_Y rotation values
        xrs=0:yrs=0
        xr =0:yr =0
end if
           
if multikey(&h12) then zt=-15 ' "E key" reset zoom level
if multikey(&h20) then yt=  0  ' "D key" reset UP/DOWN    position to center
if multikey(&h2E) then xt=  0  ' "C key" reset Left/Right position to center

red   = red   +((multikey(&h13)) - (multikey(&h14))) ' r , t adjust red level
green = green +((multikey(&h21)) - (multikey(&h22))) ' f , g adjust green level
blue  = blue  +((multikey(&h2f)) - (multikey(&h30))) ' v , b adjust blue level

Loop

END