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 & HelpSyntax Questions › Changing vertex object rotation axis position.
Page Index Toggle Pages: 1
Changing vertex object rotation axis position. (Read 629 times)
Changing vertex object rotation axis position.
Aug 16th, 2007, 8:29pm
 
Hi guys,

Let's say i've got a rectangle made of vertex shape.
When i try to rotateX it, the rotation applies at its first vertex point ( vertex(0,0,0,0); )

How can i change its rotation axis to be right in the middle of it ( objrotate.width/2 , objrotate.height/2 ) ?

Here is my code :

Quote:
import processing.opengl.*;

PImage a;

void setup() {
 size(640, 480, OPENGL);
 a = loadImage("a.jpg");
}

void draw() {
background(0);
objrotate();
}

void objrotate() {
    pushMatrix();
    rotateX(0.45);
    beginShape(POLYGON);
    textureMode(NORMALIZED);
    texture(a);
    vertex(0,0,0,0);
    vertex(320,0,1,0);
    vertex(320,240,1,1);
    vertex(0,240,0,1);
    endShape();
    popMatrix();
 }


Thx for your help.
Re: Changing vertex object rotation axis position.
Reply #1 - Aug 16th, 2007, 10:11pm
 
Do something like:

Code:
translate(whereYouWantTheMiddleX,whereYouWantTheMiddleY);
rotateX(...);
translate(-shapewidth/2,-shapeheight/2);
//draw
Re: Changing vertex object rotation axis position.
Reply #2 - Aug 17th, 2007, 1:14am
 
Thx JohnG, i've found out with your help Smiley
Page Index Toggle Pages: 1