Kochol Game Engine  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Terrain

Introduction

This tutorial shows how to use terrain in Kochol Game Engine and shows the basic usage of tile terrain scene node You have to read Hello Kochol Game Engine and Camera movement tutorials before this tutorial.

We will delete old comments in this tutorial.

The minimal code for terrain rendering

#include "../../Include/kge.h"
#pragma comment(lib, "../../bin/debug/kge.lib")
// Use TileTerrain2 scene node to add a terrain
const float fCamSpeed = 3.0f;
void keys(float elaspedtime)
{
if (key.KeyDown('W'))
pCam->MoveBF(fCamSpeed * elaspedtime);
if (key.KeyDown('S'))
pCam->MoveBF(-fCamSpeed * elaspedtime);
if (key.KeyDown('D'))
pCam->MoveRL(fCamSpeed * elaspedtime);
if (key.KeyDown('A'))
pCam->MoveRL(-fCamSpeed * elaspedtime);
pCam->AutoRotateByMouse(true);
pCam->AutoRotateByMouse(false);
}
int main()
{
dev.Init(params);
pRen = dev.GetRenderer();
pSnMgr = dev.GetSceneManager();
pCam = pSnMgr->AddCameraNode
(
kge::math::Vector(5, 5, 5),
kge::math::Vector(0, 0, 0),
);
//------------------------------------------------------------------------------------
// Now lets create the terrain
//------------------------------------------------------------------------------------
// Load the texture for terrain
pTer->GetMaterial(0)->ppTexture[0] = pSnMgr->AddTexture("../../media/textures/t1.dds");
// Set the tile texure parameters
(
pTer->GetMaterial(0)->ppTexture[0], // Tile texture
2048, // Texture width
2048, // texture height
4, // Horizontal tiles count
4, // Vertical tiles count
512 // Texture size of each tile
);
// Set the terrain scene manager
pTer->SetSceneManager(pSnMgr);
// Create the terrain triangles and shaders
// The terrain size must be a number divided by 16
// for example 16, 32, 48, 64, 80, 96, 112, 128, ...
pTer->ReCreate
(
112, // Width
112, // Height
0.0, // Minimum of Random height
0.2 // Maximum of Random height
);
// For now you have to add at least one directional light to your scene to make terrain work.
while (dev.Run())
{
float fElaspedTime = t.GetTimeElapsed();
keys(fElaspedTime);
pRen->BeginRendering(true, true, false);
pSnMgr->RenderAll(fElaspedTime);
pRen->EndRendering();
}
}