I use getHeightAtWorldPosition (Ogre 1.9) to get terrain height for grassloader, I found it return 0 if the area is near from camera, my grass will grow at 0(inside hills), If I move the camera far away, and come back, things become correct.
I found a thread mentions this (I agree with him):
http://www.ogre3d.org/forums/viewtopic.php?f=1&t=78857
but no useful answer.
Need your help please, thanks.
Ogre 1.9 getHeightAtWorldPosition problem
-
- Gnoblar
- Posts: 4
- Joined: Sat Oct 11, 2014 4:41 am
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Ogre 1.9 getHeightAtWorldPosition problem
I think the solution is there in the other thread. It's that if the terrain in the slot where that particular world position resides is not loaded, you will always get a 0 return value. Look at the code:
I bet if you use the debugger you will see you are getting the "return 0" path because the actual Terrain instance in that slot is not loaded.
Code: Select all
//---------------------------------------------------------------------
float TerrainGroup::getHeightAtWorldPosition(const Vector3& pos, Terrain** ppTerrain /*= 0*/)
{
long x, y;
convertWorldPositionToTerrainSlot(pos, &x, &y);
TerrainSlot* slot = getTerrainSlot(x, y);
if (slot && slot->instance && slot->instance->isLoaded())
{
if (ppTerrain)
*ppTerrain = slot->instance;
return slot->instance->getHeightAtWorldPosition(pos);
}
else
{
if (ppTerrain)
*ppTerrain = 0;
return 0;
}
}
-
- Gnoblar
- Posts: 4
- Joined: Sat Oct 11, 2014 4:41 am
Re: Ogre 1.9 getHeightAtWorldPosition problem
Thank you c6burnsc6burns wrote: I bet if you use the debugger you will see you are getting the "return 0" path because the actual Terrain instance in that slot is not loaded.
I'v readed this part of codes some days ago (not deep inside), What I wonder, is why getHeightAtWorldPosition always return 0 after the terrain already loaded and visiable in camera? Why the slot not loaded?
I must leave the area and back to get it refreshed as I mentioned.
or can I have a chance to refresh slots manually, such as a terrain loaded callback? as this (seems not implement?)
http://www.ogre3d.org/forums/viewtopic. ... 3&start=75
Excuse me if I mis-understand something. I am a newbee of ogreThough the previous version said somewhere that callbacks have been provided when a terrain finishes streaming in, I haven't found any related code, yet.
I'll provide that API, so it's both ok for users to bind additional-resources-loading to the terrain loading callback, or paging callback.
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Ogre 1.9 getHeightAtWorldPosition problem
No idea. I use TerrainGroup::loadAllTerrains and wait behind a loading screen until all slots isLoaded returns true.fclddcn wrote:Why the slot not loaded?
-
- Gnoblar
- Posts: 4
- Joined: Sat Oct 11, 2014 4:41 am
Re: Ogre 1.9 getHeightAtWorldPosition problem
Yeah, maybe this is the key different, do you use async loading? loadAllTerrains(true) ?c6burns wrote:Wait behind a loading screen until all slots isLoaded returns true.
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Ogre 1.9 getHeightAtWorldPosition problem
Both sync and async loading work for me by waiting until all my slots isLoaded() returns true. I just tried async to test. All I'm doing is playing music in another thread so I actually just use synchronous loading after rendering a "Please wait" frame for the user. I may switch to async and have a little spinning icon, I just haven't tested it on mobile platforms yet.
-
- Gnoblar
- Posts: 4
- Joined: Sat Oct 11, 2014 4:41 am
Re: Ogre 1.9 getHeightAtWorldPosition problem
I have a dirty solution now (just for further research), I can see grass at correct postion.c6burns wrote:Both sync and async loading work for me by waiting until all my slots isLoaded() returns true. I just tried async to test. All I'm doing is playing music in another thread so I actually just use synchronous loading after rendering a "Please wait" frame for the user. I may switch to async and have a little spinning icon, I just haven't tested it on mobile platforms yet.
Code: Select all
// in every frame
Ogre::Camera *c=mSceneMgr->getCameraIterator().begin()->second;
mPGHandleGrass->reloadGeometryPage(c->getPosition());