0

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

Anonymous 5 years ago 0
This discussion was imported from CodePlex

ezolotko wrote at 2013-08-02 04:28:

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?

ezolotko wrote at 2013-08-05 03:03:

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.

ezolotko wrote at 2013-08-06 04:03:

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.

Mrme wrote at 2013-08-06 10:09:

So , are there any changes to be submitted to the source code ?

ezolotko wrote at 2013-08-06 10:17:

@Mrme: no, I just used the library the other way to workaround my issue.

ShadesJeff wrote at 2013-09-24 23:02:

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.

objo wrote at 2013-09-25 08:59:

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.

objo wrote at 2013-09-26 22:40:

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.

ShadesJeff wrote at 2013-09-26 22:47:

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.

objo wrote at 2013-09-27 11:12:

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.

rinaldin wrote at 2013-10-03 22:14:

@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

rinaldin wrote at 2013-10-25 22:27:

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.

wangzh wrote at 2014-07-24 04:56:

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!

rinaldin wrote at 2014-07-24 19:46:

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.

wangzh wrote at 2014-07-25 02:42:

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

wangzh wrote at 2014-07-25 15:49:

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,