Orthographic Camera - Undesired Clipping on Zoom In (Near Plane Issues?)

Aug 2, 2013 at 2:28 AM
Hi,

Thank you for the great library.
I have successfully used the orthographic camera to display my scene, but with one problem:
when I zoom in my scene by moving the mouse wheel forward, I encounter the polygons clipping like it is shown in the picture:
Image

I tried to reduce the camera near plane distance, but with no noticeable effect. Here is my camera definition:
            Camera = new OrthographicCamera
            {
                LookDirection = new Vector3D(-398.987, -42.626, -19.482),
                UpDirection = new Vector3D(-0.049, -0.001, 0.999),
                Position = new Point3D(398.987, 42.626, 19.482),
                Width = 235,
            };
Am I doing anything wrong?
Aug 5, 2013 at 1:03 AM
Edited Aug 5, 2013 at 1:04 AM
My latest experiments showed that if I use "Zoom to mouse point" selection method, and there is a polygon under the mouse pointer, the issue seem to stop reproducing. I think this somehow may be related to use of GetNearestPoint method to calculate the camera target in this case, so the camera view matrix gets recalculated in more suitable way. Still have no exact thoughts how to fix the issue concisely.
Aug 6, 2013 at 2:03 AM
Finally, I ended up using CameraHelper.LookAt to position the camera and OrthographicCamera.Width to zoom - manually, it doesn't produce the effects the CameraController does.
Aug 6, 2013 at 8:09 AM
So , are there any changes to be submitted to the source code ?
Aug 6, 2013 at 8:17 AM
@Mrme: no, I just used the library the other way to workaround my issue.
Sep 24, 2013 at 9:02 PM
I can recreate this issue with the Camera example shipped with the toolkit. It happens with both zoom and rotation.

To reproduce, open the Camera demo, then switch to the Orthographic mode. Do some random zooming and rotating and you should be able to get it into a mode where the clipping is incorrect. In my trials, it seems that the incorrect clipping only affects the top and bottom regions, it does not appear to clip incorrectly on the left or right.

Sometimes the incorrect clipping is dynamic, e.g. the clipping line will move as you rotate the model whereas other times it is fixed.
Coordinator
Sep 25, 2013 at 6:59 AM
Did you try changing the NearPlaneDistance?
The near plane distance should not be changed when zooming or rotating.
Currently the near plane distance is copied when the user change from perspective to orthographic, maybe this code should be removed.
Coordinator
Sep 26, 2013 at 8:40 PM
The problem could also being related to the Position of the camera being too close to the model. The camera controller uses Position+LookDirection to define the target point that the camera rotates around. Maybe the problem is related to the length of LookDirection being changed when toggling between perspective and orthographic camera...
Set ShowCameraInfo = true on the HelixViewport3D to review the settings of the camera.
Sep 26, 2013 at 8:47 PM
Hi objo,

That's essentially was the problem - I had universally specified my look directions as unit vectors, when in fact they need to be scaled to world units in order for the view to function correctly. I still think there is an issue when changing between orthographic and perspective projections (field of view explodes), but I cannot reliably recreate it.
Coordinator
Sep 27, 2013 at 9:12 AM
In orthographic mode try to press "S" to move away from the target, or "W" to move closer.
Maybe zooming in orthographic mode should change the CameraPosition and LookDirection in the same way as for perspective camera.
Oct 3, 2013 at 8:14 PM
@objo and @ezolotko
so what's the solution? Pressing "S" in my case solved the problem, but I just want to prevent the clipping happening.
From this:
Finally, I ended up using CameraHelper.LookAt to position the camera and OrthographicCamera.Width to zoom - manually, it doesn't produce the effects the CameraController does.
How can I leave the default mouse control and ovverride the Zoom function? Sorry, but it is not clear to me.

Giovanni
Oct 25, 2013 at 8:27 PM
I finally solved changing the Helix source code in the file ZoomHandles.cs at line:
var newRelativePosition = relativePosition * (1 + delta);
changing it to:
var newRelativePosition = relativePosition * (1.1 + delta);
No more clipping and no need to use LookAt.
Jul 24, 2014 at 2:56 AM
Edited Jul 24, 2014 at 3:00 AM
rinaldin wrote:
I finally solved changing the Helix source code in the file ZoomHandles.cs at line:
var newRelativePosition = relativePosition * (1 + delta);
changing it to:
var newRelativePosition = relativePosition * (1.1 + delta);
No more clipping and no need to use LookAt.
rinaldin,

I have the same issue when I use the latest Helix version. I checked the source codes and didn't find the ZoomHandles.cs file. Only ZoomHandler.cs found. Is it same file? Also, I didn't find the code
var newRelativePosition = relativePosition * (1 + delta); 
in the file ZoomHandler.cs.


Any comment and suggestion to resolve the problem?


Thanks in advance!
Jul 24, 2014 at 5:46 PM
Yes, the file is ZoomHandler.cs, it was a typing mistake. Anyway, I noticed that in the later version of Helix Toolkit that code changes and it is written in a different way. I used the version helixtoolkit_f5a96293a071.
Jul 25, 2014 at 12:42 AM
Edited Jul 25, 2014 at 1:57 AM
rinaldin wrote:
Yes, the file is ZoomHandler.cs, it was a typing mistake. Anyway, I noticed that in the later version of Helix Toolkit that code changes and it is written in a different way. I used the version helixtoolkit_f5a96293a071.
rinaldin,

Thanks for your reply. I found the latest revision changed from:
 var newRelativePosition = relativePosition * (1 + delta);
 var newRelativeTarget = relativeTarget * (1 + delta);
to
 var f = Math.Pow(2.5, delta);
 var newRelativePosition = relativePosition * f;
 var newRelativeTarget = relativeTarget * f;
The latest version still has the same issue. It is a great library. However, I am stuck in this step. Since I am new in WPF, I am wondering if you could send me correct HelixToolkit.Wpf.dll to me it will be greatly appreciated.
my email: wangzh2000@yahoo.com
Jul 25, 2014 at 1:49 PM
Edited Jul 26, 2014 at 1:05 PM
I finally figured out the problem in other way as follows:
 public MainWindow()
        {
            InitializeComponent();
            resetZoom();
         }
Then write resetZoom()
private void resetZoom()
        {
            OrthographicCamera myOCamera = new OrthographicCamera(new Point3D(0, 0, 0), new Vector3D(100000, 100000, -100000), new Vector3D(0, 0, 1), 5000);
            ViewPort.Camera = myOCamera;
            
        }
Each time, when creating a model, using ZoomExtents() at the end of method, for instance:
double z1 = 0;
double h = 500;
        private void cylinder_Click(object sender, RoutedEventArgs e)
        {
            PipeVisual3D pipe = new PipeVisual3D();
            pipe.Point1 = new Point3D(0, 0, z1);
            pipe.Point2 = new Point3D(0, 0, z1+h);
            pipe.Material = Materials.LightGray;
            pipe.Diameter = 1200;
            pipe.InnerDiameter = 1180;
            z1 += h;
            SolidModels.Children.Add(pipe);
            ViewPort.ZoomExtents();
        }
I am a green bee in WPF and C#, any education and new simple way in the issue sharing will be greatly appreciated.

This WPF library package is great. Thanks objo for this work!!!


Cheers,