I got it working, with a lot of trial and error.
My main issue was picking the Chicago man, it's a very small coordinate system... I guess it makes sense the man modeled to a human size lol.
I hope it helps others looking at horde3d for the first time, it's a great little rendering framework!
Code:
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>
#include "Horde3D.h"
#include "Horde3DUtils.h"
H3DNode model = 0, cam = 0;
void initGame( int winWidth, int winHeight )
{
// Initialize engine
h3dInit( H3DRenderDevice::OpenGL4 );
// Add pipeline resource
H3DRes pipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 );
// Add model resource
H3DRes modelRes = h3dAddResource( H3DResTypes::SceneGraph, "models/man/man.scene.xml", 0 );
// Add animation resource
H3DRes animRes = h3dAddResource( H3DResTypes::Animation, "animations/man.anim", 0 );
// Load added resources
// ISSUE: assume current folder is inside the root Horde3D folder.
// Or somewhere else, its more helpful having a folder pointing to the sample content.
h3dutLoadResourcesFromDisk( "../Horde3D/Binaries/Content" );
// Add model to scene
model = h3dAddNodes( H3DRootNode, modelRes );
// Apply animation
h3dSetupModelAnimStage( model, 0, animRes, 0, "", false );
// Add light source
H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
// Set light position and radius
//ISSUE: 20 +Y is too much for the man model!
h3dSetNodeTransform( light, 0, 2, 0, 0, 0, 0, 1, 1, 1 );
h3dSetNodeParamF( light, H3DLight::RadiusF, 0, 50.0f );
// Add camera
// ISSUE: no not instanciate new H3DNode cam, use the global one!
cam = h3dAddCameraNode( H3DRootNode, "Camera", pipeRes );
// Setup viewport and render target sizes
h3dSetNodeParamI( cam, H3DCamera::ViewportXI, 0 );
h3dSetNodeParamI( cam, H3DCamera::ViewportYI, 0 );
h3dSetNodeParamI( cam, H3DCamera::ViewportWidthI, winWidth );
h3dSetNodeParamI( cam, H3DCamera::ViewportHeightI, winHeight );
h3dSetupCameraView( cam, 45.0f, (float)winWidth / winHeight, 0.5f, 2048.0f );
h3dResizePipelineBuffers( pipeRes, winWidth, winHeight );
// ISSUE: camera needs to be place correctly for the model, default is 0,0,0 looking down -Z
h3dSetNodeTransform( cam, 0, 1.0, -0.05, 0, 0, 0, 1, 1, 1 );
// ISSUE: check if model, light or cam failed!
if ( !cam || !model || !light)
printf("initGame cam or model failed!\n");
}
void gameLoop( float fps )
{
static float t = 0;
// Increase animation time
t = t + 10.0f * (1 / fps);
// ISSUE: print something useful?
printf("%f\n", t);
// Play animation
h3dSetModelAnimParams( model, 0, t, 1.0f );
h3dUpdateModel( model, H3DModelUpdateFlags::Animation | H3DModelUpdateFlags::Geometry );
// Set new model position
// ISSUE: move down the -Z spinning around Y makes more sense then
h3dSetNodeTransform( model,
0, 0, t * -0.01, // Translation - walk down -Z
0, t, 0, // Rotation - around Y
1, 1, 1 ); // Scale - none
// Render scene
h3dRender( cam );
// Finish rendering of frame
h3dFinalizeFrame();
}
void releaseGame()
{
// Release engine
h3dRelease();
}
int main(int argv, char** args)
{
int w= 640, h=480;
// returns zero on success else non-zero
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("error initializing SDL: %s\n", SDL_GetError());
}
SDL_GL_LoadLibrary(NULL); // Default OpenGL is fine.
#if 1
// Request an OpenGL 4.5 context (should be core)
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
// Also request a depth buffer
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
//SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
#endif
SDL_Window* win = SDL_CreateWindow("GAME",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
w, h, SDL_WINDOW_OPENGL );
// Check that the window was successfully created
if (win == NULL) {
// In the case that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_GLContext maincontext = SDL_GL_CreateContext(win);
if (maincontext == NULL)
{
printf("Could not create maincontext: %s\n", SDL_GetError());
return 1;
}
// The window is open: could enter program loop here (see SDL_PollEvent())
initGame( w, h );
SDL_Event event;
bool quit = false;
while (!quit) {
gameLoop(20);
//SDL_Delay(30); // Pause execution for 30 milliseconds, for example
SDL_GL_SwapWindow(win);
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
releaseGame();
// Close and destroy the window
SDL_DestroyWindow(win);
// Clean up
SDL_Quit();
return 0;
}
And working in +Z
Code:
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>
#include "Horde3D.h"
#include "Horde3DUtils.h"
H3DNode model = 0, cam = 0;
void initGame( int winWidth, int winHeight )
{
// Initialize engine
h3dInit( H3DRenderDevice::OpenGL4 );
// Add pipeline resource
H3DRes pipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 );
// Add model resource
H3DRes modelRes = h3dAddResource( H3DResTypes::SceneGraph, "models/man/man.scene.xml", 0 );
// Add animation resource
H3DRes animRes = h3dAddResource( H3DResTypes::Animation, "animations/man.anim", 0 );
// Load added resources
// ISSUE: assume current folder is inside the Samples folder.
// Or somewhere else, it more helpful having a folder pointing to the sample content.
h3dutLoadResourcesFromDisk( "../Horde3D/Binaries/Content" );
// Add model to scene
model = h3dAddNodes( H3DRootNode, modelRes );
// Apply animation
h3dSetupModelAnimStage( model, 0, animRes, 0, "", false );
// Add light source
H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
// Set light position and radius
//ISSUE: 20 +Y is too much for the man model!
h3dSetNodeTransform( light, 0, 2, 0, 0, 180, 0, 1, 1, 1 );
h3dSetNodeParamF( light, H3DLight::RadiusF, 0, 50.0f );
// Add camera
// ISSUE: no not instanciate new H3DNode cam, use the global one!
cam = h3dAddCameraNode( H3DRootNode, "Camera", pipeRes );
// Setup viewport and render target sizes
h3dSetNodeParamI( cam, H3DCamera::ViewportXI, 0 );
h3dSetNodeParamI( cam, H3DCamera::ViewportYI, 0 );
h3dSetNodeParamI( cam, H3DCamera::ViewportWidthI, winWidth );
h3dSetNodeParamI( cam, H3DCamera::ViewportHeightI, winHeight );
h3dSetupCameraView( cam, 45.0f, (float)winWidth / winHeight, 0.5f, 2048.0f );
h3dResizePipelineBuffers( pipeRes, winWidth, winHeight );
// ISSUE: camera needs to be place correctly for the model, default is 0,0,0 looking down -Z
h3dSetNodeTransform( cam, 0, 1.0, 0.05, 0, 180, 0, 1, 1, 1 );
// ISSUE: check if model, light or cam failed!
if ( !cam || !model || !light)
printf("initGame cam or model failed!\n");
}
void gameLoop( float fps )
{
static float t = 0;
// Increase animation time
t = t + 10.0f * (1 / fps);
// ISSUE: print something useful?
printf("%f\n", t);
// Play animation
h3dSetModelAnimParams( model, 0, t, 1.0f );
h3dUpdateModel( model, H3DModelUpdateFlags::Animation | H3DModelUpdateFlags::Geometry );
// Set new model position
// ISSUE: move down the -Z spinning around Y makes more sense then
h3dSetNodeTransform( model,
0, 0, t * 0.01, // Translation - walk down -Z
0, t, 0, // Rotation - around Y
1, 1, 1 ); // Scale - none
// Render scene
h3dRender( cam );
// Finish rendering of frame
h3dFinalizeFrame();
}
void releaseGame()
{
// Release engine
h3dRelease();
}
int main(int argv, char** args)
{
int w= 640, h=480;
// returns zero on success else non-zero
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("error initializing SDL: %s\n", SDL_GetError());
}
SDL_GL_LoadLibrary(NULL); // Default OpenGL is fine.
#if 1
// Request an OpenGL 4.5 context (should be core)
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
// Also request a depth buffer
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
//SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
#endif
SDL_Window* win = SDL_CreateWindow("GAME",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
w, h, SDL_WINDOW_OPENGL );
// Check that the window was successfully created
if (win == NULL) {
// In the case that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_GLContext maincontext = SDL_GL_CreateContext(win);
if (maincontext == NULL)
{
printf("Could not create maincontext: %s\n", SDL_GetError());
return 1;
}
// The window is open: could enter program loop here (see SDL_PollEvent())
initGame( w, h );
SDL_Event event;
bool quit = false;
while (!quit) {
gameLoop(20);
//SDL_Delay(30); // Pause execution for 30 milliseconds, for example
SDL_GL_SwapWindow(win);
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
releaseGame();
// Close and destroy the window
SDL_DestroyWindow(win);
// Clean up
SDL_Quit();
return 0;
}