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
   Programs
(Moderators: fry, REAS)
   translates, rotates and keeping it in perspective
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: translates, rotates and keeping it in perspective  (Read 296 times)
jedierikb

WWW
translates, rotates and keeping it in perspective
« on: Dec 20th, 2003, 3:19pm »

anyone have tips on how to accomplish this trick?  I want two X-rotated rectangles to look identical on screen, one on top of the other.
 
here is the code that doesn't do it:
void setup()
{
    size( 400, 400 );
    background( 40, 80, 120 );
 
    stroke( 250, 20, 50 );
 
    //this is rotated to the desired position
    rectMode( CENTER_DIAMETER );
    translate( width/2, height/2 );
    rotateX( PI/3 );
    rect( 0, 0, 100, 100 );
    rotateX( -(PI/3) );
    translate( -(width/2), -(height/2) );
 
 
    //this is not.  i would like it to appear
    //identical to the previous rect,
    //just directly above it.
    //in other words, the same graphic as above,
    //just shifted up a few 100 pixels
    rectMode( CENTER_DIAMETER );
    translate( width/2, height/4 );
    rotateX( PI/3 );
    rect( 0, 0, 100, 100 );
    rotateX( -(PI/3) );
    translate( -(width/2), -(height/4) );
}
 
any suggestions?  thanks much.
 
TomC

WWW
Re: translates, rotates and keeping it in perspect
« Reply #1 on: Dec 20th, 2003, 6:10pm »

OK, your code draws two identical rectangles, one above the other.  Because of perspective, they look different.  You don't want that?
 
If you want two shapes as you have specified them to look identical on screen, you're going to need to find out about Orthographic Projection.  I'm not sure if processing can do that, but it's not too hard to do for yourself...
 
Alternatively, if you are asking how to specify two shapes so that they look identical in spite of the perspective projection, then I have two suggestions...
 
1.  Fake it, by drawing trapeziums in 2D instead of rectangles in 3D (easiest).
 
2. Fake it, by trial and error work out a different rotation which makes the second one look the same (harder, but only because it's time consuming).
 
3.  Fake it, by working out the camera projection in reverse.  (Hard, never done it).
 
 
Oh, a quick tip... where you have:
 
Code:

translation(x,y);
rotation(a);
rect(...);
rotation(-a);
translation(-x,-y);

 
the same thing can be accomplished with:
 
Code:

push(); // remember the current transform
translation(x,y);
rotation(a);
rect(...);
pop(); // restore the transform from the last push()

 
Hope that helps,
 
Tom.
 
TomC

WWW
Re: translates, rotates and keeping it in perspect
« Reply #2 on: Dec 20th, 2003, 9:06pm »

OK, talking to myself here, but here's a possible solution - just scale the z axis to something tiny.  I don't know how flexible/robust it is, but it's worth playing around with.
 
Code:

 void setup()
{
    size( 400, 400 );
    background( 40, 80, 120 );
 
    stroke( 250, 20, 50 );
    fill( 255 );
    rectMode( CENTER_DIAMETER );
     
    push();
 
    scale( 1.0, 1.0, 0.00001 ); // this squishes everything onto the x-y plane  
 
    //this is rotated to the desired position
    push();
    translate( width/2, height/2 );
    rotateX( PI/3 );
    rect( 0, 0, 100, 100 );
    pop();
 
    // this is the same, but higher up
    push();
    translate( width/2, height/4 );
    rotateX( PI/3 );
    rect( 0, 0, 100, 100 );
    pop();
     
    pop();
}  

 
Pages: 1 

« Previous topic | Next topic »