Plane Transformation.. WRONG

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:

Plane Transformation.. WRONG

Post by devsh »

you cannot transform a plane by playing around with the normal, because shear matrices will make the normal not perpendicular to the plane anymore

This will work a lot better

Code: Select all

    //! Transforms a plane by this matrix
    template <class T>
    inline void CMatrix4<T>::transformPlane( core::plane3d<f32> &plane) const
    {
        core::plane3df temp;
        transformPlane(plane,temp);
        plane = temp;
    }
 
    //! Transforms a plane by this matrix
    template <class T>
    inline void CMatrix4<T>::transformPlane( const core::plane3d<f32> &in, core::plane3d<f32> &out) const
    {
        CMatrix4<T> transposedInverse(*this, EM4CONST_INVERSE);
        out.Normal.X = in.Normal.X*transposedInverse[0] + in.Normal.Y*transposedInverse[1] + in.Normal.Z*transposedInverse[2] + in.D*transposedInverse[3];
        out.Normal.Y = in.Normal.X*transposedInverse[4] + in.Normal.Y*transposedInverse[5] + in.Normal.Z*transposedInverse[6] + in.D*transposedInverse[7];
        out.Normal.Z = in.Normal.X*transposedInverse[8] + in.Normal.Y*transposedInverse[9] + in.Normal.Z*transposedInverse[10] + in.D*transposedInverse[11];
        out.D = in.Normal.X*transposedInverse[12] + in.Normal.Y*transposedInverse[13] + in.Normal.Z*transposedInverse[14] + in.D*transposedInverse[15];
    }
Post Reply