|
Post by bluatigro on Nov 30, 2019 7:17:47 GMT -5
blua gl : a 3dengine wrap around opengl
i got it working in free basic so it shoot work i aperently made a typo some were
whit this you can easely code animated avartars
example is added [ sub hand ]
'' bluatigro 31 jan 2019 '' bluaGL_1 dim pnt#( 255 )( 2 ) sub setpoint( no , x# , y# , z# ) pnt#( no )( 0 ) = x# pnt#( no )( 1 ) = y# pnt#( no )( 2 ) = z# end sub sub tri( p1 , p2 , p3 ) glBegin( GL_TRIANGLES ) dim n#( 2 ) = crossproduct( pnt#( p2 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p1 ) ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glEnd() end sub sub quad( p1 , p2 , p3 , p4 ) glBegin( GL_QUADS ) dim n#( 2 ) = crossproduct( pnt#( p2 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p1 ) ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glVertex3fv( pnt#( p4 ) ) glEnd() end sub dim black#( 3 ) = vec4( 0 , 0 , 0 , 1 ) dim red#( 3 ) = vec4( 1 , 0 , 0 , 1 ) dim green#( 3 ) = vec4( 0 , 1 , 0 , 1 ) dim yellow#( 3 ) = vec4( 1 , 1 , 0 , 1 ) dim blue#( 3 ) = vec4( 0 , 0 , 1 , 1 ) dim magenta#( 3 ) = vec4( 1 , 0 , 1 , 1 ) dim cyan#( 3 ) = vec4( 0 , 1 , 1 , 1 ) dim white#( 3 ) = vec4( 1 , 1 , 1 , 1 ) dim positionr#( 3 ) = vec4( 1 , 1 , -1 , 1 ) dim positiong#( 3 ) = vec4( 0 , -1 , -1 , 1 ) dim positionb#( 3 ) = vec4( -1 , 1 , 1 , 1 )
glenable( gl_lightiNG ) gllightfv( gl_lIGHT0 , gl_diFFUSE , red# ) gllightfv( gl_liGHT0 , gl_posITION , positionr# ) glenable( gl_lIGHT0 ) gllightfv( gl_lIGHT1 , gl_diFFUSE , green# ) gllightfv( gl_liGHT1 , gl_posITION , positiong# ) glenable( gl_lIGHT1 ) gllightfv( gl_lIGHT2 , gl_diFFUSE , blue# ) gllightfv( gl_liGHT2 , gl_posITION , positionb# ) glenable( gl_lIGHT2 )
dim box#( 5 ) sub setbox( x# , y# , z# , dx# , dy# , dz# ) box#( 0 ) = x# box#( 1 ) = y# box#( 2 ) = z# box#( 3 ) = dx# box#( 4 ) = dy# box#( 5 ) = dz# end sub sub cube() '' fil points of swarm setpoint( 0 , -1 , -1 , -1 ) setpoint( 1 , -1 , -1 , 1 ) setpoint( 2 , -1 , 1 , -1 ) setpoint( 3 , -1 , 1 , 1 ) setpoint( 4 , 1 , -1 , -1 ) setpoint( 5 , 1 , -1 , 1 ) setpoint( 6 , 1 , 1 , -1 ) setpoint( 7 , 1 , 1 , 1 ) '' use swarmpoints to create mesh glPushMatrix() glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) ) glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) ) quad( 0 , 1 , 3 , 2 ) ''left quad( 7 , 6 , 4 , 5 ) ''right quad( 0 , 1 , 5 , 4 ) ''bottom quad( 7 , 6 , 2 , 3 ) ''top quad( 0 , 2 , 6 , 4 ) ''front quad( 7 , 5 , 1 , 3 ) ''back glPopMatrix() end sub dim sk#( 64 )( 2 ) sub skelet( no , x# , y# , z# ) sk#( no )( 0 ) = x# sk#( no )( 1 ) = y# sk#( no )( 2 ) = z# end sub const xyz = 0 const xzy = 1 const yxz = 2 const yzx = 3 const zxy = 4 const zyx = 5 sub child( x# , y# , z# , lim , ax ) glTranslatef( x# , y# , z# ) if ax = xyz then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) elseif ax = xzy then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = yxz then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 ) elseif ax = yzx then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) elseif ax = zxy then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = zyx then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) else end if end sub function pend#( fase# , amp# ) return sin( fase# * m_pi / 180 ) * amp# end function const leftno = 0 const arm = 1 const elbow = 2 const wrist = 3 const leg = 4 const knee = 5 const enkle = 6 const neck = 7 const thumb = 8 const index = 11 const middle = 14 const ring = 17 const pinky = 20 const rightno = 32 sub finger( lim ) '' part of human robot avatar setbox( 0 , -2 , 0 , 1 , 1 , 1 ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 1 , xyz ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 2 , xyz ) cube() glpopmatrix() glpopmatrix() end sub sub hand( lr , kl#() ) glmaterialfv( gl_frONT_AND_BACK , gl_diFFUSE , kl# ) '' part of human robot avatar setbox( 0 , -2 , 0 , 1 , 3 , 4 ) cube() glpushmatrix() child( 0 , -4 , 3 , lr + index , zxy ) finger( lr + index ) glpopmatrix() glpushmatrix() child( 0 , -4 , 1 , lr + middle , zxy ) finger( lr + middle ) glpopmatrix() glpushmatrix() child( 0 , -4 , -1 , lr + ring , zxy ) finger( lr + ring ) glpopmatrix() glpushmatrix() child( 0 , -4 , -3 , lr + pinky , zxy ) finger( lr + pinky ) glpopmatrix() glpushmatrix() child( 0 , -1 , 5 , lr + thumb , zxy ) finger( lr + thumb ) glpopmatrix() end sub sub human_robot() end sub glclearcolor( 0 , 0 , 1 , 1 ) sub test_blua_gl() dim frame# while true glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT ) glLoadidentity() glpushmatrix() gltranslatef( 0 , 5 , -20 ) glrotatef( frame# , 0 , 1 , 0 ) skelet( rightno + index , 0 , 0 , pend#( frame# , 15 ) + 15 ) skelet( rightno + middle , 0 , 0 , pend#( frame# + 20 , 15 ) + 15 ) skelet( rightno + ring , 0 , 0 , pend#( frame# + 40 , 15 ) + 15 ) skelet( rightno + pinky , 0 , 0 , pend#( frame# + 60 , 15 ) + 15 ) skelet( rightno + index + 1 , 0 , 0 , pend#( frame# , 15 ) + 15 ) skelet( rightno + middle + 1 , 0 , 0 , pend#( frame# + 20 , 15 ) + 15 ) skelet( rightno + ring + 1 , 0 , 0 , pend#( frame# + 40 , 15 ) + 15 ) skelet( rightno + pinky + 1 , 0 , 0 , pend#( frame# + 60 , 15 ) + 15 ) skelet( rightno + index + 2, 0 , 0 , pend#( frame# , 15 ) + 15 ) skelet( rightno + middle + 2 , 0 , 0 , pend#( frame# + 20 , 15 ) + 15 ) skelet( rightno + ring + 2 , 0 , 0 , pend#( frame# + 40 , 15 ) + 15 ) skelet( rightno + pinky + 2 , 0 , 0 , pend#( frame# + 60 , 15 ) + 15 ) hand( rightno , white# ) glpopmatrix() swapbuffers() sleep( 40 ) frame# = frame# + 10 wend end sub test_blua_gl
|
|
|
blua gl
Dec 1, 2019 15:54:56 GMT -5
Post by matthew on Dec 1, 2019 15:54:56 GMT -5
Hey, that's really good. You could probably animate an entire human figure that way.
|
|
|
Post by bluatigro on Dec 6, 2019 6:39:57 GMT -5
Hey, that's really good. You could probably animate an entire human figure that way. that is true , thank for the complement in freebasic i have made a humanrobot a dogrobot a skeleton a dog out of spherers a human out of spherers and a bugrobot when i have the latest version of basic4gl i wil post what i got so far
i did not see anything : what did i not good
|
|
|
Post by bluatigro on Dec 6, 2019 9:42:21 GMT -5
this is freebasic code this does not work in GB
i need help to rewrite it to GB
''bluatigro 9 jun 2018
''_open_gl_dbl.bas
#ifndef OPENGL_H
#define OPENGL_H
dim shared as integer mousex , mousey
''DBL3D
type dbl3d
x as double
y as double
z as double
declare constructor()
declare constructor ( x as double , y as double, z as double )
declare sub fill( x as double , y as double , z as double )
declare sub normalize
end type
constructor dbl3d()
this.x = 0
this.y = 0
this.z = 0
end constructor
constructor dbl3d( x as double , y as double , z as double )
this.x = x
this.y = y
this.z = z
end constructor
operator +( a as dbl3d , b as dbl3d ) as dbl3d
return type( a.x + b.x , a.y + b.y , a.z + b.z )
end operator
operator *( a as dbl3d , d as double ) as dbl3d
return type( a.x * d , a.y * d , a.z * d )
end operator
operator \( a as dbl3d , b as dbl3d ) as dbl3d
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 dbl3d , b as dbl3d ) as dbl3d
return type( a.x - b.x , a.y - b.y , a.z - b.z )
end operator
operator /( a as dbl3d , d as double ) as dbl3d
return type( a.x / d , a.y / d , a.z / d )
end operator
sub dbl3d.fill( x as double , y as double , z as double )
this.x = x
this.y = y
this.z = z
end sub
declare function dot( a as dbl3d , b as dbl3d ) as double
function dot( a as dbl3d , b as dbl3d ) as double
return a.x * b.x + a.y * b.y + a.z * b.z
end function
declare function length( q as dbl3d ) as double
function length( q as dbl3d ) as double
return sqr( q.x * q.x + q.y * q.y + q.z * q.z ) + 1e-7
end function
declare function anlge( a as dbl3d , b as dbl3d ) as double
function getangle( a as dbl3d , b as dbl3d ) as double
return acos( dot( a , b ) _
/ ( length( a ) * length( b ) ) )
end function
sub dbl3d.normalize
this /= length( this )
end sub
#include once "GL/gl.bi"
#include once "GL/glu.bi"
''MATH
const as double PI = atn( 1 ) * 4
const as double GOLDEN_RATIO = ( sqr( 5 ) - 1 ) / 2
function rad( x as double ) as double
''help function degrees to radians
return x * pi / 180
end function
function degrees( x as double ) as double
return x * 180 / pi
end function
function range( l as double , h as double ) as double
return rnd * ( h - l ) + l
end function
sub rotate( byref k as double , byref l as double , deg as double )
dim as double s , c , hk , hl
s = sin( rad( deg ) )
c = cos( rad( deg ) )
hk = k * c - l * s
hl = k * s + l * c
k = hk
l = hl
end sub
''CAMARA
type t_camara
public :
dim as double x,y,z,pan,tilt
declare sub move( dx as double _
, dy as double , dz as double , dpan as double )
declare sub use()
end type
sub t_camara.move( dx as double _
, dy as double , dz as double , dpan as double )
rotate dx , dz , -pan
x += dx
y += dy
z += dz
pan += dpan
end sub
sub t_camara.use
glLoadIdentity
glRotated -tilt , 0 , 0 , 1
glRotated -pan , 0 , 1 , 0
glTranslated -x , -y , -z
end sub
dim as t_camara camara
''3DENGINE
declare sub child( x as double , y as double , z as double , ax as integer , lim as integer )
declare function pend( fase as double , amp as double ) as double
declare sub skelet( no as integer , x as double , y as double , z as double )
dim shared sk( 63 ) as dbl3d
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
sub child( x as double , y as double , z as double , lim as integer , ax as integer )
glTranslatef x , y , z
select case ax
case xyz
glrotated sk( lim ).x , 1 , 0 , 0
glrotated sk( lim ).y , 0 , 1 , 0
glrotated sk( lim ).z , 0 , 0 , 1
case xzy
glrotated sk( lim ).x , 1 , 0 , 0
glrotated sk( lim ).z , 0 , 0 , 1
glrotated sk( lim ).y , 0 , 1 , 0
case yxz
glrotated sk( lim ).y , 0 , 1 , 0
glrotated sk( lim ).x , 1 , 0 , 0
glrotated sk( lim ).z , 0 , 0 , 1
case yzx
glrotated sk( lim ).y , 0 , 1 , 0
glrotated sk( lim ).z , 0 , 0 , 1
glrotated sk( lim ).x , 1 , 0 , 0
case zxy
glrotated sk( lim ).z , 0 , 0 , 1
glrotated sk( lim ).x , 1 , 0 , 0
glrotated sk( lim ).y , 0 , 1 , 0
case zyx
glrotated sk( lim ).z , 0 , 0 , 1
glrotated sk( lim ).y , 0 , 1 , 0
glrotated sk( lim ).x , 1 , 0 , 0
case else
end select
end sub
function pend( fase as double , amp as double ) as double
return sin( fase * PI / 180 ) * amp
end function
sub skelet( no as integer , x as double , y as double , z as double )
sk( no and 63 ).x = x
sk( no and 63 ).y = y
sk( no and 63 ).z = z
end sub
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB
#endif
SCREEN 18 , 32 , , 2
dim shared as integer letterpart( 255 , 20 )
dim as integer char , ix , iy
for char = 30 to 255
cls
print chr( char )
for ix = 0 to 16
for iy = 0 to 20
if point( ix , iy ) <> -16777216 then
letterpart( char , iy ) += 2 ^ ix
end if
next iy
next ix
next char
DIM shared AS INTEGER winx , winy
SCREENINFO winx , winy
''SCREENRES winx , winy , 32 , 2 , FB.GFX_FULLSCREEN
'' ReSizeGLScene
glViewport 0, 0, winx , winy '' Reset The Current Viewport
glMatrixMode GL_PROJECTION '' Select The Projection Matrix
glLoadIdentity '' Reset The Projection Matrix
gluPerspective 45.0, csng(winx/winy), 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, 1.0, 1.0 '' Blue 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 ) = { -50 , 50 , 50 , 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 )
''COLORS
type sng4d
dim as single x , y , z , w
declare constructor ()
declare constructor ( nx as single , ny as single , nz as single , nw as single )
declare sub fill( nx as single , ny as single , nz as single , nw as single )
end type
constructor sng4d()
end constructor
constructor sng4d( nx as single , ny as single , nz as single , nw as single )
x = nx
y = ny
z = nz
w = nw
end constructor
operator + ( a as sng4d , b as sng4d ) as sng4d
return sng4d(a.x+b.x,a.y+b.y,a.z+b.z,1)
end operator
operator - ( a as sng4d , b as sng4d ) as sng4d
return sng4d(a.x-b.x,a.y-b.y,a.z-b.z,1)
end operator
operator / ( a as sng4d , b as single ) as sng4d
return sng4d(a.x/b,a.y/b,a.z/b,1)
end operator
operator * ( a as sng4d , b as single ) as sng4d
return sng4d(a.x*b,a.y*b,a.z*b,1)
end operator
function rainbow( deg as double ) as sng4d
return sng4d( sin( rad( deg ) ) / 2 + .5 _
, sin( rad( deg - 120 ) ) / 2 + .5 _
, sin( rad( deg + 120 ) ) / 2 + .5 , 1 )
end function
sub sng4d.fill( nx as single , ny as single , nz as single , nw as single )
x = nx
y = ny
z = nz
w = nw
end sub
dim shared as sng4d black , red , green , yellow _
, blue , magenta , cyan , white _
, orange , gray , pink
black.fill 0,0,0,1
red.fill 1,0,0,1
green.fill 0,1,0,1
yellow.fill 1,1,0,1
blue.fill 0,0,1,1
magenta.fill 1,0,1,1
cyan.fill 0,1,1,1
white.fill 1,1,1,1
orange.fill 1,.5, 0,1
gray.fill .5,.5,.5,1
pink.fill 1,.5,.5,1
function mix( a as sng4d , f as double , b as sng4d ) as sng4d
dim uit as sng4d
uit.x = a.x + ( b.x - a.x ) * f
uit.y = a.y + ( b.y - a.y ) * f
uit.z = a.z + ( b.z - a.z ) * f
uit.w = 1
return uit
end function
''MATERIAL
type t_material
dim as sng4d ambient , diffuse , specular , emision
dim as single shininess
end type
dim shared as t_material material
sub setMaterial( a as long , m as t_material )
glMaterialfv a , GL_AMBIENT , @m.ambient.x
glMaterialfv a , GL_DIFFUSE , @m.diffuse.x
glMaterialfv a , GL_SPECULAR , @m.specular.x
glMaterialfv a , GL_EMISSION , @m.emision.x
glMaterialf a , GL_SHININESS , m.shininess
end sub
''text
declare sub setbox(x as double,y as double,z as double _
,dx as double,dy as double,dz as double )
declare sub cube()
declare sub sphere( a as integer , b as integer _
, c as double , d as double )
''PRIMATIVS
dim shared as dbl3d pnt( 256 )
sub setpoint( no as integer , x as double , y as double , z as double )
if no < 0 or no > ubound( pnt ) then exit sub
pnt( no ) = dbl3d( x , y , z )
end sub
sub tri( p1 as integer , p2 as integer , p3 as integer )
if p1 < 0 or p1 > 255 then exit sub
if p2 < 0 or p2 > 255 then exit sub
if p3 < 0 or p3 > 255 then exit sub
dim as dbl3d n = ( pnt( p2 ) - pnt( p1 ) ) _
\ ( pnt( p3 ) - pnt( p1 ) )
n.normalize()
glbegin gl_triangles
glnormal3d n.x , n.y , n.z
glvertex3d pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
glvertex3d pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
glvertex3d 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 )
if p1 < 0 or p1 > 255 then exit sub
if p2 < 0 or p2 > 255 then exit sub
if p3 < 0 or p3 > 255 then exit sub
if p4 < 0 or p4 > 255 then exit sub
dim as dbl3d n = ( pnt( p2 ) - pnt( p1 ) ) _
\ ( pnt( p3 ) - pnt( p1 ) )
n.normalize()
glbegin gl_quads
glnormal3d n.x , n.y , n.z
glvertex3d pnt( p1 ).x , pnt( p1 ).y , pnt( p1 ).z
glvertex3d pnt( p2 ).x , pnt( p2 ).y , pnt( p2 ).z
glvertex3d pnt( p3 ).x , pnt( p3 ).y , pnt( p3 ).z
glvertex3d pnt( p4 ).x , pnt( p4 ).y , pnt( p4 ).z
glend
end sub
sub five( p1 as integer _
, p2 as integer , p3 as integer _
, p4 as integer , p5 as integer )
if p1 < 0 or p1 > 255 then exit sub
if p2 < 0 or p2 > 255 then exit sub
if p3 < 0 or p3 > 255 then exit sub
if p4 < 0 or p4 > 255 then exit sub
if p5 < 0 or p5 > 255 then exit sub
dim as dbl3d n = ( pnt( p2 ) - pnt( p1 ) ) _
\ ( pnt( p3 ) - pnt( p1 ) )
n.normalize()
glbegin gl_polygon
glnormal3d n.x , n.y , n.z
glvertex3dv @ pnt( p1 ).x
glvertex3dv @ pnt( p2 ).x
glvertex3dv @ pnt( p3 ).x
glvertex3dv @ pnt( p4 ).x
glvertex3dv @ pnt( p5 ).x
glend
end sub
sub six( p1 as integer _
, p2 as integer , p3 as integer _
, p4 as integer , p5 as integer _
, p6 as integer )
if p1 < 0 or p1 > 255 then exit sub
if p2 < 0 or p2 > 255 then exit sub
if p3 < 0 or p3 > 255 then exit sub
if p4 < 0 or p4 > 255 then exit sub
if p5 < 0 or p5 > 255 then exit sub
dim as dbl3d n = ( pnt( p2 ) - pnt( p1 ) ) _
\ ( pnt( p3 ) - pnt( p1 ) )
n.normalize()
glbegin gl_polygon
glnormal3f n.x , n.y , n.z
glvertex3dv @ pnt( p1 ).x
glvertex3dv @ pnt( p2 ).x
glvertex3dv @ pnt( p3 ).x
glvertex3dv @ pnt( p4 ).x
glvertex3dv @ pnt( p5 ).x
glvertex3dv @ pnt( p6 ).x
glend
end sub
''SHAPES
type Tbox
m as dbl3d
d as dbl3d
end type
dim shared box as Tbox
declare sub isoca( i as integer )
declare sub hsphere( h as integer , r as integer _
, t as integer , a as double , b as double )
declare sub torus( hsides as integer , rsides as integer )
declare sub cilinder( sides as integer _
, dx as double , dy as double , top as integer , bot as integer )
declare sub hcube( )
declare sub geo( no as integer , p1 as integer _
, p2 as integer , p3 as integer )
sub geo( no as integer , p1 as integer _
, p2 as integer , p3 as integer )
if no < 1 then
tri p1 , p2 , p3
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 ).normalize
pnt( p13 ).normalize
pnt( p23 ).normalize
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
glTranslated box.m.x , box.m.y , box.m.z
glScaled 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 ).normalize
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 double , db as double )
dim as double i , j , i2 , j2
dim as double 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
glTranslated box.m.x , box.m.y , box.m.z
glScaled 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 - pi / b * 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
next j
next i
glPopMatrix
end sub
sub hsphere( a as integer , b as integer _
, t as integer , da as double , db as double )
dim as double i , j , i2 , j2
dim as double 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
glTranslated box.m.x , box.m.y , box.m.z
glScaled 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 t * pi / b / 2 - pi / b * 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
next j
next i
glPopMatrix
end sub
sub torus( a as integer , b as integer )
dim i as double , j as double , i2 as double , j2 as double
if a < 3 then a = 3
if a > 64 then a = 64
if b < 3 then b = 3
if b > 64 then b = 64
dim mx as double , my as double , mz as double , dx as double , dy as double , dz as double
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
next j
next i
end sub
sub banana( a as integer , b as integer )
dim i as double , j as double , i2 as double , j2 as double
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 double , my as double , mz as double , dx as double , dy as double , dz as double
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/1.99 to PI/1.99 - pi/b*2 step PI / b * 1.99
j2 = j + PI / b * 1.99
setpoint 0 _
, mx + ( dx + dy * cos( i ) * cos( j ) ) _
* cos( j ) _
, my + ( dx + dy * cos( i ) * cos( j ) ) _
* sin( j ) _
, mz + sin( i ) * dz * cos( j )
setpoint 1 _
, mx + ( dx + dy * cos( i ) * cos( j2 ) ) _
* cos( j2 ) _
, my + ( dx + dy * cos( i ) * cos( j2 ) ) _
* sin( j2 ) _
, mz + sin( i ) * dz * cos( j2 )
setpoint 2 _
, mx + ( dx + dy * cos( i2 ) * cos( j2 ) ) _
* cos( j2 ) _
, my + ( dx + dy * cos( i2 ) * cos( j2 ) ) _
* sin( j2 ) _
, mz + sin( i2 ) * dz * cos( j2 )
setpoint 3 _
, mx + ( dx + dy * cos( i2 ) * cos( j ) ) _
* cos( j ) _
, my + ( dx + dy * cos( i2 ) * cos( j ) ) _
* sin( j ) _
, mz + sin( i2 ) * dz * cos( j )
quad 0 , 1 , 2 , 3
next j
next i
end sub
sub cilinder( sides as integer , dx as double , dy as double , top as integer , bot as integer )
dim f as double
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
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
tri 255 , f , f + 1
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
tri 255 , f , f + 1
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 ''right
quad 7 , 6 , 4 , 5 ''left
quad 0 , 4 , 5 , 1 ''up
quad 7 , 3 , 2 , 6 ''down
quad 0 , 4 , 6 , 2 ''back
quad 7 , 5 , 1 , 3 ''front
end sub
sub hcube()
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
setpoint 0 , box.m.x + box.d.x , box.m.y - box.d.y , 0
setpoint 8 , box.m.x + box.d.x , 0 , box.m.z - box.d.z
setpoint 9 , 0 , box.m.y + box.d.y , box.m.z - box.d.z
setpoint 10 , box.m.x - box.d.x , box.m.x + box.d.y , 0
setpoint 11 , box.m.x - box.d.x , 0 , box.m.z + box.d.z
setpoint 12, 0 , box.m.y - box.d.y , box.m.z + box.d.z
tri 7 , 6 , 3
tri 7 , 5 , 6
tri 7 , 3 , 5
quad 6 , 5 , 10 , 11
quad 5 , 3 , 8 , 9
quad 3 , 6 , 12 , 0
tri 6 , 12 , 11
tri 3 , 8 , 0
tri 5 , 9 , 10
end sub
sub setbox( mx as double , my as double , mz as double , dx as double , dy as double , dz as double )
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
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 ear = 9
const as integer wenk = 10
const as integer thumb = 11
const as integer index_finger = 14
const as integer mid_finger = 17
const as integer ring_finger = 21
const as integer tail = 24
const as integer mouth = 25
const as integer iarm = 1
const as integer ielbow = 2
const as integer iwrist = 3
const as integer ileg = 4
const as integer iknee = 9
const as integer iwing = 14
const as integer itail = 16
const as integer isensor = 17
const as integer ithumb = 18
const as integer ifinger = 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
const as integer eyes = 10
sub animate( anim as integer , f as double , a as double )
DIM I AS INTEGER
select case anim
case eyes
skelet eye , pend( f , 20 ) , pend( f + 90 , 20 ) , 0
skelet eye+lr , pend( f + 180 , 20 ) , pend( f - 90 , 20 ) , 0
skelet mouth , pend( f , 20 ) + 20 , 0 , 0
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
skelet thumb , -pend( f , 10 ) - 10 , 0 , 0
skelet thumb +lr , -pend( f , 10 ) - 10 , 0 , 0
for i = 0 to 2
skelet index_finger + i , 0 , 0 , -pend( f + 30 , 10 ) - 10
skelet mid_finger + i , 0 , 0 , -pend( f , 10 ) - 10
skelet ring_finger + i , 0 , 0 , -pend( f - 30 , 10 ) - 10
skelet index_finger + lr + i , 0 , 0 , pend( f + 30 , 10 ) + 10
skelet mid_finger + lr + i , 0 , 0 , pend( f , 10 ) + 10
skelet ring_finger + lr + i , 0 , 0 , pend( f - 30 , 10 ) + 10
next i
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 iwing + i, 0 , 0 , Pend(f, a)
skelet iwing+lr + i, 0,0, Pend(f, -a)
Next
Case I_LEFT_BOX
skelet iarm, 0, Pend(f, -a) + 45 , 0
skelet ielbow, 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 iarm+lr, 0, Pend(f, a) - 45,0
skelet ielbow+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 iarm, 0, 45, 0
skelet ielbow, 0, -60 , 0
skelet ifinger, 0, 0, 0
skelet ithumb, 0, 0, 0
skelet iarm+lr, 0, -45, 0
skelet ielbow+lr, 0, 60 , 0
skelet ifinger+lr, 0, 0, 0
skelet ithumb+lr, 0, 0, 0
skelet itail, 10, 0 , 0
skelet itail+lr, 10, 0 , 0
Case I_STING
skelet itail, 10 + Pend(f, a), 0, 0
skelet itail+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
sub insect( kl as sng4d )
material.diffuse = kl
setmaterial gl_front , material
Dim i as integer
glPushmatrix
glScaled .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 , itail , xyz
For i = 0 To 9
glPushMatrix
child 0.0, 0.0, -30.0 , itail, 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 , itail+lr , xyz
cube
next i
for i = 0 to 8
glPopMatrix
glPopMatrix
next i
glPopMatrix
glPushMatrix
child 30.0, 0.0, 65.0, iarm, xyz
setbox 0.0, 0.0, 65.0 , 5 , 35 , 5
Cube
glPushMatrix
child 0.0, 0.0, 65.0, ielbow, xyz
Cube
glPushmatrix
child 0.0, 0.0, 65.0 , iwrist, xyz
glPushmatrix
child -10.0, 0.0, 5.0 , ithumb, xyz
Cube
glPopMatrix
glPushMatrix
child 5.0, 0.0, 5.0, ifinger, 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, iarm + lr, xyz
setbox 0.0, 0.0, 30.0, 5.0, 5.0, 30.0
Cube
glPushMatrix
child 0.0, 0.0, 65.0, ielbow +lr, xyz
Cube
glPushMatrix
child 0.0, 0.0, 65.0, iwrist+lr, xyz
glPushMatrix
child 10.0, 0.0, 5.0, ithumb+lr, xyz
Cube
glPopMatrix
glPushMatrix
child -5.0, 0.0, 5.0, ifinger+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, iwing + 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 , iwing+lr + i, xyz
setbox -60.0, 0.0, 8.0, 60.0, 2.0, 16.0
Cube
glPopmatrix
Next
glPopMatrix
end sub
sub kootjes( f as integer )
setbox 0,-.2,0 , .1,.1,.1
cube
glpushmatrix
child 0,-.2,0 , f + 1 , xyz
cube
glpushmatrix
child 0,-.2,0 , f + 2 , xyz
cube
glpopmatrix
glpopmatrix
end sub
sub hand( kl as sng4d , i as integer )
material.diffuse = kl
setmaterial gl_front , material
glpushmatrix
setbox 0,-.3,0 , .1,.3,.3
cube
glpushmatrix
child 0,-.6,.2 , index_finger + i , xyz
kootjes index_finger + i
glpopmatrix
glpushmatrix
child 0,-.6,0 , mid_finger + i , xyz
kootjes mid_finger + i
glpopmatrix
glpushmatrix
child 0,-.6,-.2 , ring_finger + i , xyz
kootjes ring_finger + i
glpopmatrix
glpushmatrix
child 0,-.2,.4 , thumb + i , xyz
kootjes thumb + i
glpopmatrix
glpopmatrix
end sub
sub human( kl as sng4d )
material.diffuse = kl
setmaterial gl_front , material
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
glscalef .5,.5,.5
hand white , 0
glPopMatrix
glPopMatrix
glPopMatrix
material.diffuse = kl
setmaterial gl_front , material
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
glscalef .5,.5,.5
hand white , lr
glPopMatrix
glPopMatrix
glPopMatrix
end sub
sub dog( kl as sng4d )
material.diffuse = kl
setmaterial gl_front , material
setbox 0,.2,.5 , .3,.3,.7
cube
glpushmatrix
child 0 , .6 , 1.5 , neck , xyz
glpushmatrix
child 0 , 0 , 0 , neck + lr , zyx
setbox 0,0,0 , .3 , .3 , .3
cube
setbox 0,-.2,.3 , .2,.2,.2
cube
setbox 0,0,.5 , .1,.1,.1
cube
setbox .3,-.15,0 , .05,.3,.2
cube
setbox -.3,-.15,0 , .05,.3,.2
cube
glpopmatrix
glpopmatrix
glpushmatrix
child 0 , .4 , -.5 , tail , yzx
setbox 0,.3,0 , .1 , .3 , .1
cube
glpopmatrix
glPushMatrix
child .3 , 0 , 1 , 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 -.3 , 0 , 1 , 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 .3 , 0 , 0 , arm , zyx
setbox 0 , -.6 , 0 , .1 , .4 , .1
cube
glPushMatrix
child 0 , -1 , 0 , elbow , xyz
cube
glPushMatrix
child 0 , -1.2 , 0 , wrist , xyz
setbox 0 , 0 , .2 , .1 , .1 , .3
cube
glPopMatrix
glPopMatrix
glPopMatrix
glPushMatrix
child -.3 , 0 , 0 , arm + lr , zyx
setbox 0 , -.6 , 0 , .1 , .4 , .1
cube
glPushMatrix
child 0 , -1 , 0 , elbow + lr , xyz
cube
glPushMatrix
child 0 , -1.2 , 0 , wrist + lr , xyz
setbox 0 , 0 , .2 , .1 , .1 , .3
cube
glPopMatrix
glPopMatrix
glPopMatrix
end sub
sub digit( b as integer )
dim as integer i , j
for i = 0 to 16
for j = 0 to 20
if ( letterpart( b , i ) and 2 ^ j ) <> 0 then
setbox j * 1 / 20 - .5 , i * -1 / 20 + .5 , 0 _
, .08 , .08 , .08
sphere 4 , 4 , 1 , 1
end if
next j
next i
end sub
sub text( txt as string , kl as sng4d )
material.diffuse = kl
setmaterial gl_front , material
dim as integer i
for i = 1 to len( txt )
glpushmatrix
gltranslatef i - len( txt ) / 2 - .5 , 0 , 0
digit asc( mid( txt, i , 1 ) )
glpopmatrix
next i
end sub
sleep
#endif
|
|
|
blua gl
Dec 6, 2019 16:24:09 GMT -5
Post by matthew on Dec 6, 2019 16:24:09 GMT -5
I wouldn't even know where to start to help on a program that large. I currently haven't got FreeBASIC installed on the computer that I'm using, is your program a 3D engine or something similar?
|
|
|
Post by bluatigro on Dec 7, 2019 10:33:08 GMT -5
I wouldn't even know where to start to help on a program that large. I currently haven't got FreeBASIC installed on the computer that I'm using, is your program a 3D engine or something similar? i realized that so i started to translate it error : i m using crossproduct not good what is the good way ? and if there are more error's please help fix them '' bluatigro 7 dec 2019
'' bluaGL_1
dim pnt#( 255 )( 2 )
sub setpoint( no , x# , y# , z# )
pnt#( no )( 0 ) = x#
pnt#( no )( 1 ) = y#
pnt#( no )( 2 ) = z#
end sub
sub tri( p1 , p2 , p3 )
dim n( 2 ) = crossproduct( pnt#( p3 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p2 ) )
n = normalize( n )
glBegin( GL_TRIANGLES )
glnormal3fv( n )
glVertex3fv( pnt#( p1 ) )
glVertex3fv( pnt#( p2 ) )
glVertex3fv( pnt#( p3 ) )
glEnd()
end sub
sub quad( p1 , p2 , p3 , p4 )
dim n( 2 ) = crossproduct( pnt#( p1 ) , pnt#( p2) )
n = normalize( n )
glBegin( GL_QUADS )
glnormal3fv( n )
glVertex3fv( pnt#( p1 ) )
glVertex3fv( pnt#( p2 ) )
glVertex3fv( pnt#( p3 ) )
glVertex3fv( pnt#( p4 ) )
glEnd()
end sub
glEnable( gl_lighting )
dim lightpos#( 3 ) = vec4( -50 , 50 , 50 , 1 )
dim diffuse#( 3 ) = vec4( 1 , 1 , 1 , 1 )
glLightfv( gl_light0 , gl_position, lightpos# )
glLightfv( gl_light0 , gl_diffuse , diffuse# )
glEnable( gl_light0 )
type tmaterial
ambient( 3 ) as single
diffuse( 3 ) as single
specular( 3 ) as single
emision( 3 ) as single
shininess as single
end type
dim tmaterial material
sub material_use( a , mat as tmaterial )
glMaterialfv a , GL_AMBIENT , m.ambient
glMaterialfv a , GL_DIFFUSE , m.diffuse
glMaterialfv a , GL_SPECULAR , m.specula
glMaterialfv a , GL_EMISSION , m.emision
glMaterialf a , GL_SHININESS , m.shininess
end sub
dim black( 3 ) = vec4( 0 , 0 , 0 , 1 )
dim red( 3 ) = vec4( 1 , 0 , 0 , 1 )
dim green( 3 ) = vec4( 0 , 1 , 0 , 1 )
dim yellow( 3 ) = vec4( 1 , 1 , 0 , 1 )
dim blue( 3 ) = vec4( 0 , 0 , 1 , 1 )
dim magenta( 3 ) = vec4( 1 , 0 , 1 , 1 )
dim cyan( 3 ) = vec4( 0 , 1 , 1 , 1 )
dim white( 3 ) = vec4( 1 , 1 , 1 , 1 )
type tcam
x as single
y as single
z as single
pan as single
end type
dim tcam cam
sub camara_use( c as tcam )
glRotatef( -c.pan , 0 , 1 , 0 )
gltranslatef( -c.x , -c.y , -c.z )
end sub
dim box#(5)
sub setbox( x# , y# , z# , dx# , dy# , dz# )
box#(0) = x#
box#(1) = y#
box#(2) = z#
box#(3) = dx#
box#(4) = dy#
box#(5) = dz#
end sub
sub cube( l , bt , f , r , t , bk )
'' fil points of swarm
setpoint( 0 , -1 , -1 , -1 )
setpoint( 1 , -1 , -1 , 1 )
setpoint( 2 , -1 , 1 , -1 )
setpoint( 3 , -1 , 1 , 1 )
setpoint( 4 , 1 , -1 , -1 )
setpoint( 5 , 1 , -1 , 1 )
setpoint( 6 , 1 , 1 , -1 )
setpoint( 7 , 1 , 1 , 1 )
'' use swarmpoints to create mesh
glPushMatrix()
glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) )
glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) )
quad1( 0 , 1 , 3 , 2 , l ) ''left
quad1( 7 , 6 , 4 , 5 , r ) ''right
quad1( 0 , 1 , 5 , 4 , bt ) ''bottom
quad1( 7 , 6 , 2 , 3 , t ) ''top
quad1( 0 , 2 , 6 , 4 , f ) ''front
quad1( 7 , 5 , 1 , 3 , bk ) ''back
glPopMatrix()
end sub
sub colorcube()
cube( red , green , blue , cyan , magenta , yellow )
end sub
dim sk#( 64 )( 2 )
sub skelet( no , x# , y# , z# )
sk#( no )( 0 ) = x#
sk#( no )( 1 ) = y#
sk#( no )( 2 ) = z#
end sub
const xyz = 0
const xzy = 1
const yxz = 2
const yzx = 3
const zxy = 4
const zyx = 5
sub child( x# , y# , z# , lim , ax )
glTranslatef( x# , y# , z# )
if ax = xyz then
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
elseif ax = xzy then
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
elseif ax = yxz then
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 )
elseif ax = yzx then
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
elseif ax = zxy then
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
elseif ax = zyx then
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
else
end if
end sub
function pend#( fase# , amp# )
return sind( fase# ) * amp#
end function
const leftno = 0
const arm = 1
const elbow = 2
const wrist = 3
const leg = 4
const knee = 5
const enkle = 6
const neck = 7
const thumb = 8
const index_finger = 11
const middle_finger = 14
const ring_finger = 17
const pinky_finger = 20
const rightno = 32
sub finger( lim )
'' part of human robot avatar
setbox( 0 , -1 , 0 , 1 , 1 , 1 )
colorcube()
glpushmatrix()
child( 0 , -1 , 0 , lim + 1 , xyz )
colorcube()
glpushmatrix()
child( 0 , -1 , 0 , lim + 2 , xyz )
colorcube()
glpopmatrix()
glpopmatrix()
end sub
sub hand( lr , kl# )
'' part of human robot avatar
material.diffuse() = kl#()
material_use( gl_frONT , material )
setbox( 0 , -4 , 0 , 1 , 4 , 1 )
colorcube()
glpushmatrix()
child( 0 , -4 , 1.5 , lr + index_finger , zxy )
finger( lr + index )
glpopmatrix()
glpushmatrix()
child( 0 , -4 , .5 , lr + middle_finger , zxy )
finger( lr + middle )
glpopmatrix()
glpushmatrix()
child( 0 , -4 , -.5 , lr + ring_finger , zxy )
finger( lr + ring )
glpopmatrix()
glpushmatrix()
child( 0 , -4 , -1.5 , lr + pinky_finger , zxy )
finger( lr + pinky )
glpopmatrix()
glpushmatrix()
child( 0 , -1 , 2.5 , lr + thumb , zxy )
finger( lr + thumb )
glpopmatrix()
end sub
sub human_robot( h , kl# , klh#)
material.diffuse = kl#
setmaterial( gl_front , material )
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 + rightno , zyx )
setbox( 0 , -.6 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , knee + rightno , xyz )
cube()
glPushMatrix()
child( 0 , -1.2 , 0 , enkle + rightno , xyz )
setbox( 0 , 0 , .2 , .1 , .1 , .3 )
cube()
glPopMatrix()
glPopMatrix()
glPopMatrix()
glPushMatrix()
child( -.45 , 0 , 0 , leg + leftno , zyx )
setbox( 0 , -.6 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , knee + leftno , xyz )
cube()
glPushMatrix()
child( 0 , -1.2 , 0 , enkle + leftno , xyz )
setbox( 0 , 0 , .2 , .1 , .1 , .3 )
cube()
glPopMatrix()
glPopMatrix()
glPopMatrix()
glPushMatrix()
child( .65 , 1.3 , 0 , arm + rightno , xyz )
setbox( 0 , -.5 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , elbow + rightno , xyz )
cube()
glPushMatrix()
child( 0 , -1 , 0 , wrist + rightno , zyx )
glscalef( .5 , .5 , .5 )
hand( rightno , klh# )
glPopMatrix()
glPopMatrix()
glPopMatrix()
material.diffuse = kl#
setmaterial( gl_front , material )
glPushMatrix()
child( -.65 , 1.3 , 0 , arm + leftno , xyz )
setbox( 0 , -.5 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , elbow + leftno , xyz )
cube()
glPushMatrix()
child( 0 , -1 , 0 , wrist + leftno , zyx )
glscalef( .5 , .5 , .5 )
hand( leftno , klh# )
glPopMatrix()
glPopMatrix()
glPopMatrix()
end sub
end sub
sub animate( anim , fase# , amp# )
dim i
if anim = human_walk then
skelet( arm + rightno, pend#( fase# , amp# ) , 0 , 0 )
skelet( elbow + rightno, -abs( amp# ) , 0 , 0 )
skelet( arm + leftno , pend#( fase# + 180, amp# ) , 0 , 0 )
skelet( elbow + leftno , -abs( amp# ) , 0 , 0 )
skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 )
skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 )
skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 )
skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 )
skelet( thumb + rightno , -pend#( fase# , 10 ) - 10 , 0 , 0 )
skelet( thumb + leftno , -pend#( fase# , 10 ) - 10 , 0 , 0 )
for i = 0 to 2
skelet( index_finger + rightno + i , 0 , 0 , -pend#( fase# + 30 , 10 ) - 10 )
skelet( mid_finger + rightno + i , 0 , 0 , -pend#( fase# , 10 ) - 10 )
skelet( ring_finger + rightno + i , 0 , 0 , -pend#( fase# - 30 , 10 ) - 10 )
skelet( index_finger + leftno + i , 0 , 0 , pend#( fase# + 30 , 10 ) + 10 )
skelet( mid_finger + leftno + i , 0 , 0 , pend#( fase# , 10 ) + 10 )
skelet( ring_finger + leftno + i , 0 , 0 , pend#( fase# - 30 , 10 ) + 10 )
next i
end if
end sub
dim frame#
while true
glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT )
glLoadidentity()
glpushmatrix()
gltranslatef( 0 , 0 , -10 )
animate( human_walk , frame# , 30.0 )
human_robot( 1 , cyan# , white# )
glpopmatrix()
swapbuffers()
sleep( 40 )
frame# = frame# + 10
wend
|
|
|
blua gl
Dec 7, 2019 11:45:50 GMT -5
Post by matthew on Dec 7, 2019 11:45:50 GMT -5
The reason why you're getting the error with the CrossProduct command is because you've declared n as an Integer rather than a Float n#.
|
|
|
Post by bluatigro on Dec 8, 2019 6:45:31 GMT -5
update :
some error's removed
what do i do whit line 127
'' bluatigro 7 dec 2019
'' bluaGL_1
dim pnt#( 255 )( 2 )
sub setpoint( no , x# , y# , z# )
pnt#( no )( 0 ) = x#
pnt#( no )( 1 ) = y#
pnt#( no )( 2 ) = z#
end sub
sub tri( p1 , p2 , p3 )
dim n#( 2 ) = crossproduct( pnt#( p3 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p2 ) )
n# = normalize( n# )
glBegin( GL_TRIANGLES )
glnormal3fv( n# )
glVertex3fv( pnt#( p1 ) )
glVertex3fv( pnt#( p2 ) )
glVertex3fv( pnt#( p3 ) )
glEnd()
end sub
sub quad( p1 , p2 , p3 , p4 )
dim n#( 2 ) = crossproduct( pnt#( p1 ) , pnt#( p2) )
n# = normalize( n# )
glBegin( GL_QUADS )
glnormal3fv( n# )
glVertex3fv( pnt#( p1 ) )
glVertex3fv( pnt#( p2 ) )
glVertex3fv( pnt#( p3 ) )
glVertex3fv( pnt#( p4 ) )
glEnd()
end sub
glEnable( gl_lighting )
dim lightpos#( 3 ) = vec4( -50 , 50 , 50 , 1 )
dim diffuse#( 3 ) = vec4( 1 , 1 , 1 , 1 )
glLightfv( gl_light0 , gl_position, lightpos# )
glLightfv( gl_light0 , gl_diffuse , diffuse# )
glEnable( gl_light0 )
type tmaterial
ambient( 3 ) as single
diffuse( 3 ) as single
specular( 3 ) as single
emision( 3 ) as single
shininess as single
end type
dim tmaterial material
sub material_use( a , m as tmaterial )
glMaterialfv( a , GL_AMBIENT , m.ambient )
glMaterialfv( a , GL_DIFFUSE , m.diffuse )
glMaterialfv( a , GL_SPECULAR , m.specular )
glMaterialfv( a , GL_EMISSION , m.emision )
glMaterialf( a , GL_SHININESS , m.shininess )
end sub
dim black#( 3 ) = vec4( 0 , 0 , 0 , 1 )
dim red#( 3 ) = vec4( 1 , 0 , 0 , 1 )
dim green#( 3 ) = vec4( 0 , 1 , 0 , 1 )
dim yellow#( 3 ) = vec4( 1 , 1 , 0 , 1 )
dim blue#( 3 ) = vec4( 0 , 0 , 1 , 1 )
dim magenta#( 3 ) = vec4( 1 , 0 , 1 , 1 )
dim cyan#( 3 ) = vec4( 0 , 1 , 1 , 1 )
dim white#( 3 ) = vec4( 1 , 1 , 1 , 1 )
type tcam
x as single
y as single
z as single
pan as single
end type
dim tcam cam
sub camara_use( c as tcam )
glRotatef( -c.pan , 0 , 1 , 0 )
gltranslatef( -c.x , -c.y , -c.z )
end sub
dim box#(5)
sub setbox( x# , y# , z# , dx# , dy# , dz# )
box#(0) = x#
box#(1) = y#
box#(2) = z#
box#(3) = dx#
box#(4) = dy#
box#(5) = dz#
end sub
sub cube()
'' fil points of swarm
setpoint( 0 , -1 , -1 , -1 )
setpoint( 1 , -1 , -1 , 1 )
setpoint( 2 , -1 , 1 , -1 )
setpoint( 3 , -1 , 1 , 1 )
setpoint( 4 , 1 , -1 , -1 )
setpoint( 5 , 1 , -1 , 1 )
setpoint( 6 , 1 , 1 , -1 )
setpoint( 7 , 1 , 1 , 1 )
'' use swarmpoints to create mesh
glPushMatrix()
glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) )
glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) )
quad( 0 , 1 , 3 , 2 ) ''left
quad( 7 , 6 , 4 , 5 ) ''right
quad( 0 , 1 , 5 , 4 ) ''bottom
quad( 7 , 6 , 2 , 3 ) ''top
quad( 0 , 2 , 6 , 4 ) ''front
quad( 7 , 5 , 1 , 3 ) ''back
glPopMatrix()
end sub
dim sk#( 64 )( 2 )
sub skelet( no , x# , y# , z# )
sk#( no )( 0 ) = x#
sk#( no )( 1 ) = y#
sk#( no )( 2 ) = z#
end sub
const xyz = 0
const xzy = 1
const yxz = 2
const yzx = 3
const zxy = 4
const zyx = 5
sub child( x# , y# , z# , lim , ax )
glTranslatef( x# , y# , z# )
if ax = xyz then
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
elseif ax = xzy then
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
elseif ax = yxz then
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 )
elseif ax = yzx then
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
elseif ax = zxy then
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
elseif ax = zyx then
glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 )
glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 )
glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 )
else
end if
end sub
function pend#( fase# , amp# )
return sind( fase# ) * amp#
end function
const leftno = 0
const arm = 1
const elbow = 2
const wrist = 3
const leg = 4
const knee = 5
const enkle = 6
const neck = 7
const thumb = 8
const index_finger = 11
const middle_finger = 14
const ring_finger = 17
const pinky_finger = 20
const rightno = 32
sub finger( lim )
'' part of human robot avatar
setbox( 0 , -1 , 0 , 1 , 1 , 1 )
cube()
glpushmatrix()
child( 0 , -1 , 0 , lim + 1 , xyz )
cube()
glpushmatrix()
child( 0 , -1 , 0 , lim + 2 , xyz )
cube()
glpopmatrix()
glpopmatrix()
end sub
sub hand( lr , kl# )
'' part of human robot avatar
material.diffuse = kl#
material_use( gl_frONT , material )
setbox( 0 , -4 , 0 , 1 , 4 , 1 )
cube()
glpushmatrix()
child( 0 , -4 , 1.5 , lr + index_finger , zxy )
finger( lr + index )
glpopmatrix()
glpushmatrix()
child( 0 , -4 , .5 , lr + middle_finger , zxy )
finger( lr + middle )
glpopmatrix()
glpushmatrix()
child( 0 , -4 , -.5 , lr + ring_finger , zxy )
finger( lr + ring )
glpopmatrix()
glpushmatrix()
child( 0 , -4 , -1.5 , lr + pinky_finger , zxy )
finger( lr + pinky )
glpopmatrix()
glpushmatrix()
child( 0 , -1 , 2.5 , lr + thumb , zxy )
finger( lr + thumb )
glpopmatrix()
end sub
sub human_robot( h , kl# , klh#)
material.diffuse = kl#
setmaterial( gl_front , material )
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 + rightno , zyx )
setbox( 0 , -.6 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , knee + rightno , xyz )
cube()
glPushMatrix()
child( 0 , -1.2 , 0 , enkle + rightno , xyz )
setbox( 0 , 0 , .2 , .1 , .1 , .3 )
cube()
glPopMatrix()
glPopMatrix()
glPopMatrix()
glPushMatrix()
child( -.45 , 0 , 0 , leg + leftno , zyx )
setbox( 0 , -.6 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , knee + leftno , xyz )
cube()
glPushMatrix()
child( 0 , -1.2 , 0 , enkle + leftno , xyz )
setbox( 0 , 0 , .2 , .1 , .1 , .3 )
cube()
glPopMatrix()
glPopMatrix()
glPopMatrix()
glPushMatrix()
child( .65 , 1.3 , 0 , arm + rightno , xyz )
setbox( 0 , -.5 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , elbow + rightno , xyz )
cube()
glPushMatrix()
child( 0 , -1 , 0 , wrist + rightno , zyx )
glscalef( .5 , .5 , .5 )
hand( rightno , klh# )
glPopMatrix()
glPopMatrix()
glPopMatrix()
material.diffuse = kl#
setmaterial( gl_front , material )
glPushMatrix()
child( -.65 , 1.3 , 0 , arm + leftno , xyz )
setbox( 0 , -.5 , 0 , .1 , .4 , .1 )
cube()
glPushMatrix()
child( 0 , -1 , 0 , elbow + leftno , xyz )
cube()
glPushMatrix()
child( 0 , -1 , 0 , wrist + leftno , zyx )
glscalef( .5 , .5 , .5 )
hand( leftno , klh# )
glPopMatrix()
glPopMatrix()
glPopMatrix()
end sub
end sub
sub animate( anim , fase# , amp# )
dim i
if anim = human_walk then
skelet( arm + rightno, pend#( fase# , amp# ) , 0 , 0 )
skelet( elbow + rightno, -abs( amp# ) , 0 , 0 )
skelet( arm + leftno , pend#( fase# + 180, amp# ) , 0 , 0 )
skelet( elbow + leftno , -abs( amp# ) , 0 , 0 )
skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 )
skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 )
skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 )
skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 )
skelet( thumb + rightno , -pend#( fase# , 10 ) - 10 , 0 , 0 )
skelet( thumb + leftno , -pend#( fase# , 10 ) - 10 , 0 , 0 )
for i = 0 to 2
skelet( index_finger + rightno + i , 0 , 0 , -pend#( fase# + 30 , 10 ) - 10 )
skelet( mid_finger + rightno + i , 0 , 0 , -pend#( fase# , 10 ) - 10 )
skelet( ring_finger + rightno + i , 0 , 0 , -pend#( fase# - 30 , 10 ) - 10 )
skelet( index_finger + leftno + i , 0 , 0 , pend#( fase# + 30 , 10 ) + 10 )
skelet( mid_finger + leftno + i , 0 , 0 , pend#( fase# , 10 ) + 10 )
skelet( ring_finger + leftno + i , 0 , 0 , pend#( fase# - 30 , 10 ) + 10 )
next i
end if
end sub
dim frame#
while true
glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT )
glLoadidentity()
glpushmatrix()
gltranslatef( 0 , 0 , -10 )
animate( human_walk , frame# , 30.0 )
human_robot( 1 , cyan# , white# )
glpopmatrix()
swapbuffers()
sleep( 40 )
frame# = frame# + 10
wend
how do i select code from this forum ?
|
|
|
Post by matthew on Dec 8, 2019 9:53:54 GMT -5
I don't understand what the problem is with line 127? When I run the program the first error occurs on line 351 and that's probably because you missed the parentheses when you declared the hand sub. sub hand( lr , kl#() ) The old fashioned way. Hold down the Left Mouse button and drag to select, then right-click and select Copy.
|
|
|
Post by bluatigro on Dec 9, 2019 7:26:53 GMT -5
update : syntax good error : lightambient has no effect
'' bluatigro 9 dec 2019 '' bluaGL_2 dim pnt#( 255 )( 2 ) sub setpoint( no , x# , y# , z# ) pnt#( no )( 0 ) = x# pnt#( no )( 1 ) = y# pnt#( no )( 2 ) = z# end sub sub tri( p1 , p2 , p3 ) dim n#( 2 ) = crossproduct( pnt#( p3 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p2 ) ) n# = normalize( n# ) glBegin( GL_TRIANGLES ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glEnd() end sub sub quad( p1 , p2 , p3 , p4 ) dim n#( 2 ) = crossproduct( pnt#( p1 ) , pnt#( p2) ) n# = normalize( n# ) glBegin( GL_QUADS ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glVertex3fv( pnt#( p4 ) ) glEnd() end sub
glEnable( gl_lighting ) dim lightposition#( 3 ) = vec4( -50 , 50 , 10 , 1 ) dim lightdiffuse#( 3 ) = vec4( 1 , 1 , 1 , 1 ) dim lightambient#( 3 ) = vec4( .4 , .4 , .4 , 1 ) glLightfv( gl_light0 , gl_position, lightposition# ) glLightfv( gl_light0 , gl_diffuse , lightdiffuse# ) gllightfv( gl_lIGHT0 , gl_amBIENT , lightambient# ) glEnable( gl_light0 )
type tmaterial ambient( 3 ) as single diffuse( 3 ) as single specular( 3 ) as single emision( 3 ) as single shininess as single end type dim tmaterial material sub material_use( a , m as tmaterial ) glMaterialfv( a , GL_AMBIENT , m.ambient ) glMaterialfv( a , GL_DIFFUSE , m.diffuse ) glMaterialfv( a , GL_SPECULAR , m.specular ) glMaterialfv( a , GL_EMISSION , m.emision ) glMaterialf( a , GL_SHININESS , m.shininess ) end sub dim black#( 3 ) = vec4( 0 , 0 , 0 , 1 ) dim red#( 3 ) = vec4( 1 , 0 , 0 , 1 ) dim green#( 3 ) = vec4( 0 , 1 , 0 , 1 ) dim yellow#( 3 ) = vec4( 1 , 1 , 0 , 1 ) dim blue#( 3 ) = vec4( 0 , 0 , 1 , 1 ) dim magenta#( 3 ) = vec4( 1 , 0 , 1 , 1 ) dim cyan#( 3 ) = vec4( 0 , 1 , 1 , 1 ) dim white#( 3 ) = vec4( 1 , 1 , 1 , 1 ) type tcam x as single y as single z as single pan as single end type dim tcam cam sub camara_use( c as tcam ) glRotatef( -c.pan , 0 , 1 , 0 ) gltranslatef( -c.x , -c.y , -c.z ) end sub dim box#(5) sub setbox( x# , y# , z# , dx# , dy# , dz# ) box#(0) = x# box#(1) = y# box#(2) = z# box#(3) = dx# box#(4) = dy# box#(5) = dz# end sub sub cube() '' fil points of swarm setpoint( 0 , -1 , -1 , -1 ) setpoint( 1 , -1 , -1 , 1 ) setpoint( 2 , -1 , 1 , -1 ) setpoint( 3 , -1 , 1 , 1 ) setpoint( 4 , 1 , -1 , -1 ) setpoint( 5 , 1 , -1 , 1 ) setpoint( 6 , 1 , 1 , -1 ) setpoint( 7 , 1 , 1 , 1 ) '' use swarmpoints to create mesh glPushMatrix() glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) ) glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) ) quad( 0 , 1 , 3 , 2 ) ''left quad( 7 , 6 , 4 , 5 ) ''right quad( 0 , 1 , 5 , 4 ) ''bottom quad( 7 , 6 , 2 , 3 ) ''top quad( 0 , 2 , 6 , 4 ) ''front quad( 7 , 5 , 1 , 3 ) ''back glPopMatrix() end sub dim sk#( 64 )( 2 ) sub skelet( no , x# , y# , z# ) sk#( no )( 0 ) = x# sk#( no )( 1 ) = y# sk#( no )( 2 ) = z# end sub const xyz = 0 const xzy = 1 const yxz = 2 const yzx = 3 const zxy = 4 const zyx = 5 sub child( x# , y# , z# , lim , ax ) glTranslatef( x# , y# , z# ) if ax = xyz then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) elseif ax = xzy then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = yxz then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 ) elseif ax = yzx then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) elseif ax = zxy then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = zyx then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) else end if end sub function pend#( fase# , amp# ) return sind( fase# ) * amp# end function const leftno = 0 const arm = 1 const elbow = 2 const wrist = 3 const leg = 4 const knee = 5 const enkle = 6 const neck = 7 const thumb = 8 const index_finger = 11 const middle_finger = 14 const ring_finger = 17 const pinky_finger = 20 const rightno = 32 sub finger( lim ) '' part of human robot avatar setbox( 0 , -1 , 0 , 1 , 1 , 1 ) cube() glpushmatrix() child( 0 , -1 , 0 , lim + 1 , xyz ) cube() glpushmatrix() child( 0 , -1 , 0 , lim + 2 , xyz ) cube() glpopmatrix() glpopmatrix() end sub sub hand( lr , kl#() ) '' part of human robot avatar material.diffuse = kl# material_use( gl_frONT , material ) setbox( 0 , -4 , 0 , 1 , 4 , 1 ) cube() glpushmatrix() child( 0 , -4 , 1.5 , lr + index_finger , zxy ) finger( lr + index_finger ) glpopmatrix() glpushmatrix() child( 0 , -4 , .5 , lr + middle_finger , zxy ) finger( lr + middle_finger ) glpopmatrix() glpushmatrix() child( 0 , -4 , -.5 , lr + ring_finger , zxy ) finger( lr + ring_finger ) glpopmatrix() glpushmatrix() child( 0 , -4 , -1.5 , lr + pinky_finger , zxy ) finger( lr + pinky_finger ) glpopmatrix() glpushmatrix() child( 0 , -1 , 2.5 , lr + thumb , zxy ) finger( lr + thumb ) glpopmatrix() end sub sub human_robot( h , kl#() , klh#() ) material.diffuse = kl# material_use( gl_front , material ) 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 + rightno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + rightno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + rightno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( -.45 , 0 , 0 , leg + leftno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + leftno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + leftno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( .65 , 1.3 , 0 , arm + rightno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + rightno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + rightno , zyx ) glscalef( .3 , .3 , .3 ) hand( rightno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() material.diffuse = kl# material_use( gl_front , material ) glPushMatrix() child( -.65 , 1.3 , 0 , arm + leftno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + leftno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + leftno , zyx ) glscalef( .3 , .3 , .3 ) hand( leftno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() end sub const human_walk = 0 sub animate( anim , fase# , amp# ) dim i if anim = human_walk then skelet( arm + rightno, pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + rightno, -abs( amp# ) , 0 , 0 ) skelet( arm + leftno , pend#( fase# + 180, amp# ) , 0 , 0 ) skelet( elbow + leftno , -abs( amp# ) , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( thumb + rightno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) skelet( thumb + leftno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) for i = 0 to 2 skelet( index_finger + rightno + i , 0 , 0 , -pend#( fase# + 30 , 10 ) - 10 ) skelet( middle_finger + rightno + i , 0 , 0 , -pend#( fase# , 10 ) - 10 ) skelet( ring_finger + rightno + i , 0 , 0 , -pend#( fase# - 30 , 10 ) - 10 ) skelet( index_finger + leftno + i , 0 , 0 , pend#( fase# + 30 , 10 ) + 10 ) skelet( middle_finger + leftno + i , 0 , 0 , pend#( fase# , 10 ) + 10 ) skelet( ring_finger + leftno + i , 0 , 0 , pend#( fase# - 30 , 10 ) + 10 ) next : i end if end sub dim frame# while true glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT ) glLoadidentity() glpushmatrix() gltranslatef( 0 , 0 , -10 ) animate( human_walk , frame# , 30.0 ) human_robot( 1 , cyan# , white# ) glpopmatrix() swapbuffers() sleep( 40 ) frame# = frame# + 10 wend
|
|
|
blua gl
Dec 10, 2019 13:48:16 GMT -5
Post by matthew on Dec 10, 2019 13:48:16 GMT -5
I've noticed that in your human_robot sub, material.diffuse is holding a value of {1, 1, 1, 1} while material.ambient has a value of {0, 0, 0, 0}.
Could that explain why ambient lighting seems to have no effect?
|
|
|
Post by bluatigro on Dec 11, 2019 7:49:19 GMT -5
update : lightamient good now
added a bug robot al animations of the bug begin whit i_ you can add animations
'' bluatigro 9 dec 2019 '' bluaGL_2 dim pnt#( 255 )( 2 ) sub setpoint( no , x# , y# , z# ) pnt#( no )( 0 ) = x# pnt#( no )( 1 ) = y# pnt#( no )( 2 ) = z# end sub sub tri( p1 , p2 , p3 ) dim n#( 2 ) = crossproduct( pnt#( p3 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p2 ) ) n# = normalize( n# ) glBegin( GL_TRIANGLES ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glEnd() end sub sub quad( p1 , p2 , p3 , p4 ) dim n#( 2 ) = crossproduct( pnt#( p1 ) , pnt#( p2) ) n# = normalize( n# ) glBegin( GL_QUADS ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glVertex3fv( pnt#( p4 ) ) glEnd() end sub
glEnable( gl_lighting ) dim lightposition#( 3 ) = vec4( -50 , 50 , 10 , 1 ) dim lightdiffuse#( 3 ) = vec4( 1 , 1 , 1 , 1 ) dim lightambient#( 3 ) = vec4( .4 , .4 , .4 , 1 ) glLightfv( gl_light0 , gl_position, lightposition# ) glLightfv( gl_light0 , gl_diffuse , lightdiffuse# ) gllightfv( gl_lIGHT0 , gl_amBIENT , lightambient# ) glEnable( gl_light0 )
type tmaterial ambient( 3 ) as single diffuse( 3 ) as single specular( 3 ) as single emision( 3 ) as single shininess as single end type dim tmaterial material sub material_use( a , m as tmaterial ) glMaterialfv( a , GL_AMBIENT , m.ambient ) glMaterialfv( a , GL_DIFFUSE , m.diffuse ) glMaterialfv( a , GL_SPECULAR , m.specular ) glMaterialfv( a , GL_EMISSION , m.emision ) glMaterialf( a , GL_SHININESS , m.shininess ) end sub dim black#( 3 ) = vec4( 0 , 0 , 0 , 1 ) dim red#( 3 ) = vec4( 1 , 0 , 0 , 1 ) dim green#( 3 ) = vec4( 0 , 1 , 0 , 1 ) dim yellow#( 3 ) = vec4( 1 , 1 , 0 , 1 ) dim blue#( 3 ) = vec4( 0 , 0 , 1 , 1 ) dim magenta#( 3 ) = vec4( 1 , 0 , 1 , 1 ) dim cyan#( 3 ) = vec4( 0 , 1 , 1 , 1 ) dim white#( 3 ) = vec4( 1 , 1 , 1 , 1 ) type tcam x as single y as single z as single pan as single end type dim tcam cam sub camara_use( c as tcam ) glRotatef( -c.pan , 0 , 1 , 0 ) gltranslatef( -c.x , -c.y , -c.z ) end sub dim box#(5) sub setbox( x# , y# , z# , dx# , dy# , dz# ) box#(0) = x# box#(1) = y# box#(2) = z# box#(3) = dx# box#(4) = dy# box#(5) = dz# end sub sub cube() '' fil points of swarm setpoint( 0 , -1 , -1 , -1 ) setpoint( 1 , -1 , -1 , 1 ) setpoint( 2 , -1 , 1 , -1 ) setpoint( 3 , -1 , 1 , 1 ) setpoint( 4 , 1 , -1 , -1 ) setpoint( 5 , 1 , -1 , 1 ) setpoint( 6 , 1 , 1 , -1 ) setpoint( 7 , 1 , 1 , 1 ) '' use swarmpoints to create mesh glPushMatrix() glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) ) glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) ) quad( 0 , 1 , 3 , 2 ) ''left quad( 7 , 6 , 4 , 5 ) ''right quad( 0 , 1 , 5 , 4 ) ''bottom quad( 7 , 6 , 2 , 3 ) ''top quad( 0 , 2 , 6 , 4 ) ''front quad( 7 , 5 , 1 , 3 ) ''back glPopMatrix() end sub dim sk#( 64 )( 2 ) sub skelet( no , x# , y# , z# ) sk#( no )( 0 ) = x# sk#( no )( 1 ) = y# sk#( no )( 2 ) = z# end sub const xyz = 0 const xzy = 1 const yxz = 2 const yzx = 3 const zxy = 4 const zyx = 5 sub child( x# , y# , z# , lim , ax ) glTranslatef( x# , y# , z# ) if ax = xyz then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) elseif ax = xzy then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = yxz then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 ) elseif ax = yzx then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) elseif ax = zxy then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = zyx then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) else end if end sub function pend#( fase# , amp# ) return sind( fase# ) * amp# end function const leftno = 0 const arm = 1 const elbow = 2 const wrist = 3 const leg = 4 const knee = 5 const enkle = 6 const neck = 7 const thumb = 8 const index_finger = 11 const middle_finger = 14 const ring_finger = 17 const pinky_finger = 20 const tail = 25
const iarm = 1 const ielbow = 2 const iwrist = 3 const ileg = 4 const iknee = 9 const iwing = 14 const itail = 16 const isensor = 17 const ithumb = 18 const ifinger = 19
const rightno = 32 sub finger( lim ) '' part of human robot avatar setbox( 0 , -2 , 0 , 1 , 1 , 1 ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 1 , xyz ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 2 , xyz ) cube() glpopmatrix() glpopmatrix() end sub sub hand( lr , kl#() ) '' part of human robot avatar material.diffuse = kl# MATERIAL.AMBIENT = KL# / 2 material_use( gl_frONT , material ) setbox( 0 , -4 , 0 , 1 , 4 , 1 ) cube() glpushmatrix() child( 0 , -8 , 1.5 , lr + index_finger , zxy ) finger( lr + index_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , .5 , lr + middle_finger , zxy ) finger( lr + middle_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , -.5 , lr + ring_finger , zxy ) finger( lr + ring_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , -1.5 , lr + pinky_finger , zxy ) finger( lr + pinky_finger ) glpopmatrix() glpushmatrix() child( 0 , -1 , 2.5 , lr + thumb , zxy ) finger( lr + thumb ) glpopmatrix() end sub sub human_robot( h , kl#() , klh#() ) material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front , material ) 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 + rightno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + rightno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + rightno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( -.45 , 0 , 0 , leg + leftno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + leftno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + leftno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( .65 , 1.3 , 0 , arm + rightno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + rightno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + rightno , zyx ) glscalef( .1 , .1 , .1 ) hand( rightno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front , material ) glPushMatrix() child( -.65 , 1.3 , 0 , arm + leftno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + leftno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + leftno , zyx ) glscalef( .1 , .1 , .1 ) hand( leftno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() end sub
sub bug_robot( kl#() ) material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front , material ) Dim i as integer glPushmatrix() glScaled( .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 + rightno + 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 + rightno + 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 + leftno + 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 + leftno + i + 1, xyz) setbox( 0.0, -30.0, 0.0, 5.0, 30.0, 5.0) Cube() glPopmatrix() glPopMatrix() Next glPushMatrix() child( 0 , 0 , -50 , itail + rightno, xyz) For i = 0 To 9 glPushMatrix() child( 0.0, 0.0, -30.0 , itail + rightno , 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 , itail + leftno , xyz ) cube() next :i for i = 0 to 8 glPopMatrix() glPopMatrix() next :i glPopMatrix() glPushMatrix() child( 30.0, 0.0, 65.0, iarm + rightno, xyz) setbox( 0.0, 0.0, 65.0 , 5 , 5 , 30 ) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, ielbow + rightno, xyz ) Cube() glPushmatrix() child( 0.0, 0.0, 65.0 , iwrist + rightno, xyz) glPushmatrix() child(-10.0, 0.0, 5.0 , ithumb + rightno, xyz) Cube() glPopMatrix() glPushMatrix() child( 5.0, 0.0, 5.0, ifinger+ rightno, 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, iarm + leftno, xyz) setbox( 0.0, 0.0, 30.0, 5.0, 5.0, 30.0) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, ielbow +leftno, xyz) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, iwrist+leftno, xyz) glPushMatrix() child( 10.0, 0.0, 5.0, ithumb+leftno, xyz) Cube() glPopMatrix() glPushMatrix() child(-5.0, 0.0, 5.0, ifinger+leftno, 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, iwing + rightno+ 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 , iwing+leftno + i, xyz) setbox( -60.0, 0.0, 8.0, 60.0, 2.0, 16.0) Cube() glPopmatrix() Next glPopMatrix() end sub
const human_walk = 0 const dog_walk = 1 const I_FLY = 3 const I_LEFT_LEGS = 4 const I_LEFT_BOX = 5 const I_RIGHT_LEGS = 6 const I_RIGHT_BOX = 7 const I_STING = 8 const I_STAND = 9
sub animate( anim , fase# , amp# ) dim i if anim = human_walk then skelet( arm + rightno, pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + rightno, -abs( amp# ) , 0 , 0 ) skelet( arm + leftno , pend#( fase# + 180, amp# ) , 0 , 0 ) skelet( elbow + leftno , -abs( amp# ) , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( thumb + rightno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) skelet( thumb + leftno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) for i = 0 to 2 skelet( pinky_finger + rightno + i , 0 , 0 , -pend#( fase# + 60 , 10 ) - 10 ) skelet( index_finger + rightno + i , 0 , 0 , -pend#( fase# + 30 , 10 ) - 10 ) skelet( middle_finger + rightno + i , 0 , 0 , -pend#( fase# , 10 ) - 10 ) skelet( ring_finger + rightno + i , 0 , 0 , -pend#( fase# - 30 , 10 ) - 10 ) skelet( pinky_finger + leftno + 1 , 0 , 0 , pend#( fase# + 60 , 10 ) + 10 ) skelet( index_finger + leftno + i , 0 , 0 , pend#( fase# + 30 , 10 ) + 10 ) skelet( middle_finger + leftno + i , 0 , 0 , pend#( fase# , 10 ) + 10 ) skelet( ring_finger + leftno + i , 0 , 0 , pend#( fase# - 30 , 10 ) + 10 ) next : i else if anim = dog_walk then skelet( arm + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( elbow + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( arm + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + leftno, pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( tail , -45 , pend#( fase# * 2 , 30 ) , 0 ) skelet( neck + rightno , 0 , 0 , 0 ) skelet( neck + leftno , 0 , 0 , 0 ) elseif anim = I_FLY then For i = 0 To 1 skelet( iwing + rightno + i , 0 , 0 , Pend#( fase# , amp# ) ) skelet( iwing + leftno + i , 0 , 0 , Pend#( fase# , -amp# ) ) Next: elseif anim = I_LEFT_BOX then skelet( iarm + rightno , 0 , Pend#( fase# , -amp# ) + 45 , 0 ) skelet( ielbow + rightno , 0 , Pend#( fase# , amp# * 2 ) - 60 , 0 ) elseif anim = I_LEFT_LEGS then For i = 0 To 4 skelet( ileg + leftno + i , 0 , 0 , Pend#( fase# + i * 180 , amp# ) ) skelet( iknee + leftno + i , Pend#( fase# + i * 180 + 90 , amp# ) , 0 , 0 ) Next: elseif anim = I_RIGHT_BOX then skelet( iarm + rightno , 0 , Pend#( fase#, amp# ) - 45,0 ) skelet( ielbow + rightno , 0 , Pend#( fase# , -amp# * 2) + 60, 0 ) elseif anim = I_RIGHT_LEGS then For i = 0 To 4 skelet( ileg + rightno + i , 0 , 0 , Pend#( fase# + i * 180 , amp# ) ) skelet( iknee + rightno + i , Pend#( fase# + i * 180 + 90 , amp# ) , 0 , 0 ) Next: elseif anim = I_STAND then skelet( iarm + rightno , 0, 45, 0 ) skelet( ielbow + rightno , 0, -60 , 0 ) skelet( ifinger + rightno , 0, 0, 0 ) skelet( ithumb + rightno , 0, 0, 0 ) skelet( iarm + leftno , 0 , -45 , 0 ) skelet( ielbow + leftno , 0 , 60 , 0 ) skelet( ifinger + leftno , 0 , 0 , 0 ) skelet( ithumb + leftno , 0 , 0 , 0 ) skelet( itail + rightno , 10 , 0 , 0 ) skelet( itail + leftno , 10 , 0 , 0 ) elseif anim = I_STING then skelet( itail + rightno , 10 + Pend#( fase# , amp# ) , 0 , 0 ) skelet( itail + leftno , 10 - Pend#( fase# , amp# ) , 0 , 0 ) else for i = 0 to 63 skelet( i , 0 , 0 , 0 ) next: i end if end if end sub dim frame# while true glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT ) glLoadidentity() glpushmatrix() gltranslatef( 5 , 0 , -10 ) glrotatef( frame# / 10 , 0 , 1 , 0 ) animate( 13 , 0 , 0 ) animate( human_walk , frame# , 30.0 ) human_robot( 1 , cyan# , white# ) glpopmatrix() glpushmatrix() gltranslatef( -5 , 0 , -10 ) glrotatef( -frame# / 10 , 0 , 1 , 0 ) animate( 13 , 0 , 0 ) animate( i_stand , 0 , 0 ) animate( i_sting , frame# , 7 ) bUg_robot( magenta# ) glpopmatrix() swapbuffers() sleep( 40 ) frame# = frame# + 10 wend
|
|
|
blua gl
Dec 11, 2019 13:42:39 GMT -5
Post by matthew on Dec 11, 2019 13:42:39 GMT -5
Very impressive, it works fine on my computer. :-)
|
|
|
Post by bluatigro on Dec 16, 2019 5:38:04 GMT -5
if you like that i have more : sub tree added WARNING : folow instructions in rem in sub tree error : my cilinder is not shown material.diffuse in sub tree not working good
if you solve the error's you see somthing special Q : how many different trees you can make whit sub tree
REM : sub tree is my masterpice [ dark age idea ]
'' bluatigro 9 dec 2019 '' bluaGL_2 dim pnt#( 255 )( 2 ) sub setpoint( no , x# , y# , z# ) pnt#( no )( 0 ) = x# pnt#( no )( 1 ) = y# pnt#( no )( 2 ) = z# end sub sub tri( p1 , p2 , p3 ) dim n#( 2 ) = crossproduct( pnt#( p3 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p2 ) ) n# = normalize( n# ) glBegin( GL_TRIANGLES ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glEnd() end sub sub quad( p1 , p2 , p3 , p4 ) dim n#( 2 ) = crossproduct( pnt#( p1 ) , pnt#( p2) ) n# = normalize( n# ) glBegin( GL_QUADS ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glVertex3fv( pnt#( p4 ) ) glEnd() end sub
glEnable( gl_lighting ) dim lightposition#( 3 ) = vec4( -50 , 50 , 10 , 1 ) dim lightdiffuse#( 3 ) = vec4( 1 , 1 , 1 , 1 ) dim lightambient#( 3 ) = vec4( .4 , .4 , .4 , 1 ) glLightfv( gl_light0 , gl_position, lightposition# ) glLightfv( gl_light0 , gl_diffuse , lightdiffuse# ) gllightfv( gl_lIGHT0 , gl_amBIENT , lightambient# ) glEnable( gl_light0 )
type tmaterial ambient( 3 ) as single diffuse( 3 ) as single specular( 3 ) as single emision( 3 ) as single shininess as single end type dim tmaterial material sub material_use( a , m as tmaterial ) glMaterialfv( a , GL_AMBIENT , m.ambient ) glMaterialfv( a , GL_DIFFUSE , m.diffuse ) glMaterialfv( a , GL_SPECULAR , m.specular ) glMaterialfv( a , GL_EMISSION , m.emision ) glMaterialf( a , GL_SHININESS , m.shininess ) end sub dim black#( 3 ) = vec4( 0 , 0 , 0 , 1 ) dim red#( 3 ) = vec4( 1 , 0 , 0 , 1 ) dim green#( 3 ) = vec4( 0 , 1 , 0 , 1 ) dim yellow#( 3 ) = vec4( 1 , 1 , 0 , 1 ) dim blue#( 3 ) = vec4( 0 , 0 , 1 , 1 ) dim magenta#( 3 ) = vec4( 1 , 0 , 1 , 1 ) dim cyan#( 3 ) = vec4( 0 , 1 , 1 , 1 ) dim white#( 3 ) = vec4( 1 , 1 , 1 , 1 ) type tcam x as single y as single z as single pan as single end type dim tcam cam sub camara_use( c as tcam ) glRotatef( -c.pan , 0 , 1 , 0 ) gltranslatef( -c.x , -c.y , -c.z ) end sub dim box#(5) sub setbox( x# , y# , z# , dx# , dy# , dz# ) box#(0) = x# box#(1) = y# box#(2) = z# box#(3) = dx# box#(4) = dy# box#(5) = dz# end sub sub cube() '' fil points of swarm setpoint( 0 , -1 , -1 , -1 ) setpoint( 1 , -1 , -1 , 1 ) setpoint( 2 , -1 , 1 , -1 ) setpoint( 3 , -1 , 1 , 1 ) setpoint( 4 , 1 , -1 , -1 ) setpoint( 5 , 1 , -1 , 1 ) setpoint( 6 , 1 , 1 , -1 ) setpoint( 7 , 1 , 1 , 1 ) '' use swarmpoints to create mesh glPushMatrix() glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) ) glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) ) quad( 0 , 1 , 3 , 2 ) ''left quad( 7 , 6 , 4 , 5 ) ''right quad( 0 , 1 , 5 , 4 ) ''bottom quad( 7 , 6 , 2 , 3 ) ''top quad( 0 , 2 , 6 , 4 ) ''front quad( 7 , 5 , 1 , 3 ) ''back glPopMatrix() end sub sub cilinder( sides as integer , dx as single , dz as single , top as integer , bot as integer ) dim f as double if sides < 3 then sides = 3 : end if if sides > 64 then sides = 64 : end if for f = 0 to sides + 2 setpoint( f , box#( 0 ) + sin( f * m_pi * 2 / sides ) * box#( 3 ) , box#( 1 ) - box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * box#( 5 ) ) setpoint( f + sides + 1 , box#( 0 ) + sin( f * m_pi * 2 / sides ) * dx , box#( 1 ) + box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * dz ) next : f for f = 0 to sides + 1 quad( f , f + 1 , f + 2 + sides , f + 1 + sides ) next : f if top then setpoint( 255 , box#( 0 ) , box#( 1 ) , box#( 2 ) ) for f = 0 to sides + 2 setpoint( f , box#( 0 ) + sin( f * m_pi * 2 / sides ) * dx , box#( 1 ) + box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * dz ) next : f for f = 0 to sides tri( 255 , f , f + 1 ) next : f end if if bot then setpoint( 255 , 0 , box#( 0 ) - box#( 3 ) , 0 ) for f = 0 to sides + 2 setpoint( f , box#( 0 ) - sin( f * m_pi * 2 / sides ) * box#( 3 ) , box#( 1 ) - box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * box#( 5 ) ) next : f for f = 0 to sides + 2 tri( 255 , f , f + 1 ) next : f end if end sub
dim sk#( 64 )( 2 ) sub skelet( no , x# , y# , z# ) sk#( no )( 0 ) = x# sk#( no )( 1 ) = y# sk#( no )( 2 ) = z# end sub const xyz = 0 const xzy = 1 const yxz = 2 const yzx = 3 const zxy = 4 const zyx = 5 sub child( x# , y# , z# , lim , ax ) glTranslatef( x# , y# , z# ) if ax = xyz then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) elseif ax = xzy then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = yxz then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 ) elseif ax = yzx then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) elseif ax = zxy then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = zyx then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) else end if end sub function pend#( fase# , amp# ) return sind( fase# ) * amp# end function const leftno = 0 const arm = 1 const elbow = 2 const wrist = 3 const leg = 4 const knee = 5 const enkle = 6 const neck = 7 const thumb = 8 const index_finger = 11 const middle_finger = 14 const ring_finger = 17 const pinky_finger = 20 const tail = 25
const iarm = 1 const ielbow = 2 const iwrist = 3 const ileg = 4 const iknee = 9 const iwing = 14 const itail = 16 const isensor = 17 const ithumb = 18 const ifinger = 19
const rightno = 32 sub finger( lim ) '' part of human robot avatar setbox( 0 , -2 , 0 , 1 , 1 , 1 ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 1 , xyz ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 2 , xyz ) cube() glpopmatrix() glpopmatrix() end sub sub hand( lr , kl#() ) '' part of human robot avatar material.diffuse = kl# MATERIAL.AMBIENT = KL# / 2 material_use( gl_frONT , material ) setbox( 0 , -4 , 0 , 1 , 4 , 1 ) cube() glpushmatrix() child( 0 , -8 , 1.5 , lr + index_finger , zxy ) finger( lr + index_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , .5 , lr + middle_finger , zxy ) finger( lr + middle_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , -.5 , lr + ring_finger , zxy ) finger( lr + ring_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , -1.5 , lr + pinky_finger , zxy ) finger( lr + pinky_finger ) glpopmatrix() glpushmatrix() child( 0 , -1 , 2.5 , lr + thumb , zxy ) finger( lr + thumb ) glpopmatrix() end sub sub human_robot( h , kl#() , klh#() ) material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front , material ) 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 + rightno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + rightno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + rightno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( -.45 , 0 , 0 , leg + leftno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + leftno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + leftno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( .65 , 1.3 , 0 , arm + rightno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + rightno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + rightno , zyx ) glscalef( .1 , .1 , .1 ) hand( rightno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front , material ) glPushMatrix() child( -.65 , 1.3 , 0 , arm + leftno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + leftno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + leftno , zyx ) glscalef( .1 , .1 , .1 ) hand( leftno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() end sub
sub bug_robot( kl#() ) material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front , material ) Dim i as integer glPushmatrix() glScaled( .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 + rightno + 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 + rightno + 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 + leftno + 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 + leftno + i + 1, xyz) setbox( 0.0, -30.0, 0.0, 5.0, 30.0, 5.0) Cube() glPopmatrix() glPopMatrix() Next glPushMatrix() child( 0 , 0 , -50 , itail + rightno, xyz) For i = 0 To 9 glPushMatrix() child( 0.0, 0.0, -30.0 , itail + rightno , 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 , itail + leftno , xyz ) cube() next :i for i = 0 to 8 glPopMatrix() glPopMatrix() next :i glPopMatrix() glPushMatrix() child( 30.0, 0.0, 65.0, iarm + rightno, xyz) setbox( 0.0, 0.0, 65.0 , 5 , 5 , 30 ) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, ielbow + rightno, xyz ) Cube() glPushmatrix() child( 0.0, 0.0, 65.0 , iwrist + rightno, xyz) glPushmatrix() child(-10.0, 0.0, 5.0 , ithumb + rightno, xyz) Cube() glPopMatrix() glPushMatrix() child( 5.0, 0.0, 5.0, ifinger+ rightno, 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, iarm + leftno, xyz) setbox( 0.0, 0.0, 30.0, 5.0, 5.0, 30.0) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, ielbow +leftno, xyz) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, iwrist+leftno, xyz) glPushMatrix() child( 10.0, 0.0, 5.0, ithumb+leftno, xyz) Cube() glPopMatrix() glPushMatrix() child(-5.0, 0.0, 5.0, ifinger+leftno, 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, iwing + rightno+ 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 , iwing+leftno + i, xyz) setbox( -60.0, 0.0, 8.0, 60.0, 2.0, 16.0) Cube() glPopmatrix() Next glPopMatrix() end sub
const human_walk = 0 const dog_walk = 1 const I_FLY = 3 const I_LEFT_LEGS = 4 const I_LEFT_BOX = 5 const I_RIGHT_LEGS = 6 const I_RIGHT_BOX = 7 const I_STING = 8 const I_STAND = 9
sub animate( anim , fase# , amp# ) dim i if anim = human_walk then skelet( arm + rightno, pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + rightno, -abs( amp# ) , 0 , 0 ) skelet( arm + leftno , pend#( fase# + 180, amp# ) , 0 , 0 ) skelet( elbow + leftno , -abs( amp# ) , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( thumb + rightno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) skelet( thumb + leftno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) for i = 0 to 2 skelet( pinky_finger + rightno + i , 0 , 0 , -pend#( fase# + 60 , 10 ) - 10 ) skelet( index_finger + rightno + i , 0 , 0 , -pend#( fase# + 30 , 10 ) - 10 ) skelet( middle_finger + rightno + i , 0 , 0 , -pend#( fase# , 10 ) - 10 ) skelet( ring_finger + rightno + i , 0 , 0 , -pend#( fase# - 30 , 10 ) - 10 ) skelet( pinky_finger + leftno + 1 , 0 , 0 , pend#( fase# + 60 , 10 ) + 10 ) skelet( index_finger + leftno + i , 0 , 0 , pend#( fase# + 30 , 10 ) + 10 ) skelet( middle_finger + leftno + i , 0 , 0 , pend#( fase# , 10 ) + 10 ) skelet( ring_finger + leftno + i , 0 , 0 , pend#( fase# - 30 , 10 ) + 10 ) next : i else if anim = dog_walk then skelet( arm + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( elbow + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( arm + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + leftno, pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( tail , -45 , pend#( fase# * 2 , 30 ) , 0 ) skelet( neck + rightno , 0 , 0 , 0 ) skelet( neck + leftno , 0 , 0 , 0 ) elseif anim = I_FLY then For i = 0 To 1 skelet( iwing + rightno + i , 0 , 0 , Pend#( fase# , amp# ) ) skelet( iwing + leftno + i , 0 , 0 , Pend#( fase# , -amp# ) ) Next: elseif anim = I_LEFT_BOX then skelet( iarm + rightno , 0 , Pend#( fase# , -amp# ) + 45 , 0 ) skelet( ielbow + rightno , 0 , Pend#( fase# , amp# * 2 ) - 60 , 0 ) elseif anim = I_LEFT_LEGS then For i = 0 To 4 skelet( ileg + leftno + i , 0 , 0 , Pend#( fase# + i * 180 , amp# ) ) skelet( iknee + leftno + i , Pend#( fase# + i * 180 + 90 , amp# ) , 0 , 0 ) Next: elseif anim = I_RIGHT_BOX then skelet( iarm + rightno , 0 , Pend#( fase#, amp# ) - 45,0 ) skelet( ielbow + rightno , 0 , Pend#( fase# , -amp# * 2) + 60, 0 ) elseif anim = I_RIGHT_LEGS then For i = 0 To 4 skelet( ileg + rightno + i , 0 , 0 , Pend#( fase# + i * 180 , amp# ) ) skelet( iknee + rightno + i , Pend#( fase# + i * 180 + 90 , amp# ) , 0 , 0 ) Next: elseif anim = I_STAND then skelet( iarm + rightno , 0, 45, 0 ) skelet( ielbow + rightno , 0, -60 , 0 ) skelet( ifinger + rightno , 0, 0, 0 ) skelet( ithumb + rightno , 0, 0, 0 ) skelet( iarm + leftno , 0 , -45 , 0 ) skelet( ielbow + leftno , 0 , 60 , 0 ) skelet( ifinger + leftno , 0 , 0 , 0 ) skelet( ithumb + leftno , 0 , 0 , 0 ) skelet( itail + rightno , 10 , 0 , 0 ) skelet( itail + leftno , 10 , 0 , 0 ) elseif anim = I_STING then skelet( itail + rightno , 10 + Pend#( fase# , amp# ) , 0 , 0 ) skelet( itail + leftno , 10 - Pend#( fase# , amp# ) , 0 , 0 ) else for i = 0 to 63 skelet( i , 0 , 0 , 0 ) next: i end if end if end sub dim orange#( 3 ) = vec4( 1 , .5 , 0 , 1 ) sub tree( i as integer , prog as string , f as double , x as double , y as double , z as double , kl#() ) dim q , t , w$ '' 1 < i < 7 '' 0 < f < 1 ''prog : no[ = no] and [ left of ] if i > 0 then for q = 1 to len( prog ) w$ = mid$( prog , q , 1 ) if w$ = "f" then ''draw trunk or twig and move pen material.diffuse = orange# material.ambient = orange# / 2 material_use( gl_front_AND_BACK , material ) setbox( 0 , 1 , 0 , .3,1,.3 ) cilinder( 6 , .3 * f , .3 * f , 1 , 0 ) gltranslated( 0 , 2 , 0 ) elseif w$ = "l" then ''draw leaf material.diffuse = green# material.ambient = green# / 2 material_use( gl_front_and_back , material ) glpushmatrix() glscaled( .5 , .5 , .5 ) setpoint( 0 , 0 , 0 , 0 ) setpoint( 1 , 1 , 0 , 1 ) setpoint( 2 , 3 , 0 , 0 ) setpoint( 3 , 1 , 0 , -1 ) quad( 0 , 1 , 2 , 3 ) glpopmatrix() elseif w$ = "L" then ''draw set of leaves material.diffuse = green# material.ambient = green# / 2 material_use( gl_front_and_back , material ) for t = 0 to 4 glpushmatrix() glrotated( 72 * t , 0 , 1 , 0 ) glscaled( .5 , .5 , .5 ) setpoint( 0 , 0 , 0 , 0 ) setpoint( 1 , 1 , 0 , 1 ) setpoint( 2 , 3 , 0 , 0 ) setpoint( 3 , 1 , 0 , -1 ) quad( 0 , 1 , 2 , 3 ) glpopmatrix() next : t elseif w$ = "h" then ''draw a flower material.diffuse = kl# material.ambient = kl# / 2 material_use( gl_front_and_back , material ) for t = 0 to 4 glpushmatrix() glscaled( .5 , .5 , .5 ) glrotated( 72 * t , 0 , 1 , 0 ) setpoint( 0 , 0 , 0 , 0 ) setpoint( 1 , 1 , 1 , 1 ) setpoint( 2 , 3 , 3 , 0 ) setpoint( 3 , 1 , 1 , -1 ) quad( 0 , 1 , 2 , 3 ) glpopmatrix() next : t elseif w$ = "g" then ''move pen gltranslated( 0 , 2 , 0 ) elseif w$ = "[" then ''store x,y,z glpushmatrix() elseif w$ = "]" then ''read x,y,z glpopmatrix() elseif w$ = "X" then glrotated( x , 1,0,0 ) elseif w$ = "x" then glrotated( -x , 1,0,0 ) elseif w$ = "Y" then glrotated( y , 0,1,0 ) elseif w$ = "y" then glrotated( -y , 0,1,0 ) elseif w$ = "Z" then glrotated( z , 0,0,1 ) elseif w$ = "z" then glrotated( -z , 0,0,1 ) elseif w$ = "b" then ''draw hole tree smaler glscaled( f,f,f ) tree( i - 1 , prog , f,x,y,z,kl# ) else end if next : q end if end sub
dim frame# while true glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT ) glLoadidentity() glpushmatrix() gltranslatef( 5 , 0 , -10 ) glrotatef( frame# / 10 , 0 , 1 , 0 ) animate( 13 , 0 , 0 ) animate( human_walk , frame# , 30.0 ) '' human_robot( 1 , cyan# , white# ) glpopmatrix() glpushmatrix() gltranslated( 0 , -2 , -10 ) glrotatef( frame# / 5 , 0 , 1 , 0 ) tree( 5 , "f[xybLh]XybLh" , .7 , 45 , 90 , 30 , white# ) glpopmatrix() glpushmatrix() gltranslatef( -5 , 0 , -10 ) glrotatef( -frame# / 10 , 0 , 1 , 0 ) animate( 13 , 0 , 0 ) animate( i_stand , 0 , 0 ) animate( i_sting , frame# , 7 ) '' bUg_robot( magenta# ) glpopmatrix() swapbuffers() sleep( 40 ) frame# = frame# + 10 wend
|
|
|
Post by bluatigro on Dec 23, 2019 6:47:15 GMT -5
update : cilinder in sub tree replaced by cube hole tree is visable now
how many different trees can we make now ? or how de i calc that ? can the prog string be automate writen ?
'' bluatigro 23 dec 2019 '' bluaGL_2 dim pnt#( 255 )( 2 ) sub setpoint( no , x# , y# , z# ) pnt#( no )( 0 ) = x# pnt#( no )( 1 ) = y# pnt#( no )( 2 ) = z# end sub sub tri( p1 , p2 , p3 ) dim n#( 2 ) = crossproduct( pnt#( p3 ) - pnt#( p1 ) , pnt#( p3 ) - pnt#( p2 ) ) n# = normalize( n# ) glBegin( GL_TRIANGLES ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glEnd() end sub sub quad( p1 , p2 , p3 , p4 ) dim n#( 2 ) = crossproduct( pnt#( p1 ) - pnt#( p3 ) , pnt#( p2 ) - pnt#( p3 ) ) n# = normalize( n# ) glBegin( GL_QUADS ) glnormal3fv( n# ) glVertex3fv( pnt#( p1 ) ) glVertex3fv( pnt#( p2 ) ) glVertex3fv( pnt#( p3 ) ) glVertex3fv( pnt#( p4 ) ) glEnd() end sub
glEnable( gl_lighting ) dim lightposition#( 3 ) = vec4( -50 , 50 , 10 , 1 ) dim lightdiffuse#( 3 ) = vec4( 1 , 1 , 1 , 1 ) dim lightambient#( 3 ) = vec4( .2 , .2 , .2 , 1 ) glLightfv( gl_light0 , gl_position, lightposition# ) glLightfv( gl_light0 , gl_diffuse , lightdiffuse# ) gllightfv( gl_lIGHT0 , gl_amBIENT , lightambient# ) glEnable( gl_light0 )
type tmaterial ambient( 3 ) as single diffuse( 3 ) as single specular( 3 ) as single emision( 3 ) as single shininess as single end type dim tmaterial material sub material_use( a , m as tmaterial ) glMaterialfv( a , GL_AMBIENT , m.ambient ) glMaterialfv( a , GL_DIFFUSE , m.diffuse ) glMaterialfv( a , GL_SPECULAR , m.specular ) glMaterialfv( a , GL_EMISSION , m.emision ) glMaterialf( a , GL_SHININESS , m.shininess ) end sub dim black#( 3 ) = vec4( 0 , 0 , 0 , 1 ) dim red#( 3 ) = vec4( 1 , 0 , 0 , 1 ) dim green#( 3 ) = vec4( 0 , 1 , 0 , 1 ) dim yellow#( 3 ) = vec4( 1 , 1 , 0 , 1 ) dim blue#( 3 ) = vec4( 0 , 0 , 1 , 1 ) dim magenta#( 3 ) = vec4( 1 , 0 , 1 , 1 ) dim cyan#( 3 ) = vec4( 0 , 1 , 1 , 1 ) dim white#( 3 ) = vec4( 1 , 1 , 1 , 1 ) type tcamera x as single y as single z as single pan as single end type dim tcamera camera sub camara_use( c as tcamera ) glRotatef( -c.pan , 0 , 1 , 0 ) gltranslatef( -c.x , -c.y , -c.z ) end sub dim box#(5) sub setbox( x# , y# , z# , dx# , dy# , dz# ) box#(0) = x# box#(1) = y# box#(2) = z# box#(3) = dx# box#(4) = dy# box#(5) = dz# end sub sub cube() '' fil points of swarm setpoint( 0 , -1 , -1 , -1 ) setpoint( 1 , -1 , -1 , 1 ) setpoint( 2 , -1 , 1 , -1 ) setpoint( 3 , -1 , 1 , 1 ) setpoint( 4 , 1 , -1 , -1 ) setpoint( 5 , 1 , -1 , 1 ) setpoint( 6 , 1 , 1 , -1 ) setpoint( 7 , 1 , 1 , 1 ) '' use swarmpoints to create mesh glPushMatrix() glTranslatef( box#( 0 ) , box#( 1 ) , box#( 2 ) ) glScalef( box#( 3 ) , box#( 4 ) , box#( 5 ) ) quad( 0 , 1 , 3 , 2 ) ''left quad( 7 , 6 , 4 , 5 ) ''right quad( 0 , 1 , 5 , 4 ) ''bottom quad( 7 , 6 , 2 , 3 ) ''top quad( 0 , 2 , 6 , 4 ) ''front quad( 7 , 5 , 1 , 3 ) ''back glPopMatrix() end sub sub cilinder( sides as integer , dx as single , dz as single , top as integer , bot as integer ) dim f if sides < 3 then sides = 3 : end if if sides > 64 then sides = 64 : end if for f = 0 to sides + 2 setpoint( f , box#( 0 ) + sin( f * m_pi * 2 / sides ) * box#( 3 ) , box#( 1 ) - box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * box#( 5 ) ) setpoint( f + sides + 1 , box#( 0 ) + sin( f * m_pi * 2 / sides ) * dx , box#( 1 ) + box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * dz ) next : f for f = 0 to sides + 1 quad( f , f + 1 , f + 2 + sides , f + 1 + sides ) next : f if top then setpoint( 255 , box#( 0 ) , box#( 1 ) , box#( 2 ) ) for f = 0 to sides + 2 setpoint( f , box#( 0 ) + sin( f * m_pi * 2 / sides ) * dx , box#( 1 ) + box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * dz ) next : f for f = 0 to sides + 1 tri( 255 , f , f + 1 ) next : f end if if bot then setpoint( 255 , 0 , box#( 0 ) - box#( 3 ) , 0 ) for f = 0 to sides + 3 setpoint( f , box#( 0 ) + sin( f * m_pi * 2 / sides ) * box#( 3 ) , box#( 1 ) - box#( 4 ) , box#( 2 ) + cos( f * m_pi * 2 / sides ) * box#( 5 ) ) next : f for f = 0 to sides + 1 tri( 255 , f , f + 1 ) next : f end if end sub
dim sk#( 64 )( 2 ) sub skelet( no , x# , y# , z# ) sk#( no )( 0 ) = x# sk#( no )( 1 ) = y# sk#( no )( 2 ) = z# end sub const xyz = 0 const xzy = 1 const yxz = 2 const yzx = 3 const zxy = 4 const zyx = 5 sub child( x# , y# , z# , lim , ax ) glTranslatef( x# , y# , z# ) if ax = xyz then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) elseif ax = xzy then glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = yxz then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 2 ) elseif ax = yzx then glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) elseif ax = zxy then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) elseif ax = zyx then glrotatef( sk#( lim )( 2 ) , 0 , 0 , 1 ) glrotatef( sk#( lim )( 1 ) , 0 , 1 , 0 ) glrotatef( sk#( lim )( 0 ) , 1 , 0 , 0 ) else end if end sub function pend#( fase# , amp# ) return sind( fase# ) * amp# end function const leftno = 0 const arm = 1 const elbow = 2 const wrist = 3 const leg = 4 const knee = 5 const enkle = 6 const neck = 7 const thumb = 8 const index_finger = 11 const middle_finger = 14 const ring_finger = 17 const pinky_finger = 20 const tail = 25
const iarm = 1 const ielbow = 2 const iwrist = 3 const ileg = 4 const iknee = 9 const iwing = 14 const itail = 16 const isensor = 17 const ithumb = 18 const ifinger = 19
const rightno = 32 sub finger( lim ) '' part of human robot avatar setbox( 0 , -2 , 0 , 1 , 1 , 1 ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 1 , xyz ) cube() glpushmatrix() child( 0 , -2 , 0 , lim + 2 , xyz ) cube() glpopmatrix() glpopmatrix() end sub sub hand( lr , kl#() ) '' part of human robot avatar material.diffuse = kl# MATERIAL.AMBIENT = KL# material_use( gl_frONT , material ) setbox( 0 , -4 , 0 , 1 , 4 , 3 ) cube() glpushmatrix() child( 0 , -8 , 1.5 , lr + index_finger , zxy ) finger( lr + index_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , .5 , lr + middle_finger , zxy ) finger( lr + middle_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , -.5 , lr + ring_finger , zxy ) finger( lr + ring_finger ) glpopmatrix() glpushmatrix() child( 0 , -8 , -1.5 , lr + pinky_finger , zxy ) finger( lr + pinky_finger ) glpopmatrix() glpushmatrix() child( 0 , -1 , 3.5 , lr + thumb , zxy ) finger( lr + thumb ) glpopmatrix() end sub sub human_robot( h , kl#() , klh#() ) material.diffuse = kl# material.ambient = kl# material_use( gl_front , material ) 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 + rightno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + rightno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + rightno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( -.45 , 0 , 0 , leg + leftno , zyx ) setbox( 0 , -.6 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , knee + leftno , xyz ) cube() glPushMatrix() child( 0 , -1.2 , 0 , enkle + leftno , xyz ) setbox( 0 , 0 , .2 , .1 , .1 , .3 ) cube() glPopMatrix() glPopMatrix() glPopMatrix() glPushMatrix() child( .65 , 1.3 , 0 , arm + rightno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + rightno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + rightno , zyx ) glscalef( .1 , .1 , .1 ) hand( rightno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() material.diffuse = kl# material.ambient = kl# material_use( gl_front , material ) glPushMatrix() child( -.65 , 1.3 , 0 , arm + leftno , xyz ) setbox( 0 , -.5 , 0 , .1 , .4 , .1 ) cube() glPushMatrix() child( 0 , -1 , 0 , elbow + leftno , xyz ) cube() glPushMatrix() child( 0 , -1 , 0 , wrist + leftno , zyx ) glscalef( .1 , .1 , .1 ) hand( leftno , klh# ) glPopMatrix() glPopMatrix() glPopMatrix() end sub
sub bug_robot( kl#() ) material.diffuse = kl# material.ambient = kl# material_use( gl_front , material ) Dim i as integer glPushmatrix() glScaled( .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 + rightno + 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 + rightno + 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 + leftno + 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 + leftno + i + 1, xyz) setbox( 0.0, -30.0, 0.0, 5.0, 30.0, 5.0) Cube() glPopmatrix() glPopMatrix() Next glPushMatrix() child( 0 , 0 , -50 , itail + rightno, xyz) For i = 0 To 9 glPushMatrix() child( 0.0, 0.0, -30.0 , itail + rightno , 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 , itail + leftno , xyz ) cube() next :i for i = 0 to 8 glPopMatrix() glPopMatrix() next :i glPopMatrix() glPushMatrix() child( 30.0, 0.0, 65.0, iarm + rightno, xyz) setbox( 0.0, 0.0, 65.0 , 5 , 5 , 30 ) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, ielbow + rightno, xyz ) Cube() glPushmatrix() child( 0.0, 0.0, 65.0 , iwrist + rightno, xyz) glPushmatrix() child(-10.0, 0.0, 5.0 , ithumb + rightno, xyz) Cube() glPopMatrix() glPushMatrix() child( 5.0, 0.0, 5.0, ifinger+ rightno, 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, iarm + leftno, xyz) setbox( 0.0, 0.0, 30.0, 5.0, 5.0, 30.0) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, ielbow +leftno, xyz) Cube() glPushMatrix() child( 0.0, 0.0, 65.0, iwrist+leftno, xyz) glPushMatrix() child( 10.0, 0.0, 5.0, ithumb+leftno, xyz) Cube() glPopMatrix() glPushMatrix() child(-5.0, 0.0, 5.0, ifinger+leftno, 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, iwing + rightno+ 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 , iwing+leftno + i, xyz) setbox( -60.0, 0.0, 8.0, 60.0, 2.0, 16.0) Cube() glPopmatrix() Next glPopMatrix() end sub
const human_walk = 0 const dog_walk = 1 const I_FLY = 3 const I_LEFT_LEGS = 4 const I_LEFT_BOX = 5 const I_RIGHT_LEGS = 6 const I_RIGHT_BOX = 7 const I_STING = 8 const I_STAND = 9
sub animate( anim , fase# , amp# ) dim i if anim = human_walk then skelet( arm + rightno, pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + rightno, -abs( amp# ) , 0 , 0 ) skelet( arm + leftno , pend#( fase# + 180, amp# ) , 0 , 0 ) skelet( elbow + leftno , -abs( amp# ) , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( thumb + rightno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) skelet( thumb + leftno , -pend#( fase# , 10 ) - 10 , 0 , 0 ) for i = 0 to 2 skelet( pinky_finger + rightno + i , 0 , 0 , -pend#( fase# + 60 , 10 ) - 10 ) skelet( index_finger + rightno + i , 0 , 0 , -pend#( fase# + 30 , 10 ) - 10 ) skelet( middle_finger + rightno + i , 0 , 0 , -pend#( fase# , 10 ) - 10 ) skelet( ring_finger + rightno + i , 0 , 0 , -pend#( fase# - 30 , 10 ) - 10 ) skelet( pinky_finger + leftno + 1 , 0 , 0 , pend#( fase# + 60 , 10 ) + 10 ) skelet( index_finger + leftno + i , 0 , 0 , pend#( fase# + 30 , 10 ) + 10 ) skelet( middle_finger + leftno + i , 0 , 0 , pend#( fase# , 10 ) + 10 ) skelet( ring_finger + leftno + i , 0 , 0 , pend#( fase# - 30 , 10 ) + 10 ) next : i else if anim = dog_walk then skelet( arm + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( elbow + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( arm + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( elbow + leftno, pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + rightno , pend#( fase# + 180 , amp# ) , 0 , 0 ) skelet( knee + rightno , pend#( fase# + 90 , amp# ) + amp# , 0 , 0 ) skelet( leg + leftno , pend#( fase# , amp# ) , 0 , 0 ) skelet( knee + leftno , pend#( fase# - 90 , amp# ) + amp# , 0 , 0 ) skelet( tail , -45 , pend#( fase# * 2 , 30 ) , 0 ) skelet( neck + rightno , 0 , 0 , 0 ) skelet( neck + leftno , 0 , 0 , 0 ) elseif anim = I_FLY then For i = 0 To 1 skelet( iwing + rightno + i , 0 , 0 , Pend#( fase# , amp# ) ) skelet( iwing + leftno + i , 0 , 0 , Pend#( fase# , -amp# ) ) Next: elseif anim = I_LEFT_BOX then skelet( iarm + rightno , 0 , Pend#( fase# , -amp# ) + 45 , 0 ) skelet( ielbow + rightno , 0 , Pend#( fase# , amp# * 2 ) - 60 , 0 ) elseif anim = I_LEFT_LEGS then For i = 0 To 4 skelet( ileg + leftno + i , 0 , 0 , Pend#( fase# + i * 180 , amp# ) ) skelet( iknee + leftno + i , Pend#( fase# + i * 180 + 90 , amp# ) , 0 , 0 ) Next: elseif anim = I_RIGHT_BOX then skelet( iarm + rightno , 0 , Pend#( fase#, amp# ) - 45,0 ) skelet( ielbow + rightno , 0 , Pend#( fase# , -amp# * 2) + 60, 0 ) elseif anim = I_RIGHT_LEGS then For i = 0 To 4 skelet( ileg + rightno + i , 0 , 0 , Pend#( fase# + i * 180 , amp# ) ) skelet( iknee + rightno + i , Pend#( fase# + i * 180 + 90 , amp# ) , 0 , 0 ) Next: elseif anim = I_STAND then skelet( iarm + rightno , 0, 45, 0 ) skelet( ielbow + rightno , 0, -60 , 0 ) skelet( ifinger + rightno , 0, 0, 0 ) skelet( ithumb + rightno , 0, 0, 0 ) skelet( iarm + leftno , 0 , -45 , 0 ) skelet( ielbow + leftno , 0 , 60 , 0 ) skelet( ifinger + leftno , 0 , 0 , 0 ) skelet( ithumb + leftno , 0 , 0 , 0 ) skelet( itail + rightno , 10 , 0 , 0 ) skelet( itail + leftno , 10 , 0 , 0 ) elseif anim = I_STING then skelet( itail + rightno , 10 + Pend#( fase# , amp# ) , 0 , 0 ) skelet( itail + leftno , 10 - Pend#( fase# , amp# ) , 0 , 0 ) else for i = 0 to 63 skelet( i , 0 , 0 , 0 ) next: i end if end if end sub dim orange#( 3 ) = vec4( 1 , .5 , 0 , 1 ) sub tree( i as integer , prog as string , f as double , x as double , y as double , z as double , kl#() ) dim q , t , w$ '' 1 < i < 7 '' 0 < f < 1 ''prog : no[ = no] and [ left of ] if i > 0 then for q = 1 to len( prog ) w$ = mid$( prog , q , 1 ) if w$ = "f" then ''draw trunk or twig and move pen material.diffuse = orange# material.ambient = orange# material_use( gl_front_AND_BACK , material ) setbox( 0 , 1 , 0 , .3,1,.3 ) '' cilinder( 6 , .3 * f , .3 * f , 1 , 1 ) cube() gltranslated( 0 , 2 , 0 ) elseif w$ = "l" then ''draw leaf material.diffuse = green# material.ambient = green# material_use( gl_front_and_back , material ) glpushmatrix() glscaled( .5 , .5 , .5 ) setpoint( 0 , 0 , 0 , 0 ) setpoint( 1 , 1 , 0 , 1 ) setpoint( 2 , 3 , 0 , 0 ) setpoint( 3 , 1 , 0 , -1 ) quad( 0 , 1 , 2 , 3 ) glpopmatrix() elseif w$ = "L" then ''draw set of leaves material.diffuse = green# material.ambient = green# material_use( gl_front_and_back , material ) for t = 0 to 4 glpushmatrix() glrotated( 72 * t , 0 , 1 , 0 ) glscaled( .5 , .5 , .5 ) setpoint( 0 , 0 , 0 , 0 ) setpoint( 1 , 1 , 0 , 1 ) setpoint( 2 , 3 , 0 , 0 ) setpoint( 3 , 1 , 0 , -1 ) quad( 0 , 1 , 2 , 3 ) glpopmatrix() next : t elseif w$ = "h" then ''draw a flower material.diffuse = kl# material.ambient = kl# material_use( gl_front_and_back , material ) for t = 0 to 4 glpushmatrix() glscaled( .5 , .5 , .5 ) glrotated( 72 * t , 0 , 1 , 0 ) setpoint( 0 , 0 , 0 , 0 ) setpoint( 1 , 1 , 1 , 1 ) setpoint( 2 , 3 , 3 , 0 ) setpoint( 3 , 1 , 1 , -1 ) quad( 0 , 1 , 2 , 3 ) glpopmatrix() next : t elseif w$ = "g" then ''move pen gltranslated( 0 , 2 , 0 ) elseif w$ = "[" then ''store x,y,z glpushmatrix() elseif w$ = "]" then ''read x,y,z glpopmatrix() elseif w$ = "X" then glrotated( x , 1,0,0 ) elseif w$ = "x" then glrotated( -x , 1,0,0 ) elseif w$ = "Y" then glrotated( y , 0,1,0 ) elseif w$ = "y" then glrotated( -y , 0,1,0 ) elseif w$ = "Z" then glrotated( z , 0,0,1 ) elseif w$ = "z" then glrotated( -z , 0,0,1 ) elseif w$ = "b" then ''draw hole tree smaler glscaled( f,f,f ) tree( i - 1 , prog , f,x,y,z,kl# ) else end if next : q end if end sub
dim frame# while true glclear( GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT ) glLoadidentity() glpushmatrix() gltranslatef( 5 , 0 , -10 ) glrotatef( frame# / 10 , 0 , 1 , 0 ) animate( 13 , 0 , 0 ) animate( human_walk , frame# , 30.0 ) human_robot( 1 , cyan# , white# ) glpopmatrix() glpushmatrix() gltranslated( 0 , -2 , -10 ) glrotatef( frame# / 5 , 0 , 1 , 0 ) tree( 4 , "f[xybLh]XybLh" , .7 , 45 , 90 , 30 , white# ) '' setbox( 0,0,0 , 1,1,1 ) '' cilinder( 64 , 1 , 1 , 1 , 1 ) glpopmatrix() glpushmatrix() gltranslatef( -5 , 0 , -10 ) glrotatef( -frame# / 10 , 0 , 1 , 0 ) animate( 13 , 0 , 0 ) animate( i_stand , 0 , 0 ) animate( i_sting , frame# , 7 ) bUg_robot( magenta# ) glpopmatrix() swapbuffers() sleep( 40 ) frame# = frame# + 10 wend
|
|