Trackball / arcball in OpenGL 4

Standard

Is there any reason why the OpenGL’s arcball / trackball implementation based on this Wikibooks entry rotates the object itself rather than the virtual camera? Or is it just a sample of one of the implementations?

I prefer rotation of the camera itself, but that depends on the needs. Here’s a sample video of trackball rotating the camera (left) and the object (right)

If you’re interested with quick and dirty trackball implementation, you can use my codes over here: https://github.com/subokita/Arcball/tree/master/Arcball. Below is the example on how to use the class.

/* Instantiation */
static Arcball arcball( WINDOW_WIDTH, WINDOW_HEIGHT, 1.5f, true, true );

...
/* In GLFW callbacks */
void mouseButtonCallback( GLFWwindow * window, int button, int action, int mods ){
    /* Pass the arguments to our arcball object */
    arcball.mouseButtonCallback( window, button, action, mods );
}

void cursorCallback( GLFWwindow *window, double x, double y ) {
    /* Pass the arguments to our arcball object */
    arcball.cursorCallback( window, x, y );
}

...

/* Creating rotation matrices */
glm::mat4 rotated_view = view * arcball.createViewRotationMatrix();
glm::mat4 rotated_model = model * arcball.createModelRotationMatrix( view );

Advertisements

5 thoughts on “Trackball / arcball in OpenGL 4

  1. Olivier

    hello, your job is awesome, i tried to use your code,but a have a problem .
    i’m using freeglut.
    so when i try to move my camera(or model), it moves only when i hold off the left button of my mouse.
    (sorry for my english i’m from french).
    do you have an idea of how i can fix that ?
    thank you

    • Thanks Olivier, but sadly I have never tried freeglut. So I don’t really know how to deal with this issue.

      Maybe you could post the question on stack overflow, I guess it’s more of the problem of the event handling (onMouseEvent?) on freeglut.

  2. joobei

    Just a comment for people who might come across this. The title says Arcball/Trackball but this is NOT the standard trackball algorithm described by Michael Chen in his “A study in interactive 3-D rotation using 2-D control devices” paper.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s