//x,y,z,-x-y-z, 6个面的颜色 var box={ x:1, y:2, z:3, fx:4, fy:5, fz:6, } // 'y','fz','fy','z' x旋转 // 'x','fz','fx','z' y旋转 // 'x','fy','fx','y' z旋转 function rotateX90(box){ var carr=['y','fz','fy','z'] let temp=box[carr[0]]; for(let i=0;i<carr.length-1;i++){ box[carr[i]]= box[carr[i+1]] } box[carr[carr.length-1]]=temp; } function rotateY90(box){ var carr=['x','fz','fx','z'] let temp=box[carr[0]]; for(let i=0;i<carr.length-1;i++){ box[carr[i]]= box[carr[i+1]] } box[carr[carr.length-1]]=temp; } function rotateZ90(box){ var carr=['x','fy','fx','y'] let temp=box[carr[0]]; for(let i=0;i<carr.length-1;i++){ box[carr[i]]= box[carr[i+1]] } box[carr[carr.length-1]]=temp; } console.log(box) rotateX90(box) console.log(box) rotateY90(box) console.log(box) rotateZ90(box) console.log(box)
研究的方向错误,有现成的旋转公式,修正js数字计算溢出问题,就能用公式算出旋转值,可以查看文章https://www.cnblogs.com/caoke/p/10529713.html