Using two different views okay like this?

#1

I am trying to find out if the following C++ code that I wrote is acceptable because it uses two different views (of the same variable) but seems to be working fine. The first code segment rotates the terrain. The second code segment centers a rolling ball.

    glm::mat4 model = { {1, 0, 0, 0}, { 0,1,0,0 }, { 0,0,1,0 }, { 0,0,0,1 } };
    glm::mat4 view = { {1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1} };
    model = glm::translate(model, glm::vec3(-19.5f, 0.0f, -19.5f));
    view = c_mycamera.GetViewMatrix();

second segment:

    glm::mat4 ball1 = { {1, 0, 0, 0}, { 0,1,0,0 }, { 0,0,1,0 }, { 0,0,0,1 } };
    glm::mat4 ball = { {1, 0, 0, 0}, { 0,1,0,0 }, { 0,0,1,0 }, { 0,0,0,1 } };
    ball = glm::translate(ball, glm::vec3(0.0f, -0.85f, -6.3f));
    ball = glm::rotate(ball, (float)glfwGetTime(), glm::vec3(-1.0f, 0.0f, 0.0f));
    ball = glm::scale(ball, scale);
    ball1 = glm::translate(ball, glm::vec3(0.0f, 0.0f, 2.5f));
    view = glm::inverse(ball)  *ball1;

here’s a link to it’s video however the rotate might not be centered!

https://youtu.be/Fe08NHlTW6Y

Thanks in advance,
Josheir

#2

Hard site to get a question answered. Here’s my conclusion:

The terrain view is projected and then the next view is projected on the same display by the nature of it.

#3

I think the main reason you didn’t get a response here is that your question wasn’t very clear. And it wasn’t obvious how it pertained to OpenGL.

Are you talking about the viewing transforms stored in the view variable? Also, “acceptable” how? It’s your variable, so you can do whatever you want with it. You don’t really show or say what you’re using both of the view matrix values for in your code (if you are even using both), so we can’t comment on that.

Now, If you’re asking whether there ever might be some utility in using two viewing transforms to render pieces of the same scene to the same viewport, yes. But it’s not the common case, and probably not what you want here. Typically you want to show the entire scene from a consistent viewpoint so that it makes visual sense to the user.

1 Like