3D、AS3、Flex - 将旋转角度转换为可见高度

发布于 2024-08-10 08:07:26 字数 438 浏览 2 评论 0原文

我需要知道更改显示对象的rotationX 值后其可见高度是多少。

我有一个应用程序,允许用户在 3D 空间中布置地板。我希望地板的尺寸在 3D 旋转后自动拉伸,以便它始终覆盖某个区域。

有人知道解决这个问题的公式吗?

编辑:我想我真正想做的是将度数转换为像素。

在 2D 平面上,例如 100 x 100 像素,旋转 X 的 -10 度变化意味着该平面在顶部有一个间隙,该间隙不再可见。我想知道这个间隙有多少像素,以便我可以拉伸平面。

在 Flex 中,显示对象高度属性的值在应用旋转之前和之后保持不变,这实际上可能是一个错误。

编辑 2:必须有一个通用的数学公式来解决这个问题,而不是 Flash/Flex 特定的公式。在 3D 空间中查看对象时,如果对象向后旋转(对象的顶部翻筋斗远离观看者),则基于旋转度数的新可见高度是多少?这可以是像素、米、肘或其他单位。

I need to know what the visible height of a display object will be after I change it's rotationX value.

I have an application that allows users to lay out a floor in 3D space. I want the size of the floor to automatically stretch after a 3D rotation so that it always covers a certain area.

Anyone know a formula for working this out?

EDIT: I guess what I am really trying to do is convert degrees to pixels.

On a 2D plane say 100 x 100 pixels, a -10 degree change on rotationX means that the plane has a gap at the top where it is no longer visible. I want to know how many pixels this gap will be so that I can stretch the plane.

In Flex, the value for the display objects height property remains the same both before and after applying the rotation, which may in fact be a bug.

EDIT 2: There must be a general math formula to work this out rather than something Flash/Flex specific. When viewing an object in 3D space, if the object rotates backwards (top of object somersaults away from the viewer), what would the new visible height be based on degrees of rotation? This could be in pixels, metres, cubits or whatever.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

奶茶白久 2024-08-17 08:07:26

我没有测试用例,但我突然想到:

var d:DisplayObject;
var rotationRadians:Number = d.rotationX * Math.PI / 180;
var visibleHeight:Number = d.height * Math.cos(rotationRadians);

不过,这并没有考虑任何其他转换。

I don't have a test case, but off the top of my head I'd guess something like:

var d:DisplayObject;
var rotationRadians:Number = d.rotationX * Math.PI / 180;
var visibleHeight:Number = d.height * Math.cos(rotationRadians);

This doesn't take any other transformations into account, though.

夜唯美灬不弃 2024-08-17 08:07:26

您是否尝试过使用对象的边界矩形并进行测试?

var dO:DisplayObject = new DisplayObject();
dO.rotation = 10;
var rect:Rectangle = dO.getRect();

// rect.topLeft.y is now the new top point.
// rect.width is the new width.
// rect.height is the new height.

至于地板,我需要更多信息,但是你尝试过设置 Floor.percentWidth = 100 吗?这可能有用。

Have you tried using the object's bounding rectangle and testing that?

var dO:DisplayObject = new DisplayObject();
dO.rotation = 10;
var rect:Rectangle = dO.getRect();

// rect.topLeft.y is now the new top point.
// rect.width is the new width.
// rect.height is the new height.

As to the floor, I would need more information, but have you tried setting floor.percentWidth = 100? That might work.

_失温 2024-08-17 08:07:26

你检查过 DisplayObject.transform.pixelBounds 吗?我还没有尝试过,但可能更有可能考虑轮换。

Have you checked DisplayObject.transform.pixelBounds? I haven't tried it, but it might be more likely to take the rotation into account.

孤芳又自赏 2024-08-17 08:07:26

旋转实际上改变了 DisplayObject 的轴(即 x 轴和 y 轴旋转)。这就是为什么您看不到高度差异的原因。因此,为了获得视觉高度和 y,你可以尝试这个。

var dO:DisplayObject = new DisplayObject();
addChild();
var rect1:Rectangle = dO.getRect(dO.parent);
dO.rotation = 10;
var rect2:Rectangle = dO.getRect(dO.parent);

rect1 and rect2 should be different in this case. If you want to check the visual coordinates of the dO then just change dO.parent with root.

Rotation actually changes DisplayObject's axis's (i.e. x and y axes are rotated). That is why you are not seeing the difference in height. So for getting the visual height and y you might try this.

var dO:DisplayObject = new DisplayObject();
addChild();
var rect1:Rectangle = dO.getRect(dO.parent);
dO.rotation = 10;
var rect2:Rectangle = dO.getRect(dO.parent);

rect1 and rect2 should be different in this case. If you want to check the visual coordinates of the dO then just change dO.parent with root.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文