terrain picking

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Fred

Post by Fred »

Thanks - I was away for a few days and didn't see your code but I'll consider using a physics engine, though it seems overkill when all I want is a working getHeightAt function for the terrain.

Thanks again
Fred

Post by Fred »

Thanks - hopefull Niko will see this and fix the bug in Irrlicht :)
Fred

Post by Fred »

The problem lies in here somewhere:

isPointInside

Don't know why yet.
Fred

Post by Fred »

Not sure if this makes a difference, but in CSceneManager::getCollisionPoint, use this for a minor performance improvement, and I mean minor!:

Code: Select all

	while (!found && i<cnt)

	{

		if (Triangles[i].getIntersectionWithLine(ray.start, linevect, intersection))
		{

			tmp = (f32)intersection.getDistanceFromSQ(ray.start);

			tmp2 = (f32)intersection.getDistanceFromSQ(ray.end);
			
			std::cout << "tmp = " << tmp << " " << "tmp2 = " << tmp2 << std::endl;



            if (tmp < raylenght && tmp2 < raylenght &&

				tmp < nearest)

			{

				nearest = tmp;

				outTriangle = Triangles[i];

				outIntersection = intersection;

				found = true;

			}

		}

		i++;

	}
Fred

Post by Fred »

The problem is in isOnSameSide. a is always FALSE.
Fred

Post by Fred »

Some success!

In isPointInside, change the line to this:

c = isOnSameSide(p, pointC, pointA, pointB);



In isOnSameSide change the line to this:

if (cp1.dotProduct(cp2) >= 0.0f)



First test appears to give 99% success rate, but I'll test more later.
Fred

Post by Fred »

This is in triangle3d.h.
Fred

Post by Fred »

Further tests show the results are worse than the original code! :?
Fred

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

Post by Spintz »

I'll look into the info you've posted recently and see what I can find. I'll dive into the collision code of Irrlicht, it's quite confusing tho, will take some time.
Image
Fred

Post by Fred »

Thanks Spintz. I'm trying to debug further down, but 3d maths is my weak point. I'll see if can narrow it down further - it may well be a bounding box problem - more collision detection. But I can't promise anything!
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Image
Fred

Post by Fred »

Still doesn't work properly - still getting the Y returned as 0.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Well, I need your code then, to test that instance.

If you'd like, you can download my modifed irrlicht engine, Irrlicht-Spintz-0.12 from http://irrlicht.spintz.com/irrlicht-spintz-0.12.rar

There are precompiled DLL's and libs for Win32-VisualStudio, I have edited the DevC++ and makefile and they should work to build it if you need them, haven't tested them yet tho. Try out example1, it's not build, but is very easy to build. example1 is where i've been testing out these problems and it works perfectly there. Someone sent me a form of that code earlier and I got it working. If you're code doesn't work with my modified engine, then I'd definitely like to see youre code, to test further.

If you need help, I'm in IRC at irc.freenode.net in #irrlicht and #irrlichtnx or email me or just respond here again! :)

Just read through the thread again, and you're code is the code Example1 is based off of. It's working in my modified engine, I'll need to see what else is different, that's making it work, I might have an idea!.

Yeah, i was right, posted the fix to that in the thread you started in the Bug Reports forum, simple change. Triangles for the selector were being pulled from the base static vertex data, not the dynamic data, which holds the vertices with the transformations applied to them. Sorry I looked over that! :D
Image
Post Reply