3D、AS3、Flex - 将旋转角度转换为可见高度
我需要知道更改显示对象的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有测试用例,但我突然想到:
不过,这并没有考虑任何其他转换。
I don't have a test case, but off the top of my head I'd guess something like:
This doesn't take any other transformations into account, though.
您是否尝试过使用对象的边界矩形并进行测试?
至于地板,我需要更多信息,但是你尝试过设置 Floor.percentWidth = 100 吗?这可能有用。
Have you tried using the object's bounding rectangle and testing that?
As to the floor, I would need more information, but have you tried setting floor.percentWidth = 100? That might work.
你检查过 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.
旋转实际上改变了 DisplayObject 的轴(即 x 轴和 y 轴旋转)。这就是为什么您看不到高度差异的原因。因此,为了获得视觉高度和 y,你可以尝试这个。
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.
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.