我有一个 3D 立方体,我试图沿 Y 轴平滑旋转。截至目前,当我单击鼠标按钮时,立方体会立即旋转到新值(如俄罗斯方块),但希望显示它逐渐旋转到特定的新旋转值。这是我正在使用的代码:
// Within Shp_Cube class
public float cubeRotY = 1.0f; // rotate on Y-axis
public static float cubeAngle = .01f; // angle of rotation
public static float cubeSpeed = 1.0f; // speed of rotation
...
// Within drawCube() method (called in JOGL's display(GLAutoDrawable...) )
gl.glRotatef(cubeAngle, 0, cubeRotY, 0); // rotation of cube
...
// Within MouseInput class
@Override
public void mouseClicked(MouseEvent m)
{
switch(m.getButton())
{
case 1:
System.out.println("Left Mouse Button Clicked");
if(Shp_Cube.cubeAngle < Shp_Cube.cubeAngle + 90f)
{
Shp_Cube.cubeAngle += Shp_Cube.cubeSpeed;
}
break;
case ...
我一直试图达到的预期效果是当用户单击鼠标左键时,立方体将开始旋转并继续旋转,直到它的角度达到某个值。