Jump to content
  • Advertisement
Sign in to follow this  
kelvindavies11

Simple cycle

This topic is 4526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

IM using the fllowing code to create a simple circle, which i intend to turn into a sphere. I knwo i could useing gluSphere however i fancy trying to do it this way. When i use the following code it gives me a syntax error on the '=', any idea why?? thanks, kelvin void cyclinder(void) { glBegin(GL_LINE_LOOP); for(int i=0;i<360;i++) { float xcoord = 1 * cos(i*2*PI/360); float ycoord = 1 * sin(i*2*PI/360); glVertex2f(xcoord,ycoord); } glEnd(); }

Share this post


Link to post
Share on other sites
Advertisement
i have amended the above code so it is simpler however im still getting the syntax error on the = sign. Any ideas?

void cyclinder(void)
{

glBegin(GL_LINE_LOOP);
for(int i=0;i<360;i++)
{
angle =2*PI*i/360;
glVertex3f(cos(angle),sin(angle), 1);
}

glEnd();

}

kind regards,
kelvin

Share this post


Link to post
Share on other sites
First of all it is a bad idea to define "float xcoord" and "float ycoord" in your for loop because the OS needs to alloc memory for those variables everytime again. This causes a strain on performance. Declare them before your for loop or make them static.

I am using vc++ and it gives no errors.

But try typecasting.

xcoord = (float) 1 * cos(i*2*PI/360);


hope it works.
^_^

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyEsser
I don't know much about C/C++ but isn't it supposed to be i==0?


No, "i = 0" is correct.

Quote:

First of all it is a bad idea to define "float xcoord" and "float ycoord" in your for loop because the OS needs to alloc memory for those variables everytime again. This causes a strain on performance.


Any modern compiler will move the space "allocation" outside the loop for you. But, more importantly, since the code does not even compile for the OP, this is hardly is biggest concern right now.

Share this post


Link to post
Share on other sites
the aove does compile now, however when im using the above code i draw a circle however it only draws a circle containing 8 sides not the 360 that i require for a smooth circular effect.

any ideas please,
kelvin

Share this post


Link to post
Share on other sites
What is happening is i/360 is interger division. Change the line

angle =2*PI*i/360;

to

angle =2.0*PI*(float)i/360.0;

Also make sure that the variable angle is a float.

I do not have a CPP compiler in front of me but the floating point division instead of integer division will at least push you in the right direction.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!