Possible small bug in TerrainSceneManager

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Tripnotik
Gnoblar
Posts: 2
Joined: Wed Apr 20, 2005 1:00 am
Location: Québec, Canada

Possible small bug in TerrainSceneManager

Post by Tripnotik » Wed Apr 20, 2005 7:33 pm

Hi,

I think I found a small bug in TerrainSceneManager. The bug is that it doesn't apply the world texture and the detail texture correctly (the code for setting the texture coordinates has an error). I made a small example to reproduce the bug, based on basic tutorial 3. Here is the code and the textures I used.

Code: Select all

#include "ExampleApplication.h"

class TutorialApplication : public ExampleApplication
{
protected:
public:
    TutorialApplication()
    {
    }

    ~TutorialApplication() 
    {
    }
protected:
    void chooseSceneManager(void)
    {
        mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
    }

    void createScene(void)
    {
        mSceneMgr->setWorldGeometry( "terrain.cfg" );
    }

    void createCamera(void)
    {
        mCamera = mSceneMgr->createCamera("PlayerCam");
        mCamera->setPosition(Vector3(0,100,0));
        mCamera->lookAt(Vector3(250,100,0));
        mCamera->setNearClipDistance(5);

    }
};

#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    TutorialApplication app;

    try {
        app.go();
    } catch( Exception& e ) {
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        fprintf(stderr, "An exception has occured: %s\n",
                e.getFullDescription().c_str());
#endif
    }

    return 0;
}
In terrain.cfg, DetailTile=3, PageSize=33 and TileSize=17.

The world texture Image

The detail texture Image

Here is what it looks like when running the program
Image
As you can see, the right and top side of the world texture is not displayed, and the detail texture doesn't display correctly at the right and top.

Here is how it looks with the fix
Image
Everything is now as it should.

The fix:
In the file OgreTerrainRenderable.cpp, at line 211, change this

Code: Select all

                *pTex0++ = ( float ) i / ( float ) msOptions->pageSize;
                *pTex0++ = ( float ) ( float ) j / ( float ) msOptions->pageSize;

                *pTex1++ = ( ( float ) i / ( float ) msOptions->tileSize ) * msOptions->detailTile;
                *pTex1++ = ( ( float ) ( float ) j / ( float ) msOptions->tileSize ) * msOptions->detailTile;
to this

Code: Select all

                *pTex0++ = ( float ) i / ( float ) (msOptions->pageSize - 1);
                *pTex0++ = ( float ) ( float ) j / ( float ) (msOptions->pageSize - 1);

                *pTex1++ = ( ( float ) i / ( float ) (msOptions->tileSize - 1) ) * msOptions->detailTile;
                *pTex1++ = ( ( float ) ( float ) j / ( float ) (msOptions->tileSize - 1) ) * msOptions->detailTile;
Also, is there a reason for the "(float) (float) j" on the second and third line? It seems to me that "(float) j" is enough.
0 x

User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark
Contact:

Post by DWORD » Wed Apr 20, 2005 8:17 pm

That makes sense (except the (float)(float) which I don't understand either). I think it's best if you can submit a patch, because posts quickly get lost in the forum.
0 x

User avatar
Clay
OGRE Community Helper
OGRE Community Helper
Posts: 518
Joined: Wed Mar 17, 2004 4:14 am
Contact:

Post by Clay » Wed Apr 20, 2005 9:20 pm

Also, is there a reason for the "(float) (float) j" on the second and third line? It seems to me that "(float) j" is enough.
This should do it:

Code: Select all

                *pTex0++ =  i / ( Real ) (msOptions->pageSize - 1);
                *pTex0++ = j / ( Real ) (msOptions->pageSize - 1);

                *pTex1++ = ( i / ( Real ) (msOptions->tileSize - 1) ) * msOptions->detailTile;
                *pTex1++ = ( j / ( Real ) (msOptions->tileSize - 1) ) * msOptions->detailTile;
The sheer amount of floats are unneccissary. Especially considering they should be Real.
0 x

Tripnotik
Gnoblar
Posts: 2
Joined: Wed Apr 20, 2005 1:00 am
Location: Québec, Canada

Post by Tripnotik » Wed Apr 20, 2005 10:33 pm

Ok, I just submitted a patch.

I didn't change the floats to Reals because I fear it could break something and I don't know Ogre well enough to make this decision.
0 x

Post Reply