OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: BloodyMess Ogre::Terrain Heightfield
View page
Source of version: 6
(current)
{INCLUDE(page="BloodyMess tpl")}{INCLUDE} %help%~hs~__Help:__ For any problems you encounter while working with these code, please visit the [http://www.ogre3d.org/addonforums/viewtopic.php?f=6&t=10859|thread in the NxOgre forum]. !!{img src="img/wiki_up/NxOgreCube.png" alt="NxOgreCube.png"} BloodyMess Ogre::Terrain heightfield This code shows how to create a matching heightfield from the new Ogre::Terrain, a new feature in Ogre 1.7. It does everything in realtime, so there is no need to use flour to create an .xhf or flip and rotate the ((-Height Map|heightmap)). Thanks to XpLoDWilD for solving an issue with vertex under the origin. {CODE(wrap="1", colors="c++")}void loadTerrainGeometry(const Ogre::String& name, float* data, Ogre::uint16 size, Ogre::Real worldSize, Ogre::Real minHeight, Ogre::Real maxHeight, const Ogre::Vector3& position) { // Create the manual heightfield NxOgre::ManualHeightField *mhf = OGRE_NEW_T(NxOgre::ManualHeightField, Ogre::MEMCATEGORY_GENERAL)(); mhf->begin(size, size); Ogre::Real normMin = -32768.0f; Ogre::Real normMax = 32767.0f; // Sample the data to the manual heightfield for(int x = 0; x < size; ++x) { NxOgre::Enums::HeightFieldTesselation tess = NxOgre::Enums::HeightFieldTesselation_NW_SE; for(int z = size-1; z >= 0; --z) { Ogre::Real height = data[(size * z) + x]; short sample = (short)(((height - minHeight) / (maxHeight - minHeight)) * (normMax - normMin) + normMin); mhf->sample(sample, 0, 0, tess); if(tess == NxOgre::Enums::HeightFieldTesselation_NE_SW) tess = NxOgre::Enums::HeightFieldTesselation_NW_SE; else tess = NxOgre::Enums::HeightFieldTesselation_NE_SW; } } // Create the actual heightfield NxOgre::HeightField *hf = mhf->end(name.c_str()); Ogre::Real hf_size = worldSize + (worldSize / size); Ogre::Real hf_height = (maxHeight - minHeight) / 2.0f; Ogre::Real hf_pose_x = position.x - (worldSize / 2.0f); Ogre::Real hf_pose_y = position.y + ((maxHeight + minHeight) / 2.0f); Ogre::Real hf_pose_z = position.z - (worldSize / 2.0f); #if NxOgreVersionMajor <= 1 && NxOgreVersionMinor <= 5 NxOgre::HeightFieldGeometry* hfg = new NxOgre::HeightFieldGeometry(hf, NxOgre::Vec3(hf_size, hf_height, hf_size)); hfg->setLocalPose(NxOgre::Matrix44(NxOgre::Vec3(hf_pose_x, hf_pose_y, hf_pose_z))); mScene->createSceneGeometry(hfg); #else NxOgre::HeightFieldGeometryDescription desc(hf, NxOgre::Vec3(hf_size, hf_height, hf_size)); mScene->createSceneGeometry(desc, NxOgre::Matrix44(NxOgre::Vec3(hf_pose_x, hf_pose_y, hf_pose_z))); #endif // Free memory OGRE_DELETE_T(mhf, ManualHeightField, Ogre::MEMCATEGORY_GENERAL); }{CODE} You can use it like that, with "terrain" being a pointer to your Ogre::Terrain. {CODE(wrap="1", colors="c++")}loadTerrainGeometry(terrain->getMaterialName(), terrain->getHeightData(), terrain->getSize(), terrain->getWorldSize(), terrain->getMinHeight(), terrain->getMaxHeight(), terrain->getPosition());{CODE} Or you can supply the data yourself. {INCLUDE(page="NxOgre tpl")}{INCLUDE} --- Alias: (alias(BloodyMess_Ogre::Terrain_Heightfield))
Search by Tags
Search Wiki by Freetags
Latest Changes
DotScene
Easy Ogre Exporter
Mesh Viewer
Ogre Meshy
Custom Shadow Mapping
ETM
TheoraVideoPlugin
Video Overview
TheoraVideoPlugin Toolbar tpl
ogregallery
...more
Search
Find
Advanced
Search Help
Online Users
58 online users