FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   precise rotation possible?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: precise rotation possible?  (Read 244 times)
christian


precise rotation possible?
« on: Aug 31st, 2004, 12:26pm »

i did not manage to get a precise rotation  
of cubes running this code below:
 
<B>code</B>
bloqueElement b;
boolean isRotatable=false;
boolean turn45=false;
 
void setup(){
  size(800,600);
  background(44);
  b=new bloqueElement(new Point3D(width/2, height/2, 0));
  //rectMode(CENTER_DIAMETER);
}
 
void loop(){
  clear();
  b.draw();
}
 
class Point3D{
  float x,y,z;
 
  Point3D(float _x, float _y, float _z){
    x=_x; y=_y; z=_z;
  }
  Point3D(Point3D p){
    x=p.x; y=p.y; z=p.z;
  }
}
 
class bloqueElement{
  Point3D bePos;
  float x,y,z;
  float rotX=0;  
  float rotY=0;
  float tempRotX, tempRotY;
 
  bloqueElement(Point3D _bePos){
    bePos=_bePos;
  }
 
  void rotation(){
    if(isRotatable){
      rotX+=((mouseY)*.018-rotX)*0.09;
      rotY+=((mouseX)*.018-rotY)*0.09;
    };
 
    if(rotX<=this.tempRotX){
      rotX+=(PI/2)*.1;
      //rotY=2;
    }
    
     if(rotX>this.tempRotX){
      rotX-=(PI/2)*.1;
      //rotY=2;
    }
 
  }
 
  void draw(){
    rotation();
 
    fill(255,255,255,80);
    stroke(200,200,200,120);
 
    push();
    translate(width/2, height/2, 0);
    rotateX(rotX);
    rotateY(rotY);
    beginShape(QUADS);
    //vorn
 
    vertex(-50,50,50);
    vertex(50,50,50);
    vertex(50,-50,50);
    vertex(-50,-50,50);
 
    //hinten
    vertex(-50,50,-50);
    vertex(50,50,-50);
    vertex(50,-50,-50);
    vertex(-50,-50,-50);
 
    //rechts
    vertex(50,-50,50);
    vertex(50,-50,-50);
    vertex(50,50,-50);
    vertex(50,50,50);
 
    //links
    vertex(-50,-50,50);
    vertex(-50,-50,-50);
    vertex(-50,50,-50);
    vertex(-50,50,50);
 
    //oben
    fill(200,0,0);
    vertex(50,-50,50);
    vertex(50,-50,-50);
    vertex(-50,-50,-50);
    vertex(-50,-50,50);
 
    fill(200,200,200);
    //unten
    vertex(50,50,50);
    vertex(50,50,-50);
    vertex(-50,50,-50);
    vertex(-50,50,50);
    endShape();
    pop();
  }
 
}
 
void keyPressed(){
  switch(key){
    case 'r': isRotatable=!isRotatable;break;
    case 't': b.tempRotX=b.rotX+PI/2;break;
    case 'f': b.tempRotX=b.rotX-PI/2;break;
  }
}
 
« Last Edit: Aug 31st, 2004, 4:33pm by christian »  
gll

WWW Email
Re: precise rotation possible?
« Reply #1 on: Aug 31st, 2004, 8:38pm »

Code:
 void rotation(){  
    if(isRotatable){  
 rotX+=((mouseY)*.018f-rotX)*0.09f;  
 rotY+=((mouseX)*.018f-rotY)*0.09f;  
    };
    if(rotX<=this.tempRotX){  
 rotX+=((PI/2f)*.1f);  
 //rotY=2;  
    }  
     
     if(rotX>this.tempRotX){  
 rotX-=((PI/2f)*.1f);  
 //rotY=2;  
    }
  println("("+rotX+" | "+rotY+")");  
  }
 
Would give in the corner
([rotX] - [rotY])
(-0.069032505 | 2.9227154)
(-0.040139586 | 2.923731)
(-0.013847023 | 2.9246552)

 
It seems to be when rotX is negative, try to remove the tests after;
Code:
  void rotation(){  
    if(isRotatable){  
 rotX+=((mouseY)*.018f-rotX)*0.09f;  
 rotY+=((mouseX)*.018f-rotY)*0.09f;  
    };  
  println("("+rotX+" | "+rotY+")");  
  }
 

guillaume LaBelle
Pages: 1 

« Previous topic | Next topic »