metatriangleselector bugfix suggestion

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!
Post Reply
corban
Posts: 35
Joined: Fri Nov 14, 2003 10:36 am
Contact:

metatriangleselector bugfix suggestion

Post by corban »

hi there,

i ran into a bug (a forum post by niko said so) with the metatriangleselector (mts): it calculates collisions for the last appended selector only. i think i found the reason: mts::getTriangles uses the getTriangle methods of it's members and these write the triangles into the given array, starting at index 0, so each member overrides the triangles found by it's forerunner.

wouldn't be useful without, so i have a (quick and dirty) suggestions to fix this until niko provides a clean and fast solution :D. in the CCMetaTriangleSelector.cpp file you could change the getTriangle() methods in a way like this:

Code: Select all

[...]
s32 outWritten = 0;
for (s32 i=0; i<(s32)TriangleSelectors.size(); ++i)
{	
    core::triangle3df _triangles[arraySize - outWritten]; //addition		
    s32 t = 0;
    TriangleSelectors[i]->getTriangles(_triangles, arraySize - outWritten, t, box, transform); //changed
    for(s32 a = 0; a < t; a++) {
        triangles[outWritten + a] = _triangles[a]; 
    }//addition	
    outWritten += t;
}
outTriangleCount = outWritten;
[...]
as i said, it's slow and dirty and may crash and insult your mother, and yes, you could place the array declaration outside the loop. i think it would be better to extend the getTriangle() method of TriangleSelector with a parameter where to start in the array, but i did not want to change the api :D .

hope that helps,
corban
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Well I don't really know anything about this code block :) But couldn't you just do

...
TriangleSelectors->getTriangles(&triangles[outWritten],......);
...

and avoid the temp array and the array copy?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Boogle is right :)
Or as in my bugfix: triangles + outWritten
corban
Posts: 35
Joined: Fri Nov 14, 2003 10:36 am
Contact:

Post by corban »

niko wrote:Boogle is right :)
Or as in my bugfix: triangles + outWritten
i know, but at the moment i'm working (job) heavily with java and i wasn't quite sure bout the c++ treatment of arrays, especially at night :D.

corban
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

awesome :!: BTW FYI 4 everyone else who wants to fix it, you have to make that change to all 3 of the getTriangles functions...
Post Reply