Rotate on Command

I tested the code you posted, and I liked how it worked, although when I pressed space again, the box was reset back to its original person. I looked at the code, and I believe this is because the box is put after the rotation code.

boolean rotateU=false;
boolean rotateD=false;
boolean rotateL=false;
boolean rotateR=false;
float angleX=0;
float angleY=0;
float anglechgU=HALF_PI/90;
float anglechgD=HALF_PI/90;
float anglechgL=HALF_PI/90;
float anglechgR=HALF_PI/90;
void setup() {
  size(1000,1000,P3D);
  noFill();
  stroke(255);
  println("press a to rotate right, b for left");
}
void draw(){
  background(0);
  translate(width/2,height/2);
  if(rotateU){
    rotateX(angleX);
    angleX+=anglechgU;
  }else{
    anglechgU=0;
  }
  if(rotateD){
    rotateX(angleX);
    angleX-=anglechgD;
  }else{
    anglechgD=0;
  }
  if(rotateL){
    rotateY(angleY);
    angleY-=anglechgL;
  }else{
    anglechgL=0;
  }
  if(rotateR){
    rotateY(angleY);
    angleY+=anglechgR;
  }else{
    anglechgR=0;
  }
  box(500);
}
void keyPressed(){
  if(key=='w'){
    rotateU=!rotateU;
  }
  if(key=='s'){
    rotateD=!rotateD;
  }
  if(key=='a'){
    rotateL=!rotateL;
  }
  if(key=='d'){
    rotateR=!rotateR;
  }
}

I edited the code to my liking, and created some new variables to make the rotation a little more regulated. I still do not understand why the box keeps reappearing in its original position.

1 Like