Reputation: 83
I am plotting a 2D-graph using OpenTK. I am zooming in by changing the fovy value in Projection matrix depending OnMouseWheel
event. The zooming works fine but it is limited by fovy >0 . I need to zoom in more to see more details on the graph. Is there a better way for zooming in which isn't limited by any number?
private void OnRenderFrame()
{
Matrix4 view, projection;
projection = Matrix4.CreatePerspectiveFieldOfView(((float)fov * (float)Math.PI) /(float)180, (float)Width / (float)Height, 0.01f, 100f);
view = Matrix4.LookAt(CameraPos,
CameraPos + CameraFront, CameraUp);
shader.Use();
shader.SetMatrix4("model", Matrix4.Identity);
shader.SetMatrix4("view", view);
shader.SetMatrix4("projection", projection);
SwapBuffers();
base.OnRenderFrame(e);
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
if (fov > 90.0f)
{
fov = 90.0f;
}
else if (fov <5.0f)
{
fov = 5.0f;
}
else
{
fov -= e.DeltaPrecise;
}
base.OnMouseWheel(e);
}
Upvotes: 1
Views: 1205
Reputation: 210878
The zooming works fine but it is limited by fovy > 0
Of course the perspective projection defines a Viewing frustum. If fovy == 0 then the viewing volume is 0, that makes not any sens at all.
At perspective projection the size of an object decreases by the distance to the point of view. Thus it is possible to "zoom" and object by the distance to the camera respectively shifting the camera along the line of sight.
The line of sight is the front vector of the camera (CameraFront
).
Upvotes: 3