gpt4 book ai didi

flash - 在 3D 中反转旋转,使对象始终面向相机?

转载 作者:行者123 更新时间:2023-12-04 16:22:29 28 4
gpt4 key购买 nike

我在 3D 空间中排列了很多 Sprite ,并且它们的父容器应用了旋转。
我如何反转 Sprite 3D 旋转,使它们始终面向相机(Actionscript 3)?

继承人的代码来测试它:

package{
import flash.display.Sprite;
import flash.events.Event;
public class test extends Sprite{

var canvas:Sprite = new Sprite();
var sprites:Array = []

public function test(){
addChild(canvas)
for (var i:int=0;i<20;i++){
var sp:Sprite = new Sprite();
canvas.addChild(sp);
sp.graphics.beginFill(0xFF0000);
sp.graphics.drawCircle(0,0,4);
sp.x = Math.random()*400-200;
sp.y = Math.random()*400-200;
sp.z = Math.random()*400-200;
sprites.push(sp);
}
addEventListener(Event.ENTER_FRAME,function():void{
canvas.rotationX++;
canvas.rotationY = canvas.rotationY+Math.random()*2;
canvas.rotationZ++;
for (var i:int=0;i<20;i++){
//this is not working...
sprites[i].rotationX = -canvas.rotationX
sprites[i].rotationY = -canvas.rotationY
sprites[i].rotationZ = -canvas.rotationZ
}
})
}
}
}

我猜我必须对 Sprite 的rotation3D矩阵做一些魔术......
我试图实现这个脚本: http://ughzoid.wordpress.com/2011/02/03/papervision3d-sprite3d/ ,但如此成功
感谢帮助。

最佳答案

最简单的方法是“清除”变换矩阵的旋转部分。您典型的同构变换如下所示

| xx xy xz xw |
| yx yy yz yw |
| zx zy zz zw |
| wx wy wz ww |

wx = wy = wz = 0, ww = 1。如果你仔细观察,你会发现这个矩阵实际上由一个定义旋转的 3x3 子矩阵、一个 3 个用于平移的子向量和一个同质行 0 0 组成0 1
| R       T |
| (0,0,0) 1 |

对于广告牌/ Sprite ,您希望保持平移,但摆脱旋转,即 R = I。如果应用了一些缩放,则身份也需要缩放。

这给出了以下配方:

d = sqrt( xx² + yx² + zx² )
| d 0 0 T.x |
| 0 d 0 T.y |
| 0 0 d T.z |
| 0 0 0 1 |

加载此矩阵允许您绘制相机对齐的 Sprite 。

关于flash - 在 3D 中反转旋转,使对象始终面向相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5467007/

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