我怀疑这是一个数学问题,而不是闪光问题。简而言之,我有两个围绕共同中心点旋转的立方体。到现在为止还挺好。使用appendTranslation和appendRotation矩阵函数,我设法让两个立方体旋转正常。Flash CS4 3D Sprite旋转Z顺序问题
问题是绘图顺序似乎对Z缓冲影响不大。我已经正确设置了Z缓冲区,并按深度顺序排列了立方体。然而,尽管正确的绘制顺序,cueb只有一半的时间被正确遮挡。
想象一下x轴平面上的两个立方体,两边都以相等的间距围绕Y轴旋转。在90度时,一个立方体会在270度旋转时遮挡另一个,反之亦然。我的问题是,只有在其中一个地方才会发生这种情况。这似乎是一个迹象问题,因为向后旋转(如-90和-270)仅在相反的位置具有相同的效果。
下面是相关代码:
PixelCubeGroup.as - 旋转称为每个周期
function rotateObj(rotx:Number,roty:Number,rotz:Number):void {
var i:int;
for(i=0; i<pixelVec.length; i++){
var v:Vector3D = centerPos;
v = v.subtract(pixelVec[i].getPos());
pixelVec[i].rotateObj(rotx,roty,rotz,v);
}
}
PixelCube.as已经绘制和旋转
function rotateObj(xrot:Number,yrot:Number,zrot:Number, pivot:Vector3D){
// rotate the cube by changing the values in the matrix 3D around a pivot point
m.identity();
m.appendTranslation(-pivot.x,-pivot.y, -pivot.z);
m.appendRotation(xrot, Vector3D.X_AXIS);
m.appendRotation(yrot, Vector3D.Y_AXIS);
m.appendRotation(zrot, Vector3D.Z_AXIS);
m.appendTranslation(pivot.x,pivot.y,pivot.z);
}
function draw():void
{
var renderV:Vector.<Number> = new Vector.<Number>();
currentV = new Vector.<Vector3D>();
for each(var vv:Vector3D in v)
{
// apply the matrix to the vertices in 'v'
vv = m.transformVector(vv);
vv.w = (400 + vv.z)/400;
vv.project();
renderV.push(vv.x, vv.y);
currentV.push(vv);
}
// draw things out
container.graphics.clear();
container.x = xPos;
container.y = yPos;
container.z = 1;
var id = 0
plane.sort(sortByZ);
for each(var p:Vector.<int> in plane)
{
container.graphics.beginFill(palleteColours[id],1.0);
var planeV:Vector.<Number> = new Vector.<Number>();
for (var i:int = 0; i < planeSides; i++)
{
planeV.push(renderV[p[i]* 2], renderV[p[i] * 2 + 1]);
}
container.graphics.drawTriangles(planeV, indices, null, TriangleCulling.NEGATIVE);
container.graphics.endFill();
id ++;
}
}
我以前做的事情设法将其缩小到翻译线。在没有翻译的情况下执行两个立方体的旋转可以正常工作,并且遵守绘图顺序,而这不是。我怀疑一个流氓Z值进入那里。
这看起来比AS3 3D API更适用于此。您可能更适合使用完整的3D引擎,例如PaperVision – bgw 2009-07-07 20:22:26