Remember the SET OBJECT KEYFRAME command from DBC? It was useful for no media games, so I decided to try and re-make them for DBPro. Here is what I have so far, it's not very user friendly (both the program and the code). The only down side that I know of is that you can't use ROTATE OBJECT when trying to capture keyframes.
Anyway, tell me what you think of it please.
REM Project: Animation
REM Created: 4/3/2007 7:26:05 AM
REM
REM ***** Main Source File *****
REM
sync on
sync rate 60
autocam off
set normalization on
GOSUB Key_Setup
`set shadow light 0,100,100,100,10000
`position light 0,100,100,100
v=48
Make object sphere 1,10,v,v
Make object sphere 2,5,v,v
make mesh from object 2,2
delete object 2
add limb 1,1,2
offset limb 1,1,5,-10,0
delete mesh 2
Make object sphere 3,5,v,v
make mesh from object 3,3
delete object 3
add limb 1,2,3
offset limb 1,2,-5,-10,0
delete mesh 3
Make object sphere 4,10,v,v
scale object 4,100,200,100
make mesh from object 4,4
delete object 4
add limb 1,3,4
offset limb 1,3,0,-10,0
delete mesh 4
color limb 1,1,rgb(255,0,0)
color limb 1,2,rgb(255,0,0)
color limb 1,0,rgb(0,255,0)
color limb 1,3,rgb(0,0,255)
offset limb 1,1,5,-10,0
Key_SetObjectKeyframe(1,1)
offset limb 1,1,5,-10,30/2
Key_SetObjectKeyframe(1,2)
offset limb 1,1,5,-10,0
Key_SetObjectKeyframe(1,3)
offset limb 1,2,-5,-10,0
Key_SetObjectKeyframe(1,5)
offset limb 1,2,-5,-10,30/2
Key_SetObjectKeyframe(1,6)
offset limb 1,2,-5,-10,0
Key_SetObjectKeyframe(1,7)
offset limb 1,1,5,-10,0
Key_SetObjectKeyframe(1,8)
offset limb 1,1,5,-10,30/2
Key_SetObjectKeyframe(1,9)
offset limb 1,1,5,-10,0
Key_SetObjectKeyframe(1,10)
offset limb 1,2,-5,0,15
Key_SetObjectKeyframe(1,11)
offset limb 1,2,-5,10,15
Key_SetObjectKeyframe(1,12)
offset limb 1,2,-5,0,15
Key_SetObjectKeyframe(1,13)
offset limb 1,2,-5,0,10
Key_SetObjectKeyframe(1,14)
Key_SetObjectSpeed(1,10)
Key_LoopObject(1,1,11)
set shadow shading on 1,-1,100,1
set shadow position 0,0,0,0
position light 0,100,100,100
make object box 2,1000,1,1000
position object 2,0,-20,0
color object 2,rgb(255,155,0)
set object normals 2
do
rotate limb 1,0,90,0,0
`turn object left 1,1
control camera using arrowkeys 0,2,2
Key_Update(1,0)
sync
loop
rem ===========================================================
rem
rem
rem KEYFRAME ANIMATION FUNCTIONS
rem
rem
rem ===========================================================
end
Key_Setup:
TYPE Key_Keys
obj as integer
TotalLimbs as integer
X as float `xpos
Y as float
Z as float
ax as float `x angle
ay as float
az as float
status as string `what is the object doing
`Playing,Looping,Stopped
MaxFrame as integer `the maximum frame of the object
frame as integer `the object's current frame
startFrame as integer
EndFrame as integer
`Remember, for the things that don't apply to limbs they will be stored in slot 1 for their object slot. This includes object numbers.
`EX: Key_Anim(1,1).MaxSlot= whatever.
speed as float
cstep as integer `The object's current step in the frame.
endtype
global Key_MaxAnimSlot
global Key_MaxObjectSlot=100
global Key_MaxKeyframeSlot=400
global Key_MaxLimbSlot=100
`Each 2nd array slot is the keyframe.
`Keyframes start at slot 1.
`The first array slot is the object slot. Object numbers will be stored here.
`The second is the keyframe.
`The third is the limb #.
DIM Key_Anim(Key_MaxObjectSlot,Key_MaxKeyframeSlot,Key_MaxLimbSlot) as Key_Keys
DIM Key_ObjectSlots(500000)
return
function Key_SetObjectKeyframe(obj as integer,frame as integer)
if object exist(obj)=0 then exitfunction
slot=Key_GETOBJECTSLOT(obj)
if slot<=0 then slot=Key_FreeAnimSlot() : Key_ObjectSlots(obj)=slot : Key_Anim(slot,1,1).obj=obj
perform checklist for object limbs obj
cq=checklist quantity()
empty checklist
for limb = 1 to cq-1
slot2=frame-1
if slot2<0 then slot2=0
repeat
inc slot2
Key_Anim(slot,slot2,limb).x=Limb Offset x(obj,limb)
Key_Anim(slot,slot2,limb).y=Limb Offset y(obj,limb)
Key_Anim(slot,slot2,limb).z=Limb Offset z(obj,limb)
Key_Anim(slot,slot2,limb).ax=Limb Angle x(obj,limb)
Key_Anim(slot,slot2,limb).ay=Limb Angle y(obj,limb)
Key_Anim(slot,slot2,limb).az=Limb Angle z(obj,limb)
Key_Anim(slot,1,1).status="stopped"
until slot2=Key_MaxKeyframeSlot
next limb
Key_Anim(slot,1,1).TotalLimbs=cq-1
if frame>Key_Anim(slot,1,1).Maxframe then Key_Anim(slot,1,1).Maxframe=frame
Key_UpdateMaxSlot()
endfunction
function Key_GetObjectSlot(obj as integer)
if object exist(obj)=0 then exitfunction
TEMP=Key_ObjectSlots(obj)
endfunction TEMP
function Key_UpdateMaxSlot()
Key_MaxAnimSlot=0
for o = 1 to Key_MaxObjectSlot
if Key_Anim(o,1,1).obj>0 then Key_MaxAnimSlot=o
next o
endfunction
function Key_ObjectExist(obj)
slot=Key_GetObjectSlot(obj)
if Key_Anim(slot,1,1).obj>0
TEMP=1
else
TEMP=0
endif
endfunction TEMP
function Key_FreeAnimSlot()
repeat
s=s+1
until Key_Anim(s,1,1).obj<=0
endfunction s
function Key_Update(o as integer,Smooth as boolean)
if object exist(o)=0 then Key_ERROR("Object "+str$(o)+" does not exist in 'Key_Update'")
for s = 1 to Key_MaxAnimSlot
if o>0 then ss=Key_GetObjectSlot(o) else ss=s
if Key_ObjectExist(o)=1
DONE=0
Total=Key_Anim(s,1,1).totallimbs
for l = 1 to Total
lx#=Limb Offset x(o,l)
ly#=Limb Offset y(o,l)
lz#=Limb Offset z(o,l)
lax#=Limb Angle x(o,l)
lay#=Limb Angle y(o,l)
laz#=Limb Angle z(o,l)
FRAME=Key_Anim(ss,1,1).frame
Status$=Key_Anim(ss,1,1).status
speed#=Key_Anim(s,1,1).speed
tx#=Key_Anim(ss,frame,l).x
ty#=Key_Anim(ss,frame,l).y
tz#=Key_Anim(ss,frame,l).z
tax#=Key_Anim(ss,frame,l).ax
tay#=Key_Anim(ss,frame,l).ay
taz#=Key_Anim(ss,frame,l).az
if Status$="playing" or Status$="looping"
ff=Frame-1
if ff<1 then ff=Key_Anim(ss,1,1).endframe
ox#=Key_Anim(ss,ff,l).x
oy#=Key_Anim(ss,ff,l).y
oz#=Key_Anim(ss,ff,l).z
oax#=Key_Anim(ss,ff,l).ax
oay#=Key_Anim(ss,ff,l).ay
oaz#=Key_Anim(ss,ff,l).az
IF SMOOTH=1
lx#=CURVEVALUE(tx#,lx#,speed#)
ly#=CURVEVALUE(ty#,ly#,speed#)
lz#=CURVEVALUE(tz#,lz#,speed#)
ELSE
if tx#>lx# then LX#=LX#+abs(TX#-OX#)/SPEED#
if tx#<lx# then LX#=LX#-abs(TX#-OX#)/SPEED#
if ty#>ly# then Ly#=Ly#+abs(Ty#-Oy#)/SPEED#
if ty#<ly# then Ly#=Ly#-abs(Ty#-Oy#)/SPEED#
if tz#>lz# then Lz#=Lz#+abs(Tz#-Oz#)/SPEED#
if tz#<lz# then Lz#=Lz#-abs(Tz#-Oz#)/SPEED#
ENDIF
lax#=CURVEANGLE(tax#,lax#,speed#)
lay#=CURVEANGLE(tay#,lay#,speed#)
laz#=CURVEANGLE(taz#,laz#,speed#)
offset limb o,l,lx#,ly#,lz#
rotate limb o,l,lax#,lay#,laz#
endif
next l
inc Key_Anim(ss,1,1).cstep
if Key_Anim(ss,1,1).cstep>Speed#
Key_Anim(ss,1,1).cstep=0
Done=1
endif
if DONE=1
Key_Anim(ss,1,1).frame=Key_Anim(ss,1,1).frame+1
if Key_anim(ss,1,1).frame>Key_Anim(ss,1,1).endframe
if Status$="playing" then Key_anim(ss,1,1).frame=Key_Anim(ss,1,1).endframe : Key_Anim(ss,1,1).status="stopped"
if Status$="looping" then Key_anim(ss,1,1).frame=Key_Anim(ss,1,1).StartFrame
endif
endif
endif
if o>0 then exit
next s
endfunction
function Key_DeleteObject(obj as integer)
slot=Key_GetObjectSlot(obj)
Key_Anim(slot,1,1).obj=0
Key_ObjectSlots(obj)=0
Key_UpdateMaxSlot()
endfunction
function Key_SetObjectSpeed(obj as integer,speed as float)
s=Key_GetObjectslot(obj)
Key_Anim(s,1,1).speed=speed
endfunction
function Key_LoopObject(obj as integer,startFrame as integer,EndFrame as integer)
s=Key_GetObjectslot(obj)
Key_Anim(s,1,1).StartFrame=StartFrame
Key_Anim(s,1,1).EndFrame=EndFrame
Key_Anim(s,1,1).status="looping"
Key_Anim(s,1,1).frame=StartFrame
endfunction
function Key_PlayObject(obj as integer,startFrame as integer,EndFrame as integer)
s=Key_GetObjectslot(obj)
IF StartFrame=0 then StartFrame=1
IF EndFrame=0 then EndFrame=Key_Anim(s,1,1).MaxFrame
Key_Anim(s,1,1).StartFrame=StartFrame
Key_Anim(s,1,1).EndFrame=EndFrame
Key_Anim(s,1,1).status="playing"
Key_Anim(s,1,1).frame=StartFrame
endfunction
function Key_ObjectPLaying(obj as integer)
TEMP=0
s=Key_GetObjectSlot(obj)
if Key_Anim(s,1,1).status="playing" then TEMP=1
endfunction TEMP
function Key_ObjectLooping(obj as integer)
TEMP=0
s=Key_GetOBjectSlot(obj)
if Key_Anim(s,1,1).status="playing" then TEMP=1
endfunction TEMP
function Key_Error(t as string)
exit prompt t,"DBPro Keyframe Functions"
end
endfunction