[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43733] trunk/blender/source/blender/ blenlib/intern/math_matrix.c: Fix orthogonality check for mat3 and mat4
Sergey Sharybin
sergey.vfx at gmail.com
Thu Mar 29 21:43:17 CEST 2012
Hi,
Pardon for late reply on this thing but unfortunately didn't check code
that time.
This is still not a check for orthogonal matrix, it's check for orthonormal
matrix which is slight different things and current behavior/naming is
confusing.
I'd say either we need to rename function to make it reflect exactly what
it's doing or change logic in which it's doing this. Also i wouldn't mind
having both orthogonal and orthonormal checks.
On Sat, Jan 28, 2012 at 10:31 AM, Lockal S <lockalsash at gmail.com> wrote:
> Sorry for double posting, I'm not sure if the previous mail got to the
> list.
>
> Old behavior:
> Matrix(((0, 0, 10), (0, 20, 0), (0, 0, 0))).is_orthogonal returned
> true, but this matrix is not orthogonal
>
> Matrix(((0, 0, 1, 42), (0, 1, 0, 0x42), (0, 0, 0, 100500), (-42, 42,
> 0xDEAD, 0))).is_orthogonal also returned true (but this matrix is not
> orthogonal)
>
> So as you can see m3 version completely ignored the main diagonal and
> m4 version also ignored 4-th column and 4-th row. Now it works as it
> described in Wikipedia and Wolfram MathWorld.
>
> At this moment orthogonality check is being used only one time in
> blender (in draw_manipulator_rotate), and this one case seems to be a
> real orthogonality check.
>
> Also it should not be a big problem with this "1", because floatval -
> intval => floatval - (float)intval in C.
>
> - Sv. Lockal
>
> 2012/1/26 Campbell Barton <ideasman42 at gmail.com>:
> > Can you give an example as to what case this fixes?
> >
> > On Fri, Jan 27, 2012 at 4:11 AM, Sv. Lockal <lockalsash at gmail.com>
> wrote:
> >> Revision: 43733
> >>
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43733
> >> Author: lockal
> >> Date: 2012-01-26 17:11:43 +0000 (Thu, 26 Jan 2012)
> >> Log Message:
> >> -----------
> >> Fix orthogonality check for mat3 and mat4
> >>
> >> Modified Paths:
> >> --------------
> >> trunk/blender/source/blender/blenlib/intern/math_matrix.c
> >>
> >> Modified: trunk/blender/source/blender/blenlib/intern/math_matrix.c
> >> ===================================================================
> >> --- trunk/blender/source/blender/blenlib/intern/math_matrix.c
> 2012-01-26 17:03:30 UTC (rev 43732)
> >> +++ trunk/blender/source/blender/blenlib/intern/math_matrix.c
> 2012-01-26 17:11:43 UTC (rev 43733)
> >> @@ -778,32 +778,38 @@
> >> mul_v3_fl(mat[2], size[2]);
> >> }
> >>
> >> -int is_orthogonal_m3(float mat[][3])
> >> +int is_orthogonal_m3(float m[][3])
> >> {
> >> - if (fabsf(dot_v3v3(mat[0], mat[1])) > 1.5f * FLT_EPSILON)
> >> - return 0;
> >> + int i, j;
> >>
> >> - if (fabsf(dot_v3v3(mat[1], mat[2])) > 1.5f * FLT_EPSILON)
> >> - return 0;
> >> + for (i = 0; i < 3; i++) {
> >> + for (j = 0; j < i; j++) {
> >> + if (fabsf(dot_v3v3(m[i], m[j])) > 1.5f * FLT_EPSILON)
> >> + return 0;
> >> + }
> >>
> >> - if (fabsf(dot_v3v3(mat[0], mat[2])) > 1.5f * FLT_EPSILON)
> >> - return 0;
> >> -
> >> - return 1;
> >> + if (fabsf(dot_v3v3(m[i], m[i]) - 1) > 1.5f * FLT_EPSILON)
> >> + return 0;
> >> + }
> >> +
> >> + return 1;
> >> }
> >>
> >> -int is_orthogonal_m4(float mat[][4])
> >> +int is_orthogonal_m4(float m[][4])
> >> {
> >> - if (fabsf(dot_v3v3(mat[0], mat[1])) > 1.5f * FLT_EPSILON)
> >> - return 0;
> >> + int i, j;
> >>
> >> - if (fabsf(dot_v3v3(mat[1], mat[2])) > 1.5f * FLT_EPSILON)
> >> - return 0;
> >> + for (i = 0; i < 4; i++) {
> >> + for (j = 0; j < i; j++) {
> >> + if (fabsf(dot_vn_vn(m[i], m[j], 4)) > 1.5f * FLT_EPSILON)
> >> + return 0;
> >> + }
> >>
> >> - if (fabsf(dot_v3v3(mat[0], mat[2])) > 1.5f * FLT_EPSILON)
> >> - return 0;
> >> -
> >> - return 1;
> >> + if (fabsf(dot_vn_vn(m[i], m[i], 4) - 1) > 1.5f * FLT_EPSILON)
> >> + return 0;
> >> + }
> >> +
> >> + return 1;
> >> }
> >>
> >> void normalize_m3(float mat[][3])
> >>
> >> _______________________________________________
> >> Bf-blender-cvs mailing list
> >> Bf-blender-cvs at blender.org
> >> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
> >
> >
> >
> > --
> > - Campbell
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>
--
With best regards, Sergey Sharybin
More information about the Bf-committers
mailing list