簡體   English   中英

Flash CS4 3D精靈旋轉Z順序問題

[英]Flash CS4 3D Sprite Rotation Z Order Problem

我懷疑這是一個數學問題,而不是一個速寫問題。 簡而言之,我有兩個繞其共同中心點旋轉的立方體。 到現在為止還挺好。 使用appendTranslation和appendRotation矩陣函數,我設法使兩個多維數據集可以旋轉。

問題在於繪制順序似乎對Z緩沖幾乎沒有影響。 我設法正確地Z緩沖區和按深度順序對多維數據集進行排序。 但是,盡管繪制順序正確,但只有一半時間正確封閉了后座。

想象一下在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值進入某個地方。

排序。 顯然,繪圖/ Z順序(如果要執行)由調用addChild()和removeChild()的順序(而不是任何圖形調用的順序)控制。 有點傻Adobe!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM