WPF, 3d camera won't rotate correctly
I'm trying to make my camera rotatable around the center point by holding
down the left button. Here's my code so far:
private void mouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta < 0) { _posZ = _posZ - 0.5; } else { _posZ = _posZ +
0.5; }
_perspectiveCamera.Position = new Point3D(_posX, _posY, _posZ);
}
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 ;
_posX = _posX - currentDelataX / 1000;
_posY = _posY - currentDelataY / 1000;
_perspectiveCamera.Position = new Point3D(_posX, _posY,
_posZ);
Point3D objectPosition = new Point3D(0, 0, 0);
_perspectiveCamera.LookDirection = new
Vector3D(objectPosition.X - _perspectiveCamera.Position.X,
objectPosition.Y - _perspectiveCamera.Position.Y,
objectPosition.Z - _perspectiveCamera.Position.Z);
}
}
/////////////////////////////////////////
if (e.LeftButton == MouseButtonState.Released)
{
isLeftDown = false;
}
}
Yet the rotation itself doesn't seem to work right, looks like the camera
moves far away by the Z axe ( object moves away from the viewer ).
What do you think might be wrong?
Thanks
No comments:
Post a Comment