void Draw2DCircle( float x, float y, float z, float radius, int Segments, bool edgeOnly );
Where the user tells the function how many segments they want in the circle, the problem I'm unsure on how to solve is how i make sure each vertic is placed correctly based on the center origin of the circle as a switch statement is not possible due to not having a constant for the segments, same goes for if statements, I've got the displacement change that need to be applied to each vertex stored in variables, but i need to update each as i go around the circle... say i had a radius of 10 with 8 segments, the angle from the center would be 45 degrees, meaning that if my first vertex after the origin was straight above so coordinates ( -10, 0 ) respectivly x and y axis, the next vertex placement would be of displacement from the previous by roughly 7 units on the x-axis and roughly 3 on the y but the next vertex would be only 3 on the x but 7 on the y. any ideas how i would go about this without knowing the amount of segments the user wants? Code so far is as follows:
void CGfxOpenGL::Draw2DCircle( float x, float y, float z, float radius, int Segments, bool edgeOnly )
{
/* Init temp variables */
double Change_angle = 360 / Segments;
double SeparationValue = sqrt( (radius*radius) + (radius*radius) - ( 2 * 10 * 10 * sin(Change_angle) ) );
/* displacement variables */
double Tx, Ty;
float Nx, Ny;
Tx = radius * sin((double)Change_angle);
Ty = radius * cos((double)Change_angle);
Nx = (float)Tx;
Ny = radius - (float)Ty;
glBegin( GL_TRIANGLE_FAN );
glVertex3f( x, y, z ); // Plot center point
for( int segs = 0; segs < Segments; segs++ )
{
/* plot vertices based on current segment */
}
glEnd();
}

New Topic/Question
Reply




MultiQuote



|