I needed help to manage to create a simple mesh animation and Roger brought this to me.
Great!
'As far as I know the only way to do animations in IBasic Standard
'is to create one object for each frame of the animation.
'You then show only one of the objects for each frame of the animation.
AUTODEFINE "OFF"
'Declare timer
DECLARE "kernel32",GetTickCount(),INT
DEF win:WINDOW
DEF run,error:INT
DEF numberofframesinanimation,frameduration,animationstarttime:INT
DEF animationframe:FLOAT
DEF scene,camera,light,shape[4]:INT
DEF lastframetime,timesincelastframe:INT
DEF camerax,cameraz:FLOAT
numberofframesinanimation=4
frameduration=100:'Time to show each frame in milliseconds
'Open a window
WINDOW win,0,0,640,480,@NOAUTODRAW,0,"Animation test",mainwindow
STARTTIMER win,100
run=1
'Create a 3D screen
error=CREATE3DSCREEN(win,640,480)
IF error<>0
MESSAGEBOX win, "Could not create Direct3D screen","Error"
CLOSEWINDOW win
END
ENDIF
D3DSETQUALITY win,@LIGHTON | @FILLSOLID | @SHADEGOURAUD
FRONTPEN win,RGB(255,255,255)
BACKPEN win,0
DRAWMODE win,@TRANSPARENT
'The parent scene frame
scene = D3DSCENE(win)
D3DCOMMAND scene,@SETSCENEBACKCOLOR,.2,.2,1
'Create and position the camera
camera = D3DCAMERA(scene)
D3DCOMMAND camera,@SETPOSITION,scene,0,20,-100
D3DCOMMAND camera,@SETORIENTATION,scene,0,0,1,0,1,0
'Create and orient a light source
light = D3DLIGHT(scene,@LIGHTDIRECTIONAL,.5,.5,.5)
D3DCOMMAND light,@SETORIENTATION,scene,0,0,1, 0,1,0
'Load the animation frame objects
FOR n=0 TO numberofframesinanimation-1
shape[n]=D3DSHAPE(scene, @SHAPECUSTOM)
D3DCOMMAND shape[n], @LOADSHAPE,GETSTARTPATH+"frame"+LTRIM$(STR$(n))+".x",0
NEXT n
lastframetime=GetTickCount()
animationstarttime=GetTickCount()
'Process messages until somebody closes us
WAITUNTIL run=0
'Delete all the frames
D3DDELETE light
D3DDELETE camera
FOR n=0 TO numberofframesinanimation-1
D3DDELETE shape[n]
NEXT n
D3DDELETE scene
CLOSEWINDOW win
END
SUB mainwindow
SELECT @class
CASE @IDCHAR
IF (@CODE = ASC("Q")) | (@CODE = ASC("q")) THEN run = 0
CASE @IDCREATE
CENTERWINDOW win
CASE @IDCLOSEWINDOW
run=0
CASE @IDDXUPDATE
'Find time since last frame to make things run at a constant speed
timesincelastframe=GetTickCount()-lastframetime
IF timesincelastframe>2
lastframetime=GetTickCount()
'The camera can move in the scene using the arrow keys
'Up arrow
IF(GETKEYSTATE(0x26))
D3DCOMMAND camera,@ADDTRANSLATION,0,0,timesincelastframe*.1
ENDIF
'Down arrow
IF(GETKEYSTATE(0x28))
D3DCOMMAND camera,@ADDTRANSLATION,0,0,-timesincelastframe*.1
ENDIF
'Left arrow
IF(GETKEYSTATE(0x25))
D3DCOMMAND camera,@ADDROTATION,0,1,0,-.001*timesincelastframe
ENDIF
'Right arrow
IF(GETKEYSTATE(0x27))
D3DCOMMAND camera,@ADDROTATION,0,1,0,.001*timesincelastframe
ENDIF
animationframe=animationframe+timesincelastframe/frameduration
IF INT(animationframe)>numberofframesinanimation-1 THEN animationframe=0
'Hide all animation frames by moving them behind the camera
FOR n=0 TO numberofframesinanimation-1
D3DCOMMAND shape[n],@SETPOSITION,camera,0,0,-10000
NEXT n
'Move the required animation frame into position
D3DCOMMAND shape[INT(animationframe)],@SETPOSITION,scene,0,0,0
'Render the scene to the DirectX surface
D3DRENDER scene,camera
'Add any 2D elements after the scene is rendered.
MOVE win,10,10
PRINT win,"Move around the scene with the arrow keys.Press Q to exit"
'Show the DirectX surface
DXFLIP win,0,0
ENDIF
ENDSELECT
RETURN
Ah! .. I'm missing the .X file to load into this one .. have you still got it? .. :)
Graham
Uups!
Sorry , i may have forget many files.
I will surely add them 1 by one.
anyway , i got the 4 frames required for that animation .
see the attached file ^^