i found Stefan Roettgers terrainengine libmini. vterrain.org says:
"libMini by Stefan Röttger - implements his paper Real-Time Generation of Continuous Levels of Detail for Height Fields
LGPL source, highly optimized, 5 bytes/heixel, very fast"
I translate it with: " Quick and Cool !".
The terrain rendering algorithm (abbreviated GOLD) has also been included into the game AquaNox.
Normally it draws with OPENGL, but it also has a stubengine inside, where the user
has to write some interface-functions and the user can draw with other things.
I wrote the interface for Irrlicht. The first little example with the interface is below.
If you want to use it, first you have to download Stefan Roettgers engine:
http://www9.informatik.uni-erlangen.de/ ... /download/
Then you have to compile the stubengine - in UNIx/LINUX use the build.sh like written in the
README, with Microsoft c++/Relo you have to put in the parameter -DNOOGL
Then you can try to compile this first example. I will try to do an better example, maybe
i would need help, please mailto zenprogramming at yahoo dot de.
And many thanks for the help of Stefan Roettger and im sure i need more.
Code: Select all
// Example v0.2 for Roettgers libmini-terrainengine with Irrlicht
//
// The mini library is the core of the terrain renderer described in the
// paper "Real-Time Generation of Continuous Levels of Detail for Height Fields".
// Copyright (c) 1995-2004 by Stefan Roettger (Version 5.02 as of 18.August.2004).
//
// The terrain renderer is licensed under the terms of the LGPL (see
// http://www.gnu.org/copyleft/ for more information on the license).
// Any commercial use of the code or parts of it requires the explicit
// permission of the author!
//
// The author's contact address is:
//
// mailto:roettger@cs.fau.de
// http://www9.cs.fau.de/Persons/Roettger
//
// The original terrain rendering paper and the talk are available here:
//
// http://www9.cs.fau.de/Persons/Roettger/papers/TERRAIN.PDF
// http://www9.cs.fau.de/Persons/Roettger/papers/WSCG98.PPT
//
//
// example and Irrlicht-interface-functions by zenprogramming
// (with help from Stefan Roettger ;-) )
// mailto: zenprogramming at yahoo dot de
// http://zenprogramming.tripod.com
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
#include "ministub.hpp"
scene::IAnimatedMeshSceneNode* terrainnode = 0;
scene::IAnimatedMesh* mesh = 0;
video::IVideoDriver* driver=0;
video::SMaterial material;
int triangleindex=-1;
int vertex0=0;
SMeshBuffer* buffer = 0;
video::S3DVertex vertex;
int size=3;
float dim=10.0f;
float scale=5.0f;
//libmini->Irrlichtinterfacefunctions
//this function starts every trianglefan
void mybeginfan()
{
triangleindex=0;
vertex0=buffer->getVertexCount();
}
//libmini->Irrlichtinterfacefunctions
//this function gives one vertex
void myfanvertex(float i,float y,float j)
{
vertex.Pos.set(dim*(i-size/2),
y*scale,
dim*(size/2-j));
// instead of using vertex-colors with a white texture,
// you can use a normal texture
// and you can use the vertex-colors for shadows
vertex.Color.set(255,255/i,255/y,255/j);
buffer->Vertices.push_back(vertex);
if (triangleindex==2)
{
buffer->Indices.push_back(vertex0);
buffer->Indices.push_back(buffer->getVertexCount()-2);
buffer->Indices.push_back(buffer->getVertexCount()-1);
return;
}
triangleindex++;
}
IAnimatedMesh* createTerrainMesh(SMeshBuffer* buffer)
{
SMesh* mesh = new SMesh();
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
for (s32 i=0; i<(s32)buffer->Indices.size(); i+=3)
{
core::plane3d<f32> p(
buffer->Vertices[buffer->Indices[i+0]].Pos,
buffer->Vertices[buffer->Indices[i+1]].Pos,
buffer->Vertices[buffer->Indices[i+2]].Pos);
p.Normal.normalize();
buffer->Vertices[buffer->Indices[i+0]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+1]].Normal = p.Normal;
buffer->Vertices[buffer->Indices[i+2]].Normal = p.Normal;
}
mesh->addMeshBuffer(buffer);
animatedMesh->addMesh(mesh);
mesh->drop();
return animatedMesh;
}
int main(int argc,char *argv[])
{
IrrlichtDevice *device =
createDevice(video::EDT_DIRECTX8, core::dimension2d<s32>(640, 480));
driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
material.Texture1=0;
material.Lighting=false;
driver->setMaterial(material);
short int hfield[]={0,0,0,
0,1,0,
0,0,0};
ministub *stub;
stub=new ministub(hfield,
&size,&dim,scale,1.0f,
mybeginfan,myfanvertex,0,0, NULL);
float res=1.0f;
float ex=0.0f,ey=10.0f,ez=30.0f;
float dx=0.0f,dy=-0.25f,dz=-1.0f;
float ux=0.0f,uy=1.0f,uz=0.0f;
float fovy=60.0f;
float aspect=1.0f;
float nearp=1.0f;
float farp=100.0f;
int lastFPS = -1;
vertex.Normal.set(0,1,0);
vertex.TCoords.set(0,1);
vertex.Color.set(255,255,255,255);
// this part from the new buffer to the buffer drop
// can generate a terrain mesh like in this case one
// time static, or in the main-loop every frame
// if you put it there
buffer = new SMeshBuffer();
stub->draw(res,
ex,ey,ez,
dx,dy,dz,
ux,uy,uz,
fovy,aspect,
nearp,farp);
mesh = createTerrainMesh(buffer);
smgr->getMeshManipulator()->makePlanarTextureMapping(
mesh->getMesh(0), 0.075f);
buffer->drop();
terrainnode = smgr->addAnimatedMeshSceneNode(mesh);
terrainnode->setPosition(core::vector3df(-50,45,-60));
terrainnode->setMaterialFlag(video::EMF_LIGHTING, false);
terrainnode->setMaterialTexture(0, driver->getTexture("texture.BMP"));
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(-50,50,-100));
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Roettgers Terrainengine-libmini and Irrlicht Engine by zenprogramming (fps:%d) Triangles:%d",
fps, driver->getPrimitiveCountDrawn());
device->setWindowCaption(tmp);
lastFPS = fps;
}
}
delete(stub);
buffer->drop();
device->drop();
return 0;
}