SceneManager.getCollisionPoint and MetaTriangleSelectors

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
LexManos
Posts: 15
Joined: Fri May 23, 2008 6:18 pm

SceneManager.getCollisionPoint and MetaTriangleSelectors

Post by LexManos »

Problem: Does not return the correct scene node
Cause:
getCollisionPoint() uses the optimized getTriangles() that only returns triangles near the supplied ray. But, passes the raw loop counter to MetaTriangleSelector.getSceneNodeForTriangle(). The problem with this is that the optimized getTriangles() returns a subset of triangles so the indexes do not represent the true indexes.

Solution:
Instead of getSceneNodeForTriangle() accepting an integer index, it accepts a triangle, which is then used to compare against all triangles in all sub-selectors. the problem with this is that is slow and costly in computations. So rather write up a patch myself I figured i'd let one of you guys think of how to do it.

Another possible solution, would would be most cost effective, would be to make getTirangles() accept another paramter for and outbound int array. Which you store the boundaries in.
Example:

Code: Select all

void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
		s32& outTriangleCount, const core::aabbox3d<f32>& box,
		const core::matrix4* transform, core::u32 *boundaries) const
{
	s32 outWritten = 0;
	for (u32 i=0; i<TriangleSelectors.size(); ++i)
	{
		s32 t = 0;
		TriangleSelectors[i]->getTriangles(triangles + outWritten,
											arraySize - outWritten, t, 
											box, transform);
		outWritten += t;
               boundaries[i] = outWritten;
               
	}

	outTriangleCount = outWritten;
}
And if you added a getTriangleSelector(index) into Meta selector {to keep compatible with the other interfaces you'd have to add in dummie functions that simply 'return this;'} And getSelectorCount() would be useful. Of coarse returning 1 on anything but Meta.

getSelectorCount() would be used to initialize the array you send to getTriangles()

Code: Select all

for(u32 i = 0; i < selector.getSelectorCount(); i++){
  if(boundaries[i] >= triangle_index) {
    node = selector.getTriangleSelector(i).getSceneNode();
  }
}
This is code I jsut pull out of my bum, but you guys get the ideas.
I am bad at considering optimizations so take a look and please tell me what you think.



Because I got tired of waiting, {ya I know im impatient}
I decided to implement the method using Boundaries and SelectorCounts
I posted the patch file here against SVN rev2295
PasteBin.com - [2295]getCollisionPoint Fix LexManos Apply to /trunk/

this modifies 12 files so its kinda important it gets added ASAP if its going to be added at all. As to have less of a chance to conflict with anything. Also please tell me if this breaks anything, it shouldnt as all I did was add a single optional parameter to getTriangles(line)
Post Reply