|
Post by Rod on Apr 14, 2018 7:35:21 GMT -5
I had a quick browse to see if anyone had managed to find a "copy code" plugin but I am not finding anything. I am sure it could be coded but right now we are reluctant to move too far from plain vanilla. So we are just using the functionality the forum offers.
Probably hosting and linking to a .zip would be best for your OpenGL code. That way you can include bmps of the output in the .zip.
|
|
|
Post by bluatigro on Apr 17, 2018 3:49:38 GMT -5
can't i do what i did in my first post's : place a *.bas as attachment ? that wil solve a lot of problem's and i don't know how to zip a *.bas
i m not ready to do light and material and texture's i can't even do in freeB so i don't have the need jet to include a *.bmp
|
|
|
Post by Rod on Apr 17, 2018 4:02:43 GMT -5
Well we have found a fix so please just keep posting between the code tags. Chris has managed to code a plugin that now scrolls text in the code box. That fixes the problem because we don't need to scroll past long code anymore. We just scroll the code box if we have an interest.
We are finding our feet, but it is all coming together.
|
|
|
Post by bluatigro on Apr 26, 2018 7:36:41 GMT -5
update : empty game
this can be used to build your game whit openGL
the mesh's i kept in if you need more mesh's pleace ask
if you need to build a animated avartar see old post's or ask if you need to know how to animate a avartar see old post's or ask
i have a problem : i do not get my world to be smal in the distance does anyone know how to do that ?
''bluatigro 26 apr 2018 ''empty openGL | bluaGL game
global GL.COLOR.BUFFER.BIT : GL.COLOR.BUFFER.BIT = 16384 global GL.DEPTH.BUFFER.BIT : GL.DEPTH.BUFFER.BIT = 256 global GL.DEPTH.TEST : GL.DEPTH.TEST = 2929 global GL.PROJECTION : GL.PROJECTION = 5889 global GL.MODELVIEW : GL.MODELVIEW = 5888 global GL.SMOOTH : GL.SMOOTH = 7425 global GL.CULL.FACE : GL.CULL.FACE = 2884 ' primatifs global GL.POINTS : GL.POINTS = 0 global GL.LINES : GL.LINES = 1 global GL.LINE.STRIP : GL.LINE.STRIP = 3 global GL.LINE.LOOP : GL.LINE.LOOP = 2 global GL.LINE.STIPPLE : GL.LINE.STIPPLE = 2852 global GL.TRIANGLES : GL.TRIANGLES = 4 global GL.TRIANGLE.FAN : GL.TRIANGLE.FAN = 6 global GL.TRIANGLE.STRIP : GL.TRANGLE.STRIP = 5 global GL.QUADS : GL.QUADS = 7 global GL.QUAD.STRIP : GL.QUAD.STRIP = 8 ' light + material global GL.COLOR.MATERIAL : GL.COLOR.MATERIAL = 2903 Global GL.LIGHTING : GL.LIGHTING = 2896 Global GL.LIGHT0 : GL.LIGHT0 = 16384 Global GL.AMBIENT : GL.AMBIENT = 4608 Global GL.DIFFUSE : GL.DIFFUSE = 4609 Global GL.SPECULAR : GL.SPECULAR = 4610 Global GL.SHININESS : GL.SHININESS = 5633 Global GL.EMISSION : GL.EMISSION = 5632 Global GL.POSITION : GL.POSITION = 4611 global GL.SPOT.DIRCTION : GL.SPOT.DIRECTION = 4612 global GL.SPOT.EXPONENT : GL.SPOT.EXPONENT = 4613 global GL.SPOT.CUTOFF : GL.SPOT.CUTOFF = 4614 global GL.CONSTANT.ATTENUATION GL.CONSTANT.ATTENUATION = 4615 global GL.LINEAR.ATTENUATION GL.LINEAR.ATTENUATION = 4616 global GL.QUADRATIC.ATTENUATION GL.QUADRATIC.ATTENUATION = 4617 global GL.FRONT : GL.FRONT = 1028 Global GL.FRONT.AND.BACK : GL.FRONT.AND.BACK = 103 '' Fog Global GL.FOG : GL.FOG = 2912 Global GL.FOG.MODE : GL.FOG.MODE = 2917 Global GL.FOG.DENSITY : GL.FOG.DENSITY = 2914 Global GL.FOG.COLOR : GL.FOG.COLOR = 2918 Global GL.FOG.INDEX : GL.FOG.INDEX = 2913 Global GL.FOG.START : GL.FOG.START = 2915 Global GL.FOG.END : GL.FOG.END = 2916 Global GL.LINEAR : GL.LINEAR = 9729 Global GL.EXP : GL.EXP = 2048 Global GL.EXP2 : GL.EXP2 = 2049 ''bluaGL const's ''colorObject's global black , red , green , yellow global blue , magenta , cyan , white global gray , pink , purple , orange black = rgba( 000 , 000 , 000 , 255 ) red = rgba( 255 , 000 , 000 , 255 ) green = rgba( 000 , 255 , 000 , 255 ) yellow = rgba( 255 , 255 , 000 , 255 ) blue = rgba( 000 , 000 , 255 , 255 ) magenta = rgba( 255 , 000 , 255 , 255 ) cyan = rgba( 000 , 255 , 255 , 255 ) white = rgba( 255 , 255 , 255 , 255 ) gray = rgba( 127 , 127 , 127 , 255 ) pink = rgba( 255 , 127 , 127 , 255 ) purple = rgba( 127 , 000 , 127 , 255 ) orange = rgba( 255 , 127 , 000 , 255 ) ''for joint angle control global xyz , xzy , yxz , yzx , zxy , zyx xyz = 0 xzy = 1 yxz = 2 yzx = 3 zxy = 4 zyx = 5 global pi pi = atn( 1 ) * 4 WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , winyx winx = WindowWidth winy = WindowHeight winyx = winy / winx
global false , true false = 0 true = not( false )
global mouse.x , mouse.y , key$
global MainH , MainDC ''wil be filled by code
global angle ''for animation's global state open "opengl32.dll" for dll as #gl menu #m , "info" , "instruction's" , [info] if instr( Platform$ , "LBB" ) then open "openGL" for window as #m else open "openGL" for graphics as #m end if #m "trapclose [quit]" #m "when characterInput [key]" #m "when mouseMove [mouse.move]" #m "setfocus" MainH = hwnd( #m ) gosub [openGL] gosub [bluaGL] call openglInit call camera.set 0 , 0 , 0 , 0 state = -1 timer 40 , [timer] wait [timer] scan call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT call camera.use call glScale winyx , 1 , 1
''only change code below this [ exept you are sure what you do ] ''use camera.move dx , dy , dz , dpan ''to steer camera ''use key$ and mouse.x and mouse.y ''for controling thing's
''this is only there to test things call glPushMatrix call glRotate angle , 0 , 0 , 1 call glBegin GL.TRIANGLES call setcolor red call glVertex 0 , .5 , 0 call setcolor green call glVertex .5 , -.5 , 0 call setcolor blue call glVertex -.5 , -.5 , 0 call glEnd call glPopMatrix if key$ = chr$( _VK_LEFT ) then angle = angle + 1 end if if key$ = chr$( _VK_RIGHT ) then angle = angle - 1 end if key$ = ""
''only change code above this [ exept you are sure what you do ]
calldll #gdi32,"SwapBuffers" _ , MainDC as ulong _ , ret as long wait
[key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( 27 ) then wait [quit] calldll #gl , "wglMakeCurrent" _ , 0 as ulong , 0 as ulong , ret as long calldll #gl , "wglDeleteContext" _ , GLContext as ulong, ret as long calldll #user32 , "ReleaseDC" _ , MainH as ulong , MainDC as ulong , ret as long close #m close #gl end
[bluaGL] ''wrapper around openGL ''for creating mesh's dim pntx( 256 ) , pnty( 256 ) , pntz( 256 ) ''for bounding box for mesh's dim box( 5 ) ''for joint's dim sk( 64 , 2 ) ''for vertor3d output global v3d.x,v3d.y,v3d.z ''for camera global camera.x , camera.y , camera.z , camera.pan ''for light and material struct d4d _ , a as double _ , b as double _ , c as double _ , d as double
return
sub camera.set x , y , z , pan ''set camera position and angle camera.x = x camera.y = y camera.z = z camera.pan = pan end sub
sub camera.move dx , dy , dz , dpan ''change camera positon and angle call rotate dx , dz , camera.pan camera.x = camera.x + dx camera.y = camera.y + dy camera.z = camera.z + dz camera.pan = ( camera.pan + pan ) mod 360 end sub
sub camera.use ''use camera position and angle call glLoadIdentity call glRotate 0-camera.pan , 0,1,0 call glTranslate 0-camera.x , 0-camera.y , 0-camera.z end sub
sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub
function rainbow( x ) ''create a colorObject from a rainbow r = sin( rad( x ) ) * 127 + 128 g = sin( rad( x - 120 ) ) * 127 + 128 b = sin( rad( x + 120 ) ) * 127 + 128 rainbow = rgba( r , g , b , 255 ) end function
function rgba( r , g , b , a ) ''create colorObject r = r and 255 g = g and 255 b = b and 255 a = a and 255 rgba = r + g * 256 + b * 256 ^ 2 + a * 256 ^ 3 end function
function mix( kl1 , f , kl2 ) ''mix 2 colorObject's r1 = int( kl1 ) and 255 g1 = int( kl1 / 256 ) and 255 b1 = int( kl1 / 256 ^ 2 ) and 255 a1 = int( kl1 / 256 ^ 3 ) and 255 r2 = int( kl2 ) and 255 g2 = int( kl2 / 256 ) and 255 b2 = int( kl2 / 256 ^ 2 ) and 255 a2 = int( kl2 / 256 ^ 3 ) and 255 r = r1 + ( r2 - r1 ) * f g = g1 + ( g2 - g1 ) * f b = b1 + ( b2 - b1 ) * f a = a1 + ( a2 - a1 ) * f mix = rgba( r , g , b , a ) end function
sub setColor clr r = ( int( clr ) and 255 ) / 256 g = ( int( clr / 256 ) and 255 ) / 256 b = ( int( clr / 256 ^ 2 ) and 255 ) / 256 a = ( int( clr / 256 ^ 3 ) and 255 ) / 256 call glColor r , g , b , a end sub
'' vector math
function v3d.lenght( x , y , z ) v3d.lenght = sqr( x ^ 2 + y ^ 2 + z ^ 2 ) end function
sub v3d x , y , z ''constructor v3d.x = x v3d.y = y v3d.z = z end sub
sub v3d.cross x1 , y1 , z1 , x2 , y2 , z2 ''cross product call v3d y1 * z2 - y2 * z1 _ , z1 * x2 - z2 * x1 _ , x1 * y2 - x2 * y1 end sub
sub v3d.add x1,y1,z1 , x2,y2,z2 ''v3d = v1 + v2 call v3d x1 + x2 , y1 + y2, z1 + z2 end sub
sub v3d.sub x1,y1,z1 , x2,y2,z2 ''v3d = v1 - v2 call v3d x1 - x2 , y1 - y2 , z1 - z2 end sub
sub v3d.div x1,y1,z1 , d ''v3d = v1 / d call v3d x1 / d , y1 / d , z1 / d end sub
sub v3d.mul x1,y1,z1 , d ''v3d = v1 * d call v3d x1 * d , y1 * d , z1 * d end sub
sub v3d.normalize x , y , z ''v3d = v / |v| q = v3d.lenght( x , y , z ) + 1e-9 call v3d.div x , y , z , q end sub
''3d engine
sub child x , y , z , lim , ax ''create a joint of a avatar if lim < 0 or lim > 64 then exit sub call glTranslate x , y , z select case ax case xyz call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 case xzy call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 case yxz call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 case yzx call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 case zxy call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 case zyx call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 case else end select end sub
sub skelet no , x , y , z ''set joint angle's of a avatar if no < 0 or no > 64 then exit sub sk( no , 0 ) = x sk( no , 1 ) = y sk( no , 2 ) = z end sub
function pend( f , a ) ''for smooth animation's pend = sin( rad( f ) ) * a end function
function rad( x ) ''from degrees to radians rad = x * pi / 180 end function
function rad2( x , sides ) rad2 = x * pi * 2 / sides end function
function sgn( x ) uit = 0 if x < 0 then uit = -1 if x > 0 then uit = 1 sgn = uit end function
''shapes
sub setbox mx , my , mz , dx , dy , dz ''set bodinging box coordinates ''alway set this before drawing mesh's box( 0 ) = mx box( 1 ) = my box( 2 ) = mz box( 3 ) = dx box( 4 ) = dy box( 5 ) = dz end sub
sub isoca no , kl1 , kl2 call point 0 , 1,0,0 call point 1 , 0,1,0 call point 2 , 0,0,1 call point 3 , -1,0,0 call point 4 , 0,-1,0 call point 5 , 0,0,-1 call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) call geo no , 0 , 1 , 2 , kl1 , kl2 call geo no , 0 , 1 , 5 , kl2 , kl1 call geo no , 0 , 4 , 2 , kl2 , kl1 call geo no , 0 , 4 , 5 , kl1 , kl2 call geo no , 3 , 1 , 2 , kl2 , kl1 call geo no , 3 , 1 , 5 , kl1 , kl2 call geo no , 3 , 4 , 2 , kl1 , kl2 call geo no , 3 , 4 , 5 , kl2 , kl1 call glPopMatrix end sub
sub geo no , p1 , p2 , p3 , kl1 , kl2 if no < 1 then call tri p1 , p2 , p3 , kl1 else p12 = 255 - no * 3 p13 = 255 - no * 3 - 1 p23 = 255 - no * 3 - 2 x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) call v3d.add x1,y1,z1 , x2,y2,z2 call v3d.normalize v3d.x,v3d.y,v3d.z call point p12 , v3d.x , v3d.y , v3d.z call v3d.add x1,y1,z1 , x3,y3,z3 call v3d.normalize v3d.x,v3d.y,v3d.z call point p13 , v3d.x , v3d.y , v3d.z call v3d.add x2,y2,z2 , x3,y3,z3 call v3d.normalize v3d.x,v3d.y,v3d.z call point p23 , v3d.x , v3d.y , v3d.z call geo no - 1 , p1 , p12 , p13 , kl1 , kl2 call geo no - 1 , p2 , p23 , p12 , kl1 , kl2 call geo no - 1 , p3 , p13 , p23 , kl1 , kl2 call geo no - 1 , p12 , p23 , p13 , kl2 , kl1 end if end sub
sub oneColorCube cleftno ''draw a cube mesh whit i color shaded a = mix( cleftno , .6 , black ) b = mix( cleftno , .3 , black ) call cube b,b,cleftno,cleftno,a,a end sub
sub colorCube ''draw a cube mesh whit fixed color's on screen call cube red,cyan , green,magenta , blue,yellow end sub
sub cube left , right , front , back , down , up ''draw a cube mesh on screen
''first fil swarm whit points call point 0 , -1 , -1 , -1 call point 1 , -1 , -1 , 1 call point 2 , -1 , 1 , -1 call point 3 , -1 , 1 , 1 call point 4 , 1 , -1 , -1 call point 5 , 1 , -1 , 1 call point 6 , 1 , 1 , -1 call point 7 , 1 , 1 , 1
''then use points in swarm to draw quads call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) call quad 0 , 1 , 3 , 2 , left call quad 7 , 6 , 4 , 5 , right call quad 0 , 2 , 6 , 4 , down call quad 7 , 5 , 1 , 3 , up call quad 0 , 1 , 5 , 4 , front call quad 7 , 6 , 2 , 3 , back call glPopMatrix end sub
sub sphere a , b , da , db , kl1 , kl2 ''draw a sphere mesh on screen ''a = horizontal sides ''b = vertical sides ''da , db = superellipsoid [ 1 , 1 = sphere ] call sphere.half a , b , b , da , db , kl1 , kl2 end sub
sub sphere.half a , b , t , da , db , kl1 , kl2 ''draw a part of a sphere mesh on screen ''a = horizontal sides ''b = vertical sides ''da , db = superellipsoid [ 1 , 1 = sphere ] ''t = height sides if a < 4 then a = 4 if a > 64 then a = 64 if b < 4 then b = 4 if b > 64 then b = 64 call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) for i = 0-pi to pi step pi*2/a i2 = i + pi*2/a for j = 0-pi / 2 to t/b*pi step pi*2/b j2 = j + pi*2/b
x = sin( i ) * cos( j ) y = sin( j ) z = cos( i ) * cos( j ) call point 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 ) call point 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 ) call point 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 ) call point 3 _ , abs( x ) ^ da * sgn( x ) _ , abs( y ) ^ db * sgn( y ) _ , abs( z ) ^ da * sgn( z )
if ( int(i*a/pi/2) + int(j*b/pi/2) ) and 1 then call quad 0 , 1 , 2 , 3 , kl1 else call quad 0 , 1 , 2 , 3 , kl2 end if
next j next i call glPopMatrix end sub
sub torus a , b , kl1 , kl2 ''draw a donut mesh on screen ''a , b = sides if a < 4 then a = 4 if a > 64 then a = 643 if b < 4 then b = 4 if b > 64 then b = 64 mx = box(0) my = box(1) mz = box(2) dx = box(3) dy = box(4) dz = box(5) for i = 0-pi to pi step pi*2/a i2 = i + pi*2/a for j = 0-pi to pi step pi*2/b j2 = j + pi*2/a call point 0 _ , mx + ( dx + dy * cos( i ) ) * cos( j ) _ , my + ( dx + dy * cos( i ) ) * sin( j ) _ , mz + sin( i ) * dz call point 1 _ , mx + ( dx + dy * cos( i ) ) * cos( j2 ) _ , my + ( dx + dy * cos( i ) ) * sin( j2 ) _ , mz + sin( i ) * dz call point 2 _ , mx + ( dx + dy * cos( i2 ) ) * cos( j2 ) _ , my + ( dx + dy * cos( i2 ) ) * sin( j2 ) _ , mz + sin( i2 ) * dz call point 3 _ , mx + ( dx + dy * cos( i2 ) ) * cos( j ) _ , my + ( dx + dy * cos( i2 ) ) * sin( j ) _ , mz + sin( i2 ) * dz
if ( int(i*a/pi/2) + int(j*b/pi/2) ) and 1 then call quad 0 , 1 , 2 , 3 , kl1 else call quad 0 , 1 , 2 , 3 , kl2 end if
next j next i end sub
sub banana a , b , kl1 , kl2 ''draw a 'banana' mesh on screen ''a , b = sides if a < 4 then a = 4 if a > 64 then a = 643 if b < 4 then b = 4 if b > 64 then b = 64 mx = box(0) my = box(1) mz = box(2) dx = box(3) dy = box(4) dz = box(5) for i = 0-pi to pi-pi*2/a step pi*2/a i2 = i + pi*2/a for j = 0-pi/2 to pi/2-pi/a step pi/b j2 = j + pi/b call point 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 ) call point 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 ) call point 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 ) call point 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 )
if ( int(i*a/pi/2) + int(j*b/pi/2) ) and 1 then call quad 0 , 1 , 2 , 3 , kl1 else call quad 0 , 1 , 2 , 3 , kl2 end if
next j next i end sub
sub cilinder sides , dx , dz , top , bottom , kl1 , kl2 ''draw a cilinder mesh on screen ''dx , dz = diam at top : so you can make cone's ''top , bottom = iscapped if sides < 4 then sides = 4 if sides > 64 then sides = 64 for f = 0 to sides + 2 call point f _ , box(0) + sin( f * pi * 2 / sides ) * box(3) _ , box(1) - box(4) _ , box(2) + cos( f * pi * 2 / sides ) * box(5) call point f + sides + 1 _ , box(0) + sin( f * pi * 2 / sides ) * dx _ , box(1) + box(4) _ , box(2) + cos( f * pi * 2 / sides ) * dz next f for f = 0 to sides + 1 if f and 1 then call quad f , f + 1 , f + 2 + sides _ , f + 1 + sides , kl1 else call quad f , f + 1 , f + 2 + sides _ , f + 1 + sides , kl2 end if next f if top then for f = 0 to sides call point f _ , box(0) + sin( f * pi * 2 / sides ) * dx _ , box(1) + box(4) _ , box(2) + cos( f * pi * 2 / sides ) * dy next f call polygon sides , kl1 end if if bottom then for f = 0 to sides call point f _ , box(0) - sin( f * pi * 2 / sides ) * box(3) _ , box(1) - box(4) _ , box(2) + cos( f * pi * 2 / sides ) * box(5) next f call polygon sides , kl2 end if end sub
sub cube.half kl1 , kl2 ''draw a half cube mesh on screen call point 0 , box(0) + box(3) , box(1) + box(4) , box(2) + box(5) call point 1 , box(0) + box(3) , box(1) + box(4) , box(2) - box(5) call point 2 , box(0) + box(3) , box(1) - box(4) , box(2) + box(5) call point 3 , box(0) + box(3) , box(1) - box(4) , box(2) - box(5) call point 4 , box(0) - box(3) , box(1) + box(4) , box(2) + box(5) call point 5 , box(0) - box(3) , box(1) + box(4) , box(2) - box(5) call point 6 , box(0) - box(3) , box(1) - box(4) , box(2) + box(5) call point 7 , box(0) - box(3) , box(1) - box(4) , box(2) - box(5)
call point 0 , box(0) + box(3) , box(1) - box(4) , 0 call point 8 , box(0) + box(3) , 0 , box(2) - box(5) call point 9 , 0 , box(1) + box(4) , box(2) - box(5) call point 10 , box(0) - box(3) , box(0) + box(4) , 0 call point 11 , box(0) - box(3) , 0 , box(2) + box(5) call point 12, 0 , box(1) - box(4) , box(2) + box(5)
call tri 7 , 6 , 3 , kl1 call tri 7 , 5 , 6 , kl1 call tri 7 , 3 , 5 , kl1
call quad 6 , 5 , 10 , 11 , kl2 call quad 5 , 3 , 8 , 9 , kl2 call quad 3 , 6 , 12 , 0 , kl2
call tri 6 , 12 , 11 , kl1 call tri 3 , 8 , 0 , kl1 call tri 5 , 9 , 10 , kl1 end sub
''primativ's wrapper
sub setcolor kl r = int( kl ) and 255 g = int( kl / 256 ) and 255 b = int( kl / 256 ^ 2 ) and 255 a = int( kl / 256 ^ 3 ) and 255 call glColor r , g , b , a end sub
sub point no , x , y , z ''set a point in the swarm ''for creating mesh's if no < 0 or no > 256 then exit sub pntx( no ) = x pnty( no ) = y pntz( no ) = z end sub
sub points x , y , z , size , kl ''draw a point on screen call glPointSize size call glBegin GL.POINTS call setColor kl call glVertex x , y , z call glEnd end sub
sub lines x1,y1,z1 , x2,y2,z2 , w , style , kl ''draw a line on screen ''w = width ''style = 16 bits : 2 ^ 16 - 1 = solid call glLineWidth w call glEnable GL.LINE.STIPPLE call glLineStipple style call glBegin GL.LINES call setColor kl call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glEnd end sub
sub line.strip n , w , style , kl ''draw a set of lines connected to eats other ''n = max number of point filled ''w = width ''style = 16 bits : 2 ^ 16 - 1 = solid call glLineWidth w call glEnable GL.LINE.STIPPLE call glLineStipple style call glBegin GL.LINE.STRIP call setColor kl for i = 0 to n call glVertex pntx(i) , pnty(i) , pntz(i) next i call glEnd end sub
sub line.loop n , w , style , kl ''draw a set of lines last linked whit first ''n = max number of point filled ''w = width ''style = 16 bits : 2 ^ 16 - 1 = solid call glLineWidth w call glEnable GL.LINE.STIPPLE call glLineStipple style call glBegin GL.LINE.LOOP call setColor kl for i = 0 to n call glVertex pntx(i) , pnty(i) , pntz(i) next i call glEnd end sub
sub tri p1 , p2 , p3 , kl ''draw a triangle from point's in swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) call v3d.cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.TRIANGLES call setColor kl call glNormal v3d.x , v3d.y , v3d.z call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glEnd end sub
sub quad p1 , p2 , p3 , p4 , kl ''draw a quadangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub if p4 < 0 or p4 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) x4 = pntx( p4 ) y4 = pnty( p4 ) z4 = pntz( p4 ) call v3d.cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.QUADS call setColor kl call glNormal v3d.x , v3d.y , v3d.z call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glVertex x4 , y4 , z4 call glEnd end sub
sub triangle.fan n , kl ''draw a triangle fan from point's in swarm ''n = max number of point filled ''i m not sure about this if n < 2 or n > 256 then exit sub x1 = pntx( 0 ) y1 = pnty( 0 ) z1 = pntz( 0 ) x2 = pntx( 1 ) y2 = pnty( 1 ) z2 = pntz( 1 ) x3 = pntx( 2 ) y3 = pnty( 2 ) z3 = pntz( 2 ) call v3d.cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.TRANGLE.FAN call setColor kl call glNormal v3d.x , v3d.y , v3d.z for i = 0 to n call glVertex pntx( i ) , pnty( i ) , pntz( i ) next i call glEnd end sub
sub triangle.strip n , kl ''draw a triangle strip from point's in swarm ''n = max number of point filled ''i m not sure about this if n < 2 or n > 256 then exit sub x1 = pntx( 0 ) y1 = pnty( 0 ) z1 = pntz( 0 ) x2 = pntx( 1 ) y2 = pnty( 1 ) z2 = pntz( 1 ) x3 = pntx( 2 ) y3 = pnty( 2 ) z3 = pntz( 2 ) call v3d.cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.TRANGLE.STRIP call setColor kl call glNormal v3d.x , v3d.y , v3d.z for i = 0 to n call glVertex pntx( i ) , pnty( i ) , pntz( i ) next i call glEnd end sub
sub quad.strip n , kl ''draw a quad strip from point's in swarm ''max number of point filled ''i m not sure about this if n < 3 or n > 256 then exit sub x1 = pntx( 0 ) y1 = pnty( 0 ) z1 = pntz( 0 ) x2 = pntx( 1 ) y2 = pnty( 1 ) z2 = pntz( 1 ) x3 = pntx( 2 ) y3 = pnty( 2 ) z3 = pntz( 2 ) call v3d.cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.QUAD.STRIP call setColor kl call glNormal v3d.x , v3d.y , v3d.z for i = 0 to n call glVertex pntx( i ) , pnty( i ) , pntz( i ) next i call glEnd end sub
sub polygon n , kl ''draw a polygon whit n sides from point's in swarm ''n max number of point filled ''this is expecting al point's in 1 plane if n < 2 or n > 256 then exit sub x1 = pntx( 0 ) y1 = pnty( 0 ) z1 = pntz( 0 ) x2 = pntx( 1 ) y2 = pnty( 1 ) z2 = pntz( 1 ) x3 = pntx( 2 ) y3 = pnty( 2 ) z3 = pntz( 2 ) call v3d.cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.POLYGON call setColor kl call glNormal v3d.x , v3d.y , v3d.z for i = 0 to n call glVertex pntx( i ) , pnty( i ) , pntz( i ) next i call glEnd end sub
[openGL] ''openGL stuf : wil be extended ''i wanted to put the openGL const's here ''but that didn't work return
sub glColor r , g , b , a calldll #gl , "glColor4d" _ , r as double _ , g as double _ , b as double _ , a as double _ , ret as long end sub
sub glClearColor r , g , b , a calldll #gl , "glClearColor" _ , r as double _ , g as double _ , b as double _ , a as double _ , ret as long end sub
sub glShadeModel i calldll #gl , "glShadeModel" _ , i as long _ , ret as long end sub
sub glMatrixMode i calldll #gl , "glMatrixMode" _ , i as long _ , ret as long end sub
sub glClear code ''clear the openGL screen calldll #gl , "glClear" _ , code as long _ , ret as long end sub
sub glPointSize i ''set size of point's calldll #gl , "glPointSize" _ , i as double _ , ret as long end sub
sub glLineWidth i ''set width of line calldll #gl , "glLineWidth" _ , i as double _ , ret as long end sub
sub glLineStipple style ''set style of line calldll #gl , "glLineStipple" _ , style as short _ , ret as long end sub
sub glLoadIdentity ''set drawingmatrix to standert calldll #gl , "glLoadIdentity" _ , ret as long end sub
sub glPushMatrix ''to new drawingmatrix calldll #gl , "glPushMatrix" _ , ret as long end sub
sub glPopMatrix ''to old drawingmatrix calldll #gl , "glPopMatrix" _ , ret as long end sub
sub glEnd ''end of polygon[s] calldll #gl , "glEnd" _ , ret as void end sub
sub glEnable i ''set a item calldll #gl , "glEnable" _ , i as long _ , ret as long end sub
sub glBegin i ''set polygon mode calldll #gl , "glBegin" _ , i as long _ , ret as long end sub
sub glScale x , y , z ''scale drawingmatrix calldll #gl , "glScaled" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glTranslate x , y , z ''move drawingmatrix calldll #gl , "glTranslated" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glRotate a , x , y , z ''rotate drawinmatrix calldll #gl , "glRotated" _ , a as double _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glVertex x , y , z ''add a point to a polygon calldll #gl , "glVertex3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glNormal x , y , z ''set normal of point[s] calldll #gl , "glNormal3f" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub openglInit struct PFD _ , Size as word _ , Version as word _ , Flags as long _ , pixelType as char[1] _ , ColorBits as char[1] _ , RedBits as char[1] _ , RedShift as char[1] _ , GreenBits as char[1] _ , GreenShift as char[1] _ , BlueBits as char[1] _ , BlueShift as char[1] _ , AlphaBits as char[1] _ , AlphaShift as char[1] _ , AccumBits as char[1] _ , AccumRedBits as char[1] _ , AccumGreenBits as char[1] _ , AccumBlueBits as char[1] _ , AccumAlphaBits as char[1] _ , DepthBits as char[1] _ , StencilBits as char[1] _ , AuxBuffers as char[1] _ , LayerType as char[1] _ , Reserved as char[1] _ , LayerMask as long _ , VisibleMask as long _ , DamageMask as long
PFD.Version.struct=1 PFD.ColorBits.struct=24 PFD.DepthBits.struct=16 PFD.Size.struct=len(PFD.struct) PFD.Flags.struct=37
calldll #user32 , "GetDC" _ , MainH as ulong , MainDC as ulong calldll #gdi32 , "ChoosePixelFormat" _ , MainDC as ulong , PFD as struct , ret as long calldll #gdi32 , "SetPixelFormat" _ , MainDC as ulong , ret as long , PFD as struct , t as long calldll #gl , "wglCreateContext" _ , MainDC as ulong , GLContext as ulong calldll #gl , "wglMakeCurrent" _ , MainDC as ulong , GLContext as ulong , ret as long call glEnable GL.DEPTH.TEST end sub
|
|
|
Post by bluatigro on Oct 5, 2018 4:57:11 GMT -5
update : try at light and material
error : al is green but shoot be grayscale
this is a animated avartar example
''bluatigro 5 0kt 2018 ''openGL light and material
dim pntx(256),pnty(256),pntz(256),box(5),sk(64,2) global pi pi = atn( 1 ) * 4 global tel
struct d4d _ , a as double _ , b as double _ , c as double _ , d as double
struct d3d _ , x as double _ , y as double _ , z as double
'' color objects
global black , red , green , yellow global blue , magenta , cyan , white global gray , pink , purple , orange global lgray , dgray black = rgba( 000 , 000 , 000 , 255 ) red = rgba( 255 , 000 , 000 , 255 ) green = rgba( 000 , 255 , 000 , 255 ) yellow = rgba( 255 , 255 , 000 , 255 ) blue = rgba( 000 , 000 , 255 , 255 ) magenta = rgba( 255 , 000 , 255 , 255 ) cyan = rgba( 000 , 255 , 255 , 255 ) white = rgba( 255 , 255 , 255 , 255 ) gray = rgba( 127 , 127 , 127 , 255 ) lgray = rgba( 181 , 181 , 181 , 255 ) dgray = rgba( 064 , 064 , 064 , 255 ) pink = rgba( 255 , 127 , 127 , 255 ) purple = rgba( 127 , 000 , 127 , 255 ) orange = rgba( 255 , 127 , 000 , 255 )
global xyz , xzy , yxz , yzx , zxy , zyx xyz = 0 xzy = 1 yxz = 2 yzx = 3 zxy = 4 zyx = 5 global arm,elbow,wrist,leg,knee,enkle,eye,left,right arm = 0 elbow = 1 wrist = 2 leg = 3 knee = 4 enkle = 5 eye = 6 global thumb,index.finger,mid.finger,ring.finger thumb = 7 index.finger = 10 mid.finger = 13 ring.finger = 16 left = 32 right = 0
'' opengl consts
global GL.COLOR.BUFFER.BIT : GL.COLOR.BUFFER.BIT = 16384 global GL.DEPTH.BUFFER.BIT : GL.DEPTH.BUFFER.BIT = 256 global GL.DEPTH.TEST : GL.DEPTH.TEST = 2929 ' primatifs global GL.TRIANGLES : GL.TRIANGLES = 4 global GL.QUADS : GL.QUADS = 7 ' light Global GL.LIGHTING: GL.LIGHTING = 2896 Global GL.LIGHT0: GL.LIGHT0 = 16384 Global GL.AMBIENT: GL.AMBIENT = 4608 Global GL.DIFFUSE: GL.DIFFUSE = 4609 Global GL.SPECULAR: GL.SPECULAR = 4610 Global GL.SHININESS: GL.SHININESS = 5633 Global GL.EMISSION: GL.EMISSION = 5632 Global GL.POSITION: GL.POSITION = 4611 Global GL.FRONT.AND.BACK: GL.FRONT.AND.BACK = 103 global GL.FRONT: GL.FRONT = 1028 global GL.SMOOTH : GL.SMOOTH = 7425 '' Fog Global GL.FOG: GL.FOG = 2912 Global GL.FOG.MODE: GL.FOG.MODE = 2917 Global GL.FOG.DENSITY: GL.FOG.DENSITY = 2914 Global GL.FOG.COLOR: GL.FOG.COLOR = 2918 Global GL.FOG.INDEX: GL.FOG.INDEX = 2913 Global GL.FOG.START: GL.FOG.START = 2915 Global GL.FOG.END: GL.FOG.END = 2916 Global GL.LINEAR: GL.LINEAR = 9729 Global GL.EXP: GL.EXP = 2048 Global GL.EXP2: GL.EXP2 = 2049
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , winyx winx = WindowWidth winy = WindowHeight winyx = winy / winx
global MainH , MainDC ''wil be filled by code
global angle nomainwin open "opengl32.dll" for dll as #gl if instr( Platform$ , "LBB" ) then open "openGL" for window as #m else open "openGL" for graphics as #m end if #m "trapclose [quit]" #m "when characterInput [key]" #m "setfocus" MainH = hwnd( #m ) call openglInit calldll #gl , "glShadeModel" _ , GL.SMOOTH as ulong _ , ret as ulong call glEnable GL.LIGHTING call glLight GL.LIGHT0 , GL.DIFFUSE , lgray call glLight GL.LIGHT0 , GL.AMBIENT , dgray call d4d.fill 0 , 1 , 0 , 1 call glLight GL.LIGHT0 , GL.POSITION , dummy call glEnable GL.LIGHT0
timer 40 , [tmr] wait [tmr] scan
call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT call glLoadIdentity call glScale winyx , 1 , 1 call glPushMatrix call glTranslate 0,0,0 call glScale 0.3,0.3,0.3 call glRotate 30 , 0,1,0 call walk.man angle , 30 call glMaterial GL.FRONT , GL.DIFFUSE , white call glMaterial GL.FRONT , GL.AMBIENT , white call robot 1 call glPopMatrix
calldll #gdi32,"SwapBuffers" _ , MainDC as ulong _ , ret as long angle = angle + 5 wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( 27 ) then wait [quit] calldll #gl,"wglMakeCurrent" _ , 0 as ulong, 0 as ulong, ret as long calldll #gl,"wglDeleteContext" _ , GLContext as ulong, ret as long calldll #user32, "ReleaseDC" _ , MainH as ulong, MainDC as ulong,ret as long close #m close #gl end
sub walk.man f , a ''example animation call skelet left + arm , pend( f , a ) , 0 , 0 call skelet left + elbow , abs( a ) , 0 , 0 call skelet right + arm , pend( f + 180, a ) , 0 , 0 call skelet right + elbow , abs( a ) , 0 , 0 call skelet left + leg , pend( f + 180 , a ) , 0 , 0 call skelet left + knee , pend( f + 90 , a ) - a , 0 , 0 call skelet right + leg , pend( f , a ) , 0 , 0 call skelet right + knee _ , pend( f - 90 , a ) - a , 0 , 0 call skelet right + thumb , pend( f , 15 ) + 15 , 0 , 0 for i = 0 to 2 call skelet left + index.finger + i _ , 0 , 0 , pend( f , 15 ) - 15 call skelet left + mid.finger + i _ , 0 , 0 , pend( f - 120 , 15 ) - 15 call skelet left + ring.finger + i _ , 0 , 0 , pend( f + 120 , 15 ) - 15 call skelet right + index.finger + i _ , 0 , 0 , pend( f , 15 ) + 15 call skelet right + mid.finger + i _ , 0 , 0 , pend( f - 120 , 15 ) + 15 call skelet right + ring.finger + i _ , 0 , 0 , pend( f + 120 , 15 ) + 15 next i end sub
sub finger i ''example avatar sub body part call glPushMatrix call child 0,-.2,0 , i , xyz call setbox 0,-.1,0 , .1,.1,.1 call cube call glPushMatrix call child 0,-.2,0 , i+1 , xyz call cube call glPushMatrix call child 0,-.2,0 , i+2 , xyz call cube call glPopMatrix call glPopMatrix call glPopMatrix end sub
sub hand leftorright '' example avartar body part call setbox 0,-.3,0 , .1,.3,.3 call cube call glPushMatrix call child 0,-.2,-.5 , leftorright + thumb , xyz call finger leftorright + thumb call glPopMatrix call glPushMatrix call child 0,-.6,-.3 , leftorright + index.finger , xyz call finger leftorright + index.finger call glPopMatrix call glPushMatrix call child 0,-.6,0 , leftorright + mid.finger , xyz call finger leftorright + index.finger call glPopMatrix call glPushMatrix call child 0,-.6,.3 , leftorright + ring.finger , xyz call finger leftorright + index.finger call glPopMatrix end sub
sub robot h ''example avatar call setbox 0 , 0 , 0 , .3 , .1 , .1 call cube call setbox 0 , .75 , 0 , .1 , .5 , .1 call cube call setbox 0 , 1.8 , 0 , .2 , .2 , .2 call cube call setbox 0 , 1.4 , 0 , .7 , .1 , .1 call cube call glPushMatrix call child .25 , 0 , 0 , left + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + enkle , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.25 , 0 , 0 , right + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + enkle , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .65 , 1.3 , 0 , left + arm , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + elbow , xyz call cube call glPushMatrix call child 0 , -1 , 0 , left + wrist , zyx if h then call hand left else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call cube end if call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.65 , 1.3 , 0 , right + arm , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + elbow , xyz call cube call glPushMatrix call child 0 , -1 , 0 , right + wrist , zyx if h then call hand right else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call cube end if call glPopMatrix call glPopMatrix call glPopMatrix end sub
'' color object math
function rainbow( x ) r = sin( rad( x ) ) * 127 + 128 g = sin( rad( x - 120 ) ) * 127 + 128 b = sin( rad( x + 120 ) ) * 127 + 128 rainbow = rgba( r , g , b , 255 ) end function
function rgba( r , g , b , a ) ''create color object r = r and 255 g = g and 255 b = b and 255 a = a and 255 rgba = r + g * 256 + b * 256 ^ 2 + a * 256 ^ 3 end function
function colorR( clr ) ''get red channel from color object colorR = int( clr and 255 ) / 256 end function
function colorG( clr ) ''get green channel from color object colorG = ( int( clr / 256 ) and 255 ) / 256 end function
function colorB( clr ) ''get blue channel from color object colorB = ( int( clr / 256 ^ 2 ) and 255 ) / 256 end function
function colorA( clr ) ''get alpha channel from color object colorA = ( int( clr / 256 ^ 3 ) and 255 ) / 256 end function
'' vector math
function lenght( x1 , y1 , z1 , x2 , y2 , z2 ) lenght = sqr( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ) end function
sub cross x1 , y1 , z1 , x2 , y2 , z2 ''normalized cross product x = y1 * z2 - y2 * z1 d3d.x.struct = x / lenght(x1,y1,z1,x2,y2,z2) y = z1 * x2 - z2 * x1 d3d.y.struct = y / lenght(x1,y1,z1,x2,y2,z2) z = x1 * y2 - x2 * y1 d3d.z.struct = z / lenght(x1,y1,z1,x2,y2,z2) end sub
'' blua3d engine
sub child x , y , z , lim , ax if lim < 0 or lim > 64 then exit sub select case ax case xyz call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 case xzy call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 case yxz call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 case yzx call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 case zxy call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 case zyx call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 case else end select end sub
sub skelet no , x , y , z if no < 0 or no > 64 then exit sub sk( no , 0 ) = x sk( no , 1 ) = y sk( no , 2 ) = z end sub
function pend( f , a ) pend = sin( rad( f ) ) * a end function
function rad( x ) rad = x * pi / 180 end function
function sgn( x ) uit = 0 if x < 0 then uit = -1 if x > 0 then uit = 1 sgn = uit end function
'' graphics wrapper
sub setbox mx , my , mz , dx , dy , dz ''set bodinging box coordinates box(0) = mx box(1) = my box(2) = mz box(3) = dx box(4) = dy box(5) = dz end sub
sub cube ''create a cube mesh
''first fil swarm whit points call point 0 , -1 , -1 , -1 call point 1 , -1 , -1 , 1 call point 2 , -1 , 1 , -1 call point 3 , -1 , 1 , 1 call point 4 , 1 , -1 , -1 call point 5 , 1 , -1 , 1 call point 6 , 1 , 1 , -1 call point 7 , 1 , 1 , 1
''then use points in swarm to draw quads call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) call quad 0 , 1 , 3 , 2 call quad 7 , 6 , 4 , 5 call quad 0 , 2 , 6 , 4 call quad 7 , 5 , 1 , 3 call quad 0 , 1 , 5 , 4 call quad 7 , 6 , 2 , 3 call glPopMatrix end sub
sub point no , x , y , z ''set a point in the swarm if no < 0 or no > 256 then exit sub pntx( no ) = x pnty( no ) = y pntz( no ) = z end sub
sub tri p1 , p2 , p3 ''draw a triangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) call cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.TRIANGLES call glNormal d3d.x.struct , d3d.y.struct , d3d.z.struct call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glEnd end sub
sub quad p1 , p2 , p3 , p4 ''draw a quadangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub if p4 < 0 or p4 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) x4 = pntx( p4 ) y4 = pnty( p4 ) z4 = pntz( p4 ) call cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.QUADS call glNormal d3d.x.struct , d3d.y.struct , d3d.z.struct call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glVertex x4 , y4 , z4 call glEnd end sub
'' openGl
sub glClear code ''clear the openGL screen calldll #gl,"glClear" _ , code as long _ , ret as long end sub
sub glLoadIdentity ''set drawingmatrix to standert calldll #gl , "glLoadIdentity" _ , ret as long end sub
sub glPushMatrix ''to new drawingmatrix calldll #gl , "glPushMatrix" _ , ret as long end sub
sub glPopMatrix ''to old drawingmatrix calldll #gl , "glPopMatrix" _ , ret as long end sub
sub glEnd ''end of polygon[s] calldll #gl , "glEnd" _ , ret as void end sub
sub glEnable i ''set a item calldll #gl , "glEnable" _ , i as long _ , ret as long end sub
sub glBegin i ''set polygon mode calldll #gl , "glBegin" _ , i as long _ , ret as long end sub
sub glScale x , y , z ''scale drawingmatrix calldll #gl , "glScaled" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glTranslate x , y , z ''move drawingmatrix calldll #gl , "glTranslated" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glRotate a , x , y , z ''rotate drawinmatrix calldll #gl , "glRotated" _ , a as double _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glVertex x , y , z ''add a point to a polygon calldll #gl , "glVertex3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glNormal x , y , z ''set normal of point[s] calldll #gl , "glNormal3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub setColor kl ''set color of polygon r = colorR( kl ) g = colorG( kl ) b = colorB( kl ) a = colorA( kl ) call d4d.fill r , g , b , a end sub
sub d4d.fill a , b , c , d ''fill d4d.struct d4d.a.struct = a d4d.b.struct = b d4d.c.struct = c d4d.d.struct = d end sub
function glGetError() calldll #gl , "glGetError" _ , glGetError as ulong end function
sub glLight no , e , kl select case e case GL.DIFFUSE call setColor kl calldll #gl , "glLightfv" _ , no as long _ , e as long _ , d4d as struct _ , ret as long print "light.diffuse = " ; dechex$( kl ) print "light.ret = " ; dechex$( ret ) print "error = " ; dechex$( glGetError() ) case GL.POSITION calldll #gl , "glLightfv" _ , no as long _ , e as long _ , d4d as struct _ , ret as long case else end select end sub
sub glMaterial face , e , kl if e = GL.SHININESS then calldll #gl , "glMaterialf" _ , face as long _ , e as long _ , kl as single _ , ret as long else call setColor kl calldll #gl , "glMaterialfv" _ , face as long _ , e as long _ , d4d as struct _ , ret as long if tel = 0 then print "mat.color = " ; dechex$( kl ) print "mat.ret = " ; dechex$( ret ) print "error = " ; dechex$( glGetError() ) tel = 1 end if end if end sub
sub openglInit struct PFD _ , Size as word _ , Version as word _ , Flags as long _ , pixelType as char[1] _ , ColorBits as char[1] _ , RedBits as char[1] _ , RedShift as char[1] _ , GreenBits as char[1] _ , GreenShift as char[1] _ , BlueBits as char[1] _ , BlueShift as char[1] _ , AlphaBits as char[1] _ , AlphaShift as char[1] _ , AccumBits as char[1] _ , AccumRedBits as char[1] _ , AccumGreenBits as char[1] _ , AccumBlueBits as char[1] _ , AccumAlphaBits as char[1] _ , DepthBits as char[1] _ , StencilBits as char[1] _ , AuxBuffers as char[1] _ , LayerType as char[1] _ , Reserved as char[1] _ , LayerMask as long _ , VisibleMask as long _ , DamageMask as long
PFD.Version.struct=1 PFD.ColorBits.struct=24 PFD.DepthBits.struct=16 PFD.Size.struct=len(PFD.struct) PFD.Flags.struct=37
calldll #user32,"GetDC" _ , MainH as ulong, MainDC as ulong calldll #gdi32,"ChoosePixelFormat" _ , MainDC as ulong, PFD as struct, ret as long calldll #gdi32, "SetPixelFormat" _ , MainDC as ulong, ret as long _ , PFD as struct, t as long calldll #gl,"wglCreateContext" _ , MainDC as ulong, GLContext as ulong calldll #gl,"wglMakeCurrent" _ , MainDC as ulong, GLContext as ulong _ , ret as long call glEnable GL.DEPTH.TEST end sub
|
|
|
Post by bluatigro on Oct 5, 2018 5:38:12 GMT -5
update : made a dog robot
strage error : 1 of my child sub cal's is not good
add this
sub robot.dog call setbox 0,.2,.5 , .3,.3,.7 call cube call glpushmatrix call child 0 , .6 , 1.5 , left + neck , xyz call glpushmatrix call child 0 , 0 , 0 , right + neck , zyx call setbox 0,0,0 , .3 , .3 , .3 call cube call setbox 0,-.2,.3 , .2,.2,.2 call cube call setbox 0,0,.5 , .1,.1,.1 call cube call setbox .3,-.15,0 , .05,.3,.2 call cube call setbox -.3,-.15,0 , .05,.3,.2 call cube call glpopmatrix call glpopmatrix call glpushmatrix call child 0 , .4 , -.5 , tail , yzx call setbox 0,.3,0 , .1 , .3 , .1 call cube call glpopmatrix call glPushMatrix call child .3 , 0 , 1 , left + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + enkle , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.3 , 0 , 1 , right + leg, zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + enkle , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .3 , 0 , 0 , left + arm , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + elbow , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + wrist , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.3 , 0 , 0 , right + arm , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + elbow , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + wrist , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix end sub
and this
sub walk.dog f , a call skelet left + arm , pend( f + 180 , a ) , 0 , 0 call skelet left + elbow , pend( f + 90 , a ) - a , 0 , 0 call skelet right + arm , pend( f , a ) , 0 , 0 call skelet right + elbow _ , pend( f - 90 , a ) - a , 0 , 0 call skelet left + leg , pend( f + 180 , a ) , 0 , 0 call skelet left + knee , pend( f + 90 , a ) - a , 0 , 0 call skelet right + leg , pend( f , a ) , 0 , 0 call skelet right + knee _ , pend( f - 90 , a ) - a , 0 , 0 call skelet tail , -45 , 0 , pend( f * 2 , 30 ) end sub
|
|
|
Post by bluatigro on Oct 23, 2018 8:23:55 GMT -5
update : added a robot.bug + animation's added a robot.dog + animation
error : reset.animation does not reset lim angles to 0 by robot.dog
''bluatigro 23 0kt 2018 ''openGL light and material ''robot.man + robot.dog + robot.bug avartar + animation's
dim pntx(256),pnty(256),pntz(256),box(5),sk(64,2) global pi pi = atn( 1 ) * 4 global tel
struct d4d _ , a as double _ , b as double _ , c as double _ , d as double
struct d3d _ , x as double _ , y as double _ , z as double
'' color objects
global black , red , green , yellow global blue , magenta , cyan , white global gray , pink , purple , orange global lgray , dgray black = rgba( 000 , 000 , 000 , 255 ) red = rgba( 255 , 000 , 000 , 255 ) green = rgba( 000 , 255 , 000 , 255 ) yellow = rgba( 255 , 255 , 000 , 255 ) blue = rgba( 000 , 000 , 255 , 255 ) magenta = rgba( 255 , 000 , 255 , 255 ) cyan = rgba( 000 , 255 , 255 , 255 ) white = rgba( 255 , 255 , 255 , 255 ) gray = rgba( 127 , 127 , 127 , 255 ) lgray = rgba( 181 , 181 , 181 , 255 ) dgray = rgba( 064 , 064 , 064 , 255 ) pink = rgba( 255 , 127 , 127 , 255 ) purple = rgba( 127 , 000 , 127 , 255 ) orange = rgba( 255 , 127 , 000 , 255 )
global xyz , xzy , yxz , yzx , zxy , zyx xyz = 0 xzy = 1 yxz = 2 yzx = 3 zxy = 4 zyx = 5 global arm,elbow,wrist,leg,knee,enkle,eye,left,right arm = 0 elbow = 1 wrist = 2 leg = 3 knee = 4 enkle = 5 eye = 6 global thumb,index.finger,mid.finger,ring.finger thumb = 7 index.finger = 10 mid.finger = 13 ring.finger = 16 left = 32 right = 0 '' bug anim's number's global bug.home , bug.fly , bug.left.legs , bug.left.box global bug.right.legs , bug.right.box , bug.sting , bug.stand bug.home = 0 bug.fly = 1 bug.left.legs = 2 bug.left.box = 3 bug.right.legs = 4 bug.right.box = 5 bug.sting = 6 bug.stand = 7 '' bug lim's number's global iarm,ielbow,iwrist,ileg,iknee global iwing,itail,isensor,ithumb,ifinger iarm = 1 ielbow = 2 iwrist = 3 ileg = 4 iknee = 9 iwing = 14 itail = 16 isensor = 17 ithumb = 18 ifinger = 19
'' opengl consts
global GL.COLOR.BUFFER.BIT : GL.COLOR.BUFFER.BIT = 16384 global GL.DEPTH.BUFFER.BIT : GL.DEPTH.BUFFER.BIT = 256 global GL.DEPTH.TEST : GL.DEPTH.TEST = 2929 ' primatifs global GL.TRIANGLES : GL.TRIANGLES = 4 global GL.QUADS : GL.QUADS = 7 ' light Global GL.LIGHTING: GL.LIGHTING = 2896 Global GL.LIGHT0: GL.LIGHT0 = 16384 Global GL.AMBIENT: GL.AMBIENT = 4608 Global GL.DIFFUSE: GL.DIFFUSE = 4609 Global GL.SPECULAR: GL.SPECULAR = 4610 Global GL.SHININESS: GL.SHININESS = 5633 Global GL.EMISSION: GL.EMISSION = 5632 Global GL.POSITION: GL.POSITION = 4611 Global GL.FRONT.AND.BACK: GL.FRONT.AND.BACK = 103 global GL.FRONT: GL.FRONT = 1028 global GL.SMOOTH : GL.SMOOTH = 7425 '' Fog Global GL.FOG: GL.FOG = 2912 Global GL.FOG.MODE: GL.FOG.MODE = 2917 Global GL.FOG.DENSITY: GL.FOG.DENSITY = 2914 Global GL.FOG.COLOR: GL.FOG.COLOR = 2918 Global GL.FOG.INDEX: GL.FOG.INDEX = 2913 Global GL.FOG.START: GL.FOG.START = 2915 Global GL.FOG.END: GL.FOG.END = 2916 Global GL.LINEAR: GL.LINEAR = 9729 Global GL.EXP: GL.EXP = 2048 Global GL.EXP2: GL.EXP2 = 2049
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , winyx winx = WindowWidth winy = WindowHeight winyx = winy / winx
global MainH , MainDC ''wil be filled by code
global angle , state nomainwin open "opengl32.dll" for dll as #gl if instr( Platform$ , "LBB" ) then open "openGL" for window as #m else open "openGL" for graphics as #m end if #m "trapclose [quit]" #m "when characterInput [key]" #m "setfocus" MainH = hwnd( #m ) call openglInit calldll #gl , "glShadeModel" _ , GL.SMOOTH as ulong _ , ret as ulong call glEnable GL.LIGHTING call glLight GL.LIGHT0 , GL.DIFFUSE , lgray call glLight GL.LIGHT0 , GL.AMBIENT , dgray call d4d.fill 0 , 1 , 0 , 1 call glLight GL.LIGHT0 , GL.POSITION , dummy call glEnable GL.LIGHT0
timer 40 , [tmr] wait [tmr] scan
call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT call glLoadIdentity call glScale winyx , 1 , 1 call glPushMatrix call glTranslate -1,0,0 call glScale 0.3,0.3,0.3 call glRotate 30 , 0,1,0 call reset.animation call walk.man angle , 30 call glMaterial GL.FRONT , GL.DIFFUSE , white call glMaterial GL.FRONT , GL.AMBIENT , white call robot.man 1 call glPopMatrix call glPushMatrix call glTranslate 1,0,0 call glScale 0.3,0.3,0.3 call glRotate 30 , 0,1,0 call reset.animation call walk.dog angle , 30 call glMaterial GL.FRONT , GL.DIFFUSE , white call glMaterial GL.FRONT , GL.AMBIENT , white call robot.dog call glPopMatrix call glPushMatrix call glTranslate 0,0,0 call glScale 0.3,0.3,0.3 call glRotate 30 , 0,1,0 call bug.move bug.home , 0 , 0 call bug.move bug.stand , 0 , 0 call bug.move bug.fly , angle , 5 call bug.move bug.left.legs , angle , 5 call bug.move bug.left.box , angle , 5 call bug.move bug.right.legs , angle + 180 , -5 call bug.move bug.right.box , angle + 180 , 5 call bug.move bug.sting , angle , 5 call glMaterial GL.FRONT , GL.DIFFUSE , white call glMaterial GL.FRONT , GL.AMBIENT , white call robot.bug call glPopMatrix calldll #gdi32,"SwapBuffers" _ , MainDC as ulong _ , ret as long angle = angle + 5 if angle >= 360 * 5 then state = state + 1 angle = 0 end if if state > 2 then state = 0 wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( 27 ) then wait [quit] calldll #gl,"wglMakeCurrent" _ , 0 as ulong, 0 as ulong, ret as long calldll #gl,"wglDeleteContext" _ , GLContext as ulong, ret as long calldll #user32, "ReleaseDC" _ , MainH as ulong, MainDC as ulong,ret as long close #m close #gl end
''avartar's + animation's
sub reset.animation for i = 0 to 64 call skelet i , 0 , 0 , 0 call skelet i , 0 , 0 , 0 next i end sub
sub bug.move anim , f , a select case anim Case bug.fly For i = 0 To 1 call skelet iwing + left + i , 0 , 0 , pend( f + 180 * i , a) call skelet iwing + right + i , 0 , 0 , pend( f + 180 * i , 0 - a) Next Case bug.left.box call skelet iarm + left , 0 , pend( f , 0 - a ) + 45 , 0 call skelet ielbow + left , 0 , pend( f , a * 2 ) - 60 , 0 Case bug.left.legs For i = 0 To 4 call skelet ileg + left + i, 0 , 0, pend( f + i * 180 , a ) call skelet iknee + right + i, pend( f + i * 180 + 90 , a ) , 0 , 0 Next Case bug.right.box call skelet iarm + right , 0 , pend( f , a ) - 45 ,0 call skelet ielbow + right , 0, pend( f , a * -2) + 60 , 0 Case bug.right.legs For i = 0 To 4 call skelet ileg + right + i , 0 , 0 , pend(f + i * 180, a) call skelet iknee + right + i , pend( f + i * 180 + 90 , a ) , 0 , 0 Next Case bug.stand call skelet iarm + left , 0 , 45 , 0 call skelet ielbow + left , 0 , -60 , 0 call skelet ifinger + left , 0 , 0 , 0 call skelet ithumb + left , 0 , 0 , 0 call skelet iarm + right, 0 , -45 , 0 call skelet ielbow + right , 0, 60 , 0 call skelet ifinger + right , 0 , 0 , 0 call skelet ithumb + right , 0 , 0 , 0 call skelet itail + left , 10 , 0 , 0 call skelet itail + right , -10 , 0 , 0 Case bug.sting call skelet itail + left , 10 + pend(f, a), 0, 0 call skelet itail + right , 10 - pend(f, a), 0, 0 case else ''bug.home for i = 0 to 64 call skelet i , 0 , 0 , 0 call skelet i , 0 , 0 , 0 next i end select end sub
sub robot.bug call glPushMatrix call glRotate 180 , 0 , 1 , 0 call glScale .006 , .006 , .006 call setbox 0, 0, 0, 30, 10.0, 60.0 call cube For i = 0 To 4 call glPushMatrix call child 35.0, 0.0, i * 25 - 50 , ileg + left + i, xyz call setbox 30.0, 0.0, 0.0, 30.0, 5.0, 5.0 call cube call glPushMatrix call child 65.0, -5.0, 0.0 , iknee + left + i, xyz call setbox 0.0, -30.0, 0.0, 5.0, 30.0, 5.0 call cube call glPopMatrix call glPopMatrix call glPushMatrix call child -35.0, 0.0, i * 25 - 50, ileg + right + i, xyz call setbox -30.0, 0.0, 0.0, 30.0, 5.0, 5.0 call cube call glPushMatrix call child -65.0, -5.0, 0.0 , iknee + right + 1, xyz call setbox 0.0, -30.0, 0.0, 5.0, 30.0, 5.0 call cube call glPopMatrix call glPopMatrix Next call glPushMatrix call child 0 , 0 , -50 , itail + left , xyz For i = 0 To 9 call glPushMatrix call child 0.0, 0.0, -30.0 , itail + left , xyz call setbox 0.0, 0.0, -15.0, 10.0, 10.0, 10.0 call cube Next for i = 0 to 8 call glPushMatrix call child 0 , 0 , -30 , itail + right , xyz call cube next i for i = 0 to 8 call glPopMatrix call glPopMatrix next i call glPopMatrix call glPushMatrix call child 30.0, 0.0, 65.0, iarm + left , xyz call setbox 0.0, 0.0, 65.0 , 5 , 35 , 5 call cube call glPushMatrix call child 0.0, 0.0, 65.0, ielbow + left , xyz call cube call glPushMatrix call child 0.0, 0.0, 65.0 , iwrist + left , xyz call glPushMatrix call child -10.0, 0.0, 5.0 , ithumb + left , xyz call cube call glPopMatrix call glPushMatrix call child 5.0, 0.0, 5.0, ifinger + left , xyz call setbox 0.0, 0.0, 30.0, 5.0, 10.0, 30.0 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -30.0, 0.0, 65.0, iarm + right, xyz call setbox 0.0, 0.0, 30.0, 5.0, 5.0, 30.0 call cube call glPushMatrix call child 0.0, 0.0, 65.0, ielbow + right, xyz call cube call glPushMatrix call child 0.0, 0.0, 65.0, iwrist + right , xyz call glPushMatrix call child 10.0, 0.0, 5.0, ithumb + right , xyz call cube call glPopMatrix call glPushMatrix call child -5.0, 0.0, 5.0, ifinger + right , xyz call setbox 0.0, 0.0, 30.0, 5.0, 10.0, 30.0 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPopMatrix For i = 0 To 1 call glPushMatrix call child 20.0, 20.0, 40.0 - 50.0 * i, iwing + left + i, xyz call setbox 60.0, 0.0, 8.0, 60.0, 2.0, 16.0 call cube call glPopMatrix call glPushMatrix call child -20.0, 20.0, 40.0 - 50.0 * i , iwing + right + i, xyz call setbox -60.0, 0.0, 8.0, 60.0, 2.0, 16.0 call cube call glPopMatrix Next call glPopMatrix end sub
sub walk.dog f , a call skelet left + arm , pend( f + 180 , a ) , 0 , 0 call skelet left + elbow , pend( f + 90 , a ) - a , 0 , 0 call skelet right + arm , pend( f , a ) , 0 , 0 call skelet right + elbow _ , pend( f - 90 , a ) - a , 0 , 0 call skelet left + leg , pend( f + 180 , a ) , 0 , 0 call skelet left + knee , pend( f + 90 , a ) - a , 0 , 0 call skelet right + leg , pend( f , a ) , 0 , 0 call skelet right + knee _ , pend( f - 90 , a ) - a , 0 , 0 call skelet tail , -45 , 0 , pend( f * 2 , 30 ) end sub
sub robot.dog call glPushMatrix call glRotate 180 , 0 , 1 , 0 call setbox 0,.2,.5 , .3,.3,.7 call cube call glPushMatrix call child 0 , .6 , 1.5 , left + neck , xyz call glPushMatrix call child 0 , 0 , 0 , right + neck , zyx call setbox 0,0,0 , .3 , .3 , .3 call cube call setbox 0,-.2,.3 , .2,.2,.2 call cube call setbox 0,0,.5 , .1,.1,.1 call cube call setbox .3,-.15,0 , .05,.3,.2 call cube call setbox -.3,-.15,0 , .05,.3,.2 call cube call glPopMatrix call glPopMatrix call glPushMatrix call child 0 , .4 , -.5 , tail , yzx call setbox 0,.3,0 , .1 , .3 , .1 call cube call glPopMatrix call glPushMatrix call child .3 , 0 , 1 , left + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + enkle , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.3 , 0 , 1 , right + leg, zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + enkle , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .3 , 0 , 0 , left + arm , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + elbow , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + wrist , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.3 , 0 , 0 , right + arm , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + elbow , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + wrist , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPopMatrix end sub
sub walk.man f , a ''example animation call skelet left + arm , pend( f , a ) , 0 , 0 call skelet left + elbow , abs( a ) , 0 , 0 call skelet right + arm , pend( f + 180, a ) , 0 , 0 call skelet right + elbow , abs( a ) , 0 , 0 call skelet left + leg , pend( f + 180 , a ) , 0 , 0 call skelet left + knee , pend( f + 90 , a ) - a , 0 , 0 call skelet right + leg , pend( f , a ) , 0 , 0 call skelet right + knee _ , pend( f - 90 , a ) - a , 0 , 0 call skelet right + thumb , pend( f , 15 ) + 15 , 0 , 0 for i = 0 to 2 call skelet left + index.finger + i _ , 0 , 0 , pend( f , 15 ) - 15 call skelet left + mid.finger + i _ , 0 , 0 , pend( f - 120 , 15 ) - 15 call skelet left + ring.finger + i _ , 0 , 0 , pend( f + 120 , 15 ) - 15 call skelet right + index.finger + i _ , 0 , 0 , pend( f , 15 ) + 15 call skelet right + mid.finger + i _ , 0 , 0 , pend( f - 120 , 15 ) + 15 call skelet right + ring.finger + i _ , 0 , 0 , pend( f + 120 , 15 ) + 15 next i end sub
sub finger i ''example avatar sub body part call glPushMatrix call child 0,-.2,0 , i , xyz call setbox 0,-.1,0 , .1,.1,.1 call cube call glPushMatrix call child 0,-.2,0 , i+1 , xyz call cube call glPushMatrix call child 0,-.2,0 , i+2 , xyz call cube call glPopMatrix call glPopMatrix call glPopMatrix end sub
sub hand leftorright '' example avartar body part call setbox 0,-.3,0 , .1,.3,.3 call cube call glPushMatrix call child 0,-.2,-.5 , leftorright + thumb , xyz call finger leftorright + thumb call glPopMatrix call glPushMatrix call child 0,-.6,-.3 , leftorright + index.finger , xyz call finger leftorright + index.finger call glPopMatrix call glPushMatrix call child 0,-.6,0 , leftorright + mid.finger , xyz call finger leftorright + index.finger call glPopMatrix call glPushMatrix call child 0,-.6,.3 , leftorright + ring.finger , xyz call finger leftorright + index.finger call glPopMatrix end sub
sub robot.man h ''example avatar call setbox 0 , 0 , 0 , .3 , .1 , .1 call cube call setbox 0 , .75 , 0 , .1 , .5 , .1 call cube call setbox 0 , 1.8 , 0 , .2 , .2 , .2 call cube call setbox 0 , 1.4 , 0 , .7 , .1 , .1 call cube call glPushMatrix call child .25 , 0 , 0 , left + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + enkle , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.25 , 0 , 0 , right + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + enkle , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .65 , 1.3 , 0 , left + arm , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + elbow , xyz call cube call glPushMatrix call child 0 , -1 , 0 , left + wrist , zyx if h then call hand left else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call cube end if call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.65 , 1.3 , 0 , right + arm , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + elbow , xyz call cube call glPushMatrix call child 0 , -1 , 0 , right + wrist , zyx if h then call hand right else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call cube end if call glPopMatrix call glPopMatrix call glPopMatrix end sub
'' color object math
function rainbow( x ) r = sin( rad( x ) ) * 127 + 128 g = sin( rad( x - 120 ) ) * 127 + 128 b = sin( rad( x + 120 ) ) * 127 + 128 rainbow = rgba( r , g , b , 255 ) end function
function rgba( r , g , b , a ) ''create color object r = r and 255 g = g and 255 b = b and 255 a = a and 255 rgba = r + g * 256 + b * 256 ^ 2 + a * 256 ^ 3 end function
function colorR( clr ) ''get red channel from color object colorR = int( clr and 255 ) / 256 end function
function colorG( clr ) ''get green channel from color object colorG = ( int( clr / 256 ) and 255 ) / 256 end function
function colorB( clr ) ''get blue channel from color object colorB = ( int( clr / 256 ^ 2 ) and 255 ) / 256 end function
function colorA( clr ) ''get alpha channel from color object colorA = ( int( clr / 256 ^ 3 ) and 255 ) / 256 end function
'' vector math
function lenght( x1 , y1 , z1 , x2 , y2 , z2 ) lenght = sqr( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ) end function
sub cross x1 , y1 , z1 , x2 , y2 , z2 ''normalized cross product x = y1 * z2 - y2 * z1 d3d.x.struct = x / lenght(x1,y1,z1,x2,y2,z2) y = z1 * x2 - z2 * x1 d3d.y.struct = y / lenght(x1,y1,z1,x2,y2,z2) z = x1 * y2 - x2 * y1 d3d.z.struct = z / lenght(x1,y1,z1,x2,y2,z2) end sub
'' blua3d engine
sub child x , y , z , lim , ax if lim < 0 or lim > 64 then exit sub select case ax case xyz call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 case xzy call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 case yxz call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 case yzx call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 case zxy call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 case zyx call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 case else end select end sub
sub skelet no , x , y , z if no < 0 or no > 64 then exit sub sk( no , 0 ) = x sk( no , 1 ) = y sk( no , 2 ) = z end sub
function pend( f , a ) pend = sin( rad( f ) ) * a end function
function rad( x ) rad = x * pi / 180 end function
function sgn( x ) uit = 0 if x < 0 then uit = -1 if x > 0 then uit = 1 sgn = uit end function
'' graphics wrapper
sub setbox mx , my , mz , dx , dy , dz ''set bodinging box coordinates box(0) = mx box(1) = my box(2) = mz box(3) = dx box(4) = dy box(5) = dz end sub
sub cube ''create a cube mesh
''first fil swarm whit points call point 0 , -1 , -1 , -1 call point 1 , -1 , -1 , 1 call point 2 , -1 , 1 , -1 call point 3 , -1 , 1 , 1 call point 4 , 1 , -1 , -1 call point 5 , 1 , -1 , 1 call point 6 , 1 , 1 , -1 call point 7 , 1 , 1 , 1
''then use points in swarm to draw quads call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) call quad 0 , 1 , 3 , 2 call quad 7 , 6 , 4 , 5 call quad 0 , 2 , 6 , 4 call quad 7 , 5 , 1 , 3 call quad 0 , 1 , 5 , 4 call quad 7 , 6 , 2 , 3 call glPopMatrix end sub
sub point no , x , y , z ''set a point in the swarm if no < 0 or no > 256 then exit sub pntx( no ) = x pnty( no ) = y pntz( no ) = z end sub
sub tri p1 , p2 , p3 ''draw a triangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) call cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.TRIANGLES call glNormal d3d.x.struct , d3d.y.struct , d3d.z.struct call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glEnd end sub
sub quad p1 , p2 , p3 , p4 ''draw a quadangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub if p4 < 0 or p4 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) x4 = pntx( p4 ) y4 = pnty( p4 ) z4 = pntz( p4 ) call cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.QUADS call glNormal d3d.x.struct , d3d.y.struct , d3d.z.struct call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glVertex x4 , y4 , z4 call glEnd end sub
'' openGl
sub glClear code ''clear the openGL screen calldll #gl,"glClear" _ , code as long _ , ret as long end sub
sub glLoadIdentity ''set drawingmatrix to standert calldll #gl , "glLoadIdentity" _ , ret as long end sub
sub glPushMatrix ''to new drawingmatrix calldll #gl , "glPushMatrix" _ , ret as long end sub
sub glPopMatrix ''to old drawingmatrix calldll #gl , "glPopMatrix" _ , ret as long end sub
sub glEnd ''end of polygon[s] calldll #gl , "glEnd" _ , ret as void end sub
sub glEnable i ''set a item calldll #gl , "glEnable" _ , i as long _ , ret as long end sub
sub glBegin i ''set polygon mode calldll #gl , "glBegin" _ , i as long _ , ret as long end sub
sub glScale x , y , z ''scale drawingmatrix calldll #gl , "glScaled" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glTranslate x , y , z ''move drawingmatrix calldll #gl , "glTranslated" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glRotate a , x , y , z ''rotate drawinmatrix calldll #gl , "glRotated" _ , a as double _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glVertex x , y , z ''add a point to a polygon calldll #gl , "glVertex3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glNormal x , y , z ''set normal of point[s] calldll #gl , "glNormal3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub setColor kl ''set color of polygon r = colorR( kl ) g = colorG( kl ) b = colorB( kl ) a = colorA( kl ) call d4d.fill r , g , b , a end sub
sub d4d.fill a , b , c , d ''fill d4d.struct d4d.a.struct = a d4d.b.struct = b d4d.c.struct = c d4d.d.struct = d end sub
function glGetError() calldll #gl , "glGetError" _ , glGetError as ulong end function
sub glLight no , e , kl select case e case GL.DIFFUSE call setColor kl calldll #gl , "glLightfv" _ , no as long _ , e as long _ , d4d as struct _ , ret as long print "light.diffuse = " ; dechex$( kl ) print "light.ret = " ; dechex$( ret ) print "error = " ; dechex$( glGetError() ) case GL.POSITION calldll #gl , "glLightfv" _ , no as long _ , e as long _ , d4d as struct _ , ret as long case else end select end sub
sub glMaterial face , e , kl if e = GL.SHININESS then calldll #gl , "glMaterialf" _ , face as long _ , e as long _ , kl as single _ , ret as long else call setColor kl calldll #gl , "glMaterialfv" _ , face as long _ , e as long _ , d4d as struct _ , ret as long if tel = 0 then print "mat.color = " ; dechex$( kl ) print "mat.ret = " ; dechex$( ret ) print "error = " ; dechex$( glGetError() ) tel = 1 end if end if end sub
sub openglInit struct PFD _ , Size as word _ , Version as word _ , Flags as long _ , pixelType as char[1] _ , ColorBits as char[1] _ , RedBits as char[1] _ , RedShift as char[1] _ , GreenBits as char[1] _ , GreenShift as char[1] _ , BlueBits as char[1] _ , BlueShift as char[1] _ , AlphaBits as char[1] _ , AlphaShift as char[1] _ , AccumBits as char[1] _ , AccumRedBits as char[1] _ , AccumGreenBits as char[1] _ , AccumBlueBits as char[1] _ , AccumAlphaBits as char[1] _ , DepthBits as char[1] _ , StencilBits as char[1] _ , AuxBuffers as char[1] _ , LayerType as char[1] _ , Reserved as char[1] _ , LayerMask as long _ , VisibleMask as long _ , DamageMask as long
PFD.Version.struct=1 PFD.ColorBits.struct=24 PFD.DepthBits.struct=16 PFD.Size.struct=len(PFD.struct) PFD.Flags.struct=37
calldll #user32,"GetDC" _ , MainH as ulong, MainDC as ulong calldll #gdi32,"ChoosePixelFormat" _ , MainDC as ulong, PFD as struct, ret as long calldll #gdi32, "SetPixelFormat" _ , MainDC as ulong, ret as long _ , PFD as struct, t as long calldll #gl,"wglCreateContext" _ , MainDC as ulong, GLContext as ulong calldll #gl,"wglMakeCurrent" _ , MainDC as ulong, GLContext as ulong _ , ret as long call glEnable GL.DEPTH.TEST end sub
|
|
|
Post by bluatigro on Oct 24, 2018 3:45:47 GMT -5
update : sphere , torus , cylinder , banana added
error : i see 1/2 banana cylinder not good jet
cylinder is also cone
''bluatigro 24 0kt 2018 ''openGL light and material ''shape's test
dim pntx(256),pnty(256),pntz(256),box(5),sk(64,2) global pi pi = atn( 1 ) * 4 global tel
struct d4d _ , a as double _ , b as double _ , c as double _ , d as double
struct d3d _ , x as double _ , y as double _ , z as double
'' color objects
global black , red , green , yellow global blue , magenta , cyan , white global gray , pink , purple , orange global lgray , dgray black = rgba( 000 , 000 , 000 , 255 ) red = rgba( 255 , 000 , 000 , 255 ) green = rgba( 000 , 255 , 000 , 255 ) yellow = rgba( 255 , 255 , 000 , 255 ) blue = rgba( 000 , 000 , 255 , 255 ) magenta = rgba( 255 , 000 , 255 , 255 ) cyan = rgba( 000 , 255 , 255 , 255 ) white = rgba( 255 , 255 , 255 , 255 ) gray = rgba( 127 , 127 , 127 , 255 ) lgray = rgba( 181 , 181 , 181 , 255 ) dgray = rgba( 064 , 064 , 064 , 255 ) pink = rgba( 255 , 127 , 127 , 255 ) purple = rgba( 127 , 000 , 127 , 255 ) orange = rgba( 255 , 127 , 000 , 255 )
global xyz , xzy , yxz , yzx , zxy , zyx xyz = 0 xzy = 1 yxz = 2 yzx = 3 zxy = 4 zyx = 5 global arm,elbow,wrist,leg,knee,enkle,eye,left,right arm = 0 elbow = 1 wrist = 2 leg = 3 knee = 4 enkle = 5 eye = 6 global thumb,index.finger,mid.finger,ring.finger thumb = 7 index.finger = 10 mid.finger = 13 ring.finger = 16 left = 32 right = 0 '' bug anim's number's global bug.home , bug.fly , bug.left.legs , bug.left.box global bug.right.legs , bug.right.box , bug.sting , bug.stand bug.home = 0 bug.fly = 1 bug.left.legs = 2 bug.left.box = 3 bug.right.legs = 4 bug.right.box = 5 bug.sting = 6 bug.stand = 7 '' bug lim's number's global iarm,ielbow,iwrist,ileg,iknee global iwing,itail,isensor,ithumb,ifinger iarm = 1 ielbow = 2 iwrist = 3 ileg = 4 iknee = 9 iwing = 14 itail = 16 isensor = 17 ithumb = 18 ifinger = 19
'' opengl consts
global GL.COLOR.BUFFER.BIT : GL.COLOR.BUFFER.BIT = 16384 global GL.DEPTH.BUFFER.BIT : GL.DEPTH.BUFFER.BIT = 256 global GL.DEPTH.TEST : GL.DEPTH.TEST = 2929 ' primatifs global GL.TRIANGLES : GL.TRIANGLES = 4 global GL.QUADS : GL.QUADS = 7 ' light Global GL.LIGHTING: GL.LIGHTING = 2896 Global GL.LIGHT0: GL.LIGHT0 = 16384 Global GL.AMBIENT: GL.AMBIENT = 4608 Global GL.DIFFUSE: GL.DIFFUSE = 4609 Global GL.SPECULAR: GL.SPECULAR = 4610 Global GL.SHININESS: GL.SHININESS = 5633 Global GL.EMISSION: GL.EMISSION = 5632 Global GL.POSITION: GL.POSITION = 4611 Global GL.FRONT.AND.BACK: GL.FRONT.AND.BACK = 103 global GL.FRONT: GL.FRONT = 1028 global GL.SMOOTH : GL.SMOOTH = 7425 '' Fog Global GL.FOG: GL.FOG = 2912 Global GL.FOG.MODE: GL.FOG.MODE = 2917 Global GL.FOG.DENSITY: GL.FOG.DENSITY = 2914 Global GL.FOG.COLOR: GL.FOG.COLOR = 2918 Global GL.FOG.INDEX: GL.FOG.INDEX = 2913 Global GL.FOG.START: GL.FOG.START = 2915 Global GL.FOG.END: GL.FOG.END = 2916 Global GL.LINEAR: GL.LINEAR = 9729 Global GL.EXP: GL.EXP = 2048 Global GL.EXP2: GL.EXP2 = 2049
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , winyx winx = WindowWidth winy = WindowHeight winyx = winy / winx
global MainH , MainDC ''wil be filled by code
global angle , state nomainwin open "opengl32.dll" for dll as #gl if instr( Platform$ , "LBB" ) then open "openGL" for window as #m else open "openGL" for graphics as #m end if #m "trapclose [quit]" #m "when characterInput [key]" #m "setfocus" MainH = hwnd( #m ) call openglInit calldll #gl , "glShadeModel" _ , GL.SMOOTH as ulong _ , ret as ulong call glEnable GL.LIGHTING call glLight GL.LIGHT0 , GL.DIFFUSE , lgray call glLight GL.LIGHT0 , GL.AMBIENT , dgray call d4d.fill 0 , 1 , 0 , 1 call glLight GL.LIGHT0 , GL.POSITION , dummy call glEnable GL.LIGHT0
timer 40 , [tmr] wait [tmr] scan
call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT call glLoadIdentity call glScale winyx , 1 , 1 call glMaterial GL.FRONT , GL.DIFFUSE , white call glMaterial GL.FRONT , GL.AMBIENT , white call glPushMatrix call glRotate angle , 1 , 1 , 0 select case state case 0 call setbox 0,0,0 , .5,.5,.5 call cube case 1 call setbox 0,0,0 , .5,.5,.5 call sphere 12 , 12 , 1 , 1 case 2 call setbox 0,0,0 , .7,.3,.3 call torus 12 , 12 case 3 call setbox 0,0,0 , .5,.5,.5 call cylinder 7 , .6,.6 , 1 , 1 case else call setbox 0,0,0 , .7,.3,.3 call banana 12 , 12 end select call glPopMatrix calldll #gdi32,"SwapBuffers" _ , MainDC as ulong _ , ret as long angle = angle + 5 if angle >= 360 * 3 then state = state + 1 angle = 0 end if if state > 4 then state = 0 wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( 27 ) then wait [quit] calldll #gl,"wglMakeCurrent" _ , 0 as ulong, 0 as ulong, ret as long calldll #gl,"wglDeleteContext" _ , GLContext as ulong, ret as long calldll #user32, "ReleaseDC" _ , MainH as ulong, MainDC as ulong,ret as long close #m close #gl end
''avartar's + animation's
sub reset.animation for i = 0 to 64 call skelet i , 0 , 0 , 0 call skelet i , 0 , 0 , 0 next i end sub
sub bug.move anim , f , a select case anim Case bug.fly For i = 0 To 1 call skelet iwing + left + i , 0 , 0 , pend( f + 180 * i , a) call skelet iwing + right + i , 0 , 0 , pend( f + 180 * i , 0 - a) Next Case bug.left.box call skelet iarm + left , 0 , pend( f , 0 - a ) + 45 , 0 call skelet ielbow + left , 0 , pend( f , a * 2 ) - 60 , 0 Case bug.left.legs For i = 0 To 4 call skelet ileg + left + i, 0 , 0, pend( f + i * 180 , a ) call skelet iknee + right + i, pend( f + i * 180 + 90 , a ) , 0 , 0 Next Case bug.right.box call skelet iarm + right , 0 , pend( f , a ) - 45 ,0 call skelet ielbow + right , 0, pend( f , a * -2) + 60 , 0 Case bug.right.legs For i = 0 To 4 call skelet ileg + right + i , 0 , 0 , pend(f + i * 180, a) call skelet iknee + right + i , pend( f + i * 180 + 90 , a ) , 0 , 0 Next Case bug.stand call skelet iarm + left , 0 , 45 , 0 call skelet ielbow + left , 0 , -60 , 0 call skelet ifinger + left , 0 , 0 , 0 call skelet ithumb + left , 0 , 0 , 0 call skelet iarm + right, 0 , -45 , 0 call skelet ielbow + right , 0, 60 , 0 call skelet ifinger + right , 0 , 0 , 0 call skelet ithumb + right , 0 , 0 , 0 call skelet itail + left , 10 , 0 , 0 call skelet itail + right , -10 , 0 , 0 Case bug.sting call skelet itail + left , 10 + pend(f, a), 0, 0 call skelet itail + right , 10 - pend(f, a), 0, 0 case else ''bug.home for i = 0 to 64 call skelet i , 0 , 0 , 0 call skelet i , 0 , 0 , 0 next i end select end sub
sub robot.bug call glPushMatrix call glRotate 180 , 0 , 1 , 0 call glScale .006 , .006 , .006 call setbox 0, 0, 0, 30, 10.0, 60.0 call cube For i = 0 To 4 call glPushMatrix call child 35.0, 0.0, i * 25 - 50 , ileg + left + i, xyz call setbox 30.0, 0.0, 0.0, 30.0, 5.0, 5.0 call cube call glPushMatrix call child 65.0, -5.0, 0.0 , iknee + left + i, xyz call setbox 0.0, -30.0, 0.0, 5.0, 30.0, 5.0 call cube call glPopMatrix call glPopMatrix call glPushMatrix call child -35.0, 0.0, i * 25 - 50, ileg + right + i, xyz call setbox -30.0, 0.0, 0.0, 30.0, 5.0, 5.0 call cube call glPushMatrix call child -65.0, -5.0, 0.0 , iknee + right + 1, xyz call setbox 0.0, -30.0, 0.0, 5.0, 30.0, 5.0 call cube call glPopMatrix call glPopMatrix Next call glPushMatrix call child 0 , 0 , -50 , itail + left , xyz For i = 0 To 9 call glPushMatrix call child 0.0, 0.0, -30.0 , itail + left , xyz call setbox 0.0, 0.0, -15.0, 10.0, 10.0, 10.0 call cube Next for i = 0 to 8 call glPushMatrix call child 0 , 0 , -30 , itail + right , xyz call cube next i for i = 0 to 8 call glPopMatrix call glPopMatrix next i call glPopMatrix call glPushMatrix call child 30.0, 0.0, 65.0, iarm + left , xyz call setbox 0.0, 0.0, 65.0 , 5 , 35 , 5 call cube call glPushMatrix call child 0.0, 0.0, 65.0, ielbow + left , xyz call cube call glPushMatrix call child 0.0, 0.0, 65.0 , iwrist + left , xyz call glPushMatrix call child -10.0, 0.0, 5.0 , ithumb + left , xyz call cube call glPopMatrix call glPushMatrix call child 5.0, 0.0, 5.0, ifinger + left , xyz call setbox 0.0, 0.0, 30.0, 5.0, 10.0, 30.0 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -30.0, 0.0, 65.0, iarm + right, xyz call setbox 0.0, 0.0, 30.0, 5.0, 5.0, 30.0 call cube call glPushMatrix call child 0.0, 0.0, 65.0, ielbow + right, xyz call cube call glPushMatrix call child 0.0, 0.0, 65.0, iwrist + right , xyz call glPushMatrix call child 10.0, 0.0, 5.0, ithumb + right , xyz call cube call glPopMatrix call glPushMatrix call child -5.0, 0.0, 5.0, ifinger + right , xyz call setbox 0.0, 0.0, 30.0, 5.0, 10.0, 30.0 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPopMatrix For i = 0 To 1 call glPushMatrix call child 20.0, 20.0, 40.0 - 50.0 * i, iwing + left + i, xyz call setbox 60.0, 0.0, 8.0, 60.0, 2.0, 16.0 call cube call glPopMatrix call glPushMatrix call child -20.0, 20.0, 40.0 - 50.0 * i , iwing + right + i, xyz call setbox -60.0, 0.0, 8.0, 60.0, 2.0, 16.0 call cube call glPopMatrix Next call glPopMatrix end sub
sub walk.dog f , a call skelet left + arm , pend( f + 180 , a ) , 0 , 0 call skelet left + elbow , pend( f + 90 , a ) - a , 0 , 0 call skelet right + arm , pend( f , a ) , 0 , 0 call skelet right + elbow _ , pend( f - 90 , a ) - a , 0 , 0 call skelet left + leg , pend( f + 180 , a ) , 0 , 0 call skelet left + knee , pend( f + 90 , a ) - a , 0 , 0 call skelet right + leg , pend( f , a ) , 0 , 0 call skelet right + knee _ , pend( f - 90 , a ) - a , 0 , 0 call skelet tail , -45 , 0 , pend( f * 2 , 30 ) end sub
sub robot.dog call glPushMatrix call glRotate 180 , 0 , 1 , 0 call setbox 0,.2,.5 , .3,.3,.7 call cube call glPushMatrix call child 0 , .6 , 1.5 , left + neck , xyz call glPushMatrix call child 0 , 0 , 0 , right + neck , zyx call setbox 0,0,0 , .3 , .3 , .3 call cube call setbox 0,-.2,.3 , .2,.2,.2 call cube call setbox 0,0,.5 , .1,.1,.1 call cube call setbox .3,-.15,0 , .05,.3,.2 call cube call setbox -.3,-.15,0 , .05,.3,.2 call cube call glPopMatrix call glPopMatrix call glPushMatrix call child 0 , .4 , -.5 , tail , yzx call setbox 0,.3,0 , .1 , .3 , .1 call cube call glPopMatrix call glPushMatrix call child .3 , 0 , 1 , left + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + enkle , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.3 , 0 , 1 , right + leg, zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + enkle , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .3 , 0 , 0 , left + arm , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + elbow , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + wrist , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.3 , 0 , 0 , right + arm , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + elbow , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + wrist , xyz call setbox 0 , 0 , .2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPopMatrix end sub
sub walk.man f , a ''example animation call skelet left + arm , pend( f , a ) , 0 , 0 call skelet left + elbow , abs( a ) , 0 , 0 call skelet right + arm , pend( f + 180, a ) , 0 , 0 call skelet right + elbow , abs( a ) , 0 , 0 call skelet left + leg , pend( f + 180 , a ) , 0 , 0 call skelet left + knee , pend( f + 90 , a ) - a , 0 , 0 call skelet right + leg , pend( f , a ) , 0 , 0 call skelet right + knee _ , pend( f - 90 , a ) - a , 0 , 0 call skelet right + thumb , pend( f , 15 ) + 15 , 0 , 0 for i = 0 to 2 call skelet left + index.finger + i _ , 0 , 0 , pend( f , 15 ) - 15 call skelet left + mid.finger + i _ , 0 , 0 , pend( f - 120 , 15 ) - 15 call skelet left + ring.finger + i _ , 0 , 0 , pend( f + 120 , 15 ) - 15 call skelet right + index.finger + i _ , 0 , 0 , pend( f , 15 ) + 15 call skelet right + mid.finger + i _ , 0 , 0 , pend( f - 120 , 15 ) + 15 call skelet right + ring.finger + i _ , 0 , 0 , pend( f + 120 , 15 ) + 15 next i end sub
sub finger i ''example avatar sub body part call glPushMatrix call child 0,-.2,0 , i , xyz call setbox 0,-.1,0 , .1,.1,.1 call cube call glPushMatrix call child 0,-.2,0 , i+1 , xyz call cube call glPushMatrix call child 0,-.2,0 , i+2 , xyz call cube call glPopMatrix call glPopMatrix call glPopMatrix end sub
sub hand leftorright '' example avartar body part call setbox 0,-.3,0 , .1,.3,.3 call cube call glPushMatrix call child 0,-.2,-.5 , leftorright + thumb , xyz call finger leftorright + thumb call glPopMatrix call glPushMatrix call child 0,-.6,-.3 , leftorright + index.finger , xyz call finger leftorright + index.finger call glPopMatrix call glPushMatrix call child 0,-.6,0 , leftorright + mid.finger , xyz call finger leftorright + index.finger call glPopMatrix call glPushMatrix call child 0,-.6,.3 , leftorright + ring.finger , xyz call finger leftorright + index.finger call glPopMatrix end sub
sub robot.man h ''example avatar call setbox 0 , 0 , 0 , .3 , .1 , .1 call cube call setbox 0 , .75 , 0 , .1 , .5 , .1 call cube call setbox 0 , 1.8 , 0 , .2 , .2 , .2 call cube call setbox 0 , 1.4 , 0 , .7 , .1 , .1 call cube call glPushMatrix call child .25 , 0 , 0 , left + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , left + enkle , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.25 , 0 , 0 , right + leg , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + knee , xyz call cube call glPushMatrix call child 0 , -1.2 , 0 , right + enkle , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call cube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .65 , 1.3 , 0 , left + arm , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , left + elbow , xyz call cube call glPushMatrix call child 0 , -1 , 0 , left + wrist , zyx if h then call hand left else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call cube end if call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.65 , 1.3 , 0 , right + arm , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call cube call glPushMatrix call child 0 , -1 , 0 , right + elbow , xyz call cube call glPushMatrix call child 0 , -1 , 0 , right + wrist , zyx if h then call hand right else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call cube end if call glPopMatrix call glPopMatrix call glPopMatrix end sub
'' color object math
function rainbow( x ) r = sin( rad( x ) ) * 127 + 128 g = sin( rad( x - 120 ) ) * 127 + 128 b = sin( rad( x + 120 ) ) * 127 + 128 rainbow = rgba( r , g , b , 255 ) end function
function rgba( r , g , b , a ) ''create color object r = r and 255 g = g and 255 b = b and 255 a = a and 255 rgba = r + g * 256 + b * 256 ^ 2 + a * 256 ^ 3 end function
function colorR( clr ) ''get red channel from color object colorR = int( clr and 255 ) / 256 end function
function colorG( clr ) ''get green channel from color object colorG = ( int( clr / 256 ) and 255 ) / 256 end function
function colorB( clr ) ''get blue channel from color object colorB = ( int( clr / 256 ^ 2 ) and 255 ) / 256 end function
function colorA( clr ) ''get alpha channel from color object colorA = ( int( clr / 256 ^ 3 ) and 255 ) / 256 end function
'' vector math
function lenght( x1 , y1 , z1 , x2 , y2 , z2 ) lenght = sqr( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 )+1e-9 end function
sub cross x1 , y1 , z1 , x2 , y2 , z2 ''normalized cross product x = y1 * z2 - y2 * z1 d3d.x.struct = x / lenght(x1,y1,z1,x2,y2,z2) y = z1 * x2 - z2 * x1 d3d.y.struct = y / lenght(x1,y1,z1,x2,y2,z2) z = x1 * y2 - x2 * y1 d3d.z.struct = z / lenght(x1,y1,z1,x2,y2,z2) end sub
'' blua3d engine
sub child x , y , z , lim , ax if lim < 0 or lim > 64 then exit sub select case ax case xyz call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 case xzy call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 case yxz call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 case yzx call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 case zxy call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 case zyx call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 case else end select end sub
sub skelet no , x , y , z if no < 0 or no > 64 then exit sub sk( no , 0 ) = x sk( no , 1 ) = y sk( no , 2 ) = z end sub
function pend( f , a ) pend = sin( rad( f ) ) * a end function
function rad( x ) rad = x * pi / 180 end function
function sgn( x ) uit = 0 if x < 0 then uit = -1 if x > 0 then uit = 1 sgn = uit end function
'' graphics wrapper
sub setbox mx , my , mz , dx , dy , dz ''set bodinging box coordinates box(0) = mx box(1) = my box(2) = mz box(3) = dx box(4) = dy box(5) = dz end sub
sub cube ''create a cube mesh
''first fil swarm whit points call point 0 , -1 , -1 , -1 call point 1 , -1 , -1 , 1 call point 2 , -1 , 1 , -1 call point 3 , -1 , 1 , 1 call point 4 , 1 , -1 , -1 call point 5 , 1 , -1 , 1 call point 6 , 1 , 1 , -1 call point 7 , 1 , 1 , 1
''then use points in swarm to draw quads call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) call quad 0 , 1 , 3 , 2 call quad 7 , 6 , 4 , 5 call quad 0 , 2 , 6 , 4 call quad 7 , 5 , 1 , 3 call quad 0 , 1 , 5 , 4 call quad 7 , 6 , 2 , 3 call glPopMatrix end sub
sub sphere a , b , da , db if a < 3 then a = 3 if a > 64 then a = 64 if b < 3 then b = 3 if b > 64 then b = 64 call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3), box(4) , box(5) for i = 0-pi to pi step pi / a * 2 i2 = i + pi / a * 2 for j = 0-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 ) call point 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 ) call point 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 ) call point 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 ) call point 3 _ , abs( x ) ^ da * sgn( x ) _ , abs( y ) ^ db * sgn( y ) _ , abs( z ) ^ da * sgn( z ) call quad 0 , 1 , 2 , 3 next j next i call glPopMatrix end sub
sub banana a , b if a < 3 then a = 3 if a > 64 then a = 64 if b < 3 then b = 3 if b > 64 then b = 64 mx = box(0) my = box(1) mz = box(2) dx = box(3) dy = box(4) dz = box(5) for i = 0-pi to pi step pi / a * 2 i2 = i + pi / a * 2 for j = 0-p1/1.99 to pi/1.99 - pi/b*1.99 step pi / b * 1.99 j2 = j + pi / b * 1.99 call point 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 ) call point 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 ) call point 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 ) call point 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 ) call quad 0 , 1 , 2 , 3 next j next i end sub
sub torus a , b if a < 3 then a = 3 if a > 64 then a = 64 if b < 3 then b = 3 if b > 64 then b = 64 mx = box(0) my = box(1) mz = box(2) dx = box(3) dy = box(4) dz = box(5) for i = 0-pi to pi step pi / a * 2 i2 = i + pi / a * 2 for j = 0-pi to pi step pi / b * 2 j2 = j + pi / b * 2 call point 0 _ , mx + ( dx + dy * cos( i ) ) * cos( j ) _ , my + ( dx + dy * cos( i ) ) * sin( j ) _ , mz + sin( i ) * dz call point 1 _ , mx + ( dx + dy * cos( i ) ) * cos( j2 ) _ , my + ( dx + dy * cos( i ) ) * sin( j2 ) _ , mz + sin( i ) * dz call point 2 _ , mx + ( dx + dy * cos( i2 ) ) * cos( j2 ) _ , my + ( dx + dy * cos( i2 ) ) * sin( j2 ) _ , mz + sin( i2 ) * dz call point 3 _ , mx + ( dx + dy * cos( i2 ) ) * cos( j ) _ , my + ( dx + dy * cos( i2 ) ) * sin( j ) _ , mz + sin( i2 ) * dz call quad 0 , 1 , 2 , 3 next j next i end sub
sub cylinder sides , dx , dy , top , bot if sides < 3 then sides = 3 if sides > 64 then sides = 64 for f = 0 to sides + 2 call point f , box(0) + sin( f * pi * 2 / sides ) * box(3) _ , box(1) - box(4) _ , box(2) + cos( f * pi * 2 / sides ) * box(5) call point f + sides + 1 , box(0) + sin( f * pi * 2 / sides ) * dx _ , box(1) + box(4) _ , box(2) + cos( f * pi * 2 / sides ) * dy next f for f = 0 to sides + 1 call quad f , f + 1 , f + 2 + sides , f + 1 + sides next f if top then call point 255 , 0 , box.m.y + box.d.y , 0 for f = 0 to sides call point 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 call tri 255 , f , f + 1 next f end if if bot then call point 255 , 0 , box.m.y - box.d.y , 0 for f = 0 to sides + 2 call point 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 call tri 255 , f , f + 1 next f end if end sub
sub point no , x , y , z ''set a point in the swarm if no < 0 or no > 256 then exit sub pntx( no ) = x pnty( no ) = y pntz( no ) = z end sub
sub tri p1 , p2 , p3 ''draw a triangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) call cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.TRIANGLES call glNormal d3d.x.struct , d3d.y.struct , d3d.z.struct call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glEnd end sub
sub quad p1 , p2 , p3 , p4 ''draw a quadangle from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub if p4 < 0 or p4 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) x4 = pntx( p4 ) y4 = pnty( p4 ) z4 = pntz( p4 ) call cross x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 call glBegin GL.QUADS call glNormal d3d.x.struct , d3d.y.struct , d3d.z.struct call glVertex x1 , y1 , z1 call glVertex x2 , y2 , z2 call glVertex x3 , y3 , z3 call glVertex x4 , y4 , z4 call glEnd end sub
'' openGl
sub glClear code ''clear the openGL screen calldll #gl,"glClear" _ , code as long _ , ret as long end sub
sub glLoadIdentity ''set drawingmatrix to standert calldll #gl , "glLoadIdentity" _ , ret as long end sub
sub glPushMatrix ''to new drawingmatrix calldll #gl , "glPushMatrix" _ , ret as long end sub
sub glPopMatrix ''to old drawingmatrix calldll #gl , "glPopMatrix" _ , ret as long end sub
sub glEnd ''end of polygon[s] calldll #gl , "glEnd" _ , ret as void end sub
sub glEnable i ''set a item calldll #gl , "glEnable" _ , i as long _ , ret as long end sub
sub glBegin i ''set polygon mode calldll #gl , "glBegin" _ , i as long _ , ret as long end sub
sub glScale x , y , z ''scale drawingmatrix calldll #gl , "glScaled" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glTranslate x , y , z ''move drawingmatrix calldll #gl , "glTranslated" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glRotate a , x , y , z ''rotate drawinmatrix calldll #gl , "glRotated" _ , a as double _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glVertex x , y , z ''add a point to a polygon calldll #gl , "glVertex3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glNormal x , y , z ''set normal of point[s] calldll #gl , "glNormal3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub setColor kl ''set color of polygon r = colorR( kl ) g = colorG( kl ) b = colorB( kl ) a = colorA( kl ) call d4d.fill r , g , b , a end sub
sub d4d.fill a , b , c , d ''fill d4d.struct d4d.a.struct = a d4d.b.struct = b d4d.c.struct = c d4d.d.struct = d end sub
function glGetError() calldll #gl , "glGetError" _ , glGetError as ulong end function
sub glLight no , e , kl select case e case GL.DIFFUSE call setColor kl calldll #gl , "glLightfv" _ , no as long _ , e as long _ , d4d as struct _ , ret as long print "light.diffuse = " ; dechex$( kl ) print "light.ret = " ; dechex$( ret ) print "error = " ; dechex$( glGetError() ) case GL.POSITION calldll #gl , "glLightfv" _ , no as long _ , e as long _ , d4d as struct _ , ret as long case else end select end sub
sub glMaterial face , e , kl if e = GL.SHININESS then calldll #gl , "glMaterialf" _ , face as long _ , e as long _ , kl as single _ , ret as long else call setColor kl calldll #gl , "glMaterialfv" _ , face as long _ , e as long _ , d4d as struct _ , ret as long if tel = 0 then print "mat.color = " ; dechex$( kl ) print "mat.ret = " ; dechex$( ret ) print "error = " ; dechex$( glGetError() ) tel = 1 end if end if end sub
sub openglInit struct PFD _ , Size as word _ , Version as word _ , Flags as long _ , pixelType as char[1] _ , ColorBits as char[1] _ , RedBits as char[1] _ , RedShift as char[1] _ , GreenBits as char[1] _ , GreenShift as char[1] _ , BlueBits as char[1] _ , BlueShift as char[1] _ , AlphaBits as char[1] _ , AlphaShift as char[1] _ , AccumBits as char[1] _ , AccumRedBits as char[1] _ , AccumGreenBits as char[1] _ , AccumBlueBits as char[1] _ , AccumAlphaBits as char[1] _ , DepthBits as char[1] _ , StencilBits as char[1] _ , AuxBuffers as char[1] _ , LayerType as char[1] _ , Reserved as char[1] _ , LayerMask as long _ , VisibleMask as long _ , DamageMask as long
PFD.Version.struct=1 PFD.ColorBits.struct=24 PFD.DepthBits.struct=16 PFD.Size.struct=len(PFD.struct) PFD.Flags.struct=37
calldll #user32,"GetDC" _ , MainH as ulong, MainDC as ulong calldll #gdi32,"ChoosePixelFormat" _ , MainDC as ulong, PFD as struct, ret as long calldll #gdi32, "SetPixelFormat" _ , MainDC as ulong, ret as long _ , PFD as struct, t as long calldll #gl,"wglCreateContext" _ , MainDC as ulong, GLContext as ulong calldll #gl,"wglMakeCurrent" _ , MainDC as ulong, GLContext as ulong _ , ret as long call glEnable GL.DEPTH.TEST end sub
|
|
|
Post by bluatigro on Oct 24, 2018 3:58:13 GMT -5
update : some error's removed [ not al ]
sub cylinder sides , dx , dy , top , bot if sides < 3 then sides = 3 if sides > 64 then sides = 64 for f = 0 to sides + 2 call point f , box(0) + sin( f * pi * 2 / sides ) * box(3) _ , box(1) - box(4) _ , box(2) + cos( f * pi * 2 / sides ) * box(5) call point f + sides + 1 , box(0) + sin( f * pi * 2 / sides ) * dx _ , box(1) + box(4) _ , box(2) + cos( f * pi * 2 / sides ) * dy next f for f = 0 to sides + 1 call quad f , f + 1 , f + 2 + sides , f + 1 + sides next f if top then call point 255 , 0 , box(1) + box(4) , 0 for f = 0 to sides call point f , box(0) + sin( f * pi * 2 / sides ) * dx _ , box(1) + box(4) _ , box(2) + cos( f * pi * 2 / sides ) * dy next f for f = 0 to sides + 2 call tri 255 , f , f + 1 next f end if if bot then call point 255 , 0 , box(1) - box(4) , 0 for f = 0 to sides + 2 call point f , box(0) - sin( f * pi * 2 / sides ) * box(3) _ , box(1) - box(4) _ , box(2) + cos( f * pi * 2 / sides ) * box(5) next f for f = 0 to sides + 2 call tri 255 , f , f + 1 next f end if end sub
|
|
|
Post by bluatigro on Jan 6, 2020 2:09:36 GMT -5
update : added a random element in sub tree use 'r' in prog$ for random angle
''bluatigro 6 jan 2020 ''openGL + bluaGL ''l-system example
nomainwin dim pntx(256),pnty(256),pntz(256),box(5),sk(64,2) global pi : pi = atn( 1 ) * 4
'' color objects
global black , red , green , yellow global blue , magenta , cyan , white global gray , pink , purple , orange black = rgba( 000 , 000 , 000 , 255 ) red = rgba( 255 , 000 , 000 , 255 ) green = rgba( 000 , 255 , 000 , 255 ) yellow = rgba( 255 , 255 , 000 , 255 ) blue = rgba( 000 , 000 , 255 , 255 ) magenta = rgba( 255 , 000 , 255 , 255 ) cyan = rgba( 000 , 255 , 255 , 255 ) white = rgba( 255 , 255 , 255 , 255 ) gray = rgba( 127 , 127 , 127 , 255 ) pink = rgba( 255 , 127 , 127 , 255 ) purple = rgba( 127 , 000 , 127 , 255 ) orange = rgba( 255 , 127 , 000 , 255 ) global xyz , xzy , yxz , yzx , zxy , zyx xyz = 0 xzy = 1 yxz = 2 yzx = 3 zxy = 4 zyx = 5 ''some joint number's global arm,elbow,wrist,leg,knee,enkle,eye,leftno,rightno arm = 0 elbow = 1 wrist = 2 leg = 3 knee = 4 enkle = 5 eye = 6 global thumb,index,middle,ring thumb = 7 index = 10 middle = 13 ring = 16 leftno = 0 rightno = 32
'' opengl consts
global GL.COLOR.BUFFER.BIT : GL.COLOR.BUFFER.BIT = 16384 global GL.DEPTH.BUFFER.BIT : GL.DEPTH.BUFFER.BIT = 256 global GL.DEPTH.TEST : GL.DEPTH.TEST = 2929 ' primatifs global GL.TRIANGLES : GL.TRIANGLES = 4 global GL.QUADS : GL.QUADS = 7 ' light Global GL.LIGHTING: GL.LIGHTING = 2896 Global GL.LIGHT0: GL.LIGHT0 = 16384 Global GL.AMBIENT: GL.AMBIENT = 4608 Global GL.DIFFUSE: GL.DIFFUSE = 4609 Global GL.SPECULAR: GL.SPECULAR = 4610 Global GL.SHININESS: GL.SHININESS = 5633 Global GL.EMISSION: GL.EMISSION = 5632 Global GL.POSITION: GL.POSITION = 4611 Global GL.FRONT.AND.BACK: GL.FRONT.AND.BACK = 103 '' Fog Global GL.FOG: GL.FOG = 2912 Global GL.FOG.MODE: GL.FOG.MODE = 2917 Global GL.FOG.DENSITY: GL.FOG.DENSITY = 2914 Global GL.FOG.COLOR: GL.FOG.COLOR = 2918 Global GL.FOG.INDEX: GL.FOG.INDEX = 2913 Global GL.FOG.START: GL.FOG.START = 2915 Global GL.FOG.END: GL.FOG.END = 2916 Global GL.LINEAR: GL.LINEAR = 9729 Global GL.EXP: GL.EXP = 2048 Global GL.EXP2: GL.EXP2 = 2049
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , winyx winx = WindowWidth winy = WindowHeight winyx = winy / winx
global MainH , MainDC ''wil be filled by code
global angle ''for animation's open "opengl32.dll" for dll as #gl if instr( Platform$ , "LBB" ) then open "openGL" for window as #m else open "openGL" for graphics as #m end if #m "trapclose [quit]" #m "when characterInput [key]" #m "setfocus" MainH = hwnd( #m ) call openglInit timer 40 , [timer] wait [timer] scan randomize 1 call glClear GL.COLOR.BUFFER.BIT or GL.DEPTH.BUFFER.BIT call glLoadIdentity call glScale winyx , 1 , 1 call glPushMatrix call glTranslate 0,-0.5,0 call glScale 0.2,0.2,0.2 call glRotate angle , 0,1,0 call tree 3 , "f[rrbLh]rrbLh" _ , .7 , 45 , 90 , 20 , rainbow( angle ) call glPopMatrix call glPushMatrix call glTranslate 1,-0.5,0 call glScale 0.2,0.2,0.2 call glRotate angle , 0,1,0 call tree 3 , "f[rrbLh]rrbLh" _ , .7 , 45 , 90 , 20 , rainbow( angle ) call glPopMatrix call glPushMatrix call glTranslate -1,-0.5,0 call glScale 0.2,0.2,0.2 call glRotate angle , 0,1,0 call tree 3 , "f[rrbLh]rrbLh" _ , .7 , 45 , 90 , 20 , rainbow( angle ) call glPopMatrix
calldll #gdi32,"SwapBuffers" _ , MainDC as ulong _ , ret as long angle = angle + 5 wait [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( 27 ) then wait [quit] calldll #gl,"wglMakeCurrent" _ , 0 as ulong, 0 as ulong, ret as long calldll #gl,"wglDeleteContext" _ , GLContext as ulong, ret as long calldll #user32, "ReleaseDC" _ , MainH as ulong, MainDC as ulong,ret as long close #m close #gl end
sub walk.man f , a ''example animation of a avatar call skelet arm + leftno , pend( f , a ) , 0 , 0 call skelet elbow + leftno , abs( a ) , 0 , 0 call skelet arm + rightno , pend( f + 180, a ) , 0 , 0 call skelet elbow + rightno , abs( a ) , 0 , 0 call skelet leg + leftno , pend( f + 180 , a ) , 0 , 0 call skelet knee + leftno , pend( f + 90 , a ) - a , 0 , 0 call skelet leg + rightno , pend( f , a ) , 0 , 0 call skelet knee + rightno _ , pend( f - 90 , a ) - a , 0 , 0 call skelet thumb + leftno , pend( f , 15 ) + 15 , 0 , 0 call skelet thumb + rightno , pend( f , 15 ) + 15 , 0 , 0 for i = 0 to 2 call skelet index + i + leftno _ , 0 , 0 , pend( f , 15 ) - 15 call skelet middle + i + leftno _ , 0 , 0 , pend( f - 120 , 15 ) - 15 call skelet ring + i + leftno _ , 0 , 0 , pend( f + 120 , 15 ) - 15 call skelet index + i + rightno _ , 0 , 0 , pend( f , 15 ) + 15 call skelet middle + i + rightno _ , 0 , 0 , pend( f - 120 , 15 ) + 15 call skelet ring + i + rightno _ , 0 , 0 , pend( f + 120 , 15 ) + 15 next i end sub
sub tree l , prog$ , f,x,y,z,kl ''draw a tree ''l = depth : do not make to big ''prog$ = description ''f = how mutch smaller must be < 1 ''x,y,z = angles in degrees ''kl = color of flower [ if any ] if l > 0 then for i = 1 to len( prog$ ) select case mid$( prog$ , i , 1 ) case "f" ''draw trunk or twig and move pen call setbox 0,1,0 , .3,1,.3 call klcube orange call glTranslate 0,2,0 case "l" ''draw a leave call glPushMatrix call glScale .5 , .5 , .5 call point 0 , 0,0,0 call point 1 , 1,0,1 call point 2 , 3,0,3 call point 3 , 1,0,-1 call quad 0 , 1 , 2 , 3 , green call glPopMatrix case "L" ''draw a set of leaves for t = 0 to 4 call glPushMatrix call glRotate 72 * t , 0,1,0 call glScale .5 , .5 , .5 call point 0 , 0,0,0 call point 1 , 1,0,1 call point 2 , 3,0,3 call point 3 , 1,0,-1 call quad 0 , 1 , 2 , 3 , green call glPopMatrix next t case "h" ''draw a flower for t = 0 to 4 call glPushMatrix call glRotate 72 * t , 0,1,0 call glScale .5 , .5 , .5 call point 0 , 0,0,0 call point 1 , 1,1,1 call point 2 , 3,3,3 call point 3 , 1,1,-1 call quad 0 , 1 , 2 , 3 , kl call glPopMatrix next t case "g" ''move pen call glTranslate 0,2,0 case "[" ''store pen call glPushMatrix case "]" ''read pen call glPopMatrix case "X" call glRotate 0-x , 1,0,0 case "x" call glRotate x , 1,0,0 case "Y" call glRotate 0-y , 0,1,0 case "y" call glRotate y , 0,1,0 case "Z" call glRotate 0-z , 0,0,1 case "z" call glRotate z , 0,0,1 case "r" a$ = mid$( "xyzXYZ" , int(rnd(0)*6+1) , 1 ) call tree l , a$ , f,x,y,z,kl case "b" ''draw hole tree f smaler call glScale f,f,f call tree l - 1 , prog$ , f,x,y,z,kl case else end select next i end if end sub
sub finger i ''part of avatar ''i = finger number call glPushMatrix call child 0,-.2,0 , i , xyz call setbox 0,-.1,0 , .1,.1,.1 call graycube call glPushMatrix call child 0,-.2,0 , i+1 , xyz call graycube call glPushMatrix call child 0,-.2,0 , i+2 , xyz call graycube call glPopMatrix call glPopMatrix call glPopMatrix end sub
sub hand i ''part of avatar ''i = leftno or right no call setbox 0,-.3,0 , .1,.3,.3 call graycube call glPushMatrix call child 0,-.2,-.5 , thumb + i , xyz call finger thumb + i call glPopMatrix call glPushMatrix call child 0,-.6,-.3 , index + i , xyz call finger index + i call glPopMatrix call glPushMatrix call child 0,-.6,0 , middle + i , xyz call finger middle + i call glPopMatrix call glPushMatrix call child 0,-.6,.3 , ring + i , xyz call finger ring + i call glPopMatrix end sub
sub robot h ''example avatar ''if h then robot has finger's call setbox 0 , 0 , 0 , .3 , .1 , .1 call colorcube call setbox 0 , .75 , 0 , .1 , .5 , .1 call colorcube call setbox 0 , 1.8 , 0 , .2 , .2 , .2 call colorcube call setbox 0 , 1.4 , 0 , .7 , .1 , .1 call colorcube call glPushMatrix call child .25 , 0 , 0 , leg + leftno , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call colorcube call glPushMatrix call child 0 , -1 , 0 , knee + leftno , xyz call colorcube call glPushMatrix call child 0 , -1.2 , 0 , enkle + leftno , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call colorcube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.25 , 0 , 0 , leg + rightno , zyx call setbox 0 , -.6 , 0 , .1 , .4 , .1 call colorcube call glPushMatrix call child 0 , -1 , 0 , knee + rightno , xyz call colorcube call glPushMatrix call child 0 , -1.2 , 0 , enkle + rightno , xyz call setbox 0 , 0 , -.2 , .1 , .1 , .3 call colorcube call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child .65 , 1.3 , 0 , arm + leftno , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call colorcube call glPushMatrix call child 0 , -1 , 0 , elbow + leftno , xyz call colorcube call glPushMatrix call child 0 , -1 , 0 , wrist + leftno , zyx if h then call hand leftno else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call colorcube end if call glPopMatrix call glPopMatrix call glPopMatrix call glPushMatrix call child -.65 , 1.3 , 0 , arm + rightno , xyz call setbox 0 , -.5 , 0 , .1 , .4 , .1 call colorcube call glPushMatrix call child 0 , -1 , 0 , elbow + rightno , xyz call colorcube call glPushMatrix call child 0 , -1 , 0 , wrist + rightno , zyx if h then call hand rightno else call setbox 0 , -.3 , 0 , .05 , .2 , .15 call colorcube end if call glPopMatrix call glPopMatrix call glPopMatrix end sub
[bluaGL] ''wrapper around openGL
function rainbow( x ) ''create a colorObject from a rainbow r = sin( rad( x ) ) * 127 + 128 g = sin( rad( x - 120 ) ) * 127 + 128 b = sin( rad( x + 120 ) ) * 127 + 128 rainbow = rgba( r , g , b , 255 ) end function
function rgba( r , g , b , a ) ''create color object r = r and 255 g = g and 255 b = b and 255 a = a and 255 rgba = r + g * 256 + b * 256 ^ 2 + a * 256 ^ 3 end function
function mix( kl1 , f , kl2 ) ''mix 2 colorObject's r1 = int( kl1 ) and 255 g1 = int( kl1 / 256 ) and 255 b1 = int( kl1 / 256 ^ 2 ) and 255 r2 = int( kl2 ) and 255 g2 = int( kl2 / 256 ) and 255 b2 = int( kl2 / 256 ^ 2 ) and 255 r = r1 + ( r2 - r1 ) * f g = g1 + ( g2 - g1 ) * f b = b1 + ( b2 - b1 ) * f mix = rgba( r , g , b , 255 ) end function
function colorR( clr ) ''get red channel from color object colorR = int( clr and 255 ) / 256 end function
function colorG( clr ) ''get green channel from color object colorG = ( int( clr / 256 ) and 255 ) / 256 end function
function colorB( clr ) ''get blue channel from color object colorB = ( int( clr / 256 ^ 2 ) and 255 ) / 256 end function
function colorA( clr ) ''get alpha channel from color object colorA = ( int( clr / 256 ^ 3 ) and 255 ) / 256 end function
sub setColor clr ''set color of future point's of polygon[s] ''whit a colorObject r = colorR( clr ) g = colorG( clr ) b = colorB( clr ) a = colorA( clr ) call glColor r , g , b , a end sub
'' vector math
function lenght( x1 , y1 , z1 , x2 , y2 , z2 ) lenght = sqr( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ) + 1e-10 end function
function nx( x1 , y1 , z1 , x2 , y2 , z2 ) ''normalized cross product x x = y1 * z2 - y2 * z1 nx = x / lenght(x1,y1,z1,x2,y2,z2) end function
function ny( x1 , y1 , z1 , x2 , y2 , z2 ) ''normalized cross product y y = z1 * x2 - z2 * x1 ny = y / lenght(x1,y1,z1,x2,y2,z2) end function
function nz( x1 , y1 , z1 , x2 , y2 , z2 ) ''normalized cross product z z = x1 * y2 - x2 * y1 nz = z / lenght(x1,y1,z1,x2,y2,z2) end function
sub child x , y , z , lim , ax ''create a joint of a avatar if lim < 0 or lim > 64 then exit sub select case ax case xyz call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 case xzy call glTranslate x , y , z call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 case yxz call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,2) , 0,0,1 case yzx call glTranslate x , y , z call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 case zxy call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,0) , 1,0,0 call glRotate sk(lim,1) , 0,1,0 case zyx call glTranslate x , y , z call glRotate sk(lim,2) , 0,0,1 call glRotate sk(lim,1) , 0,1,0 call glRotate sk(lim,0) , 1,0,0 case else end select end sub
sub skelet no , x , y , z ''set joint angle's of a avatar if no < 0 or no > 64 then exit sub sk( no , 0 ) = x sk( no , 1 ) = y sk( no , 2 ) = z end sub
function pend( f , a ) ''for smooth animation's pend = sin( rad( f ) ) * a end function
function rad( x ) ''from degrees to radians rad = x * pi / 180 end function
function sgn( x ) uit = 0 if x < 0 then uit = -1 if x > 0 then uit = 1 sgn = uit end function
sub setbox mx , my , mz , dx , dy , dz ''set bodinging box coordinates box( 0 ) = mx box( 1 ) = my box( 2 ) = mz box( 3 ) = dx box( 4 ) = dy box( 5 ) = dz end sub
sub klcube kl ''create a 1 color shaded cube kl1 = mix( kl , .2 , black ) kl2 = mix( kl , .4 , black ) call cube kl,kl , kl1,kl1 , kl2 , kl2 end sub
sub colorcube ''create a cube whit fixed color's call cube red,cyan , green,magenta , blue,yellow end sub
sub graycube ''create a shaded white cube kl1 = mix( white , .3 , black ) kl2 = mix( white , .7 , black ) call cube white,white,kl1,kl1,kl2,kl2 end sub
sub cube left , right , front , back , down , up ''example mesh ''create a cube ''whit 6 colors and whit bodingbox coordinates
''first fil swarm whit points call point 0 , -1 , -1 , -1 call point 1 , -1 , -1 , 1 call point 2 , -1 , 1 , -1 call point 3 , -1 , 1 , 1 call point 4 , 1 , -1 , -1 call point 5 , 1 , -1 , 1 call point 6 , 1 , 1 , -1 call point 7 , 1 , 1 , 1
''then use points in swarm to draw quads call glPushMatrix call glTranslate box(0) , box(1) , box(2) call glScale box(3) , box(4) , box(5) call quad 0 , 1 , 3 , 2 , left call quad 7 , 6 , 4 , 5 , right call quad 0 , 2 , 6 , 4 , front call quad 7 , 5 , 1 , 3 , back call quad 0 , 1 , 5 , 4 , down call quad 7 , 6 , 2 , 3 , up call glPopMatrix end sub
sub point no , x , y , z ''set a point in the swarm if no < 0 or no > 256 then exit sub pntx( no ) = x pnty( no ) = y pntz( no ) = z end sub
sub tri p1 , p2 , p3 , kl ''draw a triangle whit 1 color from point's in swarm call tri3 p1 , kl , p2 , kl , p3 , kl end sub
sub tri3 p1 , kl1 , p2 , kl2 , p3 , kl3 ''draw a triangle whit 3 color's from point's in swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) x = nx( x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 ) y = ny( x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 ) z = nz( x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 ) call glBegin GL.TRIANGLES call glNormal x , y , z call setColor kl1 call glVertex x1 , y1 , z1 call setColor kl2 call glVertex x2 , y2 , z2 call setColor kl3 call glVertex x3 , y3 , z3 call glEnd end sub
sub quad p1 , p2 , p3 , p4 , kl ''draw a quadangle whit 1 color from points in the swarm call quad4 p1 , kl , p2 , kl , p3 , kl , p4 , kl end sub
sub quad4 p1 , kl1 , p2 , kl2 , p3 , kl3 , p4 , kl4 ''draw a quadangle whit 4 color's from points in the swarm if p1 < 0 or p1 > 256 then exit sub if p2 < 0 or p2 > 256 then exit sub if p3 < 0 or p3 > 256 then exit sub if p4 < 0 or p4 > 256 then exit sub x1 = pntx( p1 ) y1 = pnty( p1 ) z1 = pntz( p1 ) x2 = pntx( p2 ) y2 = pnty( p2 ) z2 = pntz( p2 ) x3 = pntx( p3 ) y3 = pnty( p3 ) z3 = pntz( p3 ) x4 = pntx( p4 ) y4 = pnty( p4 ) z4 = pntz( p4 ) x = nx( x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 ) y = ny( x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 ) z = nz( x2-x1 , y2-y1 , z2-z1 , x3-x1 , y3-y1 , z3-z1 ) call glBegin GL.QUADS call glNormal x , y , z call setColor kl1 call glVertex x1 , y1 , z1 call setColor kl2 call glVertex x2 , y2 , z2 call setColor kl3 call glVertex x3 , y3 , z3 call setColor kl4 call glVertex x4 , y4 , z4 call glEnd end sub
[openGl] ''openGL stuf : wil be extended
sub glClear code ''clear the openGL screen calldll #gl,"glClear" _ , code as long _ , ret as long end sub
sub glLoadIdentity ''set drawingmatrix to standert calldll #gl , "glLoadIdentity" _ , ret as long end sub
sub glPushMatrix ''to new drawingmatrix calldll #gl , "glPushMatrix" _ , ret as long end sub
sub glPopMatrix ''to old drawingmatrix calldll #gl , "glPopMatrix" _ , ret as long end sub
sub glEnd ''end of polygon[s] calldll #gl , "glEnd" _ , ret as void end sub
sub glEnable i ''set a item calldll #gl , "glEnable" _ , i as long _ , ret as long end sub
sub glBegin i ''set polygon mode calldll #gl , "glBegin" _ , i as long _ , ret as long end sub
sub glScale x , y , z ''scale drawingmatrix calldll #gl , "glScaled" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glTranslate x , y , z ''move drawingmatrix calldll #gl , "glTranslated" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glRotate a , x , y , z ''rotate drawinmatrix calldll #gl , "glRotated" _ , a as double _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glVertex x , y , z ''add a point to a polygon calldll #gl , "glVertex3d" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glNormal x , y , z ''set normal of point[s] calldll #gl , "glNormal3f" _ , x as double _ , y as double _ , z as double _ , ret as long end sub
sub glColor r , g , b , a ''set color of future point[s] of polygon[s] calldll #gl , "glColor4d" _ , r as double _ , g as double _ , b as double _ , a as double _ , ret as long end sub
sub openglInit struct PFD _ , Size as word _ , Version as word _ , Flags as long _ , pixelType as char[1] _ , ColorBits as char[1] _ , RedBits as char[1] _ , RedShift as char[1] _ , GreenBits as char[1] _ , GreenShift as char[1] _ , BlueBits as char[1] _ , BlueShift as char[1] _ , AlphaBits as char[1] _ , AlphaShift as char[1] _ , AccumBits as char[1] _ , AccumRedBits as char[1] _ , AccumGreenBits as char[1] _ , AccumBlueBits as char[1] _ , AccumAlphaBits as char[1] _ , DepthBits as char[1] _ , StencilBits as char[1] _ , AuxBuffers as char[1] _ , LayerType as char[1] _ , Reserved as char[1] _ , LayerMask as long _ , VisibleMask as long _ , DamageMask as long
PFD.Version.struct=1 PFD.ColorBits.struct=24 PFD.DepthBits.struct=16 PFD.Size.struct=len(PFD.struct) PFD.Flags.struct=37
calldll #user32,"GetDC" _ , MainH as ulong, MainDC as ulong calldll #gdi32,"ChoosePixelFormat" _ , MainDC as ulong, PFD as struct, ret as long calldll #gdi32, "SetPixelFormat" _ , MainDC as ulong, ret as long _ , PFD as struct, t as long calldll #gl,"wglCreateContext" _ , MainDC as ulong, GLContext as ulong calldll #gl,"wglMakeCurrent" _ , MainDC as ulong, GLContext as ulong _ , ret as long call glEnable GL.DEPTH.TEST end sub
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Jan 7, 2020 11:58:54 GMT -5
To save space, old versions of those zipfiles can be deleted, and perhaps only the 2 or 3 most recent zipfiles can stay -- for reference.
|
|