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 › differences between gl.glRotatef and rotateZ
Page Index Toggle Pages: 1
differences between gl.glRotatef and rotateZ (Read 835 times)
differences between gl.glRotatef and rotateZ
Jul 26th, 2009, 8:58am
 
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:43am
 
Just curious, but what's wrong with simply using the rotateZ() function? Isn't Processing just calling glRotatef() itself when you're rendering in openGL?
Re: differences between gl.glRotatef and rotateZ
Reply #2 - Jul 26th, 2009, 11:54am
 
because rotateZ doesnt work with the library glgraphics, glgraphics just work with pure opengl commands. And yes i thouth glRotatef was the same as rotateZ but im having wierd results, i cant rotate in its own center with glRotate , any idea?
Re: differences between gl.glRotatef and rotateZ
Reply #3 - Jul 27th, 2009, 5:58am
 
But you use it in the above code between beginGL() and endGL() and it works completely fine. So how is it not working with glgraphics? I'm not trying to be difficult, but I'm trying to understand what the problem is. I tried running your code, and I see your difficulties with the glRotatef(), but when I tried using rotateZ it seemed to be working just fine.
Re: differences between gl.glRotatef and rotateZ
Reply #4 - Jul 27th, 2009, 8:19am
 
the code above is just example, when you use the class glmodel from glgraphics you cant use standard transformation commands from processing like translate and rotate.
Page Index Toggle Pages: 1