download: Horde3D.zip
homepage: http://www.horde3d.org
manual: http://www.horde3d.org/docs/manual.html
wiki: http://www.horde3d.org/wiki/
forum: http://www.horde3d.org/forums/
Joshy

file: animation.bas
Code: Select all
#include once "fbgfx.bi"
#include once "Horde3D.bi"
function InitHorde3D(w as integer=640,h as integer=480) as boolean
dim as integer bits
screeninfo ,,bits
' create OpenGL context
screenres w,h,bits,,fb.GFX_OPENGL
flip
' init Horde3D
return h3dInit()
end function
if InitHorde3D()=false then
screen 0
print "error: init Horde3D !"
beep:sleep:end
end if
' get current screen size
dim as integer w,h
screeninfo w,h
' Set options
h3dSetOption(H3DOptions_LoadTextures, 1)
h3dSetOption(H3DOptions_TexCompression, 0)
h3dSetOption(H3DOptions_FastAnimation, 0)
h3dSetOption(H3DOptions_MaxAnisotropy, 4)
h3dSetOption(H3DOptions_ShadowMapSize, 1024)
' Add resources
' Pipeline
'var deferredPipeRes = h3dAddResource(H3DResTypes_Pipeline,"pipelines/deferred.pipeline.xml")
var forwardPipeRes = h3dAddResource(H3DResTypes_Pipeline,"pipelines/forward.pipeline.xml")
' Environment
var envRes = h3dAddResource(H3DResTypes_SceneGraph,"models/sphere/sphere.scene.xml")
' Knight
var knightRes = h3dAddResource(H3DResTypes_SceneGraph,"models/knight/knight.scene.xml")
var knightAnim1Res = h3dAddResource(H3DResTypes_Animation, "animations/knight_order.anim")
var knightAnim2Res = h3dAddResource(H3DResTypes_Animation, "animations/knight_attack.anim")
' Particle system
var particleSysRes = h3dAddResource(H3DResTypes_SceneGraph, "particles/particleSys1/particleSys1.scene.xml")
' Load resources
var contentDir = exepath() + "/Content"
h3dutLoadResourcesFromDisk(strptr(contentDir))
' Add scene nodes
' Add camera
var cam = h3dAddCameraNode(H3DRootNode, "Camera", forwardPipeRes)
'var cam = h3dAddCameraNode(H3DRootNode, "Camera", deferredPipeRes)
' Setup viewport and render target sizes
h3dSetNodeParamI( cam, H3DCamera_ViewportXI, 0 )
h3dSetNodeParamI( cam, H3DCamera_ViewportYI, 0 )
h3dSetNodeParamI( cam, H3DCamera_ViewportWidthI, w )
h3dSetNodeParamI( cam, H3DCamera_ViewportHeightI, h)
' Set camera parameters (pos, rotation, scale)
h3dSetNodeTransform(cam, 0,5,20, 0,0,0, 1,1,1)
' Set camera parameters (fov, ratio, near, far)
h3dSetupCameraView( cam, 45.0, w / h, 0.1, 1000.0 )
h3dResizePipelineBuffers( forwardPipeRes, w, h )
'h3dResizePipelineBuffers( deferredPipeRes, w, h )
' Add environment
var env = h3dAddNodes(H3DRootNode, envRes)
h3dSetNodeTransform(env, 0, -400, 0, 0, 0, 0, 400, 400, 400)
' Add knight
var knight = h3dAddNodes(H3DRootNode, knightRes)
' pos, rotation, scale
h3dSetNodeTransform(knight, 0,0,0, 0,180,0, .1,.1,.1)
h3dSetupModelAnimStage(knight, 0, knightAnim1Res, 0, "", False)
h3dSetupModelAnimStage(knight, 1, knightAnim2Res, 0, "", False)
'' Attach particle system to hand joint
h3dFindNodes(knight, "Bip01_R_Hand", H3DNodeTypes_Joint)
var hand = h3dGetNodeFindResult(0)
var particleSys = h3dAddNodes(hand, particleSysRes)
' pos, rotation, scale
h3dSetNodeTransform(particleSys, 0,40,0, 0,0,0, 1,1,1)
#if 1
' Add light source
var light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP")
' pos, rotation, scale
h3dSetNodeTransform(light, 0,1,5, 0,0,0, 1,1,1)
h3dSetNodeParamF(light, H3DLight_RadiusF, 0, 30)
h3dSetNodeParamF(light, H3DLight_FovF, 0, 90)
h3dSetNodeParamI(light, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light, H3DLight_ShadowMapBiasF, 0, 0.01)
h3dSetNodeParamF(light, H3DLight_ColorF3, 0, 1) ' red
h3dSetNodeParamF(light, H3DLight_ColorF3, 1, 1) ' green
h3dSetNodeParamF(light, H3DLight_ColorF3, 2, 1) ' blue
#endif
#if 0
' Add light source
var light2 = h3dAddLightNode(H3DRootNode, "Light2", 0, "LIGHTING", "SHADOWMAP")
' pos, rotation, scale
h3dSetNodeTransform(light2, 5,10,5, -45,0,0, 1,1,1)
h3dSetNodeParamF(light2, H3DLight_RadiusF, 0, 30)
h3dSetNodeParamF(light2, H3DLight_FovF, 0, 90)
h3dSetNodeParamI(light2, H3DLight_ShadowMapCountI, 1)
h3dSetNodeParamF(light2, H3DLight_ShadowMapBiasF, 0, 0.01)
h3dSetNodeParamF(light2, H3DLight_ColorF3, 0, 0.2) ' red
h3dSetNodeParamF(light2, H3DLight_ColorF3, 1, 0.2) ' green
h3dSetNodeParamF(light2, H3DLight_ColorF3, 2, 0.8) ' blue
#endif
const as single FPS = 60
dim as single t
h3dutDumpMessages()
' h3dSetOption(H3DOptions_DebugViewMode,1)
' h3dSetOption(H3DOptions_WireframeMode,1)
while inkey()=""
' Increase animation time
t = t + 16 * (1 / FPS)
' Do animation blending
h3dSetModelAnimParams(knight, 0, t, 1) ' order
h3dSetModelAnimParams(knight, 1, t, 0) ' attack
h3dUpdateModel(knight,1)
' Animate particle systems (several emitters in a group node)
var cnt = h3dFindNodes(particleSys, "", H3DNodeTypes_Emitter)
for I as long = 0 to cnt - 1
h3dUpdateEmitter(h3dGetNodeFindResult(I), 1 / FPS)
next
' Render scene
h3dRender( cam )
' Finish rendering of frame
h3dFinalizeFrame()
' swap buffers
flip
wend
' free all resources
h3dRelease()