Brief overview, you can image I'm drawing points of a 3D schematic onto a Canvas, think CAD.
I have points in 3D XYZ Vector3 coordinates, and I've got a model, view, projection matrix all setup. I've done this and produced OpenGL and Metal (Mac/iOS) views and they all work great.
I now just wanted to plot points on a 2D canvas (SkiaSharp) as another view representation but I've run into an issue I just can't wrap my head around.
First I did a plain Orthographic view of it and this worked fine.
I used Matrix4x4 CreateOrthographic
to do the Projection
matrix (https://learn.microsoft.com/en-us/dotnet/api/system.numerics.matrix4x4.createorthographic?view=net-8.0)
And I used CreateLookAt
for the View
matrix (https://learn.microsoft.com/en-us/dotnet/api/system.numerics.matrix4x4.createlookat?view=net-8.0)
The Camera is placed vertically above the single model center and looks down (position is Center.X, Center.Y, 10
for example and target Center.X, Center.Y, 0
with the camera Up as the unit Y vector.
This all looks fine in Orthographic.
So then I tried a Perspective projection matrix.
I used the CreatePerspectiveFieldOfView
(https://learn.microsoft.com/en-us/dotnet/api/system.numerics.matrix4x4.createperspectivefieldofview?view=net-8.0) - which I used with the data for OpenGL/Metal (and that looks exactly as expected), but the more manually created on in a Skia canvas just doesn't look right.
It still looks Orthographic???
Here's what I've tried and found....
1 - The view looks orthographic. When I rotate the model, I have a large flat grid in it, and the far edge of the grid is the same size on screen as the near edge of the grid .... so seemingly orthographic but its a 'perspective FOV matrix'.
2 - When I try and move the camera in the Z axis (either in the CreateLookAt
position or after the fact with a translation)....the view doesn't change at all. Again, something I could understand with an Orthographic view but not perspective FOV?
3 - The Aspect Ratio I input into the perspective stretches the view vertically or horizontally. I'm having to put in 1 (square) to get a non-stretched view (Red flag!)
4 - FOV doesn't appear to do much except scale the whole view (as you'd expect, it gets smaller/larger) - but still appearing orthographic?
Does anyone have any ideas as to why/what/how you might see this sort of affect? What could I have set up wrong or interpreted wrong to result in such an output? Is there a step I've missed that a GPU would do in OpenGL/Metal as to why these matrices appear fine when transforming vertices into a shader, but not when manually processing Vector3's and drawing onto Skia?