0

I would like to reposition a circle, triangles, lines and an arc. How do I go about it? I've searched the web for solutions but nothing that address the issue specifically.

Any input that will lead me in the right direction will be helpful.

I'm using C++ with opengl.

genpfault
  • 51,148
  • 11
  • 85
  • 139
ck22
  • 41
  • 8

2 Answers2

2

Search for the function glTranslatef

As a side note, you might want to look at glRotatef and glScalef also. If you know nothing about translation, look for translation matrix, first learn it in 2D and then in 3D.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
0

I would like to reposition a circle, triangles, lines and an arc.

So you already did draw the scene and now want to change the position of the objects?

Well then, all you need to understand is, that OpenGL doesn't maintain a scene graph of sorts. After submitting a draw call, things get only updates on the target framebuffer and that's it. You want to change something? Clear the screen, redraw everything, but now with the adjustments applied.

Really, OpenGL just draws things, it's nothing more than sophisticated brushes (textures) and pencils (primitives) for some paper offered by the operating system (viewport/window).

EDIT due to comment

The usual interactive OpenGL graphics program with animations, programmed in a imperative programming language, is structured like this (pseudocode)

float T = 0
float alpha = 0, beta = 0
float red = 0, green = 0, blue = 0

paused = false

on_mousemove(mousemove):
    alpha += mousemove.rel_x
    beta  += mousemove.rel_y

on_keypress(keypress):
    switch keypress.key:
        case Key_ESCAPE:
            queue_event(Quit)
            return

        case Key_PAUSE:
            paused = not paused

        case Key_R:
            red += 0.1
        case Key_r:
            red -= 0.1

        case Key_G:
            green += 0.1
        case Key_g:
            green -= 0.1

        case Key_B:
            blue += 0.1
        case Key_b:
            blue -= 0.1

    queue_event(Redraw)

render()
    glViewport(0, 0, window.width, window.height)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    apply_projection()

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    apply_modelview()

    glColor3f(red, green, blue)
    glRotatef(T * x_revolutions_per_second_factor, 1, 0, 0)
    glRotatef(alpha, 0, 1, 0)
    glRotate(beta, 0, 0, 1)

    draw_object()

    SwapBuffers()

main:
    initialize_libraries()
    load_resources()
    create_window_and_OpenGL_context()

    previous_loop = get_time()

    loop 'eventloop':
        event = peek_event()
        switch event.type:
            case MouseMove:
                on_mousemove(event.mousemove)

            case KeyPress:
                on_keypress(event.keypress)

            case Quit:
                break 'eventloop'

            case Redraw:
                render()
                break

            case NoEvents:
                fallthrough
            default:
                if not paused
                    render()

        current_loop = get_time()
        if not paused:
            T += current_loop - previous_loop
        previous_loop = current_loop
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • I don't think I am not drawing a scene. I am just drawing simple shapes like the triangle and circle and trying to reposition them. So far, I have not used a drawScene function. The code examples I have seen so far for a scene function has the objects are created inside the drawScence function. I have been able to reposition the arc. I used a combination of glTransletf, glRotatef and tweaking the equation for the arc. I readjusted vertex values for the triangle but that is not working. I keep readjusting the vertexes so I can get the right position. Is there a concept I am missing? – ck22 Oct 19 '11 at 14:10
  • datenwolf, you are right. I've been doing some reading and researching and what I'm doing is drawing a scence. I researching on how to revise my code to include the scene function. Thanks for pointing me in the right direction. Still working on it. – ck22 Oct 19 '11 at 14:52
  • Everything is making sense to me now. Will go and work on the project again. Thanks so much. – ck22 Oct 20 '11 at 15:55
  • @Antoinette: Don't forget to accept the answer of your choice. – datenwolf Oct 20 '11 at 16:09