PagedGeometry and Advanced terrain

Netskate

12-09-2008 01:36:46

Hi all, I'm trying to use pagedgeometry with a terrain managed by advantage terrain.

but I have some problem, after I had include the headers into my project, and linked the paged geometry library, I tried to load a single tree but I can't see it.

here the code:
AdvantageTerrainApplication.h
#include "ExampleApplication.h"
#include "OgreAVTerrainSceneManager.h"
//Include PagedGeometry headers that will be needed
#include "PagedGeometry.h"
#include "BatchPage.h"
#include "ImpostorPage.h"
#include "TreeLoader3D.h"

//Include "HeightFunction.h", a header that provides some useful functions for quickly and easily
//getting the height of the terrain at a given point.
//#include "HeightFunction.h"
//PagedGeometry's classes and functions are under the "Forests" namespace
using namespace Forests;

/** Application class */
class AdVantageTerrainApplication : public ExampleApplication
{
public:

PagedGeometry *trees;

RaySceneQuery* getRaySceneQuery() const { return mRaySceneQuery; }

AVTerrainSceneManager* getTerrainSceneManager() const { return static_cast<AVTerrainSceneManager*>(mSceneMgr); }

protected:

void createScene();

void createFrameListener();

void chooseSceneManager();

RaySceneQuery* mRaySceneQuery;
};


AdvantageTerrainApplicationFrameListener.cpp
.........
//Update lod trees
mApp->trees->update();
............


AdvantageTerrainApplication.cpp
void AdVantageTerrainApplication::createScene()
{

Real viewRange = 200000;

//mSceneMgr->setFog(FOG_LINEAR, ColourValue(0.598f, 0.496f, 0.375), 0.001, viewRange * 0.6, viewRange * 0.9);
mSceneMgr->setOption("CollisionStreamingMode","0,2");
mSceneMgr->setWorldGeometry("..\\..\\media\\output.apak");
mSceneMgr->setOption("ViewRange", &viewRange);
mSceneMgr->setOption("PrimaryCamera", mCamera);

mCamera->setPosition(Vector3(19734.6, 56566.5, 204230.0));
mCamera->setNearClipDistance(50);
mCamera->setFarClipDistance(viewRange);

Light *sunLight = mSceneMgr->createLight("Sun");
sunLight->setType(Light::LT_DIRECTIONAL);
Vector3 sundir(1,-1,0);
sundir.normalise();
sunLight->setPosition(6000,200,8000);
sunLight->setAttenuation(100,1.0,1.0,0.0);
sunLight->setDirection(sundir);
sunLight->setDiffuseColour(0.5,0.5,0.5);
mSceneMgr->getRootSceneNode()->attachObject(sunLight);

mSceneMgr->setAmbientLight(ColourValue(0.5,0.5,0.5));
mSceneMgr->setSkyBox(true, "sky");

//OgreHead
Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
headNode->setPosition(44976.6,6372.01,95283.5);
headNode->setScale(80,80,80);
headNode->attachObject(ogreHead);
mCamera->lookAt(headNode->getPosition());
//---------------------------------

mRaySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));

//-------------------------------------- LOAD TREES --------------------------------------
//Create and configure a new PagedGeometry instance
trees = new PagedGeometry();
trees->setCamera(mCamera); //Set the camera so PagedGeometry knows how to calculate LODs
trees->setPageSize(80); //Set the size of each page of geometry
trees->setInfinite(); //Use infinite paging mode
trees->addDetailLevel<BatchPage>(150, 50); //Use batches up to 150 units away, and fade for 30 more units
trees->addDetailLevel<ImpostorPage>(500, 50); //Use impostors up to 400 units, and for for 50 more units

//Create a new TreeLoader3D object
TreeLoader3D *treeLoader = new TreeLoader3D(trees, TBounds(0, 0, 1500, 1500));
trees->setPageLoader(treeLoader); //Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

//Setup the height function (so the Y values of trees can be calculated when they are placed on the terrain)
//HeightFunction::initialize(sceneMgr);

//Randomly place 20,000 copies of the tree on the terrain

Vector3 position;
position.x=24885.4;
position.y=6372.01;
position.z=95283.5;
Radian yaw= Degree(Math::RangeRandom(0, 360));
Real scale=Math::RangeRandom(50, 80);;

treeLoader->addTree(ogreHead, position, yaw, scale);


I tried to load a single tree (really an ogre head), but I can't see it.

note: I can see the ogre head loaded as normal scenenode.

next step will be, load a lot of trees with random position and runtime-calculated height of terrain in a x,z point. However I should first resolve this problem.

can you help me? thanks

rubasurex

12-09-2008 04:24:10

I'm no expert... but it looks like your camera is just too far away to see it. You're final Impostor Page fades out after 500 units, but you are dealing with units much larger than this. Speaking of which, why the huge units.

For example, instead of positioning your camera at (19734.6, 56566.5, 204230.0), why not at something more workable like (197, 565, 204)? I think you should scale down all your world coordinates both for simplicity and float precision. Especially if you want to integrate physics.

Also, are you updating the trees PagedGeometry every frame?

JohnJ

12-09-2008 05:40:13

Yeah, your coordinates are huge (24885.4, etc.), while the PagedGeometry code seems to be a stock cut-and-paste from the examples. You either need to scale down your world size, or adjust the PagedGeometry view distances and batch size to fit your world, because right now PagedGeometry is operating with a few hundred units (anything beyond that doesn't get displayed), while your world seems to be many thousand units large. The tutorials should explain this I think, and how to proper configure it.

Also, like rubasurex said, having a unit scale like this is usually a bad idea, especially when you get into physics engines. As a general rule, you should try to keep 1 unit = 1 meter or somewhere around there, because that's what most physics engines use.

Netskate

12-09-2008 08:47:27

the scale of the mesh is so larger because I wanted see it :P

I follow the first tutorial and after, I see that the code is similar to example1.

myApp->trees->update(); is called in the framelistener under framestarted.

so, mesh don't appears because camera is too far.. I suspect this, then I tried to add this code:
treeLoader->addTree(ogreHead, position, yaw, scale);

mCamera->setPosition(Vector3(position.x+20, position.y+20,position.z+20));
mCamera->lookAt(position);


and I can't still see the ogre head. any idea?

ps: I need a world 20km x 20km larger, so my terrain size is 20000x20000x1500 (in advantage terrain the z axis is up). there is other way to obtain this?

JohnJ

15-09-2008 03:27:44

ps: I need a world 20km x 20km larger, so my terrain size is 20000x20000x1500 (in advantage terrain the z axis is up). there is other way to obtain this?
Those measurements should work, but if you're using a non-standard coordinate system (like Z for up), you'll need to un-comment the "//#define PAGEDGEOMETRY_ALTERNATE_COORDSYSTEM" in PagedGeometry.h, and call "trees->setCoordinateSystem(Vector3::UNIT_Z);" Otherwise the LOD system will be all messed up and won't work properly.

Also make sure you have PagedGeometry's viewing ranges set up as you like; the code you gave won't draw anything farther than 500 meters, so that may or may not be what you want). Then, scale the Ogre head to a reasonable level (if it's too big and too close, the camera may actually end up inside the Ogre head, in which case you probably won't see anything).

If that still doesn't work, let me know.

Netskate

24-09-2008 09:58:02

I resolved, thanks, but now I have another problem.

I'll open a thread for this.