2014-04-08 8 views
0

주어진 화살표 키 입력이 있으면 화면에서 객체를 변환하는 방법을 알아 내는데 어려움이 있습니다. 현재 카메라를 움직이는 데 아무런 문제가 없지만 카메라 대신 오브젝트를 오브젝트로 이동하면서 머리를 감쌀 수 없습니다. 여기 화면에서 객체 변환하기 programmable-pipeline

내가 그래서 그 대신 객체의 위치를 ​​변경하려면 보기 매트릭스 위치방향glm::vec3


입니다

ViewMatrix = glm::lookAt(
    position, //camera position 
    position+direction, //look at origin 
    up //head up 
); 

을 계산하고있어 무엇 , 모델 매트릭스를 수정합니까? 아니면 mvp으로 무엇을 할 것인가?

모델 매트릭스는 현재

computeMatricesFromInputs(window,time); //function that handles input and computes viewMatrix 
     glm::mat4 projectionMatrix = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f); 
     glm::mat4 viewMatrix = getViewMatrix(); 
     glm::mat4 modelMatrix = glm::mat4(1.0); 
     glm::mat4 MVP = projectionMatrix * viewMatrix * modelMatrix; 
+0

것은 잘라는 이름의 모델 행렬에 변환을 적용! –

답변

0

glm::mat4(1.0) 그래서 내가 @ j를-P의 도움으로 문제를 파악 결국에 남아있다. 내가하고 싶었던 것은 객체를 움직이는 것이었기 때문에 glm 함수 translate()을 모델 행렬에 적용했습니다. 이렇게하려면 내 컨트롤 파일에 가서 내가 또한 헤더 파일에 선언 한 변수 glm::mat4 ModelMatrix을 반환

glm::mat4 getModelMatrix(); 

라는 함수를 만들었습니다. 실제 코드의 부분과 객체를 이동 그렇게 같았다 :

//If the the corresponding key is pressed... 
    ModelMatrix = glm::translate(ModelMatrix, glm::vec3(0.0f, 1.0f, 0.0f); //move y 1.0f 
//else If..etc.. 

다음과 같이 최종 코드가 보일 것이다 다시 내 메인 루프를 향한 통과 :

computeMatricesFromInputs(window,time); //function that handles input and computes viewMatrix 
     glm::mat4 projectionMatrix = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f); 
     glm::mat4 viewMatrix = getViewMatrix(); 
     glm::mat4 modelMatrix = getModelMatrix(); 
     glm::mat4 MVP = projectionMatrix * viewMatrix * modelMatrix;