CTerrainTriangleSelector doesn't always return triangles

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Fred

CTerrainTriangleSelector doesn't always return triangles

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

Post by Fred »

Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post 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! :)
Image
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post 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 ( );
Image
fred

Post by fred »

I'll try this tongiht - thanks!
Fred

Post 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
Fred

Post by Fred »

Sent.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post 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.
Image
Fred

Post 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.
TrueLiar
Posts: 16
Joined: Thu Sep 29, 2005 2:13 pm
Location: Vietnam

Post 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:
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Did you build the new DLL in debug or release? I bet you built it in debug mode :D
Image
TrueLiar
Posts: 16
Joined: Thu Sep 29, 2005 2:13 pm
Location: Vietnam

Post by TrueLiar »

Yeah, you're right :P
Post Reply