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
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;
}