0

我今天注意到 XNA 4.0 中的 Plane.Transform 似乎没有给出我预期的结果。

var s = Matrix.CreateScale(0.1f);
var p = new Plane(new Vector3(1.0f, 0.0f, 0.0f), 1.0f);
var p = Plane.Transform(p, s);

我原本预计飞机现在的大小为 0.1f,但它的距离为 1,法线长度为 10:

{Normal:{X:10 Y:0 Z:0} D:1}

为什么会这样?

4

1 回答 1

2

I can't fully explain why but the matrix that is passed to the transform method (your scale matrix) is inverted before being applied to the plane so your scale went from .1 to 10.

The 3x3 section of the matrix that holds scale and rotation data gets applied to the normal of the plane which is why your normal got scaled.

The 4th row of the matrix gets applied to the D part of the plane so since your scale matrix had all zeros there (except for m44 which had a 1), the D part of the plane remained unchanged.

Scaling a plane doesn't make much sense overall since a plane is essentially dimensionless except for that D part. The normal should always be kept at unit length for intersection test purposes so scaling a normal doesn't make sense. And if you want that D part scaled, it can be simply myPlane.D *= 0.1f; instead of trying to transform it with a matrix.

Speculation follows:

One possible reason for the matrix inversion is because there are two ways to think about the D part.

1.) the distance from the origin to the plane.

2.) the distance from the plane to the origin.

Both have the same value but oppositely signed in terms of the direction. MS chose to think of D as the distance from the plane to the origin and that would mean the direction is the opposite of the normal direction. Most likely, there was good reason for this but I have no idea. That most likely forces the matrix inversion in the Plane.Transform() method. see the graphic here: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(MICROSOFT.XNA.FRAMEWORK.PLANE);k(DevLang-CSHARP)&rd=true

于 2013-07-15T12:17:53.290 回答