Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Moving part of model on circle

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    13

    Moving part of model on circle

    Hi guys.
    Need help with something.

    I have imported model and I need to rotate part of it.
    Here is what I mean.

    I have this in the beginning:


    And need to transform it to this (like when I press button I want this part of model to smoothly rotate until right angle):



    So this is the code I used
    Code :
    //somewhere in the beginning
    float angle = 0.0;
     
     
    case GLUT_KEY_RIGHT:                                                                                                                          //when this button is pressed
     
    int i, xo = 20;                                                                                                     // i is for loop and xo is x coordinate of the circle center 
     
     
    	for (i=0; i<=object.vertices_qty; i++)                                                                     //go through all the vertices
    	{
    		if(object.vertex[i].x > xo)                                                                         //if the x coordinate is bigger than xo - choose the part to rotate
    		{
     
    		     if(object.vertex[i].r == 0)                                                             //calculate the circle radius if it hasn't been already done
    		     object.vertex[i].r = object.vertex[i].x-xo;
     
    		angle += 0.001;                                                                                      //increment the angle
     
                           //now I want to calculate new vertex coordinates (after rotation)
     
                           object.vertex[i].y = object.vertex[i].w + object.vertex[i].r*cos(angle);             //object.vertex[i].w is original y coordinate (before rotation) which is also coordinate of the circle center
    		object.vertex[i].x = xo + object.vertex[i].r*sin(angle);
     
    		}
    	}		
     
    break;


    What is the problem here? The code is not working properly. The result is trash .

    Sry if there are some serious mistakes. I am just a beginner in OpenGL and geometry is not my big friend .

    Have a nice day
    Last edited by Hitokage; 11-08-2012 at 12:25 PM. Reason: fixed one mistake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •