Results 1 to 2 of 2

Thread: Moving a circle across

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    1

    Moving a circle across

    hi all.
    I want to draw a circle on the push of a particular key and make it move across the screen. Heres the snippet:
    This is the function to catch the key press:
    Code :
    void keyPressed(unsigned char key, int x, int y) 
    {
        /* avoid thrashing this procedure */
        usleep(100);
     
        /* If escape is pressed, kill everything. */
        if (key == ESCAPE) 
        { 
    	/* shut down our window */
    	glutDestroyWindow(window); 
     
    	/* exit the program...normal termination. */
    	exit(0);                   
        }
     
        if(key == 102 || key == 70)
           foo();
    }

    And this is the function to draw the circle which is not registered as a display function:
    Code :
    void foo(){
    				glTranslatef(3.0f,0.0f,0.0f);		        // Move Right 3 Units
     
    	  			glBegin(GL_LINES);
    					glColor3f(1.0f,0.0f,0.0f);
    					int j;
    					float x = 0.05f * cos(359 * PI/180.0f);
    					float y = 0.05f * sin(359 * PI/180.0f);
    					for(j = 0; j < 360; j++)
    					{
    						glVertex2f(x,y);
    						x = 0.05f * cos(j * PI/180.0f);
    						y = 0.05f * sin(j * PI/180.0f);
    						glVertex2f(x,y);
    					}
    				glEnd();
    				glutSwapBuffers();
    				glutPostRedisplay();
     
    }

    Now since the above function is not registered as a display function, it is not redrawn and i want it to be redrawn. The circle is displayed and disappears. Recursion is bit messy(in processing terms) and i am not looking at it now.

    Any suggestions?
    Thank you.

  2. #2
    Junior Member Newbie Optik's Avatar
    Join Date
    Jun 2009
    Location
    Los Angeles, CA
    Posts
    22

    Re: Moving a circle across

    I cant understand what you exactly want to do.

    How do you expect the scene to be redrawn if it is not registered as a display callback?

    If you want to see the circle drawn in steps I suggest the following:

    - declare a static counter variable ( say i)
    - iterate over i after every callback to foo();
    - use a timer function glutTimerfunc(*timer_func,value,1); value = 30ms or whatever.
    - and register your display func. That is necessary!
    - Check if you have enabled Double buffering, otherwise when you swap buffers the result will be a blank screen as you mentioned.

    hope this helped.

Similar Threads

  1. Replies: 4
    Last Post: 05-31-2016, 05:21 PM
  2. moving object in circle across of other object
    By openGLWriter in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-19-2015, 09:18 AM
  3. Two triangles moving on a circle like on a carousel
    By chromosom in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-05-2014, 12:54 AM
  4. Moving part of model on circle
    By Hitokage in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-13-2012, 11:50 AM
  5. Moving text around the circle
    By daimous in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-12-2009, 07:09 AM

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