0

Loaded objects flip upside down when zooming

Anonymous 10 years ago 0
This discussion was imported from CodePlex

Elementu wrote at 2012-02-22 15:53:

Hello.

 

I have several helix controls in my application. Some of them are froze to give the feeling of a 2D display than cannot be rotated.

The one that is not froze uses a perspective camera and the other 2D use Orthographic Camera.

The problem that I'm facing is that when I zoom into the 2D controls my objects flip upside down. this can be seen also on the view cube the view changes, however even if I bring the view(guiding myself after the view cube) as it was before the objects are still upside down.

However if I reset the camera the objects will be in the correct position.

Is there a way to prevent this behavior and stop it from happening?

 

Thank you in advance.


elementu wrote at 2012-02-23 11:07:

Hello,

What I discovered in my investigation is that in the CameraContoller.cs(HelixToolkit.Wpf.CameraController) in the OnTimeStep method at the point were the this.ZoomHandler.Zoom method is called, when the "this.zoomSpeed * time" parameter has a large value this bug will occur. In fact this bug occurred especially if I ran my application a slower machine. If I ran it on my main machine the bug only occurred if I added a thread.sleep of 500 or 1000 before calling the Zoom method.

So from the Zoom method the delta parameter is passed further in the ChangeCameraWidth method because my camera is an OrthographicCamera one.

Finally in the ChangeCameraWidth method to prevent the delta parameter from having a value that is too large  if the absolute value of the parameter is larger that 1 ( Math.Abs(delta) >= 1 ) then delta will take the value "delta = delta % 1" .

Having done this even if I add the delay or run the application on a slower machine the bug is not reproduced anymore.

I noticed that in the ChangeCameraPosition method that is called from the Zoom method in case my camera is a PerspectiveCamera not an OrthographicCamera there is a section of code with similar functionality to limit the value of the delta parameter.

if (delta < -0.5)
{
      delta = -0.5;
}

On a first look the behavior seems the same as before and everything looks all right with the change, except the bug that does not occur anymore.

What I want to ask you is what could be the implications of the change(the limitation of the delta value) I made, what is the case or were could it have a negative effect on the behavior or performance of the HelixToolkit ?

 

Thank you.


objo wrote at 2012-03-10 15:41:

thanks for debugging this! I added the clamping on the delta value as you suggested (change set c213bd42d8f7), and this seems to correct the problem. It limits the maximum zoom-out speed, but 50% zoom out per zoom event should be sufficient, I think.


stfx wrote at 2012-05-21 00:05:

Nice fix - btw this also occured on a perspective camera but yea fixed after that commit.

Another problem related to zooming is that if you zoom in too far (as far as you can) the camera will start to wobble at the end).

Fixed it by modifying the CameraHelfer.LookAt function like this:

 

        public static void LookAt(
            PerspectiveCamera camera, Point3D target, Vector3D newLookDirection, double animationTime)
        {
            Point3D newPosition = target - newLookDirection;

            // prevent zooming in until camera gets wobbly due to precision loss
            if (Math.Abs(newPosition.Z) > 0.01)
            {
                AnimateTo(camera, newPosition, newLookDirection, camera.UpDirection, animationTime);
            }
        }
EDIT: This fix is definately not correct