main.cpp
Code:
#include <horde3d/Horde3D.h>
#include <horde3d/Horde3DUtils.h>
#include <SDL.h>
#include <iostream>
#include <cmath>
using namespace std;
using namespace Horde3D;
using namespace Horde3DUtils;
ResHandle model = 0,
cam = 0;
float rotX = -45,
rotY = 0,
posX = 0,
posY = 40,
posZ = -40;
inline float deg2Rad(float f) {
return f * (3.1415926f / 180.0f);
}
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Horde3D + SDL", 0);
int w = 800,
h = 600;
SDL_SetVideoMode(w, h, 32, SDL_OPENGL);
init();
resize(0, 0, w, h);
ResHandle pipeRes = addResource(ResourceTypes::Pipeline,
"forward.pipeline.xml", 0);
ResHandle modelRes = addResource(ResourceTypes::SceneGraph,
"untitled.scene.xml", 0);
ResHandle logoMatRes = addResource(ResourceTypes::Material,
"logo.material.xml", 0);
setResourcePath (ResourceTypes::SceneGraph, "models");
setResourcePath (ResourceTypes::Geometry, "models");
setResourcePath (ResourceTypes::Animation, "models");
setResourcePath (ResourceTypes::Material, "materials");
setResourcePath (ResourceTypes::Code, "shaders");
setResourcePath (ResourceTypes::Shader, "shaders");
setResourcePath (ResourceTypes::Texture2D, "textures");
setResourcePath (ResourceTypes::TextureCube, "textures");
setResourcePath (ResourceTypes::Effect, "effects");
setResourcePath (ResourceTypes::Pipeline, "pipelines");
setOption( EngineOptions::LoadTextures, 1 );
setOption( EngineOptions::TexCompression, 0 );
setOption( EngineOptions::FastAnimation, 0 );
setOption( EngineOptions::AnisotropyFactor, 8 );
setOption( EngineOptions::ShadowMapSize, 2048 );
setOption( EngineOptions::WireframeMode, 1);
cout << "loaded all: " << loadResourcesFromDisk("data") << endl;
model = addNodes(RootNode, modelRes);
setNodeTransform(model, 0, 0, 0, 0, 0, 0, 1, 1, 1);
if(!model)
cout << "model creation failed\n";
NodeHandle light = addLightNode(RootNode, "Light1", 0, "LIGHTING",
"SHADOWMAP");
setNodeTransform(light, 0, 40, 0, 0, 0, 0, 1, 1, 1);
setNodeParami(light, LightNodeParams::ShadowMapCount, 3);
cam = addCameraNode(RootNode, "Camera", pipeRes);
setNodeTransform(cam, 0, 40, 0, 0, 0, 0, 1, 1, 1);
cout << "cam setup: " << setupCameraView(cam, 45,
static_cast<float>(w)/h, 0.1, 1000) << endl;
//setNodeTransform(cam, 0, 20, -20, 0, 0, 0, 1, 1, 1);
if(!cam)
cout << "cam creation failed\n";
bool running = true;
SDL_Event event;
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_GrabInput(SDL_GRAB_ON);
setNodeTransform(cam, posX, posY, posZ, rotX, rotY, 0, 1, 1, 1);
while(running) {
bool posRotChanged = false;
if(SDL_PollEvent(&event)) {
if(event.type == SDL_KEYDOWN) {
//cout << "keydown event caught\n";
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
running = false;
break;
// Move forward
case SDLK_w:
posX -= sinf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
posY -= sinf(-deg2Rad(rotX));
posZ -= cosf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
posRotChanged = true;
break;
// Move backward
case SDLK_s:
posX += sinf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
posY += sinf(-deg2Rad(rotX));
posZ += cosf(deg2Rad(rotY)) * cosf(-deg2Rad(rotX));
posRotChanged = true;
break;
// Strafe left
case SDLK_a:
posX += sinf(deg2Rad(rotY - 90));
posZ += cosf(deg2Rad(rotY - 90));
posRotChanged = true;
break;
// Strafe right
case SDLK_d:
posX += sinf(deg2Rad(rotY + 90));
posZ += cosf(deg2Rad(rotY + 90));
posRotChanged = true;
break;
default:
break;
}
}
else if(event.type == SDL_MOUSEMOTION) {
//cout << "mousemove event caught\n";
rotY -= event.motion.xrel;
rotX -= event.motion.yrel;
posRotChanged = true;
}
}
if(posRotChanged)
setNodeTransform(cam, posX, posY, posZ, rotX, rotY, 0,
1, 1, 1);
showOverlay(0.75f, 0, 0, 0, 1, 0, 1, 0,
1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1,
7, logoMatRes);
render(cam);
SDL_GL_SwapBuffers();
}
dumpMessages();
release();
SDL_Quit();
return 0;
}
models/untitled.scene.xml
Code:
<Model name="untitled" geometry="untitled.geo">
<Mesh name="Cube" material="untitled/Material.material.xml" batchStart="0" batchCount="36" vertRStart="0" vertREnd="23" />
materials/untitled/Material.material.xml
Code:
<Material>
<Shader source="skinning.shader.xml" />
<Uniform name="Materialcol" a="0.8" b="0.8" c="0.8" d="1.0" />
</Material>
XMLs created with Blender exporter.