# Moving part of model on circle

• 11-07-2012, 01:33 PM
Hitokage
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:
http://s12.postimage.org/go1ucs2fh/image.jpg

And need to transform it to this (like when I press button I want this part of model to smoothly rotate until right angle):
http://s15.postimage.org/qqiyrkr0r/image.jpg

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 :D.

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

Have a nice day
• 11-09-2012, 07:08 AM
Hitokage
Version 2
After some edits I ended with this but it is not working either.

Code :

```case GLUT_KEY_RIGHT: int i, xo = 20, yo = 2;   angle += 0.1;   for (i=0; i<=object.vertices_qty; i++) { if(object.vertex[i].x >= xo) {   if(object.vertex[i].r == 0.0) object.vertex[i].r = sqrt( (object.vertex[i].x-xo)*(object.vertex[i].x-xo) + (object.vertex[i].y-yo)*(object.vertex[i].y-yo) );       object.vertex[i].y = yo + object.vertex[i].r*sin(angle); object.vertex[i].x = xo + object.vertex[i].r*cos(angle);   } }```

Result is this:
http://s7.postimage.org/vt2ypfjhn/image.jpg
• 11-09-2012, 07:38 PM
tonyo_au
You really need to look at matrices for these sorts of task. There is quite a lot of information on the web about this
• 11-10-2012, 08:57 AM
Hitokage
Quote:

Originally Posted by tonyo_au
You really need to look at matrices for these sorts of task. There is quite a lot of information on the web about this

Yea heard about them :D. Thanks for advice. I will look at that.
• 11-12-2012, 11:15 AM
Hitokage
Hi it's me again.
So I learned sth about matrices but still don't know how to use them for this. I think it is not possible to change matrices during the polygons drawing. So how can I use them? Somehow apply them to the every vertex before drawing? How?
• 11-12-2012, 02:22 PM
tonyo_au
You don't do it during the draw. You modify your vertices then draw
• 11-13-2012, 11:50 AM
Hitokage
thx
Quote:

Originally Posted by tonyo_au
You don't do it during the draw. You modify your vertices then draw

Ok so I use that loop and instead of that calculations use matrix multiplication to the vertex or vector.
Have to check more about that.
Thanks for help