Liberty BASIC Community Forum
« open gl : robot walking »

Welcome Guest. Please Login or Register.
Apr 24th, 2017, 9:48pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: open gl : robot walking  (Read 333 times)
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx open gl : robot walking
« Thread started on: Feb 11th, 2017, 06:50am »


only cubes are there

see REM on how to make your owm shapes

i put only a robot in this
see sub robot on how to make avartars yourself
see sub walk.man on how to create animations

its a pitty that LB is slow in 3d

proof of concept is ready

Code:
''bluatigro 11 feb 2015
''openGL

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
global arm,elbow,wrist,leg,knee,enkle,eye,lr
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
lr = 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
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 , [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 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 arm , pend( f , a ) , 0 , 0
  call skelet elbow , abs( a ) , 0 , 0
  call skelet arm + lr , pend( f + 180, a ) , 0 , 0
  call skelet elbow + lr , abs( a ) , 0 , 0
  call skelet leg , pend( f + 180 , a ) , 0 , 0
  call skelet knee , pend( f + 90 , a ) - a , 0 , 0
  call skelet leg + lr , pend( f , a ) , 0 , 0
  call skelet knee + lr _
  , pend( f - 90 , a ) - a , 0 , 0
  call skelet thumb , pend( f , 15 ) + 15 , 0 , 0
  for i = 0 to 2
    call skelet index.finger + i _
    , 0 , 0 , pend( f , 15 ) - 15
    call skelet mid.finger + i _
    , 0 , 0 , pend( f - 120 , 15 ) - 15
    call skelet ring.finger + i _
    , 0 , 0 , pend( f + 120 , 15 ) - 15
    call skelet index.finger + i + lr _
    , 0 , 0 , pend( f , 15 ) + 15
    call skelet mid.finger + i + lr _
    , 0 , 0 , pend( f - 120 , 15 ) + 15
    call skelet ring.finger + i + lr _
    , 0 , 0 , pend( f + 120 , 15 ) + 15
  next i
end sub

sub finger i
  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
  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.finger + i , xyz
    call finger index.finger + i
  call glPopMatrix
  call glPushMatrix
    call child 0,-.6,0 , mid.finger + i , xyz
    call finger index.finger + i
  call glPopMatrix
  call glPushMatrix
    call child 0,-.6,.3 , ring.finger + i , xyz
    call finger index.finger + i
  call glPopMatrix
end sub

sub robot h
''example avatar
  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 , zyx
    call setbox 0 , -.6 , 0 , .1 , .4 , .1
    call colorcube
    call glPushMatrix
      call child 0 , -1 , 0 , knee , xyz
      call colorcube
      call glPushMatrix
        call child 0 , -1.2 , 0 , enkle , 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 + lr , zyx
    call setbox 0 , -.6 , 0 , .1 , .4 , .1
    call colorcube
    call glPushMatrix
      call child 0 , -1 , 0 , knee + lr , xyz
      call colorcube
      call glPushMatrix
        call child 0 , -1.2 , 0 , enkle + lr , 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 , xyz
    call setbox 0 , -.5 , 0 , .1 , .4 , .1
    call colorcube
    call glPushMatrix
      call child 0 , -1 , 0 , elbow , xyz
      call colorcube
      call glPushMatrix
        call child 0 , -1 , 0 , wrist , zyx
        if h then
          call hand 0
        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 + lr , xyz
    call setbox 0 , -.5 , 0 , .1 , .4 , .1
    call colorcube
    call glPushMatrix
      call child 0 , -1 , 0 , elbow + lr , xyz
      call colorcube
      call glPushMatrix
        call child 0 , -1 , 0 , wrist + lr , zyx
        if h then
          call hand lr
        else
          call setbox 0 , -.3 , 0 , .05 , .2 , .15
          call colorcube
        end if
      call glPopMatrix
    call glPopMatrix
  call glPopMatrix
end sub

''    color object math

function grijs( x )
  grijs = rgba( x , x , x , 255 )
end function

function rainbow( x )
  r = sin( x ) * 127 + 128
  g = sin( x - pi * 2 / 3 ) * 127 + 128
  b = sin( x + pi * 2 / 3 ) * 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-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

 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #1 on: Feb 11th, 2017, 06:55am »

the remainder of the Code:

''    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 colorcube
  call cube red,cyan , green,magenta , blue,yellow
end sub

sub graycube
  kl1 = grijs( 64 )
  kl2 = grijs( 185 )
  call cube white,white,kl1,kl1,kl2,kl2
end sub

sub cube left , right , front , back , down , up
''create a cube mesh
''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
  call tri3 p1 , kl , p2 , kl , p3 , kl
end sub

sub tri3 p1 , kl1 , p2 , kl2 , p3 , kl3
''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 )
  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 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 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

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 setColor clr
''set color of point[s] of polygon
  r = colorR( clr )
  g = colorG( clr )
  b = colorB( clr )
  a = colorA( clr )
  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
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 301
xx Re: open gl : robot walking
« Reply #2 on: Feb 24th, 2017, 08:50am »

Awesome.

But it is running very slowly in LB4.5
User IP Logged

.....
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #3 on: Feb 27th, 2017, 05:42am »

update :
now whit light and material

error :
glMaterialfv not recognized

what do i do wrong ?
[ part 1 of code ]
Code:
''bluatigro 27 feb 2015
''openGL

nomainwin
dim pntx(256),pnty(256),pntz(256),box(5),sk(64,2)
global pi : pi = atn( 1 ) * 4

struct d4d _
  , a as double _
  , b as double _
  , c as double _
  , d as double

''    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
global arm,elbow,wrist,leg,knee,enkle,eye,lr
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
lr = 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
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
  call glLight GL.LIGHT0 , GL.DIFFUSE , white
  call d4d.fill 0 , 50 , 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.AND.BACK , GL.DIFFUSE , yellow
    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 arm , pend( f , a ) , 0 , 0
  call skelet elbow , abs( a ) , 0 , 0
  call skelet arm + lr , pend( f + 180, a ) , 0 , 0
  call skelet elbow + lr , abs( a ) , 0 , 0
  call skelet leg , pend( f + 180 , a ) , 0 , 0
  call skelet knee , pend( f + 90 , a ) - a , 0 , 0
  call skelet leg + lr , pend( f , a ) , 0 , 0
  call skelet knee + lr _
  , pend( f - 90 , a ) - a , 0 , 0
  call skelet thumb , pend( f , 15 ) + 15 , 0 , 0
  for i = 0 to 2
    call skelet index.finger + i _
    , 0 , 0 , pend( f , 15 ) - 15
    call skelet mid.finger + i _
    , 0 , 0 , pend( f - 120 , 15 ) - 15
    call skelet ring.finger + i _
    , 0 , 0 , pend( f + 120 , 15 ) - 15
    call skelet index.finger + i + lr _
    , 0 , 0 , pend( f , 15 ) + 15
    call skelet mid.finger + i + lr _
    , 0 , 0 , pend( f - 120 , 15 ) + 15
    call skelet ring.finger + i + lr _
    , 0 , 0 , pend( f + 120 , 15 ) + 15
  next i
end sub

sub finger i
  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 i
  call setbox 0,-.3,0 , .1,.3,.3
  call cube
  call glPushMatrix
    call child 0,-.2,-.5 , thumb + i , xyz
    call finger thumb + i
  call glPopMatrix
  call glPushMatrix
    call child 0,-.6,-.3 , index.finger + i , xyz
    call finger index.finger + i
  call glPopMatrix
  call glPushMatrix
    call child 0,-.6,0 , mid.finger + i , xyz
    call finger index.finger + i
  call glPopMatrix
  call glPushMatrix
    call child 0,-.6,.3 , ring.finger + i , xyz
    call finger index.finger + i
  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 , leg , zyx
    call setbox 0 , -.6 , 0 , .1 , .4 , .1
    call cube
    call glPushMatrix
      call child 0 , -1 , 0 , knee , xyz
      call cube
      call glPushMatrix
        call child 0 , -1.2 , 0 , enkle , 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 + lr , zyx
    call setbox 0 , -.6 , 0 , .1 , .4 , .1
    call cube
    call glPushMatrix
      call child 0 , -1 , 0 , knee + lr , xyz
      call cube
      call glPushMatrix
        call child 0 , -1.2 , 0 , enkle + lr , 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 , arm , xyz
    call setbox 0 , -.5 , 0 , .1 , .4 , .1
    call cube
    call glPushMatrix
      call child 0 , -1 , 0 , elbow , xyz
      call colorcube
      call glPushMatrix
        call child 0 , -1 , 0 , wrist , zyx
        if h then
          call hand 0
        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 , arm + lr , xyz
    call setbox 0 , -.5 , 0 , .1 , .4 , .1
    call cube
    call glPushMatrix
      call child 0 , -1 , 0 , elbow + lr , xyz
      call cube
      call glPushMatrix
        call child 0 , -1 , 0 , wrist + lr , zyx
        if h then
          call hand lr
        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 grijs( x )
  grijs = rgba( x , x , x , 255 )
