View Full Version : Arcball rotation around viewport-center

12-27-2012, 01:08 AM
Hi guys,
I'm trying to write an arcball which rotates around the window center (z=0). Unfortunatly I also want to be able to move my objects with this arcball; i.e. rotate, translate scale.
My problem is that I can't figure out how to handle the rotation with the translation. Currently I'm doing this:

// Apply "arcball"-modifications to OpenGL.
GL.MultMatrix(ref rotationMatrix);
GL.Scale(this.scale, this.scale, this.scale);

Unforunatly the last translation which applies the arcball offset is affected by the rotation. I tried to transform it with the inverse of the rotation matrix but so I changed the rotation center...

If someone might be able to explain this to me it would be great!

I created a sample-project with OpenTK so if someone want's to checkout the full code: http://go4x.de/share/WindowsFormsApplication1.zip

Greetings - Thomas

Dark Photon
12-27-2012, 01:36 PM
Kinda looks like you need to separate the concepts of MODELING transform and VIEWING transform. MODELING transform positions objects in a shared world space, and VIEWING takes world space and re-positions them in eye-space. The OpenGL Programming Guide (red book) has an excellent description of this.

Figure out your MODELING transform for each object and set it aside. Then, determine where your eye is, which direction it is looking, and an up vector for that view -- that will generate your VIEWING transform. Combine them, and you're done. In other words, establish clearly how your trackball will modify the position and look direction of the eyepoint in world space.

Where is "WORLD SPACE" in your series of transformations?

12-28-2012, 11:47 PM
I think I don't have a modeling-transform at the moment. I just wan't transform the hole scene with my code.

In steps:
1. I want to translate the scene to a) the middle of the viewport and b) add the offset from the trackball.
2. I want the hole scene to rotate around the middle of the viewport.
3. Scale the scene.

I hope we're not on cross purposes.

Dark Photon
12-29-2012, 06:37 AM
Your statement is a little ambiguous. For instance, center of the viewport is whatever you make it.

I would encourage you to forget the transforms for a second and reformulate your thinking in terms of:

where is the eyepoint, and
which direction is it looking in.

The first is a point in world space. The second is a vector in world space.

Now, ask yourself what you want the trackball offset to "do" with these two values. Does this change where the eyepoint is located? How? Does it affect the direction the eye is looking in world space? How? Repeat for the other inputs like trackball rotation.

Now just pass your updated eyepoint and look direction to gluLookAt() (or your own hand-rolled version) to generate your viewing transform for you.

I'm guessing your arcball offset is intended to push the eyepoint away from the center of focus after rotation/etc. So if you keep your current transform calls instead of using something more friendly like gluLookAt then you'd want to put that translate first in the sequence, which causes it to conceptually be applied last.

01-03-2013, 12:52 AM
Ok, let's think in eyepoint and origin.
1. At the beginning (i.e. no arcball modifications) I want the origin to be located in: viewportwidth/2, viewportheight/2, 0. Eyepoint is origin but z-value > 0.
2. The offset of the arcball should translate eye and origin only in x-y-direction.
3. The rotation of the arcball should modify the eye, but not the origin.
Is this clear to you?

To your last sentence: If I put the translate first in sequence I change the rotation-center. But of course you're right about the concept.

EDIT: If you can compile my sample-project: There is almost everything correct; just the offset of the arcball is rotation-dependent.
EDIT2: I forgot to mention: I've found a site in this forum with the same problem (at least I think so). Unfortunatly the solution in this post doesn't work.

02-12-2013, 05:07 AM
Ok, I've found the error by myself.
The problem was I created the complete transformation-matrix on every render-process. With this the rotation changed also if I only changed the pan of the arcball (the rotation-center changed, i.e. the rotation became different).
After saving the the transformation after a rotation the behaviour was exactly like I wanted it to be.