Hello,
So I have more of a best practice question that I am wondering what is the best approach for.
I have a working virtual "camera" for OpenGL that builds the correct view and projection matrices for upload into OpenGL.
Let's represent that with the psuedo-function UpdateCamera(). This camera is inside a class OpenGLCamera which also has another function to set whether we want to display a perspective view or orthogonal view. Let's call this function SwitchView() and the flag isPerspectiveOn.
Now, inside the update camera function, I have code that looks something like this:
void OpenGLCamera::UpdateCamera() {
/*
Calculate position, direction, determine rotation, etc.
View Matrix is built.
*/
if (isPerspectiveOn == true)
{
ProjectionMatrix = glm::perspective(FieldOfView, AspectRatio, NearPlane, FarPlane);
} else {
Projection = glm::ortho(CurrentOrthoParameters.LeftPlane, CurrentOrthoParameters.RightPlane,
CurrentOrthoParameters.BottomPlane, CurrentOrthoParameters.TopPlane);
}
ProjectionViewMatrix = ProjectionMatrix * ViewMatrix;
}
What I am wondering is if there is a way to simply switch which projection function I am using without needing to perform if/else test all of the time?
In other words, perhaps a way to set the isPerspectiveOn flag somewhere else and with a change in how I write the code I don't have to perform this test with every loop or per frame.
I feel it may seem trivial but the least amount of testing I am doing per frame the better.
Thank you for your time and if I need to clarify further let me know.