Results 1 to 2 of 2

Thread: help adding glutWireSphere to this code

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    3

    help adding glutWireSphere to this code

    i would like add a glutWireSphere (MOON) to this code that will allow it to rotate around the earth sphere when the key 'm' is pressed

    what code would i add help much appreciated

    #include <GL/glut.h>
    #include <stdlib.h>

    #define SUN_RADIUS 1.0
    #define PLANET_RADIUS 0.2
    static int year = 0, day = 0;

    void init(void)
    {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);
    }

    void display(void)
    {
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (1.0, 1.0, 1.0);

    glPushMatrix();
    glutWireSphere(SUN_RADIUS, 20, 16); /* draw sun */
    glRotatef ((GLfloat) year, 0.0, 1.0, 0.0);
    glTranslatef (2.0, 0.0, 0.0);
    glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
    glutWireSphere(PLANET_RADIUS, 10, ; /* draw earth */
    glPopMatrix();
    glutSwapBuffers();
    }

    void reshape (int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    }

    void keyboard (unsigned char key, int x, int y)
    {
    switch (key) {
    case 'd':
    day = (day + 10) % 360;
    glutPostRedisplay();
    break;
    case 'D':
    day = (day - 10) % 360;
    glutPostRedisplay();
    break;
    case 'y':
    year = (year + 5) % 360;
    glutPostRedisplay();
    break;
    case 'Y':
    year = (year - 5) % 360;
    glutPostRedisplay();
    break;
    case 27:
    exit(0);
    break;
    default:
    break;
    }
    }

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init ();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
    return 0;
    }

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: help adding glutWireSphere to this code

    We are not here to do your homework or whatever. You have already did it for the earth and the sun, so just think a bit more and it will work.

Similar Threads

  1. Adding OpenGl to a project (Via source code work)
    By Matt101 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-03-2017, 11:39 AM
  2. adding sphere to my code
    By muhrnb in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-19-2017, 10:02 PM
  3. Adding custom code to programmers shaders?
    By imported_paul_g_griffiths in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 02-24-2017, 12:23 PM
  4. glutWireSphere
    By idan333 in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-06-2003, 10:32 AM
  5. glutWireSphere() equivalent?
    By joeyTR in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 03-26-2003, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean