Post by bluatigro on Apr 28, 2018 9:48:19 GMT
this i m looking for on the WWW for a long time
if i ask google i get 30 times the question but no answer
i like to learn new stuf al the time
i do not sovle it whit math
i let the code 'learn' the angle's
this slow but in my grasp
error :
label [timer] is not seen by some code
so i dont know if sub chain.target works
in case of infinite loop i added a scan in that sub
if i ask google i get 30 times the question but no answer
i like to learn new stuf al the time
i do not sovle it whit math
i let the code 'learn' the angle's
this slow but in my grasp
error :
label [timer] is not seen by some code
so i dont know if sub chain.target works
in case of infinite loop i added a scan in that sub
''bluatigro 28 apr 2018
''reverse kinetics try
global mmax : mmax = 20
global trans , rotx , roty , rotz , temp
trans = mmax + 1
rotx = mmax + 2
roty = mmax + 3
rotz = mmax + 4
temp = mmax + 5
global xyz , yzy , yxz , yzx , zxy , zyx
xyz = 1
xzy = 2
yxz = 3
yzx = 4
zxy = 5
zyx = 6
global true , false
false = 0
true = 1
global sholder , elbow , wrist
sholder = 0
elbow = 1
wrist = 2
global number , pi , frame , key$
pi = atn( 1 ) * 4
frame = 0
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global black , red , green , yellow
global blue , magenta , cyan , white
global pink , gray , orange , purple
black = rgb( 000 , 000 , 000 )
red = rgb( 255 , 000 , 000 )
green = rgb( 000 , 255 , 000 )
yellow = rgb( 255 , 255 , 000 )
blue = rgb( 000 , 000 , 255 )
magenta = rgb( 255 , 000 , 255 )
cyan = rgb( 000 , 255 , 255 )
white = rgb( 255 , 255 , 255 )
pink = rgb( 255 , 127 , 127 )
orange = rgb( 255 , 127 , 000 )
gray = rgb( 127 , 127 , 127 )
purple = rgb( 127 , 000 , 127 )
global tx , ty , tz ''moving target
tx = 0
ty = 0
tz = 0
nomainwin
gosub [basis3D]
menu #m , "info" , "instruction's" , [info]
open "line 3D" for graphics as #m
#m "trapclose [quit]"
#m "when characterInput [key]"
#m "setfocus"
call camara 0 , 0 , 0 , 0 , 0 , 0 , 1
''set lim constraints
call chain.set.lim 0 , sholder , true , true , true
call chain.set.lim 1 , elbow , true , false , false
call chain.set.lim 2 , wrist , true , true , true
timer 100 , [timer]
wait'
sub scene
select case val( key$ )
case 5
for i = 0 to 64
call skelet i , 0 , 0 , 0
next i
case 6
if tx < 250 then tx = tx + 10
case 4
if tx > -250 then tx = tx - 10
case 8
if ty < 250 then ty = ty + 10
case 2
if ty > -250 then ty = ty - 10
case 9
if tz < 250 then tz = tz + 10
case 1
if tz > -250 then tz = tz - 10
case else
end select
key$ = "x"
call chain.target 2 , 0,0,0 ,tx,ty,tz , 10
#m , "fill black"
call link 1 , 0,0,0 , 0,0,0 , xyz , 0
call line3d.cube 0,0,0 , 250,250,250 , blue , 5
call line3d.cross tx,ty,tz , 15,15,15 , red , 5
call child 2 , 0,0,0 , 0 , xzy , 1
call line3d.line 0,0,0 , 0,200,0 , green , 1
call child 3 , 0,200,0 , 1 , xyz , 2
call line3d.line 0,0,0 , 0,200,0 , green , 1
call child 4 , 0,200,0 , 2 , yzx , 3
call line3d.line 0,0,0 , 0,50,0 , green , 1
call line3d.cross 0,50,0 , 10,10,10 , green , 5
#m , "flush"
end sub
[key]
key$ = right$( Inkey$ , 1 )
if key$ <> chr$( 27 ) then wait
[quit]
close #m
end
[info]
timer 0
notice chr$( 13 ) _
+ "bluatigro presents : " + chr$( 13 ) _
+ "revese kinetics try ." + chr$( 13 ) _
+ "instructions :" + chr$( 13 ) _
+ "1 = move target towarts you ." + chr$( 13 ) _
+ "2 = move target down ." + chr$( 13 ) _
+ "4 = move target left ." + chr$( 13 ) _
+ "6 = move target right ." + chr$( 13 ) _
+ "8 = move target up ." + chr$( 13 ) _
+ "9 = move target from you ." + chr$( 13 )
timer 100 , [timer]
wait
[timer]
scan
frame = ( frame + 3 ) mod 360
call scene
wait
''3d engine stuf
''================================================
''bluatigro 28 apr 2018
''3d engine module
''needs :
''math module
''as global const's :
''mmax = 20
''trans = mmax + 1
''rotx = mmax + 2
''roty = mmax + 3
''rotz = mmax + 4
''temp = mmax + 5
''xyz = 1 , xzy = 2 , yxz = 3
''yzx = 4 , zxy = 5 , zyx = 6
[basis3D]
dim m( ( mmax + 5 ) * 4 * 4 + 16 ) , cam( 6 )
dim sk( 64 , 2 )
dim chain( 64 ) , chain.bool( 64 , 2 )
global number
call startmatrix
return
function pend( fase , amp )
pend = sin( rad( fase ) ) * amp
end function
sub rotate byref k , byref l, deg
s = sin( rad( deg ) )
y = cos( rad( deg ) )
hk = k * c - l * s
hl = k * s + l * c
k = hk
l = hl
end sub
sub skelet lim , x , y , z
''for animating avatar lim's
sk( lim , 0 ) = x
sk( lim , 1 ) = y
sk( lim , 2 ) = z
end sub
sub setangle lim , ax , deg
''for animating avatar lim's
sk( lim , ax ) = deg
end sub
sub child no , x , y , z , lim , ax , p
''for creating lim's of a avatar
if lim < 0 or lim > 64 then exit sub
call link no , x , y , z _
, sk( lim , 1 ) , sk( lim , 0 ) , sk( lim , 2 ) _
, ax , p
end sub
sub link no , x , y , z , xz , yz , xy , ax , p
''set draw matrix : wil efect future drawing
''no : number new matrix
''x,y,z : translation
''xz,yz,xy : rotation in degrees
''ax : sequence of axes
''p : number old matrix
if no < 1 or no > mmax then exit sub
if p < 0 or p > mmax then exit sub
if no < 1 or no > mmax then exit sub
if p < 0 or p > mmax then exit sub
if p = no then exit sub
''copy matrix 0 into matrix's
call copy 0 , rotx
call copy 0 , roty
call copy 0 , rotz
call copy 0 , trans
''create rotation matrix's
m( in( rotx , 1 , 1 ) ) = cos( rad( yz ) )
m( in( rotx , 1 , 2 ) ) = 0-sin( rad( yz ) )
m( in( rotx , 2 , 1 ) ) = sin( rad( yz ) )
m( in( rotx , 2 , 2 ) ) = cos( rad( yz ) )
m( in( roty , 0 , 0 ) ) = cos( rad( xz ) )
m( in( roty , 0 , 2 ) ) = 0-sin( rad( xz ) )
m( in( roty , 2 , 0 ) ) = sin( rad( xz ) )
m( in( roty , 2 , 2 ) ) = cos( rad( xz ) )
m( in( rotz , 0 , 0 ) ) = cos( rad( xy ) )
m( in( rotz , 0 , 1 ) ) = 0-sin( rad( xy ) )
m( in( rotz , 1 , 0 ) ) = sin( rad( xy ) )
m( in( rotz , 1 , 1 ) ) = cos( rad( xy ) )
''create translation matrix
m( in( trans , 3 , 0 ) ) = x
m( in( trans , 3 , 1 ) ) = y
m( in( trans , 3 , 2 ) ) = z
''select axes sequence [ 1 of 6 ] and act on i
select case ax
case xyz
call multiply rotx , roty , temp
call multiply temp , rotz , no
call multiply no , trans , temp
call multiply temp , p , no
case xzy
call multiply rotx , rotz , temp
call multiply temp , roty , no
call multiply no , trans , temp
call multiply temp , p , no
case yxz
call multiply roty , rotx , temp
call multiply temp , rotz , no
call multiply no , trans , temp
call multiply temp , p , no
case yzx
call multiply roty , rotz , temp
call multiply temp , rotx , no
call multiply no , trans , temp
call multiply temp , p , no
case zxy
call multiply rotz , rotx , temp
call multiply temp , roty , no
call multiply no , trans , temp
call multiply temp , p , no
case zyx
call multiply rotz , roty , temp
call multiply temp , rotx , no
call multiply no , trans , temp
call multiply temp , p , no
case else
call multiply rotx , roty , temp
call multiply temp , rotz , no
call multiply no , trans , temp
call multiply temp , p , no
end select
number = no
end sub
sub spot byref x , byref y , byref z
'''lokal coordinates to world coordinates
''x,y,z = matrix( number ) * x,y,z
no = number
hx = m( in( no , 0 , 0 ) ) * x _
+ m( in( no , 1 , 0 ) ) * y _
+ m( in( no , 2 , 0 ) ) * z _
+ m( in( no , 3 , 0 ) )
hy = m( in( no , 0 , 1 ) ) * x _
+ m( in( no , 1 , 1 ) ) * y _
+ m( in( no , 2 , 1 ) ) * z _
+ m( in( no , 3 , 1 ) )
hz = m( in( no , 0 , 2 ) ) * x _
+ m( in( no , 1 , 2 ) ) * y _
+ m( in( no , 2 , 2 ) ) * z _
+ m( in( no , 3 , 2 ) )
x = hx ''- cam( 0 )
y = hy ''- cam( 1 )
z = hz ''- cam( 2 )
'' call rotate x , y , 0 - cam( 5 )
'' call rotate y , z , 0 - cam( 4 )
'' call rotate x , z , 0 - cam( 3 )
'' if cam( 6 ) = 0 then cam( 6 ) = 1
'' x = x * cam( 6 )
'' y = y * cam( 6 )
'' z = z * cam( 6 )
end sub
sub camara x , y , z , pan , tilt , rol , zoom
cam( 0 ) = x
cam( 1 ) = y
cam( 2 ) = z
cam( 3 ) = pan
cam( 4 ) = tilt
cam( 5 ) = rol
cam( 6 ) = zoom
end sub
''matrix math
sub copy a , b
''matrix( b ) = matrix( a )
for i = 0 to 3
for j = 0 to 3
m( in( b , i , j ) ) = m( in( a , i , j ) )
next j
next i
end sub
sub multiply a , b , c
''matrix( c ) = matrix( a ) * matrix( b )
for i = 0 to 3
for j = 0 to 3
m( in( c , i , j ) ) = 0
for k = 0 to 3
m( in( c , i , j ) ) = m( in( c , i , j ) ) _
+ m( in( a , i , k ) ) * m( in( b , k , j ) )
next k
next j
next i
end sub
sub startmatrix
''set startmatrix to unity
for x = 0 to 3
for y = 0 to 3
m( in( 0 , x , y ) ) = 0
next y
m( in( 0 , x , x ) ) = 1
next x
end sub
function in( no , x , y )
''LB4 has no 3d array's
''so i simulate them
in = x + y * 4 + no * 16
end function
sub chain.set.lim i , lim , x , y , z
chain( i ) = lim
chain.bool( i , 0 ) = x
chain.bool( i , 1 ) = y
chain.bool( i , 2 ) = z
end sub
sub chain.target no , dx , dy , dz , tx , ty , tz , dist
x = dx
y = dy
z = dz
call spot x , y , z
q = length( tx - x , ty - y , tz - z )
while q > dist
scan
x = dx
y = dy
z = dz
call spot x , y , z
low = length( tx - x , ty - y , tz - z )
for i = 0 to no
for ax = 0 to 2
hoek = sk( chain( i ) , ax )
if chain.bool( i , ax ) then
dice = range( -3 , 3 )
hoek = hoek + dice
call setangle chain( i ) , ax , hoek
x = dx
y = dy
z = dz
call spot x , y , z
w = length( tx - x , ty - y , tz - z )
if w <= low then
low = w
else
hoek = hoek - dice
call setangle chain( i ) , ax , hoek
end if
end if
next ax
next i
wend
end sub
function rad( x )
rad = x * pi / 180
end function
function length( a , b , c )
length = sqr( a * a + b * b + c * c )
end function
function range( l , h )
range = rnd(0) * ( h - l ) + l
end function
''=================================================
''end 3d engine stuf
''graphics
sub line3d.cross mx , my , mz , dx , dy , dz , kl , dik
call line3d.line mx-dx,my,mz,mx+dx,my,mz , kl , dik
call line3d.line mx,my-dy,mz,mx,my+dy,mz , kl , dik
call line3d.line mx,my,mz-dz,mx,my,mz+dz , kl , dik
end sub
sub line3d.cube mx , my , mz , dx , dy , dz , kl , dik
call line3d.line mx - dx , my - dy , mz - dz _
, mx + dx , my - dy , mz - dz , kl , dik
call line3d.line mx - dx , my + dy , mz - dz _
, mx + dx , my + dy , mz - dz , kl , dik
call line3d.line mx - dx , my - dy , mz + dz _
, mx + dx , my - dy , mz + dz , kl , dik
call line3d.line mx - dx , my + dy , mz + dz _
, mx + dx , my + dy , mz + dz , kl , dik
call line3d.line mx - dx , my - dy , mz - dz _
, mx - dx , my + dy , mz - dz , kl , dik
call line3d.line mx + dx , my - dy , mz - dz _
, mx + dx , my + dy , mz - dz , kl , dik
call line3d.line mx - dx , my - dy , mz + dz _
, mx - dx , my + dy , mz + dz , kl , dik
call line3d.line mx + dx , my - dy , mz + dz _
, mx + dx , my + dy , mz + dz , kl , dik
call line3d.line mx - dx , my - dy , mz - dz _
, mx - dx , my - dy , mz + dz , kl , dik
call line3d.line mx + dx , my - dy , mz - dz _
, mx + dx , my - dy , mz + dz , kl , dik
call line3d.line mx - dx , my + dy , mz - dz _
, mx - dx , my + dy , mz + dz , kl , dik
call line3d.line mx + dx , my + dy , mz - dz _
, mx + dx , my + dy , mz + dz , kl , dik
end sub
sub line3d.line x1 , y1 , z1 , x2 , y2 , z2 , kl , dik
r = int( kl ) and 255
g = int( kl / 256 ) and 255
b = int( kl / 256 / 256 ) and 255
dx = WindowWidth
dy = WindowHeight
call spot x1 , y1 , z1
call spot x2 , y2 , z2
ax = dx / 2 + x1 / ( z1 + 1000 ) * 1000
ay = dy / 2 - y1 / ( z1 + 1000 ) * 1000
bx = dx / 2 + x2 / ( z2 + 1000 ) * 1000
by = dy / 2 - y2 / ( z2 + 1000 ) * 1000
#m "size " ; dik
#m "color " ; r ; " " ; g ; " " ; b
#m "down"
#m "line " ; ax ; " " ; ay ; " " ; bx ; " " ; by
#m "up"
end sub
sub line3d.sphere x , y , z , d , kl , dik
call spot x , y , z
''d = d * cam( 6 )
r = int( kl and 255 )
g = int( kl / 256 ) and 255
b = int( kl / 256 / 256 ) and 255
#m "size " ; dik
#m "color " ; r ; " " ; g ; " " ; b
d = d / ( z + 1000 ) * 1000
dx = WindowWidth
dy = WindowHeight
x = dx / 2 + x / ( z + 1000 ) * 1000
y = dy / 2 - y / ( z + 1000 ) * 1000
#m "go " ; x ; " " ; y
#m "down"
#m "circlefilled "; d
#m "up"
end sub
function rainbow( x )
r = sin( rad( x ) ) * 127 + 128
g = sin( rad( x - 120 ) ) * 127 + 128
b = sin( rad( x + 120 ) ) * 127 + 128
rainbow = rgb( r , g , b )
end function
function rgb( r , g , b )
r = r and 255
g = g and 255
b = b and 255
rgb = r + g * 256 + b * 256 * 256
end function