''bluatigro 18 nov 2016
''3d engine block
''needs math block
[basis3D]
global mmax
mmax = 20
dim m( ( mmax + 5 ) * 4 * 4 + 16 ) , cam( 6 )
dim skx( 64 ) , sky( 64 ) , skz( 64 )
global rotx , roty , rotz , trans , temp , number , m44nr , pi
trans = mmax + 1
rotx = mmax + 2
roty = mmax + 3
rotz = mmax + 4
temp = mmax + 5
pi = atn( 1 ) * 4
global xyz , xzy , yxz , yzx , zxy , zyx
xzy = 1
yxz = 2
yzx = 3
zxy = 4
zyx = 5
call startmatrix
return
function pend( fase , amp )
pend = sin( rad( fase ) ) * amp
end function
sub skelet lim , x , y , z
''for animating avatar lim's
skx( lim ) = x
sky( lim ) = y
skz( lim ) = z
end sub
sub push.m44
m44nr = m44nr + 1
end sub
sub pop.m44
m44nr = m44nr - 1
end sub
sub ido x , y , z , lim , ax
call child m44nr , x , y , z , lim , ax , m44nr - 1
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 _
, sky( lim ) , skx( lim ) , skz( lim ) , 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 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 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
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
''bluatigro 1 dec 2016
''avartar block
''needs sphere|ray world , color , basis3D and math block
[avartar]
global arm , elbow , wrist
arm = 0
elbow = 1
wrist = 2
global leg , knee , enkle
leg = 3
knee = 4
enkle = 5
global neck , head , eye
neck = 6
head = 7
eye = 8
global thumb , index , midle , ring
thumb = 9
index = 12
midle = 15
ring = 18
global tail , body , lr
tail = 21
body = 22
lr = 32
global ileg,iknee,iwing,ineck,iarm,ielbow
global iwrist,ithumb,ifinger,ieye,itail
ileg = 0
iknee = 5
iwing = 10
ineck = 12
iarm = 13
ielbow = 14
iwrist = 15
ithumb = 16
ifinger = 17
ieye = 18
itail = 19
global istand,ileftlegs,irightlegs,ileftbox
global irightbox,ifly,isting,home,dogwalk,manwalk
istand = 0
ileftlegs = 1
irightlegs = 2
ileftbox = 3
irightbox = 4
ifly = 5
isting = 6
home = 7
dogwalk = 8
manwalk = 9
return
Sub kop qq , kl
call link 15, 0, 0, 0, 0, 0, 0 , xyz , number
call sphere 0, 0, 0, 30, kl
If qq = 1 Then
call sphere 25, 25, 0, 9, kl
call sphere -25, 25, 0, 9, kl
call sphere 0, 0, -40, 10, gray
Else
call sphere 30, 0, 0, 9, kl
call sphere -30, 0, 0, 9, kl
call sphere 0, 0, -40, 12, kl
End If
call child 16, 14, 14, -14, eye ,xyz, 15
call sphere 0, 0, 0, 13, white
call sphere 0, 0, -10, 7, black
call child 16, -14, 14, -14, eye + lr,xyz, 15
call sphere 0, 0, 0, 13, white
call sphere 0, 0, -10, 7, black
end sub
sub man trui , broek
call child 9, 0, 0, 0, body+lr , xyz , number
call child 10, 0, 0, 0, body , xyz , 9
call sphere 0, 50, 0, 30, trui
call sphere 0, 25, 0, 23, broek
call sphere 0, 0, 0, 15, broek
call child 11, 0, 70, 0, neck, xyz, 10
call child 12, 0, 30, 0, neck+lr, xyz, 11
call kop 0, pink
call child 11, 20, -10, 0, leg, yzx, 9
call sphere 0, 0, 0, 16, broek
call sphere 0, -20, 0, 16, broek
call child 12, 0, -40, 0, knee, xyz, 11
call sphere 0, 0, 0, 16, broek
call sphere 0, -20, 0, 16, broek
call child 13, 0, -40, 0, enkle, xzy, 12
call sphere 0, 0, 0, 12, gray
call sphere 0, 0, -20, 12, gray
call child 11, -20, -10, 0, leg+lr , yzx, 10
call sphere 0, 0, 0, 16, broek
call sphere 0, -20, 0, 16, broek
call child 12, 0, -40, 0, knee+lr, xyz, 11
call sphere 0, 0, 0, 16, broek
call sphere 0, -20, 0,16, broek
call child 13, 0, -40, 0,enkle+lr, xzy, 12
call sphere 0, 0, 0, 12, gray
call sphere 0, 0, -20, 12, gray
call child 11, 40, 60, 0, arm, xzy, 10
call sphere 0, 0, 0, 16, trui
call sphere 6, -20, 0, 12, trui
call child 12, 6, -40, 0, elbow, xyz, 11
call sphere 0, 0, 0, 12, trui
call sphere 0, -20, 0, 12, trui
call sphere 0, -42, 0, 8, pink
call child 11, -40, 60, 0, arm+lr, xzy, 10
call sphere 0, 0, 0, 16, trui
call sphere -6, -20, 0, 12, trui
call child 12, -6, -40, 0, elbow+lr, xyz, 11
call sphere 0, 0, 0, 12, trui
call sphere 0, -20, 0, 12, trui
call sphere 0, -42, 0, 8, pink
end sub
sub pilko kl
call sphere 0,0,0,30 , kl
call sphere 0,0,50,30 , kl
call child 2 , 0,20,-20 , neck , xyz , 1
call child 3 , 0,20,-20 , neck + lr , zyx , 2
call kop 1 , kl
call child 11, 20, -10, 50, leg, yzx, 1
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 12, 0, -40, 0, knee, xyz, 11
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 13, 0, -40, 0, enkle, xzy, 12
call sphere 0, 0, 0, 12, kl
call sphere 0, 0, -20, 12, kl
call child 11, -20, -10, 50, leg+lr, yzx, 1
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 12, 0, -40, 0, knee+lr, xyz, 11
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 13, 0, -40, 0, enkle+lr, xzy, 12
call sphere 0, 0, 0, 12, kl
call sphere 0, 0, -20, 12, kl
call child 11, 20, -10, 0, arm, yzx, 1
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 12, 0, -40, 0, elbow, xyz, 11
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 13, 0, -40, 0, wrist, xzy, 12
call sphere 0, 0, 0, 12, kl
call sphere 0, 0, -20, 12, kl
call child 11, -20, -10, 0, arm+lr, yzx, 1
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 12, 0, -40, 0, elbow+lr, xyz, 11
call sphere 0, 0, 0, 16, kl
call sphere 0, -20, 0, 16, kl
call child 13, 0, -40, 0, wrist+lr, xzy, 12
call sphere 0, 0, 0, 12, kl
call sphere 0, 0, -20, 12, kl
call child 3 , 0,14,90 , tail , xyz , 2
for i = 0 to 5
call sphere 0,i*12,0,10 , kl
next i
end sub
sub animation anim , frame , amp
select case anim
case manwalk
call skelet leg , pend( frame , amp ) , 0 , 0
call skelet knee , pend( frame - 90 , amp ) + amp , 0 , 0
call skelet leg + lr , pend( frame + 180 , amp ) , 0 , 0
call skelet knee + lr , pend( frame + 90 , amp ) + amp , 0 , 0
call skelet arm , pend( frame + 180 , amp ) , 0 , 0
call skelet elbow , 0 -amp , 0 , 0
call skelet arm + lr , pend( frame , amp ) , 0 , 0
call skelet elbow + lr , 0 -amp , 0 , 0
case dogwalk
call skelet leg , pend( frame , amp ) , 0 , 0
call skelet knee , pend( frame - 90 , amp ) + amp , 0 , 0
call skelet leg + lr , pend( frame + 180 , amp ) , 0 , 0
call skelet knee + lr , pend( frame + 90 , amp ) + amp , 0 , 0
call skelet arm , pend( frame , amp ) , 0 , 0
call skelet elbow , pend( frame - 90 , amp ) + amp , 0 , 0
call skelet arm + lr , pend( frame + 180 , amp ) , 0 , 0
call skelet elbow + lr , pend( frame + 90 , amp ) + amp , 0 , 0
call skelet tail , -45 , pend( frame * 2 , amp ) , 0
case ileftlegs
for i = 0 to 4
call skelet ileg+i , 0,0,pend(frame+180*i,amp)
call skelet iknee+i , pend(frame+180+180*i,amp),0,0
next i
case irightlegs
for i = 0 to 4
call skelet ileg+i+lr , 0,0,pend(frame+180*i,amp)
call skelet iknee+i+lr , pend(frame+180+180*i,amp),0,0
next i
case isting
call skelet itail , 90/7+pend(frame,amp) , 0 , 0
call skelet itail+lr , 90/7-pend(frame,amp) , 0 , 0
case ifly
call skelet iwing , 0 , 0 , pend(frame,amp)
call skelet iwing+1 , 0 , 0 , pend(frame,amp)
call skelet iwing+lr , 0 , 0 , 0-pend(frame,amp)
call skelet iwing+1+lr , 0 , 0 , 0-pend(frame,amp)
case ileftbox
call skelet iarm , 0 , pend(frame,amp)-20 , 0
call skelet ielbow , 0 , 30-pend(frame,amp) , 0
case irightbox
call skelet iarm+lr , 0 , 20-pend(frame,amp) , 0
call skelet ielbow+lr , 0 , pend(frame,amp)-30 , 0
case home
for i = 0 to 64
call skelet i , 0 , 0 , 0
next i
case else
call skelet itail , 90/7,0,0
call skelet itail+lr , 90/7,0,0
call skelet iarm , 0,-20,0
call skelet ielbow , 0,30,0
call skelet iarm+lr , 0,20,0
call skelet ielbow+lr , 0,-30,0
call skelet ineck+lr , 20,0,0
call skelet ieye , -20,0,0
call skelet ieye+lr , -20,0,0
end select
end sub