Problem with setBounds

Jules Robichaud Gagnon

02-07-2008 19:48:38

Trees will not appear anymore when setBounds is used instead of "isInfinite()"

I recreated the problem in Example2 with the current SVN version.


With 0 to 1500 it works but -1500 to 1500 the trees have odd positions.

I added MAX_BOUND and MIN_BOUND to be able to change the bounds easily.


Index: examples/source/Example2.cpp
===================================================================
--- examples/source/Example2.cpp (revision 2459)
+++ examples/source/Example2.cpp (working copy)
@@ -180,6 +180,8 @@
unload();
}

+#define MAX_BOUND 1500
+#define MIN_BOUND -1500

//[NOTE] In addition to some Ogre setup, this function configures PagedGeometry in the scene.
void World::load()
@@ -192,19 +194,25 @@
sceneMgr->setWorldGeometry("terrain.cfg");

//Start off with the camera at the center of the terrain
- camera->setPosition(700, 100, 700);
+ camera->setPosition(0, 100, 0);

//-------------------------------------- LOAD TREES --------------------------------------
//Create and configure a new PagedGeometry instance
trees = new PagedGeometry();
trees->setCamera(camera); //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->setInfinite(); //Use infinite paging mode
+ Ogre::TRect<Ogre::Real> bound;
+ bound.bottom = MAX_BOUND;
+ bound.top = MIN_BOUND;
+ bound.right = MAX_BOUND;
+ bound.left = MIN_BOUND;
+ trees->setBounds( bound );
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 TreeLoader2D object
- TreeLoader2D *treeLoader = new TreeLoader2D(trees, TBounds(0, 0, 1500, 1500));
+ TreeLoader2D *treeLoader = new TreeLoader2D(trees, bound);
trees->setPageLoader(treeLoader); //Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

//Supply a height function to TreeLoader2D so it can calculate tree Y values
@@ -221,8 +229,8 @@
for (int i = 0; i < 20000; i++){
yaw = Degree(Math::RangeRandom(0, 360));

- position.x = Math::RangeRandom(0, 1500);
- position.z = Math::RangeRandom(0, 1500);
+ position.x = Math::RangeRandom(MIN_BOUND, MAX_BOUND);
+ position.z = Math::RangeRandom(MIN_BOUND, MAX_BOUND);

scale = Math::RangeRandom(0.5f, 0.6f);


JohnJ

03-07-2008 02:29:28

Thanks for the reproducible example, it really helped. Anyway it should be fixed now, try the SVN and let me know how it goes :).

Jules Robichaud Gagnon

03-07-2008 11:00:25

Thank you very much, seems like it works. I remember I tried a while ago with bounds and it was causing the same problem. I think this bug was here for a while.

JohnJ

03-07-2008 17:44:03

Yeah, the bug was actually caused by some code that was supposed to fix this sort of problem, strangely enough. It was trying to offset the page tile X/Z values based on the bounds origin, assuming that the page tile coordinates supplied by PagedGeometry were originating at (0,0) in bounded mode (as they do in infinite mode), when in fact they originate at wherever the left/top bounds correlate.

Uh oh. I think I just realized that fixing bounded mode may have broken infinite mode in some cases. I'll check it out.

JohnJ

03-07-2008 17:59:57

Ok, it looks like the bug fix I did earlier wasn't a bug fix at all. The "real" bug was a inconsistency in the calculation of the xTile/zTile values between infinite and bounded modes - the bounded mode calculation was incorrect. My earlier "fix" incorrectly fixed the problem by making TreeLoader2D/TreeLoader3D accommodate the incorrect tile values given in bounded mode. I reverted those changes and fixed the real problem now, so bounded/infinite xTile/zTile values are now consistent. You can get the latest version from SVN as usual.

Jules Robichaud Gagnon

03-07-2008 18:07:35

That's some great service again. :D

Jules Robichaud Gagnon

03-07-2008 18:47:24

Index: include/PagedGeometry.h
===================================================================
--- include/PagedGeometry.h (revision 2467)
+++ include/PagedGeometry.h (working copy)
@@ -1476,8 +1476,8 @@
//Allocate grid array
geomGrid = new GeometryPage *[geomGridX * geomGridZ];

- int xioffset = Math::Floor(gridBounds.left / mainGeom->getPageSize());
- int zioffset = Math::Floor(gridBounds.top / mainGeom->getPageSize());
+ int xioffset = Ogre::Math::Floor(gridBounds.left / mainGeom->getPageSize());
+ int zioffset = Ogre::Math::Floor(gridBounds.top / mainGeom->getPageSize());
for (int x = 0; x < geomGridX; ++x)
{
for (int z = 0; z < geomGridZ; ++z)


It misses Ogre:: in front of Math::Floor.

JohnJ

03-07-2008 22:55:21

Ok, thanks for spotting that. It's fixed now.