[SOLVED] setOption problems

Buckcherry

24-04-2008 21:30:25

Hi everybody,

I am trying to make a map editor using PLSM2. I am following the examples and as far as I can see the main line is the following:

mSceneMgr->setOption( "DeformationCenter",&mCursorPos);

Doing this I don't get any effect.

I have been taking a look into the OgrePagingLandScapeOptions.cpp file, and I can't see any line saying something like "DeformationCenter".

Is that file where I should take a look?.

Am I using a wrong version of PLSM2?. In this case, where could I download the good one?.

Thanks!

tuan kuranes

25-04-2008 14:38:13

what version of plsm2 ?

Buckcherry

25-04-2008 15:36:57

How can I know the version I am using?. I downloaded it from the CVS repository...

tuan kuranes

25-04-2008 15:47:26

cvs is ok. SDK is too old to know what's inside.

cursorpos won't do. Deformation center needs real world position of crater center.

Did you read Demo PLSM2 code ?

Here's what myPagingLandScapeFrameListener::deform() does :

const Real clickX = static_cast <Real> (e.state.X.abs) / mWindow->getWidth();
const Real clickY = static_cast <Real> (e.state.Y.abs) / mWindow->getHeight();
Ray pickRay = mCurrentCamera->getCameraToViewportRay(clickX, clickY);
mRayQuery->setRay (pickRay); mRayQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
mRayQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);
mRayQuery->execute ();
RaySceneQueryResult& qryResult = mRayQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
mScnMgr->setOption( "DeformationCenter",
&(it->worldFragment->singleIntersection) );
}

tuan kuranes

25-04-2008 15:48:52

btw, in cvs there's a Cegui terrain editor you should use as reference deformation/painting

Buckcherry

25-04-2008 15:52:29

I am using QuickGUI instead of CEGUI. Is there any problem with this?.

tuan kuranes

25-04-2008 15:56:27

Not at all.

Cursor should come from mouse position OIS give you. so No gui involved.

I was rather giving you a way of having a "how-to" or "reference" code you should find in the cegui editor living in CVS. (has every thing needed, only lack 'decal' which is in Demo code only.).

Buckcherry

25-04-2008 16:08:14

That's the thing I have been doing during a lot of days...

At the moment I have this:

In the MainListener constructor I have:

mCursorSize = 1;
mCursor = NULL;
setBrushSize (5);
setBrushScale(0.02f);
setEditMode(EditNothing);


Where the methods setBrushSize, setBrushScale and setEditMode are as follows:

void MainListener::setBrushSize(const int value)
{
mBrushSize = value;
// beware only works with crater predefined modifications
mSceneMgr->setOption("BrushSize", &mBrushSize);

// for user height array of modif
// use
//mScnMgr->setOption("BrushArrayHeight", &mBrushSize);
//mScnMgr->setOption("BrushArrayWidth", &mBrushSize);

//Initialise the "cursorPoints"
mCursorPoints[0] = Vector3(mBrushSize*8, 0.0f, 0.0f);
const float pointsangle = 360.0 / AMOUNT_CURSOR_POINTS;
const Real x = mCursorPoints[0].x;
const Real z = mCursorPoints[0].z;
for(int i=2; i <= AMOUNT_CURSOR_POINTS; i++)
{
const float radAngle = DEG2RAD((i-1)*(pointsangle));
const float cosAngle = cos(radAngle);
const float sinAngle = sin(radAngle);

mCursorPoints[i-1].x = x*cosAngle + z*sinAngle;
mCursorPoints[i-1].z = -x*sinAngle + z*cosAngle;
}
mCursorPoints[AMOUNT_CURSOR_POINTS] = mCursorPoints[0];
}

void MainListener::setBrushScale(const int value)
{
mSceneMgr->setOption("BrushScale", &value);
}

void MainListener::setEditMode (const EditMode editMode)
{
mEditMode = editMode;
}


In the frameStarted method I have:

mTimeElapsed += evt.timeSinceLastFrame;

In the frameEnded method I have:

bool MainListener::frameEnded(const FrameEvent& evt)
{
if (mLMouseDown)
{

switch (mEditMode)
{
case EditDeformTerrain:
mSceneMgr->setOption( "DeformationCenter", &mCursorPos);
break;

case EditPaintAlphaTerrain:
mSceneMgr->setOption( "PaintAlphaCenter", &mCursorPos);
break;

case EditPaintColorTerrain:
mSceneMgr->setOption( "PaintColorCenter", &mCursorPos);
break;

default:
break;
}
}

return FrameListener::frameEnded(evt);
}


In the mousePressed method I have:

