Tiled terrain scene node
Posted: Thu Dec 28, 2006 1:39 am
TlTerrainSceneNode create tile based terrain which can be nearly limitless in size. This is accomplished by storing data about terrain (height, normal, UV coordinates) in data array. Only terrain in specified size around camera (or anything specified) is rendered. Each tile can be textured independently by part of texture. This is accomplished by setting its texture UV coordinates. This class is still work in process and I would welcome any constructive critique, suggestions or bug reports from you. You are allowed to use it freely.
header files: http://members.lycos.co.uk/arras1/downl ... 61228b.zip
most important functions:
TlTerrainSceneNode(scene::ISceneManager* smgr, core::dimension2d<u32> trsize,u32 visibility, f32 tlsize = 1.0f)
-constructor
smgr -pointer to scene manager
trsize -dimensions of whole terrain in tiles
visibility -number of tiles which are visible in X and Z directions
tlsize -size of single tile
virtual void setHeight(core::vector2d<s32> position, f32 newheight)
-set height of data point at given coordinates
position -data point coordinates in tiles
newheight -new height
virtual f32 getHeight(core::vector2d<s32> position)
-return height of data point at given coordinates
position -data point coordinates in tiles
virtual f32 getHeight(core::vector3df pos)
-return height of terrain at any coordinates, used to place scene nodes on terrain
pos -position in 3D space, only X and Z coordinates are used
virtual void setTexture(char* filename)
-loads texture to be used by terrain
filename -texture file
virtual void setTileUVs(core::vector2d<s32> position, core::vector2df uv0, core::vector2df uv1, core::vector2df uv2, core::vector2df uv3)
-set texture coordinates of tile
position -tile coordinates in tiles
uv0 -UV coordinates of lower left corner of tile
uv1 -UV coordinates of upper right corner of tile
uv2 -UV coordinates of upper right corner of tile
uv3 -UV coordinates of lower left corner of tile
virtual void centerVisibleTerrain(core::vector3df pos)
-centers visible part of terrain at given coordinates
pos -position in 3d space, only X and Z coordinates are used
virtual void centerVisibleTerrain(scene::ISceneNode* node)
-centers visible part of terrain around scene node (camera, player)
node -scene node
virtual void follow(scene::ISceneNode* node)
-sets scene node visible terrain should be centered around automatically
node -scene node
virtual void stopFollowing()
-cancel follow order
virtual bool getIntersectionWithLine( core::line3d<f32> line, core::vector3df &outIntersection)
-this function can be used to check line of sight or bulet collision
is slower than getHeight so use it only when appropriate
return true if line collide with mesh, false if not
line -3D line to test collision with terrain
outIntersection -vector were intersection point will be stored
virtual void smoothNormals()
-will recalculate normals of whole terrain in order to look smooth under light
virtual void calculateNormal(u32 x, u32 y)
-will recalculate one normal at given coordinates
for complete list of functions look in to TlTerrainSceneNode.h
header files: http://members.lycos.co.uk/arras1/downl ... 61228b.zip
most important functions:
TlTerrainSceneNode(scene::ISceneManager* smgr, core::dimension2d<u32> trsize,u32 visibility, f32 tlsize = 1.0f)
-constructor
smgr -pointer to scene manager
trsize -dimensions of whole terrain in tiles
visibility -number of tiles which are visible in X and Z directions
tlsize -size of single tile
virtual void setHeight(core::vector2d<s32> position, f32 newheight)
-set height of data point at given coordinates
position -data point coordinates in tiles
newheight -new height
virtual f32 getHeight(core::vector2d<s32> position)
-return height of data point at given coordinates
position -data point coordinates in tiles
virtual f32 getHeight(core::vector3df pos)
-return height of terrain at any coordinates, used to place scene nodes on terrain
pos -position in 3D space, only X and Z coordinates are used
virtual void setTexture(char* filename)
-loads texture to be used by terrain
filename -texture file
virtual void setTileUVs(core::vector2d<s32> position, core::vector2df uv0, core::vector2df uv1, core::vector2df uv2, core::vector2df uv3)
-set texture coordinates of tile
position -tile coordinates in tiles
uv0 -UV coordinates of lower left corner of tile
uv1 -UV coordinates of upper right corner of tile
uv2 -UV coordinates of upper right corner of tile
uv3 -UV coordinates of lower left corner of tile
virtual void centerVisibleTerrain(core::vector3df pos)
-centers visible part of terrain at given coordinates
pos -position in 3d space, only X and Z coordinates are used
virtual void centerVisibleTerrain(scene::ISceneNode* node)
-centers visible part of terrain around scene node (camera, player)
node -scene node
virtual void follow(scene::ISceneNode* node)
-sets scene node visible terrain should be centered around automatically
node -scene node
virtual void stopFollowing()
-cancel follow order
virtual bool getIntersectionWithLine( core::line3d<f32> line, core::vector3df &outIntersection)
-this function can be used to check line of sight or bulet collision
is slower than getHeight so use it only when appropriate
return true if line collide with mesh, false if not
line -3D line to test collision with terrain
outIntersection -vector were intersection point will be stored
virtual void smoothNormals()
-will recalculate normals of whole terrain in order to look smooth under light
virtual void calculateNormal(u32 x, u32 y)
-will recalculate one normal at given coordinates
for complete list of functions look in to TlTerrainSceneNode.h