How to fix the camera trackball

Topics: Developer Forum
Feb 10, 2008 at 1:47 AM
Edited Feb 10, 2008 at 3:53 PM
May not be a problem for others, but the way the camera tracks seems odd to me. To see this, place the camera at Position=0,3,0, LookDirection=0,-1,0, and UpDirection=0,0,-1. This will place the camera 3 units up the Y axis, looking down the Y axis. Create some unit-length ScreenSpaceLines on the X,Y,Z axes to see what's happening.

Run your app; you'll see the X and Z axes, since you're looking down the Y axis. Place the cursor at the center, hold the mouse, and drag left or right. Instead of rotating the ScreenSpaceLines (or model or whatever you're viewing) about the Z axis, they rotate about the Y axis.

This is due to the way the ProjectToTrackball works, which assumes the camera is placed on the Z axis, looking at the origin. It doesn't take into account the camera's current position.

To change this, insert the following in the Track() method in the TrackballDecorator class, just after the line "double angle = ...":

// Get the viewport's camera.
Camera vpCamera = this.Viewport3D.Camera;

// Get the camera's current view matrix.
Matrix3D viewMatrix = MathUtils.GetViewMatrix(vpCamera);
viewMatrix.Invert();

// Transform the trackball rotation axis relative to the camera
// orientation.
axis = viewMatrix.Transform(axis);

Give it a whirl, and see if the trackball doesn't seem more natural.

Kary
Jun 22, 2009 at 8:44 PM

Thanks very much!  I too am using an ununsual camera position, and this makes the trackball work considerably better :)

Dec 16, 2010 at 11:56 PM

Why don't you upload the patch?

Jun 9, 2011 at 7:05 PM
Edited Jun 13, 2011 at 1:50 PM

I tried simply moving the camera angle and it messes up the entire 3D enviroment of meshes.

Anyone have any code to control the trackball zoom (out and in) via code without having to scroll out and in?

Anyone figure out how to move the trackball camera in the 3D environment (event driven 3D timeline movement)?

Nevermind this project has everything, I was looking for.

http://www.kindohm.com/archive/2007/04/14/animate-a-perspectivecamera-in-wpf.html