简体   繁体   English

创建用于转动魔方的 animation

[英]Creating an animation for turning rubiks cube

i am currently creating a rubiks cube project for my a level NEA and currently the cube solves itself so i am now focussing on the implementation of the cube.我目前正在为我的级别 NEA 创建一个 rubiks 立方体项目,目前立方体解决了自己,所以我现在专注于立方体的实现。 I have got to a stage where i have a cube made up of 26 different cubes to allow me to give each face smooth rotations and nice colours.我已经到了一个阶段,我有一个由 26 个不同的立方体组成的立方体,让我可以为每个面提供平滑的旋转和漂亮的颜色。 I have the code for one of the face rotations below.我有以下面部旋转之一的代码。 The left face to be exact but you do not need to know that.确切地说是左脸,但您不需要知道。

            for (int i = 0; i < 90; i++)
            {
                cube[0].rotateX(Math.PI / 360);  // uses math.PI because the rotations are in radians
                cube[1].rotateX(Math.PI / 360);  // each of these commands rotate 1 degree
                cube[2].rotateX(Math.PI / 360);
                cube[9].rotateX(Math.PI / 360);
                cube[10].rotateX(Math.PI / 360);
                cube[11].rotateX(Math.PI / 360);
                cube[17].rotateX(Math.PI / 360);
                cube[18].rotateX(Math.PI / 360);
                cube[19].rotateX(Math.PI / 360);
                Invalidate();   // runs the paint function again to redraw the cube but rotated
            }

this code performs one 90 degree turn of the face but what i would like to know is why doesnt it update the cube with the invalidate command on each itteration of the for loop and instead only does it once after the turn is performed.这段代码执行了一个 90 度的面部转弯,但我想知道的是为什么它不在 for 循环的每次迭代中使用 invalidate 命令更新立方体,而是在执行转弯后只执行一次。 And is there a way to make it update on every itteration so i can get a nice smooth turn of the face.有没有办法让它在每次迭代时更新,这样我就可以得到一个很好的平滑转脸。

Thanks in advance.提前致谢。

In case you haven't solved this yet, you need to add short wait times after each Invalidate, so that it is not trying to loop through as fast as it can.如果您还没有解决这个问题,您需要在每次 Invalidate 之后添加较短的等待时间,这样它就不会尝试尽可能快地循环通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM