jet to build :
- fog
- textures [ need some help whit this ]
- ?
t_3d.bas
Code: Select all
''bluatigro 18 jun 2013
''OOP game lib : 3Dvector
type t3d
x as single
y as single
z as single
declare constructor()
declare constructor ( x as single , y as single, z as single )
declare sub fill( x as single , y as single , z as single )
declare sub normalize
end type
constructor t3d()
this.x = 0
this.y = 0
this.z = 0
end constructor
constructor t3d( x as single , y as single , z as single )
this.x = x
this.y = y
this.z = z
end constructor
operator +( a as t3d , b as t3d ) as t3d
return type( a.x + b.x , a.y + b.y , a.z + b.z )
end operator
operator *( a as t3d , d as single ) as t3d
return type( a.x * d , a.y * d , a.z * d )
end operator
operator \( a as t3d , b as t3d ) as t3d
return type( a.y * b.z - a.z * b.y _
, a.z * b.x - a.x * b.z _
, a.x * b.y - a.y * b.x )
end operator
operator -( a as t3d , b as t3d ) as t3d
return type( a.x - b.x , a.y - b.y , a.z - b.z )
end operator
operator /( a as t3d , d as single ) as t3d
return type( a.x / d , a.y / d , a.z / d )
end operator
sub t3d.fill( x as single , y as single , z as single )
this.x = x
this.y = y
this.z = z
end sub
declare function dot( a as t3d , b as t3d ) as single
function dot( a as t3d , b as t3d ) as single
return a.x * b.x + a.y * b.y + a.z * b.z
end function
declare function length( q as t3d ) as single
function length( q as t3d ) as single
return sqr( q.x * q.x + q.y * q.y + q.z * q.z ) + 1e-7
end function
declare function anlge( a as t3d , b as t3d ) as single
function angle( a as t3d , b as t3d ) as single
return acos( dot( a , b ) _
/ ( length( a ) * length( b ) ) )
end function
sub t3d.normalize
this /= length( this )
end sub
Code: Select all
#ifndef OPENGL_H
#define OPENGL_H
#include once "GL/gl.bi"
#include once "GL/glu.bi"
#include "t_3d.bas"
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif
const as single PI = atn( 1 ) * 4
const as integer false = 0
const as integer true = not false
dim shared as integer mouse_x
dim shared as integer mouse_y
dim shared as integer mouse_button
dim shared pnt( 255 ) as t3d
dim shared sk( 63 ) as t3d
type Tbox
m as t3d
d as t3d
end type
dim shared box as Tbox
const as integer xyz = 0
const as integer xzy = 1
const as integer yxz = 2
const as integer yzx = 3
const as integer zxy = 4
const as integer zyx = 5
declare sub child( x as single , y as single , z as single , ax as integer , lim as integer )
declare function rad( deg as single ) as single
declare function pend( fase as single , amp as single ) as single
declare sub skelet( no as integer , x as single , y as single , z as single )
declare sub animate( anim as integer , f as single , a as single )
declare sub human()
declare sub insect()
declare sub pilko()
declare sub opengl_init()
declare sub material( a as single ptr _
, d as single ptr , s as single )
declare sub isoca( i as integer )
declare sub sphere( h as integer , r as integer _
, a as single , b as single )
declare sub torus( hsides as integer , rsides as integer )
declare sub cilinder( sides as integer ,dx as single , dy as single , top as integer , bot as integer )
declare sub cube( )
declare sub setbox( mx as single , my as single , mz as single , dx as single , dy as single , dz as single )
declare sub geo( no as integer , p1 as integer _
, p2 as integer , p3 as integer )
declare sub setcolor( clr as integer )
declare sub setpoint( no as integer , x as single , y as single , z as single )
declare sub tri1( p1 as integer , p2 as integer , p3 as integer , kl as integer )
declare sub tri3( p1 as integer , kl1 as integer , p2 as integer , kl2 as integer , p3 as integer , kl3 as integer )
declare sub quad( p1 as integer , p2 as integer , p3 as integer , p4 as integer , kl as integer )
declare sub quad2( p1 as integer , kl1 as integer _
, p2 as integer , kl2 as integer _
, p3 as integer , kl3 as integer _
, p4 as integer , kl4 as integer )
declare function hill( x as double ) as integer
declare function mix( kla as integer , f as double , klb as integer ) as integer
declare function rainbow( x as double ) as integer
dim shared as single black( 3 ) = { 0 , 0 , 0 , 1 }
dim shared as single red( 3 ) = { 1 , 0 , 0 , 1 }
dim shared as single green( 3 ) = { 0 , 1 , 0 , 1 }
dim shared as single dgreen( 3 ) = { 0 , .5 , 0 , 1 }
dim shared as single yellow( 3 ) = { 1 , 1 , 0 , 1 }
dim shared as single blue( 3 ) = { 0 , 0 , 1 , 1 }
dim shared as single magenta( 3 ) = { 1 , 0 , 1 , 1 }
dim shared as single cyan( 3 ) = { 0 , 1 , 1 , 1 }
dim shared as single white( 3 ) = { 1 , 1 , 1 , 1 }
dim shared as single orange( 3 ) = { 1 , .5 , 0 , 1 }
dim shared as single gray( 3 ) = { .5 , .5 , .5 , 1 }
const as integer body = 0
const as integer arm = 1
const as integer elbow = 2
const as integer wrist = 3
const as integer leg = 4
const as integer knee = 5
const as integer enkle = 6
const as integer neck = 7
const as integer eye = 8
const as integer ileg = 4
const as integer iknee = 9
const as integer wing = 14
const as integer tail = 16
const as integer sensor = 17
const as integer thumb = 18
const as integer finger = 19
const as integer lr = 32
const as integer human_walk = 1
const as integer dog_walk = 2
const as integer I_FLY = 3
const as integer I_LEFT_LEGS = 4
const as integer I_LEFT_BOX = 5
const as integer I_RIGHT_LEGS = 6
const as integer I_RIGHT_BOX = 7
const as integer I_STING = 8
const as integer I_STAND = 9
function lenght( a as t3d ) as single
return sqr( a.x ^ 2 + a.y ^ 2 + a.z ^ 2 ) + 0.00001
end function
sub child( x as single , y as single , z as single , lim as integer , ax as integer )
glTranslatef x , y , z
select case ax
case xyz
glRotatef sk( lim ).x , 1 , 0 , 0
glRotatef sk( lim ).y , 0 , 1 , 0
glRotatef sk( lim ).z , 0 , 0 , 1
case xzy
glRotatef sk( lim ).x , 1 , 0 , 0
glRotatef sk( lim ).z , 0 , 0 , 1
glRotatef sk( lim ).y , 0 , 1 , 0
case yxz
glRotatef sk( lim ).y , 0 , 1 , 0
glRotatef sk( lim ).x , 1 , 0 , 0
glRotatef sk( lim ).z , 0 , 0 , 1
case yzx
glRotatef sk( lim ).y , 0 , 1 , 0
glRotatef sk( lim ).z , 0 , 0 , 1
glRotatef sk( lim ).x , 1 , 0 , 0
case zxy
glRotatef sk( lim ).z , 0 , 0 , 1
glRotatef sk( lim ).x , 1 , 0 , 0
glRotatef sk( lim ).y , 0 , 1 , 0
case zyx
glRotatef sk( lim ).z , 0 , 0 , 1
glRotatef sk( lim ).y , 0 , 1 , 0
glRotatef sk( lim ).x , 1 , 0 , 0
case else
end select
end sub
sub skelet( no as integer , x as single , y as single , z as single )
sk( no and 63 ).fill x , y , z
end sub
sub animate( anim as integer , f as single , a as single )
DIM I AS INTEGER
select case anim
case human_walk
skelet arm , pend( f , a ) , 0 , 0
skelet elbow , -abs( a ) , 0 , 0
skelet arm + lr , pend( f + 180, a ) , 0 , 0
skelet elbow + lr , -abs( a ) , 0 , 0
skelet leg , pend( f + 180 , a ) , 0 , 0
skelet knee , pend( f + 90 , a ) + a , 0 , 0
skelet leg + lr , pend( f , a ) , 0 , 0
skelet knee + lr , pend( f - 90 , a ) + a , 0 , 0
case dog_walk
skelet arm , pend( f + 180 , a ) , 0 , 0
skelet elbow , pend( f + 90 , a ) + a , 0 , 0
skelet arm + lr , pend( f , a ) , 0 , 0
skelet elbow + lr , pend( f - 90 , a ) + a , 0 , 0
skelet leg , pend( f + 180 , a ) , 0 , 0
skelet knee , pend( f + 90 , a ) + a , 0 , 0
skelet leg + lr , pend( f , a ) , 0 , 0
skelet knee + lr , pend( f - 90 , a ) + a , 0 , 0
skelet tail , -45 , pend( f * 2 , a ) , 0
skelet neck , 0 , 0 , 0
skelet neck + lr , 0 , 0 , 0
Case I_FLY
For i = 0 To 1
skelet wing + i, 0 , 0 , Pend(f, a)
skelet wing+lr + i, 0,0, Pend(f, -a)
Next
Case I_LEFT_BOX
skelet arm, 0, Pend(f, -a) + 45 , 0
skelet elbow, 0, Pend(f, a * 2) - 60 , 0
Case I_LEFT_LEGS
For i = 0 To 4
skelet ileg + i, 0 , 0, Pend(f + i * 180, a)
skelet iknee + i, Pend(f + i * 180 + 90, a) , 0 , 0
Next
Case I_RIGHT_BOX
skelet arm+lr, 0, Pend(f, a) - 45,0
skelet elbow+lr, 0, Pend(f, -a * 2) + 60, 0
Case I_RIGHT_LEGS
For i = 0 To 4
skelet ileg+lr+ i, 0,0, Pend(f + i * 180, a)
skelet iknee+lr + i, Pend(f + i * 180 + 90, a),0,0
Next
Case I_STAND
skelet arm, 0, 45, 0
skelet elbow, 0, -60 , 0
skelet finger, 0, 0, 0
skelet thumb, 0, 0, 0
skelet arm+lr, 0, -45, 0
skelet elbow+lr, 0, 60 , 0
skelet finger+lr, 0, 0, 0
skelet thumb+lr, 0, 0, 0
skelet tail, 10, 0 , 0
skelet tail+lr, 10, 0 , 0
Case I_STING
skelet tail, 10 + Pend(f, a), 0, 0
skelet tail+lr, 10 - Pend(f, a), 0, 0
case else
dim i as integer
for i = 0 to 63
skelet i , 0,0,0
next i
end select
end sub
function rad( deg as single ) as single
return deg * PI / 180
end function
function pend( fase as single , amp as single ) as single
return sin( rad( fase ) ) * amp
end function
sub opengl_init()
'' DIM AS INTEGER winx, winy, bitdepth
'' SCREENINFO winx, winy, bitdepth
'' SCREENRES winx, winy, 32, , FB.GFX_FULLSCREEN
screen 20 , 32 , , 2
'' ReSizeGLScene
glViewport 0, 0, 1024, 768 '' Reset The Current Viewport
glMatrixMode GL_PROJECTION '' Select The Projection Matrix
glLoadIdentity '' Reset The Projection Matrix
gluPerspective 45.0, 640.0/480.0, 0.1, 100.0 '' Calculate The Aspect Ratio Of The Window
glMatrixMode GL_MODELVIEW '' Select The Modelview Matrix
glLoadIdentity '' Reset The Modelview Matrix
'' All Setup For OpenGL Goes Here
glShadeModel GL_SMOOTH '' Enable Smooth Shading
glClearColor 0.0, 0.0, 0.0, 1 '' Black Background
glClearDepth 1.0 '' Depth Buffer Setup
glEnable GL_DEPTH_TEST '' Enables Depth Testing
glDepthFunc GL_LEQUAL '' The Type Of Depth Testing To Do
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST '' Really Nice Perspective Calculations
glEnable( gl_lighting )
dim as single lightpos( 3 ) = { 0 , 50 , 0 , 1 }
dim as single diffuse( 3 ) = { 1 , 1 , 1 , 1 }
glLightfv( gl_light0 , gl_position, @lightpos(0) )
glLightfv( gl_light0 , gl_diffuse , @diffuse(0) )
glEnable( gl_light0 )
end sub
sub pilko()
setbox 0,0,0 , .3,.3,.3
isoca 3
setbox 0,0,-.5 , .3,.3,.3
isoca 3
glpushmatrix
child .15 , -.3 , 0 , arm , yzx
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
glpushmatrix
child 0 , -.4 , 0 , elbow , xyz
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
setbox 0,-.4,0 , .07 , .07 , .07
isoca 2
setbox 0,-.4,.1 , .07 , .07 , .07
isoca 2
glpopmatrix
glpopmatrix
glpushmatrix
child .15 , -.3 , -.5 , leg , yzx
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
glpushmatrix
child 0 , -.4 , 0 , knee , xyz
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
setbox 0,-.4,0 , .07 , .07 , .07
isoca 2
setbox 0,-.4,.1 , .07 , .07 , .07
isoca 2
glpopmatrix
glpopmatrix
glpushmatrix
child -.15 , -.3 , 0 , arm + lr , yzx
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
glpushmatrix
child 0 , -.4 , 0 , elbow + lr , xyz
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
setbox 0,-.4,0 , .07 , .07 , .07
isoca 2
setbox 0,-.4,.1 , .07 , .07 , .07
isoca 2
glpopmatrix
glpopmatrix
glpushmatrix
child -.15 , -.3 , -.5 , leg + lr , yzx
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
glpushmatrix
child 0 , -.4 , 0 , knee + lr , xyz
setbox 0,0,0 , .1 , .1 , .1
isoca 2
setbox 0,-.2,0 , .1 , .1 , .1
isoca 2
setbox 0,-.4,0 , .07 , .07 , .07
isoca 2
setbox 0,-.4,.1 , .07 , .07 , .07
isoca 2
glpopmatrix
glpopmatrix
glpushmatrix
dim i as single
child 0,.3, -.7 , tail , xyz
for i = 0 to 4
setbox 0,i*.15,0 , .1 , .1 , .1
isoca 2
next i
glpopmatrix
glpushmatrix
child 0,.15,.15 , neck , xyz
glPushMatrix
child 0,.15,.15,neck+lr, zyx
setbox 0,0,0 , .2 , .2 , .2
isoca 3
setbox .2, .2 , 0 , .07 , .07 , .07
isoca 2
setbox -.2 , .2 , 0 , .07 , .07 , .07
isoca 2
setbox 0,0,.24 , .07 , .07 , .07
isoca 2
glPushMatrix
child .1 , .14 , .14 , eye , xyz
setbox 0,0,0 , .07 , .07 , .07
glmaterialfv gl_front , gl_ambient , @white( 0 )
glmaterialfv gl_front , gl_diffuse , @white( 0 )
isoca 2
setbox 0,0,.07 , .05,.05,.05
glmaterialfv gl_front , gl_ambient , @black( 0 )
glmaterialfv gl_front , gl_diffuse , @black( 0 )
isoca 2
glPopMatrix
glPushmatrix
child -.1 , .14 , .14 , eye + lr , xyz
setbox 0,0,0 , .07 , .07 , .07
glmaterialfv gl_front , gl_ambient , @white( 0 )
glmaterialfv gl_front , gl_diffuse , @white( 0 )
isoca 2
setbox 0,0,.07 , .05,.05,.05
glmaterialfv gl_front , gl_ambient , @black( 0 )
glmaterialfv gl_front , gl_diffuse , @black( 0 )
isoca 2
glPopMatrix
glPopMatrix
glpopmatrix
end sub
sub geo( no as integer , p1 as integer _
, p2 as integer , p3 as integer )
if no < 1 then
tri1 p1 , p2 , p3 , 0
else
dim p12 as integer , p13 as integer , p23 as integer
p12 = 255 - no * 3
p13 = 255 - no * 3 - 1
p23 = 255 - no * 3 - 2
pnt( p12 ) = ( pnt( p1 ) + pnt( p2 ) ) / 2
pnt( p13 ) = ( pnt( p1 ) + pnt( p3 ) ) / 2
pnt( p23 ) = ( pnt( p2 ) + pnt( p3 ) ) / 2
pnt( p12 ) = pnt( p12 ) / lenght( pnt( p12 ) )
pnt( p13 ) = pnt( p13 ) / lenght( pnt( p13 ) )
pnt( p23 ) = pnt( p23 ) / lenght( pnt( p23 ) )
geo no - 1 , p1 , p12 , p13
geo no - 1 , p2 , p23 , p12
geo no - 1 , p3 , p13 , p23
geo no - 1 , p12 , p23 , p13
end if
end sub
sub isoca( i as integer )
if i < 0 then i = 0
if i > 5 then i = 5
glPushMatrix
glTranslatef box.m.x , box.m.y , box.m.z
glScalef box.d.x , box.d.y , box.d.z
setpoint 1 , 0 , 0 , 1.118034
setpoint 2 , 1 , 0 , .5
setpoint 3 , .309017 , .95105654 , .5
setpoint 4 , -.809017 , .58778524 , .5
setpoint 5 , -.809017 , -.58778524 , .5
setpoint 6 , .309017 , -.95105654 , .5
setpoint 7 , .809017 , .58778524 , -.5
setpoint 8 , -.309017 , .95105654 , -.5
setpoint 9 , -1 , 0 , -.5
setpoint 10 , -.309017 , -.95105654 , -.5
setpoint 11 , .809017 , -.58778524 , -.5
setpoint 12 , 0 , 0 , -1.118034
dim t as integer
for t = 1 to 12
pnt( t ) = pnt( t ) / lenght( pnt( t ) )
next t
geo i , 1 , 2 , 3
geo i , 1 , 3 , 4
geo i , 1 , 4 , 5
geo i , 1 , 5 , 6
geo i , 1 , 6 , 2
geo i , 2 , 7 , 3
geo i , 3 , 7 , 8
geo i , 3 , 8 , 4
geo i , 4 , 8 , 9
geo i , 4 , 9 , 5
geo i , 5 , 9 , 10
geo i , 5 , 10 , 6
geo i , 6 , 10 , 11
geo i , 6 , 11 , 2
geo i , 2 , 11 , 7
geo i , 12 , 8 , 7
geo i , 12 , 9 , 8
geo i , 12 , 10 , 9
geo i , 12 , 11 , 10
geo i , 12 , 7 , 11
glPopMatrix
end sub
sub sphere( a as integer , b as integer _
, da as single , db as single )
dim as single i , j , i2 , j2
dim as single x , y , z
if a < 3 then a = 3
if a > 64 then a = 64
if b < 3 then b = 3
if b > 64 then b = 64
glPushMatrix
glTranslatef box.m.x , box.m.y , box.m.z
glScalef box.d.x , box.d.y , box.d.z
for i = -PI to PI step PI / a * 2
i2 = i + PI / a * 2
for j = -PI / 2 to PI / 2 step PI / b * 2
j2 = j + PI / b * 2
x = sin( i ) * cos( j )
y = sin( j )
z = cos( i ) * cos( j )
setpoint 0 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
x = sin( i2 ) * cos( j )
y = sin( j )
z = cos( i2 ) * cos( j )
setpoint 1 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
x = sin( i2 ) * cos( j2 )
y = sin( j2 )
z = cos( i2 ) * cos( j2 )
setpoint 2 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
x = sin( i ) * cos( j2 )
y = sin( j2 )
z = cos( i ) * cos( j2 )
setpoint 3 _
, abs( x ) ^ da * sgn( x ) _
, abs( y ) ^ db * sgn( y ) _
, abs( z ) ^ da * sgn( z )
quad 0 , 1 , 2 , 3 , 0
next j
next i
glPopMatrix
end sub
sub torus( a as integer , b as integer )
dim i as single , j as single , i2 as single , j2 as single
if a < 3 then a = 3
if a > 64 then a = 643
if b < 3 then b = 3
if b > 64 then b = 64
dim mx as single , my as single , mz as single , dx as single , dy as single , dz as single
mx = box.m.x
my = box.m.y
mz = box.m.z
dx = box.d.x
dy = box.d.y
dz = box.d.z
for i = -PI to PI step PI / a * 2
i2 = i + PI / a * 2
for j = -PI to PI step PI / b * 2
j2 = j + PI / b * 2
setpoint 0 _
, mx + ( dx + dy * cos( i ) ) * cos( j ) _
, my + ( dx + dy * cos( i ) ) * sin( j ) _
, mz + sin( i ) * dz
setpoint 1 _
, mx + ( dx + dy * cos( i ) ) * cos( j2 ) _
, my + ( dx + dy * cos( i ) ) * sin( j2 ) _
, mz + sin( i ) * dz
setpoint 2 _
, mx + ( dx + dy * cos( i2 ) ) * cos( j2 ) _
, my + ( dx + dy * cos( i2 ) ) * sin( j2 ) _
, mz + sin( i2 ) * dz
setpoint 3 _
, mx + ( dx + dy * cos( i2 ) ) * cos( j ) _
, my + ( dx + dy * cos( i2 ) ) * sin( j ) _
, mz + sin( i2 ) * dz
quad 0 , 1 , 2 , 3 , 0
next j
next i
end sub
sub cilinder( sides as integer , dx as single , dy as single , top as integer , bot as integer )
dim f as single
if sides < 3 then sides = 3
if sides > 64 then sides = 64
for f = 0 to sides + 2
setpoint f , box.m.x + sin( f * pi * 2 / sides ) * box.d.x _
, box.m.y - box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * box.d.z
setpoint f + sides + 1 , box.m.x + sin( f * pi * 2 / sides ) * dx _
, box.m.y + box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * dy
next f
for f = 0 to sides + 1
quad f , f + 1 , f + 2 + sides , f + 1 + sides , 0
next f
if top then
setpoint 255 , 0 , box.m.y + box.d.y , 0
for f = 0 to sides
setpoint f , box.m.x + sin( f * pi * 2 / sides ) * dx _
, box.m.y + box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * dy
next f
for f = 0 to sides
tri1 255 , f , f + 1 , 0
next f
end if
if bot then
setpoint 255 , 0 , box.m.y - box.d.y , 0
for f = 0 to sides + 2
setpoint f , box.m.x - sin( f * pi * 2 / sides ) * box.d.x _
, box.m.y - box.d.y _
, box.m.z + cos( f * pi * 2 / sides ) * box.d.z
next f
for f = 0 to sides + 2
tri1 255 , f , f + 1 , 0
next f
end if
end sub
sub cube()
setpoint 0 , box.m.x + box.d.x , box.m.y + box.d.y , box.m.z + box.d.z
setpoint 1 , box.m.x + box.d.x , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 2 , box.m.x + box.d.x , box.m.y - box.d.y , box.m.z + box.d.z
setpoint 3 , box.m.x + box.d.x , box.m.y - box.d.y , box.m.z - box.d.z
setpoint 4 , box.m.x - box.d.x , box.m.y + box.d.y , box.m.z + box.d.z
setpoint 5 , box.m.x - box.d.x , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 6 , box.m.x - box.d.x , box.m.y - box.d.y , box.m.z + box.d.z
setpoint 7 , box.m.x - box.d.x , box.m.y - box.d.y , box.m.z - box.d.z
quad 0 , 2 , 3 , 1 , 0 ''right
quad 7 , 6 , 4 , 5 , 0 ''left
quad 0 , 4 , 5 , 1 , 0 ''up
quad 7 , 3 , 2 , 6 , 0 ''down
quad 0 , 4 , 6 , 2 , 0 ''back
quad 7 , 5 , 1 , 3 , 0 ''front
end sub
sub setbox( mx as single , my as single , mz as single , dx as single , dy as single , dz as single )
box.m.x = mx
box.m.y = my
box.m.z = mz
box.d.x = dx
box.d.y = dy
box.d.z = dz
end sub
sub setcolor( clr as integer )
dim r as single , g as single ,b as single
r = ( clr and 255 ) / 256
g = ( ( clr / 256 ) and 255 ) / 256
b = ( ( clr / 256 ^ 2 ) and 255 ) / 256
glcolor3f( r , g , b )
end sub
sub tri1( p1 as integer , p2 as integer , p3 as integer , kl as integer )
tri3 p1 , kl , p2 , kl , p3 , kl
end sub
sub tri3( p1 as integer , kl1 as integer , p2 as integer , kl2 as integer , p3 as integer , kl3 as integer )
dim q as t3d
q = ( pnt( p2 ) - pnt( p1 ) ) \ ( pnt( p3 ) - pnt( p1 ) )
q = q / lenght( q )
glBegin GL_TRIANGLES
glnormal3f q.x , q.y , q.z
setcolor kl1
glVertex3f pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
setcolor kl2
glVertex3f pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
setcolor kl3
glVertex3f pnt( p3 ).x , pnt( p3 ).y , pnt( p3 ).z
glend
end sub
sub quad( p1 as integer , p2 as integer , p3 as integer , p4 as integer , kl as integer )
dim q as t3d
q = ( pnt( p2 ) - pnt( p1 ) ) \ ( pnt( p3 ) - pnt( p1 ) )
q = q / lenght( q )
glBegin GL_QUADS
setcolor kl
glnormal3f q.x , q.y , q.z
glVertex3f pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
glVertex3f pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
glVertex3f pnt( p3 ).x , pnt( p3 ).y , pnt( p3 ).z
glVertex3f pnt( p4 ).x , pnt( p4 ).y , pnt( p4 ).z
glEnd
end sub
sub quad2( p1 as integer , kl1 as integer _
, p2 as integer , kl2 as integer _
, p3 as integer , kl3 as integer _
, p4 as integer , kl4 as integer )
dim q as t3d
q = ( pnt( p2 ) - pnt( p1 ) ) \ ( pnt( p3 ) - pnt( p1 ) )
q = q / lenght( q )
glBegin GL_QUADS
setcolor kl1
glnormal3f q.x , q.y , q.z
glVertex3f pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
setcolor kl2
glVertex3f pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
setcolor kl3
glVertex3f pnt( p3 ).x , pnt( p3 ).y , pnt( p3 ).z
setcolor kl4
glVertex3f pnt( p4 ).x , pnt( p4 ).y , pnt( p4 ).z
glEnd
end sub
sub setpoint( no as integer , x as single , y as single , z as single )
pnt( no and 255 ).x = x
pnt( no and 255 ).y = y
pnt( no and 255 ).z = z
end sub
sub insect()
Dim i as integer
glPushmatrix
glScalef .01 , .01 , .01
setbox 0, 0, 0, 30, 10.0, 60.0
Cube
For i = 0 To 4
glPushMatrix
child 35.0, 0.0, i * 25 - 50 , ileg + i, xyz
setbox 30.0, 0.0, 0.0, 30.0, 5.0, 5.0
Cube
glPushMatrix
child 65.0, -5.0, 0.0 , iknee + i, xyz
setbox 0.0, -30.0, 0.0, 5.0, 30.0, 5.0
Cube
glPopMatrix
glPopMatrix
glpushMatrix
child -35.0, 0.0, i * 25 - 50, ileg + lr + i, xyz
setbox -30.0, 0.0, 0.0, 30.0, 5.0, 5.0
Cube
glPushMatrix
child -65.0, -5.0, 0.0 , iknee + lr + 1, xyz
setbox 0.0, -30.0, 0.0, 5.0, 30.0, 5.0
Cube
glPopmatrix
glPopMatrix
Next
glPushMatrix
child 0 , 0 , -50 , tail , xyz
For i = 0 To 9
glPushMatrix
child 0.0, 0.0, -30.0 , tail, xyz
setbox 0.0, 0.0, -15.0, 10.0, 10.0, 10.0
Cube
Next
for i = 0 to 8
glPushMatrix
child 0 , 0 , -30 , tail+lr , xyz
cube
next i
for i = 0 to 8
glPopMatrix
glPopMatrix
next i
glPopMatrix
glPushMatrix
child 30.0, 0.0, 65.0, arm, xyz
setbox 0.0, 0.0, 30.0, 5.0, 5.0, 30.0
Cube
glPushMatrix
child 0.0, 0.0, 65.0, elbow, xyz
Cube
glPushmatrix
child 0.0, 0.0, 65.0 , wrist, xyz
glPushmatrix
child -10.0, 0.0, 5.0 , thumb, xyz
Cube
glPopMatrix
glPushMatrix
child 5.0, 0.0, 5.0, finger, xyz
setbox 0.0, 0.0, 30.0, 5.0, 10.0, 30.0
Cube
glPopMatrix
glPopMatrix
glPopMatrix
glPopMatrix
glPushMatrix
child -30.0, 0.0, 65.0, arm + lr, xyz
setbox 0.0, 0.0, 30.0, 5.0, 5.0, 30.0
Cube
glPushMatrix
child 0.0, 0.0, 65.0, elbow +lr, xyz
Cube
glPushMatrix
child 0.0, 0.0, 65.0, wrist+lr, xyz
glPushMatrix
child 10.0, 0.0, 5.0, thumb+lr, xyz
Cube
glPopMatrix
glPushMatrix
child -5.0, 0.0, 5.0, finger+lr, xyz
setbox 0.0, 0.0, 30.0, 5.0, 10.0, 30.0
Cube
glPopMatrix
glPopMatrix
glPopMatrix
glPopMatrix
For i = 0 To 1
glPushMatrix
child 20.0, 20.0, 40.0 - 50.0 * i, wing + i, xyz
setbox 60.0, 0.0, 8.0, 60.0, 2.0, 16.0
Cube
glPopMatrix
glPushMatrix
child -20.0, 20.0, 40.0 - 50.0 * i , wing+lr + i, xyz
setbox -60.0, 0.0, 8.0, 60.0, 2.0, 16.0
Cube
glPopmatrix
Next
glPopMatrix
end sub
sub human()
setbox 0 , 0 , 0 , .5 , .1 , .1
cube
setbox 0 , .75 , 0 , .1 , .5 , .1
cube
setbox 0 , 1.8 , 0 , .2 , .2 , .2
cube
setbox 0 , 1.4 , 0 , .7 , .1 , .1
cube
glPushMatrix
child .45 , 0 , 0 , leg , zyx
setbox 0 , -.6 , 0 , .1 , .4 , .1
cube
glPushMatrix
child 0 , -1 , 0 , knee , xyz
cube
glPushMatrix
child 0 , -1.2 , 0 , enkle , xyz
setbox 0 , 0 , .2 , .1 , .1 , .3
cube
glPopMatrix
glPopMatrix
glPopMatrix
glPushMatrix
child -.45 , 0 , 0 , leg + lr , zyx
setbox 0 , -.6 , 0 , .1 , .4 , .1
cube
glPushMatrix
child 0 , -1 , 0 , knee + lr , xyz
cube
glPushMatrix
child 0 , -1.2 , 0 , enkle + lr , xyz
setbox 0 , 0 , .2 , .1 , .1 , .3
cube
glPopMatrix
glPopMatrix
glPopMatrix
glPushMatrix
child .65 , 1.3 , 0 , arm , xyz
setbox 0 , -.5 , 0 , .1 , .4 , .1
cube
glPushMatrix
child 0 , -1 , 0 , elbow , xyz
cube
glPushMatrix
child 0 , -1 , 0 , wrist , zyx
setbox 0 , -.3 , 0 , .05 , .2 , .15
cube
glPopMatrix
glPopMatrix
glPopMatrix
glPushMatrix
child -.65 , 1.3 , 0 , arm + lr , xyz
setbox 0 , -.5 , 0 , .1 , .4 , .1
cube
glPushMatrix
child 0 , -1 , 0 , elbow + lr , xyz
cube
glPushMatrix
child 0 , -1 , 0 , wrist + lr , zyx
setbox 0 , -.3 , 0 , .05 , .2 , .15
cube
glPopMatrix
glPopMatrix
glPopMatrix
end sub
#endif
Code: Select all
#include "t_opengl.bas"
opengl_init
dim as single a
dim as integer state = 0
do
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT '' Clear Screen And Depth Buffer
glLoadIdentity
gltranslatef 0 , 0 , -5
glrotatef a , 0 , 1 , 0
select case state
case 0 , 1 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11
glrotatef a , 1 , 0 , 0
case else
end select
glmaterialfv GL_FRONT_AND_BACK , GL_DIFFUSE , @red( 0 )
glmaterialfv GL_FRONT_AND_BACK , GL_AMBIENT , @red( 0 )
setbox 0,0,0 , 1,1,1
select case state
case 0
sphere 64 , 64 _
, cos( rad( a * 3 ) ) + 1.1 _
, sin( rad( a * 3 ) ) + 1.1
case 1
sphere 12 , 12 , 1 , 1
case 2
animate DOG_WALK , a * 3 , 30
pilko
case 3
animate HUMAN_WALK , a * 3 , 30
human
case 4
cube
case 5
torus 12 , 12
case 6
torus 64 , 64
case 7
isoca 0
case 8
isoca 1
case 9
isoca 2
case 10
isoca 3
case 11
isoca 4
case else
animate I_STAND , 0 , 0
insect
end select
a += 1
a = a mod 360
if a = 359 then state += 1
state = state mod 13
sleep 40
flip
loop while inkey <> chr( 27 )