Druha
14-10-2009 07:14:12
I am experimenting with runtime heightfield generation and choose ManualHeightField as a tool to get it working.
But, as expected, I've met a problem, again...
After hours of trying to figure out how does it work, I noticed that generated geometry scaled a bit wrong (look at screenshot)
[attachment=0]Esertia-2009-10-13-23-59-04-14.jpg[/attachment]
The edge of geometry (marked as red line) seems to be moving depending on number of rows/collumns that I pass to ManualHeightField::begin()
When it is a big number, the edge moves to its desired position (thick grey line on screenshot), but never reaches it. The distance between edge's position and a place it should be seems to be as between the two nearest vertexes along a world axis (they are also marked on screenshot)
When the number is small, size of geometry become smaller, so edge moves there where red arrow points.
There is also small white dots on the image - those are the cubes placed by the generator function.
And this is the code generated such stuff:
At higher resolutions of heightfield I can see, that it copies shape of original terrain almost perfectly, but that scaling... May be I am doing something wrong when creating ManualHeightField class instance?
And, yeah, a link to commit, here it is http://github.com/betajaen/nxogre/commi ... 50b4a4afb3
But, as expected, I've met a problem, again...
After hours of trying to figure out how does it work, I noticed that generated geometry scaled a bit wrong (look at screenshot)
[attachment=0]Esertia-2009-10-13-23-59-04-14.jpg[/attachment]
The edge of geometry (marked as red line) seems to be moving depending on number of rows/collumns that I pass to ManualHeightField::begin()
When it is a big number, the edge moves to its desired position (thick grey line on screenshot), but never reaches it. The distance between edge's position and a place it should be seems to be as between the two nearest vertexes along a world axis (they are also marked on screenshot)
When the number is small, size of geometry become smaller, so edge moves there where red arrow points.
There is also small white dots on the image - those are the cubes placed by the generator function.
And this is the code generated such stuff:
void MapManager::heightFromShape(const unsigned int numQueries, const Vector3& bounds){
RaySceneQuery* rq = GameRoot::getSingleton().getSceneMgr()->createRayQuery(Ray(Vector3(0,0,0),Vector3::NEGATIVE_UNIT_Y));
NxOgre::ManualHeightField* mhf = new NxOgre::ManualHeightField();
mhf->begin(numQueries,numQueries);
const Real normMin = 0.0f;
const Real normMax = 32767.0f;
short sample;
static int counter = 0;
unsigned int x,z;
for(x = 0;x<numQueries;++x){
for(z = 0;z<numQueries;++z){
Ray r = Ray(Vector3(x*(bounds.x-1)/(numQueries-1), bounds.y+1, z*(bounds.z-1)/(numQueries-1)), Vector3::NEGATIVE_UNIT_Y);
rq->setRay(r);
RaySceneQueryResult res = rq->execute();
RaySceneQueryResult::iterator it = res.begin();
while(it!=res.end()){
if(it->worldFragment){
// code based on Wiki Tutorial about Ogre::Terrain and NxOgre
sample = (short)(((it->worldFragment->singleIntersection.y)/(bounds.y)) * (normMax - normMin) + normMin);
mhf->sample(sample);
// add a cube to actually see, where is this point located
SceneNode* sn = GameRoot::getSingleton().getSceneMgr()->getRootSceneNode()->createChildSceneNode(it->worldFragment->singleIntersection);
Entity* ent = GameRoot::getSingleton().getSceneMgr()->createEntity(StringConverter::toString(counter)+"fds","cube.mesh");
sn->attachObject(ent);
sn->setScale(0.02,0.02,0.02);
++counter;
}
++it;
}
}
}
NxOgre::HeightFieldGeometry* hfg = new NxOgre::HeightFieldGeometry(mhf->end(("hf_"+StringConverter::toString(counter)).c_str()),bounds);
if(mMapGeom)
GameRoot::getSingleton().getScene()->destroySceneGeometry(mMapGeom);
mMapGeom = GameRoot::getSingleton().getScene()->createSceneGeometry(hfg);
GameRoot::getSingleton().getSceneMgr()->destroyQuery(rq);
}
At higher resolutions of heightfield I can see, that it copies shape of original terrain almost perfectly, but that scaling... May be I am doing something wrong when creating ManualHeightField class instance?
And, yeah, a link to commit, here it is http://github.com/betajaen/nxogre/commi ... 50b4a4afb3