Advertisement

describing a circle, help

Started by June 08, 2003 09:37 AM
5 comments, last by leggyguy 21 years, 8 months ago
Hi. My latest project I have a group of square polys (seperate, each on a simple poly, holding a picture textured upon it) which must be deloployed in a circle. These will be selectable icons later on, so I will basically have a circle of clickable icons. the circle has a radius of 20.0f. I have a function which draws a square. It takes 2 floats as the x and y position (z will always be -80.0f for this purpose). my first poly then will be drawn at 0.0f, 20.0f, -80.0f; The function above would be passed (0.0f, 20.0f) the poly describing the bottom of the circle (if I have a total of 8 polys, then this would be the 5th poly, 1st poly at 12 oclock position, 3rd at 3 oclock position, 5th at 6 oclock, 7th at 9 oclock) will be at 0.0f, -20.0f, -80.0f. So the square drawing function would be passed (0.0f, -20.0f) I need to come up with an algorithm to place each other poly involved in this circle. Just so you know, each poly will be a selectable item later, each item representing a peice of the player''s equipment. I need to alter the algorithm later to reflect that the number of polys may be higher than, or lower than, 8. This is something I should be able to come up with myself, but I am working this lovely Sunday afternoon and think you guys should come up with my solution so I don''t have to think about it.
LOL. Don''t have any ideas, but I like the way u think that it''s a sunday, and someone else must think for u. hahahah!!!!
cheers
---------------Gaming is Life---------------
Advertisement


step =  360 / number of icons;glRotatef(-step, 0.0f, 0.0f, 1.0f);while(not out of icons);     glRotatef(step, 0.0f, 0.0f, 1.0f);     glTranslatef(radius, 0.0f, 0.0f);     glDrawYourIcon();     glTranslatef(-radius, 0.0f, 0.0f);repeatPrint("Yay, I did it"); 


(fixed some command missplellings, and switched step)

[edited by - dede on June 8, 2003 1:27:32 PM]
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
i'd make something similar, but with less gl functions:

step = 360/number_of_icons;

for(int i=1;i<=number_of_icons){
x=radius*cos(step*i);
y=radius*sin(step*i);

gltranslatef(x,y,0.0f);
drawicon(i);
glloadidentity() ; //should put back to 0.0 0.0 0.0 (right?)
}


p.s. in this way icons are drawed in counterclockwise order..i don't want to think how to do clockwise order, it should be some "-" sign somewhere




There aren''t problems that can''t be solved with a gun...

[edited by - Thor82 on June 8, 2003 12:46:19 PM]
There aren''t problems that can''t be solved with a gun...
hehe, Thor82 , good job, but I'd format it like this to get it to work...
glPushMatrix();        step = 2*M_PI/number_of_icons;for(int i=0; i < number_of_icons; i++ ){      glLoadIdentity();      x=radius*cos(step*i);      y=radius*sin(step*i);      gltranslatef(x,y,0.0f);      drawicon(i);}glPopMatrix()          

(corrected using ThunderHawk's Suggestions)
[edited by - dede on June 8, 2003 1:33:24 PM]


[edited by - dede on June 8, 2003 2:09:11 PM]

[edited by - dede on June 8, 2003 2:09:53 PM]
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
quote:
Original post by Thor82
step = 360/number_of_icons;

for(int i=1;i<=number_of_icons){
x=radius*cos(step*i);
y=radius*sin(step*i);

gltranslatef(x,y,0.0f);
drawicon(i);
glloadidentity() ; //should put back to 0.0 0.0 0.0 (right?)
}



I can tell you right now before really delving into your code that the first line there should read:

float step = 2*Pi/number_of_icons;
(Pi is implemented in my compiler as M_PI)

...and the reason is obviously that the standard trig functions use radians.

[EDIT] You also forgot the increment in your for statement. He's also got a function to draw the icon given coords, but your code should make things obvious anyways.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________


[edited by - Thunder_Hawk on June 8, 2003 1:41:25 PM]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Advertisement
well...something similar



There aren''''t problems that can''''t be solved with a gun...
There aren''t problems that can''t be solved with a gun...

This topic is closed to new replies.

Advertisement