bool MainListener::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
if (mMouseOverWidget == false) // Si no estamos sobre ningun elemento de la GUI
{
// Left mouse button down
if (id == OIS::MB_Left)
{
switch (mEditMode)
{
case EditDeformTerrain:
mLMouseDown = true;
deform(arg);
break;
default:
break;
}
}
else if (id == OIS::MB_Right)
{
mGUIManager->getMouseCursor()->hide();
mRMouseDown = true;
}
else
{
mLMouseDown = false;
mRMouseDown = false;
}
}

mGUIManager->injectMouseButtonDown(static_cast<QuickGUI::MouseButtonID>(id));
return true;
}


In the mouseMoved method I have:

bool MainListener::mouseMoved(const OIS::MouseEvent &arg)
{
mGUIManager->injectMouseMove(arg.state.X.rel, arg.state.Y.rel);

//////////////////////////////////////////////////////////////////////////
if (mEditMode == EditDeformTerrain)
{

if(mTimeElapsed > 0.05)
{
mTimeElapsed=0;

QuickGUI::MouseCursor* mouseCursor = mGUIManager->getMouseCursor();
QuickGUI::Point mousePos = mouseCursor->getPosition();
const Ray pickRay = mCamera->getCameraToViewportRay(mousePos.x/float(arg.state.width), mousePos.y/float(arg.state.height));

mRayCursorQuery->setRay (pickRay);
mRayCursorQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
mRayCursorQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);

RaySceneQueryResult& qryResult = mRayCursorQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
mCursorPos = it->worldFragment->singleIntersection;
}

bool doattach = false;
if (!mCursor)
{
mCursor = new Line3D (AMOUNT_CURSOR_POINTS);
doattach = true;

} // if (!mCursor)

//Define the position of the points that form the cursor
Ray cameraRay( Vector3::ZERO, Vector3::UNIT_Y );
RaySceneQueryResult result;
RaySceneQueryResult::iterator itr;
mRayQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
mRayQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);
for(unsigned int i = 0; i <= AMOUNT_CURSOR_POINTS; i++)
{
cameraRay.setOrigin(Vector3(mCursorPos.x + mCursorPoints[i].x,
0.0f,
mCursorPos.z + mCursorPoints[i].z));
mRayCursorQuery->setRay( cameraRay );
// Perform the scene query
result = mRayCursorQuery->execute();
if (!result.empty())
{
itr = result.begin( );
if ( itr != result.end() && itr->worldFragment )
{
const Real terrainHeight = itr->worldFragment->singleIntersection.y;

mCursorPoints[i].y = terrainHeight;
}
else
{
mCursorPoints[i].y = 0.0f;
}
}
}

mCursor->updateLine (mCursorPoints);
if (doattach)
{
mCursorNode->detachAllObjects();
mCursorNode->attachObject(mCursor);
}
mCursorNode->setPosition(Vector3(mCursorPos.x, 0.0f, mCursorPos.z));
}
}
return true;
}


And I have changed my code for the deform method to the one you have just told me:

void MainListener::deform(const OIS::MouseEvent &arg)
{
const Real clickX = static_cast <Real> (arg.state.X.abs) / mWindow->getWidth();
const Real clickY = static_cast <Real> (arg.state.Y.abs) / mWindow->getHeight();
Ray pickRay = mCamera->getCameraToViewportRay(clickX, clickY);
mRayQuery->setRay (pickRay);
mRayQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
mRayQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);
mRayQuery->execute ();
RaySceneQueryResult& qryResult = mRayQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
mSceneMgr->setOption( "DeformationCenter",
&(it->worldFragment->singleIntersection) );
}
}


Nothing happens when I pressed the left button over the terrain...

What is wrong, please?.

tuan kuranes

25-04-2008 16:15:27

Is the mouse terrain position Circle correct ?
Are you rendering direcly on window or using a viewport/render texture ?

Buckcherry

25-04-2008 16:43:44

It seems the circle is okay. It appears over the terrain.

I am rendering directly on a window.

Any idea?

tuan kuranes

25-04-2008 16:53:43

If circle work then cursor pos is Ok.

- perhaps a misconfigure terrain config file...
Serach for option preventing deformation and/or painting perhaps or using terrain config files that works (those coming from demo_pls2)

- try playing with brush scale and size to be sure it fits terrain.

- Debug you're application and see why
"mSceneMgr->setOption( "DeformationCenter",
&(it->worldFragment->singleIntersection) ); "

doesn't work (running in debug mode both your app and plsm2)

Buckcherry

25-04-2008 20:09:30

I am unable to make it work... :-(

Is there a version of the Map Editor for Visual C++ 8.0 (2005)?

I am working with the VC++ 8.0 taking a look to the sourcecode of the Map Editor for VC++ 7.1.

Buckcherry

28-04-2008 08:47:13

Hi,

I have realised that in the Map Editor example there are these lines:

mRayCursorQuery->setRay (pickRay);
mRayQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
mRayQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);

