rotating around a fixed coordinate system

what is the initial value of c_fFactor?

2

I tried with the spheric coordinates some time ago and I didn’t solve anything (but I don’t remember if I was making the change in the up vector). I would have to take a look at the quaternions… A friend recommended me this webpage about it:

http://en.wikipedia.org/wiki/Qua

Nice story the one about Hamilton and the bridge… :slight_smile:

You rotate first on the X and then on the Y Axis and not visa versa:

//rotate automatically the sphere on it’s Y axis
glTranslatef(0.0f,10.0f,40.0f);
glRotatef( rotateSphere , 0.0f, 1.0f , 0.0f);
glRotatef ((GLfloat)90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
glScalef(5.0f, 5.0f, 5.0f);
gluSphere(q, 1.0f, 32, 16); // Draw Sphere

never mind my last statement. It looks as your order of rotations is correct.

Maybe this will give you some ideas on rotating a sphere(without texture):/******************************************************
*
*

  •                       OPEN GL 
    
  •                 GLOBE TROT VER 0.00001 
    

********************************************************/

/I N C L U D E S/
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>

/Defines/
#define BLACK_INDEX 0 /black for background/
#define GREEN_INDEX 14 /green for wireframe globe object/
#define WIDTH 640 /starting window pixel width/
#define HEIGHT 480 /starting window pixel height/
#define GLOBE 1 /The object to be rendered/

/*Prototypes */
LONG WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM);
BOOL bSetupPixelFormat(HDC);
GLvoid resize(GLsizei, GLsizei);
GLvoid initializeGL(GLsizei, GLsizei);
GLvoid drawScene(GLvoid);
void polarView( GLdouble, GLdouble, GLdouble, GLdouble);

/OpenGL globals/
GLfloat latitude, longitude, latinc, longinc;
GLdouble radius;
CHAR szAppName[]=“Win OpenGL”;
HWND ghWnd; /* handle for our window /
HDC ghDC; /
handle for device context /
HGLRC ghRC; /
handle for render context */

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wndclass;

/* Register the frame class */ 
wndclass.style         = 0; 
wndclass.lpfnWndProc   = (WNDPROC)MainWndProc; 
wndclass.cbClsExtra    = 0; 
wndclass.cbWndExtra    = 0; 
wndclass.hInstance     = hInstance; 
wndclass.hIcon         = LoadIcon (hInstance, szAppName); 
wndclass.hCursor       = LoadCursor (NULL,IDC_ARROW); 
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
wndclass.lpszMenuName  = szAppName; 
wndclass.lpszClassName = szAppName; 

if (!RegisterClass (&wndclass) ) 
    return FALSE; 

/* Create the frame */ 
ghWnd = CreateWindow (szAppName, 
         "Rotating OpenGL Globe", 
     WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 
         CW_USEDEFAULT, 
         CW_USEDEFAULT, 
         WIDTH, 
         HEIGHT, 
         NULL, 
         NULL, 
         hInstance, 
         NULL);  

/* make sure window was created */ 
if (!ghWnd) 
    return FALSE; 

/* show and update main window */ 
ShowWindow (ghWnd, nCmdShow); 

UpdateWindow (ghWnd); 

/* animation loop */ 
while (1)
 { 
    
    while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE) 
    { 
        if (GetMessage(&msg, NULL, 0, 0) ) 
        { 
            TranslateMessage(&msg); 
            DispatchMessage(&msg); 
        } 
        else 
          { 
            return TRUE; 
          } 
        
      }        

  
    drawScene(); // Call drawScene function

}

} // Close WinMain

/* main window procedure */
LONG WINAPI MainWndProc (
HWND hWnd, /*handle for our window */
UINT uMsg, /messages/
WPARAM wParam,
LPARAM lParam)
{
LONG lRet = 1;
PAINTSTRUCT ps;
RECT rect;

switch (uMsg) { 

/get device context with window´s handle/
case WM_CREATE:
ghDC = GetDC(hWnd);
if (!bSetupPixelFormat(ghDC))
PostQuitMessage (0);

/get render context concurrent with device context/
ghRC = wglCreateContext(ghDC);
wglMakeCurrent(ghDC, ghRC);
GetClientRect(hWnd, &rect);
initializeGL(rect.right, rect.bottom);
break;
/Win32 Api Paint/
case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
/Win32 Api window´s size/
case WM_SIZE:
GetClientRect(hWnd, &rect);
resize(rect.right, rect.bottom);
break;

/close window and reset render and device context to zero/
case WM_CLOSE:
if (ghRC)
wglDeleteContext(ghRC);
if (ghDC)
ReleaseDC(hWnd, ghDC);
ghRC = 0;
ghDC = 0;

    DestroyWindow (hWnd); 
    break;

/* destroy window and delete render and device context*/
case WM_DESTROY:
if (ghRC)
wglDeleteContext(ghRC);
if (ghDC)
ReleaseDC(hWnd, ghDC);
PostQuitMessage (0);
break;

/User controlled Kyboard routines/
case WM_KEYDOWN:
switch (wParam) {
case VK_LEFT:
longinc += 0.2F;
break;
case VK_RIGHT:
longinc -= 0.2F;
break;
case VK_UP:
latinc += 0.2F;
break;
case VK_DOWN:
latinc -= 0.2F;
break;
}
/* Windows procedure for messages*/
default:
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}

return lRet; 

}

