PDA

View Full Version : Spirals in OpenGL for Java



homer_j_simpson
02-26-2003, 01:28 AM
I'm a beginner in OpenGL. I have created a circle though I am having trouble creating a spiral. I've been told all I have to do is change my radius each time though I'm not sure what exactly to do with my code. Any help would be appreciated!

fringe
02-26-2003, 01:46 AM
Hi,

So a spiral should be envisaged as a circle but as you go round you make the radius smaller (as you said). Just draw it on the paper an look. So imagine your code looks like this for a circle:

glBegin(GL_LINES); <_or whatever it is for lines
float r=1;
for (int segments=0;segments<maxseg;segments++)
{
float angle = segments/maxsegg;
glVertex3f(r*cos(angle),r*sin(angle),0);
}
glEnd();

This gives you one complete circle with r as the radius. Now if we want to make a spiral makesure each loop we decrease the radius,either geometricaly (r*=0.9 ;) or arithmetically (r-=0.1 ;) in the loop.
This is almost enough to complete out spiral. But it still only goes round once it is just a defromed circle to make it loop more than once increase the loop variable maximum by n the number of times you want it to go round so. A spiral that gradually tightens and goes round 50 times with 20 segments in each loop looks like:


glBegin(GL_LINES); <_or whatever it is for lines
float r=1;
int maxseg=20;
for (int segments=0;segemnts<maxseg*50;segments++)
{
float angle = segments/maxsegg;
glVertex3f(r*cos(angle),r*sin(angle),0);
r*=0.9;
}
glEnd();

Sorry it is not in Java but it probably still makes sence.
hope this helps,

fringge

P.S. I am doing this from work where I can not test my code anbd I am still learning how to do OpengGL

[This message has been edited by fringe (edited 02-26-2003).]