Page 1 of 1

[fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSANE?

Posted: Mon May 23, 2016 3:34 pm
by devsh

Code: Select all

 
    //! Transforms a axis aligned bounding box
    template <class T>
    inline void CMatrix4<T>::transformBox(core::aabbox3d<f32>& box) const
    {
#if defined ( USE_MATRIX_TEST )
        if (isIdentity())
            return;
#endif
 
        transformVect(box.MinEdge);
        transformVect(box.MaxEdge);
        box.repair();
    }
Lets talk in 2D why this is EVIL

Now make a box from -1,-1 to 1,1 and rotate by 45 degrees clockwise.

Your MaxEdge will be (1.4.....,0) and MinEdge=-MaxEdge, where in-fact, your box should be (1.4....,1.4...) from (-1.4....,-1.4.....)

The problem is not with the fact that its not exact, the problem is that its not conservative (the transformed inexact box doesn't contain the exact box), so therefore useless!

Re: Total BUG CMatrix4<T>::transformBox, P.S. are you INSANE

Posted: Mon May 23, 2016 6:36 pm
by CuteAlien
Always those friendly, motivating bugreports...

transformBox should probably be deprecated. That problem is indeed badly documented (says just "The result box of this operation may not be accurate at all") and the function got replaced by transformBoxEx.
I suspect there is even a real bug in CSceneCollisionManager::getPickedNodeBB where the old function is used. But have to read the code there in detail - maybe I'm missing something and there's a reason why it uses transformBox instead of transformBoxEx. Will check that when I find some time.

edit: Fixed in 1.8 branch, merge with trunk next days.

Re: [fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSA

Posted: Fri May 27, 2016 7:36 pm
by CuteAlien
Fix now in trunk as well (aka function deprecated and CSceneCollisionManager::getPickedNodeBB no longe rusing transformBox).

Re: [fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSA

Posted: Fri May 27, 2016 8:57 pm
by Seven
well at least we know that you are not insane....

Re: [fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSA

Posted: Sat May 28, 2016 8:00 am
by CuteAlien
Well, I didn't answer that question yet ... ;-)

Re: [fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSA

Posted: Wed Jun 08, 2016 8:33 pm
by devsh
I made a must faster exact BBox transform function

assuming that inMatrix is a 3x4 matrix (4 columns of 3 component vectors with last representing translation), should be easy enough to backport to core::matrix4 and forward port to SSE3 using the masks of '?'

Code: Select all

 
        core::aabbox3df tmpBox;
        tmpBox.MinEdge.X = inMatrix[0].X*(inMatrix[0].X<0.f ? LoDInvariantBox.MaxEdge.X:LoDInvariantBox.MinEdge.X)+inMatrix[1].X*(inMatrix[1].X<0.f ? LoDInvariantBox.MaxEdge.Y:LoDInvariantBox.MinEdge.Y)+inMatrix[2].X*(inMatrix[2].X<0.f ? LoDInvariantBox.MaxEdge.Z:LoDInvariantBox.MinEdge.Z);
        tmpBox.MinEdge.Y = inMatrix[0].Y*(inMatrix[0].Y<0.f ? LoDInvariantBox.MaxEdge.X:LoDInvariantBox.MinEdge.X)+inMatrix[1].Y*(inMatrix[1].Y<0.f ? LoDInvariantBox.MaxEdge.Y:LoDInvariantBox.MinEdge.Y)+inMatrix[2].Y*(inMatrix[2].Y<0.f ? LoDInvariantBox.MaxEdge.Z:LoDInvariantBox.MinEdge.Z);
        tmpBox.MinEdge.Z = inMatrix[0].Z*(inMatrix[0].Z<0.f ? LoDInvariantBox.MaxEdge.X:LoDInvariantBox.MinEdge.X)+inMatrix[1].Z*(inMatrix[1].Z<0.f ? LoDInvariantBox.MaxEdge.Y:LoDInvariantBox.MinEdge.Y)+inMatrix[2].Z*(inMatrix[2].Z<0.f ? LoDInvariantBox.MaxEdge.Z:LoDInvariantBox.MinEdge.Z);
        tmpBox.MaxEdge.X = inMatrix[0].X*(inMatrix[0].X<0.f ? LoDInvariantBox.MinEdge.X:LoDInvariantBox.MaxEdge.X)+inMatrix[1].X*(inMatrix[1].X<0.f ? LoDInvariantBox.MinEdge.Y:LoDInvariantBox.MaxEdge.Y)+inMatrix[2].X*(inMatrix[2].X<0.f ? LoDInvariantBox.MinEdge.Z:LoDInvariantBox.MaxEdge.Z);
        tmpBox.MaxEdge.Y = inMatrix[0].Y*(inMatrix[0].Y<0.f ? LoDInvariantBox.MinEdge.X:LoDInvariantBox.MaxEdge.X)+inMatrix[1].Y*(inMatrix[1].Y<0.f ? LoDInvariantBox.MinEdge.Y:LoDInvariantBox.MaxEdge.Y)+inMatrix[2].Y*(inMatrix[2].Y<0.f ? LoDInvariantBox.MinEdge.Z:LoDInvariantBox.MaxEdge.Z);
        tmpBox.MaxEdge.Z = inMatrix[0].Z*(inMatrix[0].Z<0.f ? LoDInvariantBox.MinEdge.X:LoDInvariantBox.MaxEdge.X)+inMatrix[1].Z*(inMatrix[1].Z<0.f ? LoDInvariantBox.MinEdge.Y:LoDInvariantBox.MaxEdge.Y)+inMatrix[2].Z*(inMatrix[2].Z<0.f ? LoDInvariantBox.MinEdge.Z:LoDInvariantBox.MaxEdge.Z);
        tmpBox.MinEdge += inMatrix[3];
        tmpBox.MaxEdge += inMatrix[3];
 

Re: [fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSA

Posted: Wed Jun 08, 2016 10:02 pm
by CuteAlien
Thanks. But I have no easy way to evaluate that right now (I also didn't evalute the other one, simply hoping it worked as no one reported another bug in it - just not having the energy/time to write a tests for everything).

Re: [fixed] BUG CMatrix4<T>::transformBox, P.S. are you INSA

Posted: Thu Jun 09, 2016 10:00 pm
by devsh
First code listing had a typo, updated to a correct version