This is an example that converts spheres and axis-aligined-boxes to voxels. It shows how to initialise, create/remove voxel and how to render properly.
#include "blub/log/global.hpp"
#include "blub/log/system.hpp"
#include "blub/math/colour.hpp"
#include "blub/math/math.hpp"
#include "blub/math/quaternion.hpp"
#include "blub/math/sphere.hpp"
#include "blub/math/transform.hpp"
#include "blub/serialization/callBaseObject.hpp"
#include "blub/sync/identifier.hpp"
#include "blub/procedural/voxel/config.hpp"
#include "blub/procedural/voxel/edit/axisAlignedBox.hpp"
#include "blub/procedural/voxel/edit/sphere.hpp"
#include "blub/procedural/voxel/simple/accessor.hpp"
#include "blub/procedural/voxel/simple/container/inMemory.hpp"
#include "blub/procedural/voxel/simple/renderer.hpp"
#include "blub/procedural/voxel/simple/surface.hpp"
#include "blub/procedural/voxel/terrain/accessor.hpp"
#include "blub/procedural/voxel/terrain/surface.hpp"
#include "blub/procedural/voxel/terrain/renderer.hpp"
#include "blub/procedural/voxel/tile/container.hpp"
#include "blub/procedural/voxel/tile/renderer.hpp"
#include "blub/procedural/voxel/tile/surface.hpp"
#include "OgreTile.hpp"
#include "Handler.hpp"
#include <boost/function.hpp>
{
typedef container<config> t_container;
typedef accessor<config> t_accessor;
typedef surface<config> t_surface;
template <typename configType>
{
};
typedef renderer<config> t_renderer;
};
int main(int , char* [])
{
blub::log::system::addConsole();
blub::log::system::addFile("voxelterrain.log");
{
return EXIT_FAILURE;
}
handler.
camera->setPosition(
vector3(20., 0., -50.));
{
return EXIT_FAILURE;
}
scopedPointer<t_voxelContainer> voxelContainer;
scopedPointer<t_voxelAccessor> voxelAccessor;
scopedPointer<t_voxelSurface> voxelSurface;
scopedPointer<t_voxelRenderer> voxelRenderer;
{
const int32 numLod(3);
voxelAccessor.reset(
new t_voxelAccessor(terrainDispatcher, *voxelContainer, numLod));
voxelSurface.reset(
new t_voxelSurface(terrainDispatcher, *voxelAccessor));
const t_voxelRenderer::t_createTileCallback callbackCreate = boost::bind(t_renderTile::create, handler.
renderScene,
"none", &handler.
graphicDispatcher);
lodRadien[0] = t_config::voxelsPerTile*2.0;
lodRadien[1] = t_config::voxelsPerTile*2.0;
lodRadien[2] = t_config::voxelsPerTile*2.0;
voxelRenderer.reset(
new t_voxelRenderer(terrainDispatcher, *voxelSurface, lodRadien));
voxelRenderer->setCreateTileCallback(callbackCreate);
cameraIdentifier = sync::identifier::create();
voxelRenderer->addCamera(cameraIdentifier, handler.camera->getPosition());
handler.
signalFrame()->connect(
[&] (real)
{
voxelRenderer->updateCamera(cameraIdentifier, handler.camera->getPosition());
}
);
handler.
signalMouseGotPressed()->connect(
[&] (bool &left)
{
createSphere(voxelContainer.get(), handler.camera->getPosition()+handler.camera->getDirection()*10., !left);
}
);
}
{
sphereEditCut->setCut(true);
voxelContainer->editVoxel(sphereEdit);
}
{
terrainDispatcher.start();
handler.
renderSystem->startRendering();
terrainDispatcher.stop();
}
return EXIT_SUCCESS;
}
{
sphereEdit->setCut(cut);
}