Wraith  0.1.5
Basic 3D game engine in C++
Terrain

Basic functions to interact with the terrain such computing the normals and points on the terrain. More...

Collaboration diagram for Terrain:

Classes

class  TerrainObject
 A TerrainObject object used for storing TerrainObject model and texture. As well as having functionality for collision testing More...
 

Functions

const Terrain * Scene::getTerrain () const
 Gets the current terrain from the scene. More...
 
void TerrainObject::visualizeCellAt (const Collidable &collidable) const
 Visualizes the cell on the terrain that the collidable is currently above/below. More...
 
virtual void TerrainObject::visualizeCellAt (const Vect &position) const override
 Visualizes the cell on the terrain given a position. More...
 
Vect TerrainObject::computePointOnTerrainObject (const Vect &position) const
 computes the point on the terrain given a position in 3D space More...
 
Vect TerrainObject::computeNormalOnTerrainObject (const Vect &position) const
 computes the normal on the terrain given a position in 3D space More...
 

Detailed Description

Basic functions to interact with the terrain such computing the normals and points on the terrain.

Terrain Objects holds information about the model of the terrain as well as containing the internal mechanism for conducting collisions.

Here is an example of how to access the terrain within a game object to clamp the Tank to the terrain by getting the position on the terrain. As well as using the collision callback. IMPORTANT: You must include SceneManager.h, Scene.h, and Terrain.h

#include "SceneManager.h"
#include "Scene.h"
#include "Terrain.h"
// ----------------------------------------------------------
// Tank class
// ----------------------------------------------------------
void Tank::update()
{
// NOTE: returns a const Terrain* not just a Terrain*.
const Terrain* pTerrain = SceneManager::GetCurrentScene()->getTerrain();
// Setting position close the terrain
Vect terrainPosition = pTerrain->computePointOnTerrainObject();
this->setPosition(terrainPosition);
// Setting orientation based on terrain normal
// (basically using the normal to determine how to rotate tank
// to make it appear tilt as it moves on the terrain)
Vect terrainNormal = pTerrain->computePointOnTerrainObject();
this->setOrientation(terrainPosition);
// For debugging purposes
// visualizing the cell you are currently on.
pTerrain->visualizeCellAt(getPosition());
}
// ----------------------------------------------------------
// Bullet class
// ----------------------------------------------------------
void Bullet::terrainCollision() // Terrain collision
{
this->destroy();
}
static Scene * GetCurrentScene()
Gets the current scene.
Definition: SceneManager.h:130
const Terrain * getTerrain() const
Gets the current terrain from the scene.
Definition: Scene.cpp:83

Function Documentation

◆ computeNormalOnTerrainObject()

Vect TerrainObject::computeNormalOnTerrainObject ( const Vect &  position) const

computes the normal on the terrain given a position in 3D space

Parameters
positiona position.

◆ computePointOnTerrainObject()

Vect TerrainObject::computePointOnTerrainObject ( const Vect &  position) const

computes the point on the terrain given a position in 3D space

Parameters
positiona position.

◆ getTerrain()

const Terrain * Scene::getTerrain ( ) const

Gets the current terrain from the scene.

Returns
The terrain.

◆ visualizeCellAt() [1/2]

void TerrainObject::visualizeCellAt ( const Collidable collidable) const

Visualizes the cell on the terrain that the collidable is currently above/below.

Collidables uses BSphere center for its position.

Parameters
collidablea collidable.

◆ visualizeCellAt() [2/2]

void TerrainObject::visualizeCellAt ( const Vect &  position) const
overridevirtual

Visualizes the cell on the terrain given a position.

Parameters
positiona Vect position.