end function

function rainbow( x )
  r = sin( x ) * 127 + 128
  g = sin( x - pi * 2 / 3 ) * 127 + 128
  b = sin( x + pi * 2 / 3 ) * 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-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

''    blua3d engine

 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #4 on: Feb 27th, 2017, 05:43am »

[ part 2 of code ]
Code:

''    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
''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 
    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 )
  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 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 )
  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 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

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
    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
    call #gl , "glMaterialf" _
    , face as long _
    , e as long _
    , kl as single _
    , ret as long
  else
    call setColor kl
    call #gl , "glMaterialfv" _
    , face as long _
    , e as long _
    , d4d as struct _
    , ret as long
  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
  
 
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5245
xx Re: open gl : robot walking
« Reply #5 on: Feb 27th, 2017, 06:22am »

The d4d struct appears to need ulong not double. You need calldll not call in the new functions. You also have calls to colorcube which has no sub handler.
User IP Logged

bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #6 on: Feb 28th, 2017, 05:51am »

@rod :
d4d changed
colorcube => cube
call => calldll

result :
i got no syntaks error's
[ d4d : both ulong and double don't work but give no error's ]
but my robot is white
[ shoot be yellow ]
and shading don't work
[ i got normal's of polygon's ]
« Last Edit: Feb 28th, 2017, 06:27am by bluatigro » User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #7 on: Feb 28th, 2017, 06:19am »

update :
some OOP added
error :
same error's
add + change :
Code:
struct d3d _
  , x as double _
  , y as double _
  , z as double
 

Code:
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


 

Code:
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


 
« Last Edit: Feb 28th, 2017, 06:28am by bluatigro » User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5245
xx Re: open gl : robot walking
« Reply #8 on: Feb 28th, 2017, 06:58am »

When you first hit the glLight sub it seems to send four floating point values that are exactly the same. If it were yellow the bgr pattern should be different. So I would check your code that builds the color values.

There is a non zero value being returned from the dll call to set the light value, cant tell if it is an error code or not.
User IP Logged

bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #9 on: Mar 1st, 2017, 04:25am »

@ rod :
the colorobject create code is correct

i tryed Code:

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 = " ; ret
    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 = " ; ret
      tel = 1
    end if
  end if
end sub
 


i got :
ulong :
light.diffuse ffffffff
light.ret 25076000
mat.color ff00ffff
mat.ret 5763176
double :
ligh.ret 25075976
mat.ret 5824648

i shal look for explanation for those number's
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #10 on: Mar 1st, 2017, 04:45am »

update :
i tryed Code:

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
 


in both cases [ ulong and double d4d ]
i got error = 0
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #11 on: Mar 1st, 2017, 04:57am »

I GOT IT [ partly ]

change :
Code:
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  MainH = hwnd( #m )
  call openglInit
  call glEnable GL.LIGHTING   ''<< THIS I FORGOT !!!
  call glLight GL.LIGHT0 , GL.DIFFUSE , white
  call d4d.fill 0 , 1 , 0 , 1
  call glLight GL.LIGHT0 , GL.POSITION , dummy
  call glEnable GL.LIGHT0

  timer 40 , [tmr]
wait
 


i have now d4d whit double

i got a shaded robot !!
error :
it is green
and the light comes from the right side
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5245
xx Re: open gl : robot walking
« Reply #12 on: Mar 1st, 2017, 05:21am »

Then I can only assume you are running this in LBB. If you run it in Liberty BASIC the struct causes a crash if double is used in the d4d struct, ulong does not cause a crash and I get a white robot.

Also the single in glMaterial sub is not a supported Liberty BASIC data type, I used short.

It would be much easier for folks if you posted code relevant to the forum.

With lighting enabled I now get a black screen and no robot.
User IP Logged

bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 863
xx Re: open gl : robot walking
« Reply #13 on: Mar 1st, 2017, 05:39am »

add to colors Code:
global lgray , dgray
lgray   = rgba( 181 , 181 , 181 , 255 )
dgray   = rgba( 064 , 064 , 064 , 255 )
 

change Code:
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "setfocus"
  MainH = hwnd( #m )
  call openglInit
  calldll #gl , "glShadeModel" _
  , 7425 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

 


error :
i got a shaded but green robot
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls