We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Rotating about fixed axes
Page Index Toggle Pages: 1
Rotating about fixed axes (Read 1276 times)
Rotating about fixed axes
Nov 7th, 2009, 3:21pm
 
This has most probably been asked before. But a search for 'fixed axes, static axes etc' did not bring up anything I wanted.

I want to rotate an object about fixed axes in 3d. In the usual examples on rotating about the x and y  and z axes, the rotation about one axis changes the other axes and therefore subsequent rotations will be about the new rotated axes.

Here is what I could come up with( seeing some opengl program I had written long ago):
   
Quote:
PMatrix3D m3d;
void setup(){
size(400, 400, P3D);
m3d = new PMatrix3D();
}
void draw(){
background(150);
translate(width/2, height/2, 200);
applyMatrix(m3d);
box(50, 50, 50);
}

void keyPressed(){
if ( key == CODED)
{
  if (keyCode == UP )
  {
    resetMatrix();
    rotate(2*PI/180.0,1.0,0.0,0.0);
    applyMatrix(m3d);
    getMatrix(m3d);
  }
  else if (keyCode == RIGHT)
  {
    resetMatrix();
    rotate(2*PI/180.0,0.0,1.0,0.0);
    applyMatrix(m3d);
    getMatrix(m3d);    
  }
}
}



Now I have read that applyMatrix() is to be avoided. Can this sort of thing be done any other way in Processing?
Please do excuse me if this has been discussed in another post.
Re: Rotating about fixed axes
Reply #1 - Nov 17th, 2009, 7:22am
 
Hi, I am new to this field as well, I think the solution is to use quaternions, they allow to rotate around each axis without effecting the rotation of the other axis

Search for quaternions, gamedev.net is a good source, if I get a working sketch, I will post it here

Cheers
rS
Re: Rotating about fixed axes
Reply #2 - Nov 17th, 2009, 8:56am
 
something like this ?

float x = 0;
float y = 0;
void setup(){
 size(400, 400, P3D);


}
void draw(){
 background(150);
 translate(width/2, height/2, 200);
 rotateX(x);
 rotateY(y);

 box(50, 50, 50);
}

void keyPressed(){
 if ( key == CODED){

   if (keyCode == UP ){
     x+=(2*PI/180.0 );
   }

   if (keyCode == RIGHT){
     y+=(2*PI/180.0 );
   }

   if (keyCode == LEFT){
     y-=(2*PI/180.0 );
   }

   if (keyCode == DOWN){
     x-=(2*PI/180.0 );
   }

 }
}


Re: Rotating about fixed axes
Reply #3 - Nov 22nd, 2009, 10:51am
 
Thanks, but no, this doesn't work. The rotation about the x- axis is about a 'fixed' x-axis because in your 'draw' that comes first. But the rotation about the y-axis is not about a fixed y-axis because the y-axis also rotates when you rotate the x-axis.

Your website is quite inspiring.
Re: Rotating about fixed axes
Reply #4 - Nov 22nd, 2009, 11:20am
 
nardove wrote on Nov 17th, 2009, 7:22am:
Hi, I am new to this field as well, I think the solution is to use quaternions, they allow to rotate around each axis without effecting the rotation of the other axis

Search for quaternions, gamedev.net is a good source, if I get a working sketch, I will post it here

Cheers
rS



Thanks. Will look into quaternions.
Page Index Toggle Pages: 1