• 11
• 9
• 10
• 9
• 11

Object moving with camera.

This topic is 815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I was planning to make a small room using the same vertices.

    2.0f ,0.0f, -2.0f,        2.0f,2.0f,
-2.0f,0.0f,-2.0f,        0.0f,2.0f,
-2.0f,0.0f, 2.0f,        0.0f,0.0f,
2.0f, 0.0f, 2.0f,        2.0f,0.0f
GLuint indices[] = {
0,1,3,
1,2,3
};

the first 3 coordinates is for the vertices and the 2 other are for the texture

I manage to put a floor but when I tried putting a wall this where I got stuck with

    model = glm::mat4();

glm::vec3 wallPos(0.0f, 0.0f, -2.0f);
model = glm::translate(model, wallPos);
model = glm::rotate(model, -90.0f, glm::vec3(1.0f, 0.0f, 0.0f));
projection = glm::perspective(45.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);
glBindVertexArray(buffer.VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);

What I am trying to do is use the same vertices on making the floor to also making the wall. Basically I am making a big cube but with parts that is kind of like detachable. I tried rotating it first and then translate still having the same issue. Whats confusing as well is that the floor doesnt move when I move my camera yet the wall just kept on following my camera. Since the vertices of the wall is exactly the same with the floor, I dont understand why is the floor not moving yet the wall is moving. Here is the code of floor

         view = camera.look();
projection = glm::perspective(45.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 100.0f);
glBindVertexArray(buffer.VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);

You can see they are pretty much the same. And I am using a basic shader. Really basic one.

gl_Position = projection * view * model * vec4(position, 1.0f);

What is going on here? Thanks

Edited by LetsDoThis

Very intresting

Got any idea?

Share on other sites

Got it. I forgot to enable depth buffer.

What is happening is that it may look like that the wall is moving with my camera but what actually is going on is that I am seeing the bottom part of the wall and that the floor is being overwritten by wall.

Edited by LetsDoThis