Hi,
Ok, but I’m using some code from “OpenGL SuperBible 4th edition” - http://www.opengl.org/sdk/docs/books/SuperBible/ -
It includes GLee.h and gltools.h - which I didn’t include here. I don’t know if it’s easy for you to compile if these files are mising… Anyway, here’s the code and my question again:
#include “…/…/shared/gltools.h” // OpenGL toolkit
// Rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;
// Called to draw scene
void RenderScene(void)
{
// Angle of revolution around the nucleus
static GLfloat fElect1 = 0.0f;
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset the modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // Replace current matrix with 4*4 identity matrix!
// Translate the whole scene out and into view
// This is the initial viewing transformation
// glTranslatef(0.0f, 0.0f, -100.0f); // translates in direction (x,y,z)
glTranslatef(0.0f, 0.0f, 100.0f); // translates in direction (x,y,z)
// Red Nucleus - IN THE CENTER - NOT MOVING...
glColor3ub(255, 0, 0); // Sphere args: (radius, slices, stacks!)
// *** CREATE THS FIRST RED SPHERE: ***
glutSolidSphere(10.0f, 15, 15); // <============= SPHERE (IN CENTER)
// Yellow Electrons - this sets alpha=1 (full intensity) + RGB:
glColor3ub(255,255,0); // parameters mean: RED, GREEN, BLUE.
// ========= LOOK HERE - THIS CONCERNS MY QUESTION =========
glPushMatrix();
glRotatef(360.0f-45.0f,0.0f, 0.0f, 1.0f); // Rotates [Angle (deg), ...
glRotatef(fElect1, 0.0f, 1.0f, 0.0f); // around the vector x,y,z]
glTranslatef(0.0f, 0.0f, 60.0f);
// Sphere args: (radius, slices, stacks!)
glutSolidSphere(6.0f, 15, 15); // <============= SPHERE
glPopMatrix();
// Increment the angle of revolution
fElect1 += 1.0f;
if(fElect1 > 360.0f)
fElect1 = 0.0f;
// Show the image
glutSwapBuffers();
}
// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
glEnable(GL_DEPTH_TEST); // Hidden surface removal
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
glEnable(GL_CULL_FACE); // Do not calculate inside of jet
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
}
void TimerFunc(int value)
{
glutPostRedisplay();
glutTimerFunc(10, TimerFunc, 1);
}
void ChangeSize(int w, int h)
{
GLfloat nRange = 100.0f;
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Establish clipping volume (left, right, bottom, top, near, far)
if (w <= h)
glOrtho (-nRange, nRange, nRange*h/w, -nRange*h/w, -nRange*2.0f, nRange*2.0f);
else
glOrtho (-nRange*w/h, nRange*w/h, nRange, -nRange, -nRange*2.0f, nRange*2.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow(“OpenGL Atom”);
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
glutTimerFunc(500, TimerFunc, 1);
SetupRC();
glutMainLoop();
return 0;
}
hmm… The formatting is gone on this forum?!? Anyway: Question again:
The last sphere goes CW around the center of the screen, as “fElect1” increases. Right is x, y is up, so z is outwards from the screen to the viewer, right?
I think the sphere should go CCW because positive rotation around the z-axis tells me that I put my right thumb pointing towards myself and then positive direction of rotation is in the fingertips direction, which is CCW. But the sphere goes the other way around.
I don’t understand this - who can explain it to me?