BOOL bSetupPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd, *ppfd;
int pixelformat;

ppfd = &pfd; 

ppfd-&gt;nSize = sizeof(PIXELFORMATDESCRIPTOR); 
ppfd-&gt;nVersion = 1; 
ppfd-&gt;dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |   
                    PFD_DOUBLEBUFFER; 
ppfd-&gt;dwLayerMask = PFD_MAIN_PLANE; 
ppfd-&gt;iPixelType = PFD_TYPE_COLORINDEX; 
ppfd-&gt;cColorBits = 8; 
ppfd-&gt;cDepthBits = 16; 
ppfd-&gt;cAccumBits = 0; 
ppfd-&gt;cStencilBits = 0; 

pixelformat = ChoosePixelFormat(hdc, ppfd); 

if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 ) 
{ 
    MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK); 
    return FALSE; 
} 

if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE) 
{ 
    MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK); 
    return FALSE; 
} 

return TRUE; 

}

GLvoid resize( GLsizei width, GLsizei height )
{
GLfloat aspect;

glViewport( 0, 0, width, height ); 

aspect = (GLfloat) width / height; 

glMatrixMode( GL_PROJECTION ); 
glLoadIdentity(); 
gluPerspective( 45.0, aspect, 3.0, 7.0 ); 
glMatrixMode( GL_MODELVIEW ); 

}

/* Object Set Up */
GLvoid createObjects()
{
GLUquadricObj *quadObj;

glNewList(GLOBE, GL_COMPILE);         
    quadObj = gluNewQuadric ();        
   gluQuadricDrawStyle (quadObj, GLU_LINE); 
    gluSphere (quadObj, 1.5, 16, 16); 
glEndList();    

}

/* Function Initialize Scene objects */
GLvoid initializeGL(GLsizei width, GLsizei height)
{
GLfloat maxObjectSize, aspect;
GLdouble near_plane, far_plane;

/* Initial depth and background */
glClearIndex( (GLfloat)BLACK_INDEX);
glClearDepth( 1.0 );

/* Initial depth test */
glEnable(GL_DEPTH_TEST);

glMatrixMode( GL_PROJECTION ); 
aspect = (GLfloat) width / height; 
gluPerspective( 45.0, aspect, 3.0, 7.0 ); 
glMatrixMode( GL_MODELVIEW ); 

near_plane = 3.0; 
far_plane = 7.0; 
maxObjectSize = 3.0F; 
radius = near_plane + maxObjectSize/2.0; 

latitude = 0.0F; 
longitude = 0.0F; 
latinc = 3.0F; 
longinc = 0.0F; 

createObjects(); 

}

void polarView(GLdouble radius, GLdouble twist, GLdouble latitude,
GLdouble longitude)
{
glTranslated(0.0, 0.0, -radius);
glRotated(-twist, 0.0, 0.0, 1.0);
glRotated(-latitude, 1.0, 0.0, 0.0);
glRotated(longitude, 0.0, 0.0, 1.0);

}

GLvoid drawScene(GLvoid)
{
/Clear previous frame depth and color buffer enabling next frame/
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

/matrix stack save transformations/
glPushMatrix();

 /*User´s Kayboard values*/
    latitude += latinc*.3; 
    longitude += longinc*.3;
     
 /*Call to object´s function with current values*/
    polarView( radius, 0, latitude, longitude );         
     
/* Final Call for Objects to be rendered*/
    glIndexi(GREEN_INDEX); 
    glCallList(GLOBE);     

/*restore OpenGl´s matrix stack transformations */
glPopMatrix();

/* Make scene visible */
SwapBuffers(ghDC);
}