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 › differences between gl.glRotatef and rotateZ
Page Index Toggle Pages: 1
differences between gl.glRotatef and rotateZ (Read 1476 times)
differences between gl.glRotatef and rotateZ
Jul 26th, 2009, 9:33am
 
hello i need to rotate an element in its own center. I need to use glRotatef , if i use rotateZ(aumenta_rota) if works fine , but if i use gl.glRotatef(aumenta_rota , 0, 0, 1); it doenst rotate in its own center, it seems it also translate , why is that? which is the difference between both ? how can i make to rotate in its own center using glRotate?

here is the code so you can see the difference ,comment and uncomment  each of these lines to see  the difference gl.glRotatef(aumenta_rota , 0, 0, 1);
//rotateZ(aumenta_rota);

here is the code

Code:


import codeanticode.glgraphics.*;
import processing.opengl.*;

import javax.media.opengl.GL;

GL gl;
float aumenta = 0;
float aumenta_rota = 0;

float x1;
float y1;
float cx1;
float cy1;
float cx2;
float cy2;
float x2;
float y2;

void setup() {

size(640, 480, GLConstants.GLGRAPHICS);
aumenta_rota = 0;
background(250, 250 , 250);
x1 = 0;
y1 = random(200) + 200 * 2;
cx1 = 322 * 2 ;
cy1 = 322 * 2; //random(200) ; //+ 100;
cx2 = 222 * 2 ;//random(200) - 100;
cy2 = 222 * 2 ;
x2 = random(200) + 400 * 2 ;
y2 = random(200) + 400 * 2 ;

}


void draw(){
aumenta_rota = aumenta_rota + 0.1;

GLGraphics renderer = (GLGraphics)g;
gl = renderer.beginGL();
background(250, 250 , 250);
noFill();

bezier(0, y1, cx1, cy1, cx2, cy2, x2, y2 );

aumenta = aumenta + 0.003;
float x = bezierPoint(0, cx1, cx2, x2, aumenta);
float y = bezierPoint(y1, cy1, cy2, y2, aumenta);

gl.glPushMatrix();
gl.glTranslatef(x, y, 0);



//comment the line below and uncomment rotateZ(aumenta_rota); to see the differece.
gl.glRotatef(aumenta_rota , 0, 0, 1);
//rotateZ(aumenta_rota);


ellipse(0, 0, 10, 25);
gl.glPopMatrix();

renderer.endGL();

}



Re: differences between gl.glRotatef and rotateZ
Reply #1 - Jul 26th, 2009, 11:28am
 
hi sebastiano, I just posted an example of aligning Processing and OpenGL, here:

http://benhem.com/games/GLP5align

basically, GL's (0,0) is Processing's (width/2,height/2) ...
and rotatef, depending on how your gluLookAt is set up, will need to be inverted along the Y or Z + X axis.

G.L.!
Re: differences between gl.glRotatef and rotateZ
Reply #2 - Jul 26th, 2009, 12:15pm
 
hi i added (width/2,height/2) at the beginning of my code and now it works fine, thanks mate
Page Index Toggle Pages: 1