Skip to main content
gamedev.net
🔒 Locked

Rotating objects about a point..

Started by ArchangelMorph Aug 2, 2006 at 8:09 AM 0 replies 300+ views
Original Post
ArchangelMorph
ArchangelMorph
I'm in the process of developing a game's menu system using directx and i'm having trouble defining my algorithm to move the menu entities around.. I decided on a rotating menu system whereby it would have a number of menu options in 3D world space which lie on the same plane but rotate about a central point. the closest menu entity (at position x=0,y=0,z=radius) would be the one currently highlighted and the user would be able to use the left and right arrow keys to rotate the menuItem around for selection.. So far my SetupRotator() function takes an array of menuItems and positions them around a central point with even spacing in between each one by calculating the distribution of the sum of the items using the angle between each item about the y-axis. The RotateAngles() function is called each frame (provided the user pressed one of the arrow keys telling the menu to rotate)and does the following..: - retrieve the time ellapsed since the last call and calculate the amount each menu item should have moved in that time.. - set the rotations of each menu item using the value retrieved from the previous step.. - use the rotations to calculate the new positions of each menu item in the worldspace.. Also the function is supposed detect when the current angle of rotation about the centre is greater than the angle between two menuItems (making sure the rotation stops once the next menu item has reached the forefront/highlighted position) and re-adjust rotations to stop them to put them where they should be.. The problem is this.. my code to calculate the angle of rotation moved over the ellapsed time, and my code to calculate the new positions of each menuItem doesn't seem to work properly and I seem to get one item moving (but not quite far enough), another not moving at all and the last sails off into the distance.. Could anyone help me define a decent algorithm to make this work or maybe even help by advising a better method of handling the entire rotation per frame movement..?
Limitz
Limitz
How about an easy hack :)
well if the calculation of the new points is a problem, you could just use the exsisting locations. lets say you got 6 menuitems: item[6];
If you want to rotate right you'd need the new positions for the items. so, how's about:

point tmp = item[0].location;for (int i=0; i<len-1; i++){  item.next_location = item[i+1].location;}item[len-1].next_location = tmp;


and then interpolate from there. You could make a function that continuesly rotates all items untill it reaches the destination point.

void keepRotating(point x, int index){  if (item[index].location != item[index].next_location)  {    //this should give you the vector with rotation point 0,0    point offset = item[index].location - x;       //now you can simply rotate the pointover z-axis, or any other    //use a regular matrix rotation or whatever, drone function below    rotateZ(offset,0.01);    //add offset to x to get current location for item    item[index].location = x + offset;  }}

now continuesly call this function for all items.

I didn't actually test or compile this, so don't expect it to work, but it should give you an idea of how i would try to handle it.

EDIT:
note that this function only goes one way around :) You'd have ot modify it yourself. BTW. you should call the first function every time the -> key was pressed or whatever, and the 2nd one once per frame for each item (while you are in menu mode).

Hope it helps.
Greetings

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.