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: Using PLSM2 with PagedGeometry
View page
Source of version: 2
(current)
{maketoc} !!Using PLSM2 with PagedGeometry This is a stab at describing what needs to be done to use JohnJ's ((PagedGeometry Engine)) add-on with PLSM2. More information on this add-on can also be found on the forums in [http://www.ogre3d.org/phpBB2/viewtopic.php?t=24918&postdays=0&postorder=asc&start=0|this topic]. !!A Brief Overview of the Engine The PagedGeometry engine assists with displaying large numbers of billboarded objects on terrain. For example, flora and rocks. To use this engine one needs to obtain the following: * the source for the PagedGeometry engine; directions are found on the ((PagedGeometry Engine|PagedGeometry wiki page)) * models in mesh format !!Modifying the Demo Application To illustrate the process, the PLSM2 demo application was modified to support PagedGeometry. The following changes were made, with the goal of getting things working as quickly as possible. Improvements are welcomed. !!!!PagingLandScape2Application.h The createScene() method was extended to populate terrain with some trees. This is how the PagedGeometry demo operates, and in practice model placement will be done elsewhere. Add the header includes at the top: {CODE(wrap="1", colors="c++")}#include "PagedGeometry.h" #include "ImpostorPage.h" #include "BatchPage.h" #include "EntityPage.h" #include "TreeLoader.h"{CODE} Add the following to createScene (towards the bottom of the file): {CODE(wrap="1", colors="c++")}//Initialize the PagedGeometry engine PagedGeometry *trees = new PagedGeometry(mCamera, 50); //Set up LODs trees->addDetailLevel<BatchPage>(100); trees->addDetailLevel<ImpostorPage>(500); //Set up a TreeLoader for easy use TreeLoader *treeLoader = new TreeLoader(trees, TBounds(0, 0, 1500, 1500)); trees->setPageLoader(treeLoader); Entity *myTree = mSceneMgr->createEntity("MyTree", "tree2.mesh"); for (int i = 0; i < 2000; i++) { float x, z, yaw, scale; yaw = Math::RangeRandom(0, 360); x = Math::RangeRandom(0, 1500); z = Math::RangeRandom(0, 1500); scale = Math::RangeRandom(0.9f, 1.1f); treeLoader->addTree(myTree, x, z, yaw, scale); } raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));{CODE} Add the following public member to PagingLandScapeApplication: {CODE(wrap="1", colors="c++")}RaySceneQuery* raySceneQuery;{CODE} This member could likely be dispensed with, and a static used in the height lookup function. However the goal is to mirror the PagedGeometry demo as closely as possible, at least initially. !!!!PagingLandScape.cpp With apologies to JohnJ, the weakest part of the design of the PagedGeometry demo was the method used to locate terrain height. In fairness, one is expected to replace this code with something more suitable. However, once again we are going to mirror the demo and create a lookup function in the global namespace to locate terrain height. We are also going to store a RaySceneQuery object in the application (recall the public member added above). To make it easy to access the application from the global namespace, move the declaration of the app into the global namespace, and change it to a pointer: {CODE(wrap="1", colors="c++")}myPagingLandScapeApplication *app;{CODE} To make it clear where this goes, the edited section of code will look like: {CODE(wrap="1", colors="c++")}#define WIN32_LEAN_AND_MEAN #include "windows.h" #endif myPagingLandScapeApplication *app; #if !defined _DEBUG && OGRE_PLATFORM == OGRE_PLATFORM_WIN32{CODE} Since the application is now a pointer instead of an object, changes will need to be made to main, below: {CODE(wrap="1", colors="c++")} app = new myPagingLandScapeApplication; try { app -> go();{CODE} That is, create the application and change "app.go" to "app->go". Finally, add a height lookup function at the end of the file: {CODE(wrap="1", colors="c++")}float getTerrainHeight(float x, float z) { static Ray updateRay; updateRay.setOrigin(Vector3(x, 10000, z)); updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y); app -> raySceneQuery->setRay(updateRay); app -> raySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK); app -> raySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION); RaySceneQueryResult& qryResult = app -> raySceneQuery->execute(); RaySceneQueryResult::iterator i = qryResult.begin(); if (i != qryResult.end() && i->worldFragment) { return i->worldFragment->singleIntersection.y; } return 0; }{CODE} Note this has been changed slightly from the version provided in the PagedGeometry demo, and is based off of the terrain-following camera in the PLSM2 demo. !!Changes to the Visual Studio Project Similar changes will need to be made in other build environments, the following should make it clear what needs to be done: Add the PagedGeometry headers to the project (listed for completeness): * BatchPage.h * EntityPage.h * GrassLoader.h * ImpostorPage.h * PagedGeometry.h * StaticBillboardSet.h * Timer.h * TreeLoader.h Add the following source files to the project: * BatchPage.cpp * EntityPage.cpp * GrassLoader.cpp * ImpostorPage.cpp * PagedGeometry.cpp * StaticBillboardSet.cpp * TreeLoader.cpp !!In Conclusion Place models to be loaded somewhere in the resource path, and modify the entity construction in createScene(). The above uses the tree2 model supplied with PagedGeometry. Also note, if there is a problem loading a model then an incomplete impostor bitmap may be created. Delete this file (from the current working directory) before re-running the demo. Once created the impostor bitmaps can be moved anywhere in the resource path, and they will not be recreated. There are likely oversights in the above directions, and I apologize in advance. While I tried to keep accurate notes, sometimes one fixes obvious problems without being aware of it.
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
133 online users