Hi all !

I'm trying to write a rubik game in J2ME , and I'm working on the Cube class right now . I'm using a Transform object to rotate the cube if the user presses any key , but sometimes if I press UP the cube goes LEFT or RIGHT , and sometimes if I press LEFT the cube goes UP , or it gets rotated on the z-axis .

I'm using the postRotate method to rotate the cube . Here is some sample code that may help you figure out the problem :

Code:
protected void transform(int transformation, int axis,boolean positiveDirection) {
	       if(transformation == TRANSFORMATION_ROTATE) {
  		   float amount = 10.0f * (positiveDirection ? 1 : -1);

	   	   switch (axis) {
	           case TRANSFORMATION_X_AXIS:
	                iTransform.postRotate(amount, 1.0f, 0.0f, 0.0f);
	                break;

	           case TRANSFORMATION_Y_AXIS:
	           	iTransform.postRotate(amount, 0.0f, 1.0f, 0.0f);
	           	break;

	           case TRANSFORMATION_Z_AXIS:
	           	iTransform.postRotate(amount, 0.0f, 0.0f, 1.0f);
	           	break;
	       }
	     }
	 }



protected void keyPressed(int keyCode) {
   switch (getGameAction(keyCode)) {
         case UP:
	      transform(_transformation, TRANSFORMATION_X_AXIS, false);
	      break;

	 case DOWN:
	      transform(_transformation, TRANSFORMATION_X_AXIS, true);
	      break;

	 case LEFT:
	      transform(_transformation, TRANSFORMATION_Y_AXIS, false);
	      break;

	 case RIGHT:
	      transform(_transformation, TRANSFORMATION_Y_AXIS, true);
	      break;
	 case FIRE:
	       try {
		   init();
		}
		catch(Exception e) {}
	       	break;

	       case GAME_C:
	       	        _transformation++;
	       		_transformation %= 3;
	       		break;

	     }

	     repaint();
  }