Advertisement

Glut Virtual Trackball

Started by March 15, 2004 02:50 PM
2 comments, last by OpenGL_Guru 20 years, 11 months ago
ok.. i have my own version of Glut virtual trackball -- that is rotating your scene with them mouse. one problem i am having and maybe this is an easy fix. if i have something translated out lets say -100 on the x-axis clearly when i rotate it is going to rotate around that axis, not around the center point of the object or data. so i have like... glTranslate(x, y, z) glRotatef(angel, xaxis, yaxis, zaxis) ... .. draw() ... ... so like x is like -89, y is -30 and, how do i rotate it around the center point or at 0,0, maybe redraw to 0,0, rotate then draw back to -89, -30. ?? what i am drawing is a heightmap , a nice terrain so the points are -89, along the x-axis. any ideas as i hope i have been clear enough. i guess this is the same problem as a basic object in 3D space.. you want it to rotate about its origin, or center point not along the 3D world axis if you will.
heh
Well, in the beginning you are at the origin so simply rotate then and after that translate and maybe rotate again (if needed).
Translating positions the origin, rotating always goes around 0,0.

if you translate:
glLoadIdentity()
// origin is 0,0,0 now
// translate
glTranslate(x, y, z);
// origin is x,y,z
// rotate around the origin(=always (0,0,0) in modelview) which is now (x,y,z) in the identity matrix)
glRotate(amount, rnx,rnu,rnz);

Am i clear?

lol, it's you

[edited by - Tree Penguin on March 15, 2004 4:02:48 PM]
Advertisement
hey Penguin! yes its me this is what i have so far.. so where do i need another translate and/or rotate??

/this is draw

glLoadIdentity();
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glTranslatef(xnav, ynav, viewxform_z);

if(trackballMove)
{
glPushMatrix();
glLoadIdentity();
glRotatef(angle, axis[0], axis[1], axis[2]);
glMultMatrixf((GLfloat *) trackballXform);
glGetFloatv(GL_MODELVIEW_MATRIX, trackballXform);
glPopMatrix();
}

glPushMatrix();
glMultMatrixf((GLfloat *) lightXform);
glPopMatrix();

glPushMatrix();
glMultMatrixf((GLfloat *) objectXform);
drawData(data);
glPopMatrix();

//glFlush();
glutSwapBuffers();
}
heh
If you want to rotate around the initial origin (as it is when the identity matrix is loaded) place it before the first translation (before translating to the ball origin).

This topic is closed to new replies.

Advertisement