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();
}