   Attempting to draw a circle
  Okay, it works in my head, but not on the screen.I'm basically attempting to use the first half of a sin wave to get the y values for the circle.Not working so well. I keep getting lines drawn straight across the circle, and, apart from that, if I go more than 10 vertices, I basically get a sine wave that goes for a few periods.I also have a feeling that there are many things wrong with this code that I can't see, and that there is a much better way to draw a circle./** * Draw a joint (2 circles drawn at the same point with a 90 degree rotation difference) * \param p The point to draw the joint at */void drawJoint(const util::CVector3d& p) const{int num_pts = 10;util::CVector3d mesh[10];// create the mesh for drawing a jointcreateJointMesh(mesh, 2.0f);// draw the jointfor(int i=0; i < num_pts; i++)// because the starting point of both half-circles start at the right, and we are// drawing lines between i and i+1, we'll eventually get to i where mesh is at// the left of the circle and mesh[i+1] is at the right. So, this is to stop// drawing a line across the circle.if( !(i == (num_pts/2)-1) )m_sceneManager->getVideoDriver()->draw3dLine( mesh, mesh[i+1] );}/** * Using sine, create the points to draw the joint. * \param mesh A pointer to the mesh of CVector3d objects for the object points. * \param radius The radius of the circle. */void createJointMesh(util::CVector3d* mesh, float radius) const{int num_pts =10;float pts[10];float temp = PI / (radius*2);float s = 0.0f;// create the points of half a circlefor(int i=0; i < num_pts; i++){pts = sin( s );s += temp;// advance through the x interval for the circle}// create the 3d points, 10 for the circle with radius 'radius'// the top of the circlefor(i=0; i < num_pts/2; i++)mesh.y = pts;// the bottom of the circlefor(i=num_pts/2; i < num_pts; i++)mesh.y = -pts[i-(num_pts/2)];// set x values for the top part of the circlemesh[0].x = -radius;for(i=1; i < num_pts/2; i++)mesh.x = mesh[i-1].x + temp;// bottom half of circlemesh[num_pts/2].x = -radius;for(i=(num_pts/2)+1; i < num_pts; i++)mesh.x = mesh[i-(num_pts/2)-1].x + temp;}
  That's because you are drawing a sine wave - each of the vertices in your mesh has a linear x-coordinate and a sinusoidal y-coordinate.  The parameterization of a circle with center (x0, y0) and radius isx(θ) = x0 + r * cos(θ)y(θ) = y0 + r * sin(θ)for 0 <= θ <= 2 * pi.  So, you should have something likevoid createJointMesh(util::CVector3d* mesh, float radius) const{const int num_pts =10;float pts[num_pts];float deltaTheta = 2.0f * PI / num_pts;float theta = 0.0f;// create the points of half a circlefor(int i=0; i < num_pts; i++, theta += deltaTheta){mesh.x = radius * cos(theta);mesh.y = radius * sin(theta);}}You really don't need to optimize this by calculating the trig values for a quarter circle and using a lookup-table, especially not for a 10-point circle.  In today's modern computers, trig calls are practically just as fast as a table lookup (and for really large tables, the trig call can even be much faster).   ;  I knew I had forgotten some math that would have made this much easier.Thanks.   