Placing parts of static geometry on terrain

caharim

25-03-2007 22:06:12

Hi together

hope somebody can help me with my question.
I like to place some grass on the terrain, but this don't work. The camera which uses the same method works well, so I asume the y-coordinate is right. any idea what's the problem here?

thanks for your help.
greetings caharim

StaticGeometry* s = mSceneMgr->createStaticGeometry("gras");
s->setRegionDimensions(Vector3(1000,1000,1000));
// Set the region origin so the centre is at 0 world
s->setOrigin(Vector3(0, 0, 0));


raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));

for (int x = -2500; x < 2500; x += 50){
for (int z = -2500; z < 2500; z += 50){
Vector3 pos(x + Math::RangeRandom(-25, 25), getTerrainHeight(x, z), z + Math::RangeRandom(-25, 25));
Quaternion orientation;
orientation.FromAngleAxis(Degree(Math::RangeRandom(0, 359)),Vector3::UNIT_Y);
//Vector3 scale(0.07, Math::RangeRandom(0.05, 0.1), 0.07);
Vector3 scale(1, Math::RangeRandom(0.85, 1.15), 1);
//Vector3 scale(1, Math::RangeRandom(0.85, 1.15), 1);
if(Math::RangeRandom(0, 10) > 8){
s->addEntity(e1, pos, orientation, scale);
}
else{
s->addEntity(e2, pos, orientation, scale);
}
}
}
s->build();





float getTerrainHeight(float x, float z){
static Ray updateRay;
updateRay.setOrigin(Vector3(x, 1000, z));
updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
raySceneQuery->setRay(updateRay);
raySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
raySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);

RaySceneQueryResult& qryResult = raySceneQuery->execute();
RaySceneQueryResult::iterator i = qryResult.begin();
if (i != qryResult.end() && i->worldFragment){
return (i->worldFragment->singleIntersection.y);
}
return 0;
}

nindim

26-03-2007 00:58:12

maybe you should debug to find out if the y co-ord is in fact right, maybe just load in a flat terrain at some known height. Easier to debug each piece of code than all together.

It Looks ok froma quick glance though...

caharim

26-03-2007 22:16:52

hm, everything seams to be okey, only that the ray works only with terrai, but not with entities?

nindim

27-03-2007 17:46:03

You mean the ray only gets intersection with the terrain? That's bcause of the type of ray casting you're doing. These lines here define that:


raySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
raySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);


Not sure what exactly you need to change it to, but its probably the setQueryTypeMask. Take a look at the manual.

caharim

27-03-2007 18:29:50

Your are right, my y-value is always 0. But why the camera can follow the height (y-value)?
Something seams to be broken here.

I don't think I can take another choice here, all other masks or WFT_Types are for other things.
raySceneQuery->setQueryTypeMask(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK);
raySceneQuery->setWorldFragmentType(SceneQuery::WFT_SINGLE_INTERSECTION);


Is there a solution here or have I to implement ODE or NEWTON for this?

caharim

27-03-2007 19:32:32

I tried this code here, but didn't succeed either.

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3658&highlight=worldgeometrytypemask

In my y I only got zero's, nothing other.

caharim

27-03-2007 23:15:26

Has anybody had this problem too?
I tried everything I can imaging, but I'm stuck here.
thanks for your advice :-)

nindim

28-03-2007 13:51:51

Ah, i didnt understand your question, you mean when u fire the ray from the entity it doesnt give you back a valid terrain height. I thought you meant you wanted to find collisions with entities.

It may be to do witht he fact you have hard coded the y position of your ray origin to 1000, if this is below the height fo the terrain you wont get an intersection.

Another cause may be that the terrain isnt loaded in at the point you are testing and thus the ray wont find anything to intersect with.

Take a lok at the cvs demo, it places a sphere at the intersection point on the terrain where you click. Would probably help.

If I were you I'd start off with just one premade entity, then move onto all your creation of static geometry yadda yadda. Simple case first to work out the bugs, then do the more complex implementation

caharim

28-03-2007 20:21:47

Thanks for your suggestions, nindim.

I tried already everything you mentioned.
Yes, the terrain is already build, I tried all status of origin and I looked at the examples.

Other question: Has anybody already implemented this? I'm afraid, that this is broken and nobody knows about that.

Because the same code works with the normal terrain from ogre.

caharim

28-03-2007 22:36:22

So I tried again and again, but there seems to be a huge bug:
When using a FrameListener the Heights are shown correctly. But in all other cases the Ray just hit nothing.
The only explanation I have left is, that it depends on the terrain. Are there certain terrain, that is not capable with Rays?

nindim

29-03-2007 01:29:35


When using a FrameListener the Heights are shown correctly


What exactly do you mean by that?

An by the ' normal terrain from ogre", do you mean the terrain scene manager that comes in the samples with OGRE sdk, or the sample of PLSM2?

caharim

29-03-2007 18:56:57

during walking through the world I can press F2 to show the height of the terrain where the camera is. this gives me correct data. but not if I try to get the height before, during initialisation.

Yes, I ment the demo from ogre sdk.

Ah, it's a little bit frustrating that I can't go further because of this broken "feature".

nindim

29-03-2007 20:22:19

You are trying to gte the heights "during initialisation". Is the height coming out as 0? are you calling:


mScnMgr->setOption( "LoadNow", NULL );//load all possible tiles


It seems to me simply like the terrain isn't loaded in when you are doing the ray casting. The LoadNow function will load as many of the tiles/pages as you ahve defined in your .cfg file.

I'm really out of ideas though if that's not it.

caharim

30-03-2007 18:45:27

Ooo, you are right. I did load the terrain, but not all pages, so the value was always 0! :shock:
Thank you very much for the solution. Now it works :D
let me play a little bit with that.
Is there an example for loading pages and their objects in realtime?

Dibalo

30-03-2007 19:04:34

Ooo, you are right. I did load the terrain, but not all pages, so the value was always 0! :shock:
Thank you very much for the solution. Now it works :D
let me play a little bit with that.
Is there an example for loading pages and their objects in realtime?


You should try to play with tileLoaded and tileUnloaded -methods. You can attach these to your system that PLSM trigger them, when tiles are loaded or unloaded. Tile data (tile´s page and tile ids) is delivered you as a parameter. That would be some kind of solution