EDIT
Oh, and one more thing, longtitute works great, but when lattitute reached about 1.57 it flips over...
EDIT WORKS!
oh, only the rotation speed starts to build up when it makes more the one turn. guess have to reset the tempMouse after each rotation.
private void mouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta < 0) { distance = distance - 0.5; } else { distance = distance + 0.5; }
Point3D position = new Point3D
(
Math.Cos(longitude) * Math.Cos(latitude) * distance,
Math.Sin(latitude) * distance,
Math.Sin(longitude) * Math.Cos(latitude) * distance
);
_perspectiveCamera.Position = position;
}
private void mouseMove(object sender, MouseEventArgs e)
{
if ( e.LeftButton == MouseButtonState.Pressed )
{
if (isLeftDown == false)
{
isLeftDown = true;
tempMouseX = this.PointToScreen(Mouse.GetPosition(this)).X;
tempMouseY = this.PointToScreen(Mouse.GetPosition(this)).Y;
}
else
{
double currentDelataX = tempMouseX - this.PointToScreen(Mouse.GetPosition(this)).X;
double currentDelataY = tempMouseY - this.PointToScreen(Mouse.GetPosition(this)).Y;
longitude = longitude - currentDelataX / 5000;
latitude = latitude - currentDelataY / 5000;
Point3D objectPosition = new Point3D(0, 0, 0);
Point3D position = new Point3D
(
Math.Cos(longitude) * Math.Cos(latitude) * distance,
Math.Sin(latitude) * distance,
Math.Sin(longitude) * Math.Cos(latitude) * distance
);
_perspectiveCamera.Position = position;
Vector3D lookDirection = objectPosition - position;
_perspectiveCamera.LookDirection = lookDirection;
}
}
/////////////////////////////////////////
if (e.LeftButton == MouseButtonState.Released)
{
isLeftDown = false;
}
}
I think you want to move the camera on a sphere, rather than a plane as you are doing now.
Rather than storing the position of the camera in Euclidean coordinates, store it in spherical coordinates.
double distance;
double latitude;
double longitude;
In the mouse wheel handler, simply increase/decrease distance
.
In the mouse move handler, adjust latitude
proportional to the Y delta (you might want to limit it to +/-pi/2, so that you don't overshoot the poles), and longitude
proportional to the X delta.
To calculate your position, use something like this:
Point3D position = new Point3D
(
Math.Cos(longitude) * Math.Cos(latitude) * distance,
Math.Sin(latitude) * distance,
Math.Sin(longitude) * Math.Cos(latitude) * distance
);
// This line is just a simplified version of your LookDirection calculation
Vector3D lookDirection = objectPosition - position;