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: NxOgreTerrainHeightfield
View page
Source of version: 3
(current)
{maketoc} You want to build a Heightfield from a Heightmap of your Ogre Terrain using NxOgre? Then you're at the right place. I noticed that informations related to the different Physic-Engines are very rarely so I started to provide my experiences to you. !!My Setup * Ogre3D Version 1.6.3 * NxOgre Version 1.0.22T5 Bleeding * Nvidia PhysX SDK for Windows Version 2.8.1 * Nvidia PhysX System Software Version 8.04.25 !!The Terrain Loader {CODE(wrap="1", colors="c++")}void GamePhysicManager::createTerrainPhysic( Ogre::String const& terrainCFGFile, Ogre::String const& heightMapResGroup ) { /************************************************************************************ * First we will read the Configfile terrainCFGFile to get the needed informations. * * Weneed: * * * the heightmap Image * * * the terrain X, Y and Z dimensions * ***********************************************************************************/ Ogre::ConfigFile terrInfo; terrInfo.load( terrainCFGFile ); // place this by your terrain file Ogre::String terrHeightMap = terrInfo.getSetting("Heightmap.image"); Ogre::Real terrX = Ogre::StringConverter::parseReal(terrInfo.getSetting("PageWorldX")); Ogre::Real terrZ = Ogre::StringConverter::parseReal(terrInfo.getSetting("PageWorldZ")); Ogre::Real terrY = Ogre::StringConverter::parseReal(terrInfo.getSetting("MaxHeight")); /******************************************** * Now we can create the NxOgre heightfield * *******************************************/ NxOgre::Resources::Heightfield* hf = createHeightfield( terrHeightMap, heightMapResGroup ); /****************************************************************************************** * With the heightfield and the terrain informations we can now create the terrain shape. * *****************************************************************************************/ NxOgre::Terrain* terr = new NxOgre::Terrain(hf, NxOgre::float3(terrX, terrY, terrZ), NxOgre::ShapeParams(), "centering: none, hole-material: 65535"); /************************************************************************ * The final step is to create the actor with the created terrain shape * ***********************************************************************/ mNxScene_->createActor("Terrain", terr, Ogre::Vector3::ZERO, "static: yes"); }{CODE} !!The function createHeightfield {CODE(wrap="1", colors="c++")}NxOgre::Resources::Heightfield* GamePhysicManager::createHeightfield(const Ogre::String& heightmap, Ogre::String const& heightMapResGroup) { /*********************************************** * Load the Image from the given resourcegroup * **********************************************/ Ogre::Image img; img.load(heightmap, heightMapResGroup); // load from resourcegroup heightMapResGroup int w = img.getWidth(); int h = img.getHeight(); NxOgre::Resources::ManualHeightfield mh; mh.begin(w, h); // Tesselation direction bool tessltr = false; for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { /****************************************************************** * The NxOgre maxheight is not the same as the terrain maxHeight. * * In NxOgre it is from -32767 to 32767. * *****************************************************************/ short height = img.getColourAt(x, y, 0).r * 32767; mh.sample(height, tessltr); } tessltr = !tessltr; } return mh.end(true); }{CODE} This creates a Terrainfield similar to the one loaded in Ogre. If you now place some Objects with a -+NxOgre::Body+- these Objects should hit the terrain when falling down. Hope this helps somebody handling Terrain with Physic Devildeath --- {INCLUDE(page="NxOgre tpl")}{INCLUDE}
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
103 online users