gpt4 book ai didi

WPF 3D to 2D projection appears wrong?(WPF 3D到2D投影显示错误?)

转载 作者:bug小助手 更新时间:2023-10-24 20:09:22 29 4
gpt4 key购买 nike



Have a case where a point on the PerspectiveCamera’s LookDirection vector does not project to the center of the Viewport3D. Any thoughts as to why?

出现PerspectiveCamera的LookDirection向量上的点不投影到Viewport3D中心的情况。有没有想过为什么?


Here are details of the case: The Viewport3D is 778, 405. Any visible Point3D the camera is looking directly at would project to (389, 202.5). The PerspectiveCamera is located at (1379.4, -577.7, 0.7).

以下是本案的细节:Viewport3D是778,405。摄像机正直视的任何可见点3D都会投影到(389,202.5)。PerspectiveCamera位于(1379.4,-577.7,0.7)。


In the first case the center of the White sphere is (13,080.3,-6,491.9,-407.9) which is 13,117 units from the camera. Camera’s LookDirection is (0.89, -0.45, -0.03). The White sphere projects to the visual center of the Viewport3D. MathUtils.TryWorldToViewportTransform reports the sphere’s center point projects to (389, 202.5), as expected. The black lines are added to show the center of the Viewport3D.

在第一种情况下,白色球体的中心是(13,080.3,-6,491.9,-407.9),距离摄影机13,117个单位。相机的LookDirection为(0.89,-0.45,-0.03)。白色球体投影到Viewport3D的视觉中心。TryWorldToViewportTransform将球体的中心点投影报告给(389,202.5),不出所料。添加黑线以显示Viewport3D的中心。


First case screen shot here: https://photos.app.goo.gl/Cc8ch2uYWUjWgoSV6

此处的第一个案例屏幕截图:https://photos.app.goo.gl/Cc8ch2uYWUjWgoSV6


In the second case the center of the Blue sphere is (1,383.0,-579.6, 0.3) which is 4.1 units from the camera. Camera’s LookDirection is (0.88,-0.46,-0.11). The Blue sphere does NOT render to the visual center of the Viewport3D. MathUtils.TryWorldToViewportTransform reports the center point being projected to (389, 202.5), as expected. Visually though the blue sphere is not drawing at center, it is at more like (295, 303).

在第二种情况下,蓝色球体的中心是(1,383.0,-579.6,0.3),距离相机4.1个单位。相机的LookDirection为(0.88,-0.46,-0.11)。蓝色球体不会渲染到Viewport3D的视觉中心。TryWorldToViewportTransform报告被投影到(389,202.5)的中心点,正如预期的那样。从视觉上看,虽然蓝色球体没有画在中心,但它更像(295,303)。


Second case screen shot here: https://photos.app.goo.gl/1RfZh6uvjfEinaiA7

此处的第二个案例屏幕截图:https://photos.app.goo.gl/1RfZh6uvjfEinaiA7


Placing the camera at the 4.1 distance from the White sphere it projects correctly to the center of the Viewport3D. The difference is that the White sphere is further from the (0, 0, 0) origin than the Blue sphere.

将相机放置在距白色球体4.1的距离处,它会正确地投影到Viewport3D的中心。不同之处在于,白色球体比蓝色球体距离(0,0,0)原点更远。


The Blue sphere will project more correctly to the center of the Viewport3D if the camera is “far away” from it, like out near the White sphere.

如果摄影机远离它,如靠近白色球体,则蓝色球体将更准确地投影到Viewport3D的中心。


The Blue sphere is mathematically positioned to be at the center of the Viewport3D. Any thoughts as to why the Blue sphere is not rendering at the center of the Viewport3D in the second case above?

蓝色球体在数学上定位为位于Viewport3D的中心。在上面的第二种情况下,为什么蓝色球体没有渲染到Viewport3D的中心,你有什么想法吗?


Thank you!

谢谢!


更多回答
优秀答案推荐

If I manually calculate the camera direction, I get the following values:

如果我手动计算相机方向,我会得到以下值:


Blue sphere:   1383.0,    -579.6,      0.3
Camera: 1379.4, -577.7, 0.7
Difference: 3.6, -1.9, 0.4
Normalized: 0.880146, -0.464521, 0.097794

That's very close to your look direction (0.88,-0.46,-0.11), but not the same. It's not a rounding error, because the Z direction is two digits out. Based on the values you've posted, the blue sphere is not mathematically positioned to be at the center of the Viewport3D.

这非常接近你的注视方向(0.88,-0.46,-0.11),但不一样。这不是舍入误差,因为Z方向相差两位数。根据您发布的值,蓝色球体在数学上不会定位在Viewport3D的中心。


You say that manually calculating the position with MathUtils.TryWorldToViewportTransform gives you the expected result. This part has me puzzled. The only explanation I can think of is maybe the the LookDirection (and corresponding transformation matrixes) that you posted are stale values, and the MathUtils library recalculates it all on demand so it gets the correct values.

您可以说,使用MathUtils.TryWorldToViewportTransform手动计算位置会得到预期的结果。这部分让我摸不着头脑。我能想到的唯一解释是,您发布的LookDirection(和相应的转换矩阵)可能是陈旧的值,MathUtils库会根据需要重新计算所有这些值,以便获得正确的值。


更多回答

Hi, TY for the response. The values are not stale, I am sure of that. The LookDirection Z value is -0.10950268842253731, all the values were rounded for brevity in the post.

嗨,泰,感谢你的回复。价值观并没有过时,我确信这一点。LookDirection Z值为-0.10950268842253731,为简洁起见,文章中对所有值进行了四舍五入。

Using the non-rounded numbers I am pretty sure the Blue sphere is mathematically positioned to be at the center of the Viewport3D. But it does not render there. Wonder if there might be rounding issues deeper in WPF of which we should be aware of?

使用非四舍五入的数字,我非常确定蓝色球体在数学上位于Viewport3D的中心。但它并没有在那里呈现。想知道WPF中是否有我们应该意识到的更深层次的舍入问题?

Your look direction's Z is out by more than a rounding error. Compare 0.097794 to 0.10950268842253731. I suggest you add a line to manually calculate the look direction, and compare that to the camera's LookDirection property to see if you can reproduce it

你的视线方向的Z比四舍五入差多了。请比较0.097794和0.10950268842253731。我建议您添加一条线来手动计算注视方向,并将其与相机的LookDirection属性进行比较,看看是否可以重现它

Andrew, See the case at learn.microsoft.com/en-us/answers/questions/1365779/…. It has more info from digging into these "rounding conditions" being encountered. Pls check it out and pass along any comments or suggestions. TY!

安德鲁,看看learn.microsoft.com/en-us/answers/questions/1365779/…的案例。通过挖掘遇到的这些“四舍五入条件”,它获得了更多信息。如有任何意见或建议,请查收并转达。泰!

@WoodManEXP that answer from Hui Liu doesn't seem correct to me. If you are looking directly at an object, it should always be in the centre of the viewport. The distortion caused by a perspective transform may change the scale of the object in the X or Y directions, but it will not move it away from the centre (unless you're using something special like a tilted projection)

@WoodManEXP刘辉的回答在我看来是不正确的。如果您直视某个对象,则该对象应始终位于视区的中心。透视变换引起的扭曲可能会改变对象在X或Y方向上的比例,但不会使对象偏离中心(除非您使用的是倾斜投影等特殊对象)

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com