RaySceneQueryResult& qryResult = mRayCursorQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
mCursorPos = it->worldFragment->singleIntersection;
}


I think that it should be mRaySceneQuery rather than mRayQuery, shouldn't it?:

mRayCursorQuery->setRay (pickRay);
mRayCursorQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
mRayCursorQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);

RaySceneQueryResult& qryResult = mRayCursorQuery->execute();
RaySceneQueryResult::iterator it = qryResult.begin();
if (it != qryResult.end() && it->worldFragment)
{
mCursorPos = it->worldFragment->singleIntersection;
}


Is this an error or it is ok?

Buckcherry

30-04-2008 16:03:32

Is there any known problem for QuickGUI combining it with the setOption method?.

I have started to think that the problem that I have is in this way. But the strange thing is that I can place objects on the terrain clicking on it using the same method as the deform one.

Any help or suggestion would be appreciated, please.

tuan kuranes

30-04-2008 17:39:30

I can place objects on the terrain clicking on it using the same method as the deform one

as said above, if that works, the problem is that your terrain cannot be deformed.
Perhaps a config file problem ?
Did you try your terrain with the demo_plsm2 ?

Buckcherry

01-05-2008 09:21:44

This is my paginglandscape2.cfg file:

#DefaultMap=European_Alpes
DefaultMap=Terrain_Scene_Manager_Terrain


European_Alpes=Alpes
Terrain_Scene_Manager_Terrain=TsmTerrain
hf=hf_129_3

NewWorld2=NewWorld2

# need to download datasrc.zip from http://tuan.kuranes.free.fr/ogre.html for those
puget_sound=ps_height_1k
grand_canyon=gcanyon_height_4k2k
terragen_genrated=terragen16bits


# resource group name where to find map definition
GroupName=PLSM2

# Try forbidden textureformat combinations
TextureFormatDebug=no


And this is my TsmTerrain.cfg file:

GroupName=PLSM2

Width=1
Height=1

Data2DFormat=HeightField
LandScapeFileName=terrain

FileSystem=TsmTerrain
TextureStretchFactor=1

NumTextureFormatSupported=9

TextureFormatSupported0=ImagePaging
TextureFormatSupported1=Base
TextureFormatSupported2=InstantBase
TextureFormatSupported3=Splatting
TextureFormatSupported4=Splatting5
TextureFormatSupported5=Splatting2
TextureFormatSupported6=Splatting7
TextureFormatSupported7=SplattingShader
TextureFormatSupported8=ImagePagingLight
TextureFormatSupported8=PLSplattingShaderLitDecompress

TextureFormat=ImagePagingLight
ImageFilename=terrain_texture

ScaleX=15000
ScaleY=1000
ScaleZ=15000

Deformable=yes
VertexCompression=no
VertexProgramMorph=no
VertexNormals=no

NumMatHeightSplat=4
Height1=15
Height2=50
SplatFilename0=splatting_sand.png
SplatFilename1=splatting_grass.png
SplatFilename2=splatting_rock.png
SplatFilename3=splatting_snow.png

# where to put camera on load.
BaseCameraViewpoint.x=935.0f
BaseCameraViewpoint.y=24000.0f
BaseCameraViewpoint.z=-432.0f

Baselookat.x=0.0f
Baselookat.y=0.0f
Baselookat.z=0.0f


There is also a TsmTerrain.gen.cfg file that I do not know what it is for:

GroupName=General
LandScapeFileName=terrain
TextureStretchFactor=1

ScaleX=1.5
ScaleY=1
ScaleZ=1.5

OutDirectory=TsmTerrain


Data2DFormat=HeightField

ColorMapName=terrain_texture.jpg
ColorMapSplit=yes


HeightMap=yes
BaseMap=yes
CoverageMap=yes
AlphaMaps=yes
ZHorizon=yes

LightMap=yes
Sunx=0.0f
Suny=0.88f
Sunz=0.47f
Ambient=0.5f
Diffuse=0.5f
Blur=0.0f

MiniMap=yes
MiniMapWidth=64
MiniMapHeight=64

NumMatHeightSplat=5

MaterialHeight1=12
MaterialHeight2=35
MaterialHeight3=80
MaterialHeight4=100


I am using one of the maps that comes with the demo.

Any idea?.

tuan kuranes

01-05-2008 18:27:35

Deformable=yes
should be working then.

You really have to debug yourself PLSM2 to find why PLSM2SceneManger::setOption("deformcenter", myvector); doesn't work. You'll see why very fast if you do that.

Buckcherry

20-05-2008 18:13:59

Ufff, after a lot of time changing things over and over... I have found the problem!.

The problem was the following:

I defined the method setBrushScale like:

void setBrushScale(const int value);

When it should be:

void setBrushScale(float value);

Passing as parameter a integer does not work, it does nothing!.

Thanks for everything!.

:-)