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
AdvantageTerrainApplicationFrameListener.cpp
AdvantageTerrainApplication.cpp
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
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