我怀疑这是一个数学问题,而不是一个闪光问题。简而言之,我有两个围绕它们共同中心点旋转的立方体。到目前为止,一切都很好。使用 appendTranslation 和 appendRotation 矩阵函数,我设法让两个立方体旋转正常。
问题是绘图顺序似乎对 Z 缓冲几乎没有影响。我已经设法正确地 Z 缓冲区并按深度顺序排列立方体。然而,尽管绘制顺序正确,但 cueb 仅在一半时间被正确遮挡。
想象在 x 轴平面上有两个立方体,两边以相等的间距围绕 Y 轴旋转。在 90 度时,一个立方体将遮挡另一个,反之亦然,在 270 度旋转时。我的问题是这仅在这些地方之一正确发生。这似乎是一个符号问题,因为向后旋转(因此 -90 和 -270)仅在相反的位置具有相同的效果。
以下是相关代码:
PixelCubeGroup.as - 每次循环调用 Rotate
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 Value 正在某个地方进入那里。