Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have drawn a 2D circle in X,Y,Z. I wanted to draw something on specific vertices of that circle and I managed to do it. When I wanted to move the circle, I wanted the vertices to get the updated position, so I created another array of vertices and calculated the new vertex positions.

Now I want to rotate the circle, and while rotating it, the vertices should get the new orientation. How can I do this?

void creature::drawCircle(Vec3f Pos,float radius, int segments )

    // automatically determine the number of segments from the circumference
    if( segments <= 0 ) {
        segments = (int)math<double>::floor( radius * M_PI * 2 );
    if( segments < 2 ) segments = 2;

    GLfloat *verts = new float[(segments+2)*3];
    GLfloat *vertsNew = new float[(segments+2)*3];
    verts[0] = 0;
    verts[1] = 0;
    verts[2] = 0;
    vertsNew[0] = 0;
    vertsNew[1] = 0;
    vertsNew[2] = 0;

    //Create circle
    for( int s = 0; s <= segments; s++ ) {
        float t = s / (float)segments * 2.0f * 3.14159f;
        verts[(s+1)*3+0] = math<float>::cos( t ) * radius;
        verts[(s+1)*3+1] = math<float>::sin( t ) * radius;
        verts[(s+1)*3+2] = 0;

    //Transform points
    for( int s = 0; s <= segments; s++ ) {
    ci::Vec3f  m_newCirclePos;
        m_newCirclePos.x = verts[(s+1)*3+0];
        m_newCirclePos.y = verts[(s+1)*3+1];
        m_newCirclePos.z = verts[(s+1)*3+2];
        m_newCirclePos += ci::Vec3f(Pos);

        vertsNew[(s+1)*3+0] = m_newCirclePos.x;
        vertsNew[(s+1)*3+1] = m_newCirclePos.y;
        vertsNew[(s+1)*3+2] = 0;


    // Attach tentacles on specific vertices
    for (int i=0; i<m_tentacle.size(); i++)
        m_tentacle[i]->m_Nodes[0].x = vertsNew[(i+1)*3+0];
        m_tentacle[i]->m_Nodes[0].y = vertsNew[(i+1)*3+1];
        m_tentacle[i]->m_Nodes[0].z = vertsNew[(i+1)*3+2];
    glEnableClientState( GL_VERTEX_ARRAY );
    glVertexPointer( 3, GL_FLOAT, 0, vertsNew );
    glDrawArrays( GL_POINTS, 0, segments + 2 );
    glDisableClientState( GL_VERTEX_ARRAY );
    delete [] verts;
    delete [] vertsNew;
share|improve this question
-1 what have you tried already and why didn't it work? – Byte56 Apr 20 '12 at 14:10
up vote 5 down vote accepted

To do this you should be using a scene graph. Basically, the objects you want to attach to the circle can be seen as child objects and should therefore inherit their position and orientation from their parent, the circle.

Also, you should really be putting the circle into a vertex buffer and leaving it there. You shouldn't reconstruct the vertex buffer every time you want to draw it, just transform the existing one using a transformation matrix.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.