简体   繁体   English

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

[英]3D, AS3, Flex - Convert degrees of rotation to visible height

I need to know what the visible height of a display object will be after I change it's rotationX value. 我需要知道更改显示对象的rotationX值后显示对象的可见高度。

I have an application that allows users to lay out a floor in 3D space. 我有一个允许用户在3D空间中布置地板的应用程序。 I want the size of the floor to automatically stretch after a 3D rotation so that it always covers a certain area. 我希望地板的大小在3D旋转后自动拉伸,以使其始终覆盖特定区域。

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. 在说100 x 100像素的2D平面上,rotationX改变-10度表示该平面在顶部不再可见。 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. 在Flex中,显示对象的height属性的值在应用旋转之前和之后均保持不变,这实际上可能是一个错误。

EDIT 2: There must be a general math formula to work this out rather than something Flash/Flex specific. 编辑2:必须有一个通用的数学公式来解决此问题,而不是特定于Flash / Flex的数学公式。 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? 在3D空间中查看对象时,如果对象向后旋转(对象的顶部从观看者身上翻腾而来),则新的可见高度将基于旋转度? This could be in pixels, metres, cubits or whatever. 这可以是像素,米,肘节或其他形式。

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? 关于地板,我需要更多信息,但是您是否尝试设置floor.percentWidth = 100? That might work. 那可能行得通。

Have you checked DisplayObject.transform.pixelBounds? 您是否检查过DisplayObject.transform.pixelBounds? I haven't tried it, but it might be more likely to take the rotation into account. 我没有尝试过,但是可能更可能考虑轮换。

Rotation actually changes DisplayObject's axis's (ie x and y axes are rotated). 旋转实际上会更改DisplayObject的轴(即,x和y轴已旋转)。 That is why you are not seeing the difference in height. 因此,您看不到身高的差异。 So for getting the visual height and y you might try this. 因此,为了获得视觉高度和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. 在这种情况下,rect1和rect2应该不同。 If you want to check the visual coordinates of the dO then just change dO.parent with root. 如果要检查dO的视觉坐标,则只需将root更改为dO.parent。

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. 但是,这没有考虑任何其他转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM