0

this is my CAMERA class which makes viewMat uniform var in vertexshader.

struct CAMERA {
    glm::vec3 EYE{ 0.0f,0.0f,150.0f };
    glm::vec3 AT{ 0.0f,0.0f,0.0f };
    glm::vec3 UP{ 0.0f,1.0f,0.0f };
    glm::vec3 Dir() { return glm::normalize(this->EYE - this->AT); }
    glm::vec3 Right() { return glm::normalize(glm::cross(this->UP, this->Dir())); }
    glm::vec3 Up() { return glm::normalize(glm::cross(this->Dir(), this->Right())); }
    glm::mat4 view_M() {
        glm::vec3 cameraDirection = glm::normalize(this->EYE - this->AT);
        glm::vec3 cameraRight = glm::normalize(glm::cross(this->UP, cameraDirection));
        glm::vec3 cameraUp = glm::normalize(glm::cross(cameraDirection, cameraRight));
        return glm::lookAt(this->EYE, cameraDirection, cameraUp);
    }
}camera;

and I want to make camera-movement go up down right left. I think this will be work.. but this code works not like I expect..

// go up
glm::vec3 t{ camera.Up() };
camera.EYE = glm::translate(glm::mat4(1.0f), t) * glm::vec4(camera.EYE,1.0f);
camera.AT = glm::translate(glm::mat4(1.0f), t) * glm::vec4(camera.AT, 1.0f);

enter image description here enter image description here

this is what I expected.. camera go up and objects are seem go down.. red dot is not real obj.

How can I make camera movement with (CAMERA)camera struct?

        if (up) {
            glm::mat4 R = glm::rotate(glm::mat4(1.0f), glm::radians(-degree), camera.Right());
            camera.EYE = glm::vec3(R * glm::vec4(camera.EYE, 1.0f));
            camera.UP = glm::vec3(R * glm::vec4(camera.UP, 1.0f));
        }
        if (down) {
            glm::mat4 R = glm::rotate(glm::mat4(1.0f), glm::radians(degree), camera.Right());
            camera.EYE = glm::vec3(R * glm::vec4(camera.EYE, 1.0f));
            camera.UP = glm::vec3(R * glm::vec4(camera.UP, 1.0f));
        }
        if (right) {
            glm::mat4 R = glm::rotate(glm::mat4(1.0f), glm::radians(degree), camera.Up());
            camera.EYE = glm::vec3(R * glm::vec4(camera.EYE, 1.0f));
            camera.UP = glm::vec3(R * glm::vec4(camera.UP, 1.0f));
        }
        if (left) {
            glm::mat4 R = glm::rotate(glm::mat4(1.0f), glm::radians(-degree), camera.Up());
            camera.EYE = glm::vec3(R * glm::vec4(camera.EYE, 1.0f));
            camera.UP = glm::vec3(R * glm::vec4(camera.UP, 1.0f));
        }

This is my satelite movement moving around 0,0 this code works right.

sunkue
  • 278
  • 1
  • 9
  • What happens instead? – user253751 Oct 19 '20 at 16:37
  • @user253751 shape turnning down and get smaller but still in middle where the red dot is. – sunkue Oct 19 '20 at 23:07
  • 1
    Why are you passing cameraDirection as the second parameter when that is *not* what the second parameter is? And why are you using some calculation for cameraUp instead of just passing the direction that you want to be up? – user253751 Oct 19 '20 at 23:13
  • Is second parameter was wrong? maybe I misunderstansd about lookat() .. – sunkue Oct 19 '20 at 23:26
  • @user253751 and I already made satellite movement. and I want to use both of them.. so I use Up() instead of UP. I edit my satelite movement which works right way. – sunkue Oct 19 '20 at 23:28
  • @user253751 I made it !! thank you! the problem was incorect param to glm::LookAT(). correct glm::LookAT() use EYE,AT,UP as param. Thank you my man! – sunkue Oct 19 '20 at 23:43

0 Answers0