Hi guys,
I want to rotate a mesh around its center (kinda like in a arcball). The mesh is read in from a .obj file.
The way I have it now, the model is rotating around a point which is not its center (kinda like if you run around a house in circles).
I read that I would have to translate the object to 0,0,0 and then rotate, but I have no ideas which values I should take.
Oh, I am using JOGL btw.
Here’s the code for rendering:
public void display(GLAutoDrawable drawable) {
final GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
if(zoom)
setProjectionMatrix(gl);
drawBone(gl);
gl.glFlush();
private void drawBone(GL gl){
gl.glPushMatrix();
gl.glTranslated(0, 0,0);
gl.glRotated(rotX, 1, 0, 0);
gl.glRotated(rotY, 0, 1, 0);
if(faces != null){
for(Face f: faces){
f.draw(gl);
}
}
gl.glPopMatrix();
}
reshape:
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
GL gl = drawable.getGL();
if(h<=0){
this.height=1;
}
else{
this.height = h;
}
this.width = w;
aspect = (float)width/(float)height;
// Set the viewport to be the entire window
gl.glViewport(0, 0, width, height);
// Reset the coordinate system before modifying
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
// Set the correct perspective.
glu.gluPerspective(DEFAULT_ZOOM*zoomFactor, aspect, 1.0, 1000.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(0.0, 0.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
public void setProjectionMatrix(GL gl){
GLU glu = new GLU();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(DEFAULT_ZOOM*zoomFactor, aspect, 1f, 100.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
Any help is much appreciated. Thank you!
how would i center the vertices around the origin at import? with the method DzzD described below or is there a simpler way ?