Original Post
Hello, I am a newbie. Please help me draw the following using opengl (C/C++) 1) Circle 2) Archimedian .. Thank You
#include <math.h>#define MATH_PI 3.141593F#define NUM_POINTS 100void RenderCircle(){ glBegin(GL_LINE_LOOP); for(int i = 0; i < NUM_POINTS; "increment i") { float angle = 2 * MATH_PI * i / NUM_POINTS; glVertex3d(cos(angle), sin(angle), 0.0); } glEnd();}Quote:
Original post by bitshifter
To render a circle:
*** Source Snippet Removed ***
I couldn't get the 'plus' symbol into this page so i put "increment i" instead.
#include <cmath>const int numPoints = 360;const float pi = 3.141593f;void renderCircle(float posx, float posy, float radius) { glBegin(GL_LINE_LOOP); for (int i = 0; i != numPoints; ++i) { float angle = 2 * pi * i / static_cast<float>(numPoints); glVertex2f(posx + radius * cosf(angle), posy + radius * sinf(angle)); } glEnd();}#include <cmath>const int numPoints = 360;const float pi = 3.141593f;void renderSpiral(float posx, float posy, float rotations, float startRadius, float endRadius) { glBegin(GL_LINE_LOOP); for (int i = 0; i != numPoints; ++i) { float angle = 2 * pi * rotations * i / static_cast<float>(numPoints); float radius = startRadius + (endRadius - startRadius) * i / static_cast<float>(numPoints); glVertex2f(posx + radius * cosf(angle), posy + radius * sinf(angle)); } glEnd();}This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more