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

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
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

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

Post 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!
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post by CuteAlien »

Fix now in trunk as well (aka function deprecated and CSceneCollisionManager::getPickedNodeBB no longe rusing transformBox).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

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

Post by Seven »

well at least we know that you are not insane....
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post by CuteAlien »

Well, I didn't answer that question yet ... ;-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

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

Post 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];
 
Last edited by devsh on Thu Jun 09, 2016 10:00 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post 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).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

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

Post by devsh »

First code listing had a typo, updated to a correct version
Post Reply