Ogre 1.9 getHeightAtWorldPosition problem

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
fclddcn
Gnoblar
Posts: 4
Joined: Sat Oct 11, 2014 4:41 am

Ogre 1.9 getHeightAtWorldPosition problem

Post by fclddcn »

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.
User avatar
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

Post by c6burns »

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:

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;
        }
    }
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.
fclddcn
Gnoblar
Posts: 4
Joined: Sat Oct 11, 2014 4:41 am

Re: Ogre 1.9 getHeightAtWorldPosition problem

Post by fclddcn »

c6burns 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.
Thank you c6burns

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
Though 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.
Excuse me if I mis-understand something. I am a newbee of ogre :)
User avatar
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

Post by c6burns »

fclddcn wrote:Why the slot not loaded?
No idea. I use TerrainGroup::loadAllTerrains and wait behind a loading screen until all slots isLoaded returns true.
fclddcn
Gnoblar
Posts: 4
Joined: Sat Oct 11, 2014 4:41 am

Re: Ogre 1.9 getHeightAtWorldPosition problem

Post by fclddcn »

c6burns wrote:Wait behind a loading screen until all slots isLoaded returns true.
Yeah, maybe this is the key different, do you use async loading? loadAllTerrains(true) ?
User avatar
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

Post by c6burns »

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.
fclddcn
Gnoblar
Posts: 4
Joined: Sat Oct 11, 2014 4:41 am

Re: Ogre 1.9 getHeightAtWorldPosition problem

Post by fclddcn »

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.
I have a dirty solution now (just for further research), I can see grass at correct postion.

Code: Select all

  // in every frame
  Ogre::Camera *c=mSceneMgr->getCameraIterator().begin()->second;
  mPGHandleGrass->reloadGeometryPage(c->getPosition());
thanks for all of your reply.
Post Reply