Page 1 of 1

CTerrainTriangleSelector doesn't always return triangles

Posted: Mon Sep 12, 2005 1:18 am
by Fred
CTerrainTriangleSelector doesn't always return triangles The CTerrainTriangleSelector class doesn't always return triangles, when performing a selection using getCollisionPoint.

I think that the following is failing:

TrianglePatches.TrianglePatchArray.Box.intersectsWithLine(line)

This explains why objects placed using this mechanism aren't always placed on the terrain, but at a Y value of zero.

Version 0.12

Code: Select all

float getHeightAt( scene::ITriangleSelector* selector,
scene::ISceneCollisionManager* scmgr,
float x, float z)
{
// Create a line and get the point it intersects with
the terrain
core::line3d<f32> myline;
core::triangle3df tri;
core::vector3df intersection;
f32 terrainHeightAtPointXZ;

// Make sure the start.Y is higher than the highest
point of your terrain
// Make sure the end.Y is lower than the lowest point
of your terrain
myline.start = core::vector3df ( x, 5000.0f, z );
myline.end = core::vector3df ( x, -5000.0f, z );
if ( scmgr->getCollisionPoint ( myline, selector,
intersection, tri ))
{
terrainHeightAtPointXZ = intersection.Y;
}

return terrainHeightAtPointXZ;
}

Posted: Mon Sep 12, 2005 1:18 am
by Fred

Posted: Thu Sep 15, 2005 12:34 am
by Spintz
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=8751

Fixed, wasn't a problem with triangles being returned, but should all be fixed now. Please verify for me! :)

Posted: Thu Sep 15, 2005 3:46 am
by Spintz
Ah, here's the fix for this -

In CTerrainTriangleSelector.cpp, in function setTriangleData, change -

Code: Select all

// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)terrainNode->Mesh.getMeshBuffer(0)->getVertices ( );
to

Code: Select all

// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)terrainNode->RenderBuffer.getVertices ( );

Posted: Thu Sep 15, 2005 2:21 pm
by fred
I'll try this tongiht - thanks!

Posted: Thu Sep 15, 2005 9:45 pm
by Fred
That's even worse - all of the objects are now beneath the terrain.

I'll mail you my source code if you want to try it.

Thanks

Posted: Thu Sep 15, 2005 11:35 pm
by Fred
Sent.

Posted: Fri Sep 16, 2005 3:06 am
by Spintz
Found a bunch of bugs in the CTerrainSceneNode, best thing is to completely replace the files with the following files -

http://irrlicht.spintz.com/downloads/CT ... ceneNode.h
http://irrlicht.spintz.com/downloads/CT ... neNode.cpp
( Right-Click save as to save them, otherwise will just display them in IE window. )

This version of the terrain scene node is much more efficient. And includes changes that the new Irrlicht-Spintz-0.12 has ( http://irrlicht.spintz.com )

I'd recommend just downloading and using Irrlicht-Spintz-0.12. I'll update the website so if you want, you can just download modifed files and new files and update the Irrlicht solution yourselves.

Posted: Sat Sep 17, 2005 12:52 am
by Fred
Spintz wrote:Ah, here's the fix for this -

In CTerrainTriangleSelector.cpp, in function setTriangleData, change -

Code: Select all

// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)terrainNode->Mesh.getMeshBuffer(0)->getVertices ( );
to

Code: Select all

// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)terrainNode->RenderBuffer.getVertices ( );
Ok I applied all the changes except this one and the DirectX one (I'm on Linux) and it works. Thanks! If I apply this change, all of the objects are placed at Y=0.

Posted: Fri Oct 07, 2005 9:09 am
by TrueLiar
Spintz wrote:Ah, here's the fix for this -

In CTerrainTriangleSelector.cpp, in function setTriangleData, change -

Code: Select all

// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)terrainNode->Mesh.getMeshBuffer(0)->getVertices ( );
to

Code: Select all

// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)terrainNode->RenderBuffer.getVertices ( );
I fixed this and my program run well. But has a new problem. FPS of new programe is verry slowly.
Before fix: fps = 243
After fix: fps = 29
:cry: :cry: :cry:

Posted: Fri Oct 07, 2005 9:29 am
by Spintz
Did you build the new DLL in debug or release? I bet you built it in debug mode :D

Posted: Mon Oct 10, 2005 11:05 am
by TrueLiar
Yeah, you're right :P