2016-12-07 1 views
0

OpenGL을 사용하여 일부 빠른 행렬 계산을 수행하는 응용 프로그램에 기존 코드가 있습니다. 이것은 boost :: qvm으로 바꿀 수있는 것처럼 보이지만 사용법의 예는 부족합니다. 기본 코드는 다음과 같습니다 사람이 부스트 :: QVM와이를 구현하는 방법에 대해 공유 할 수있는 빠른 아이디어가 있다면 QVM을 향상시키는 OpenGL 행렬 연산

#include <boost/qvm/mat.hpp> 
#include <boost/qvm/mat_operations.hpp> 

void foo() 
{ 
    auto heading = 90.0; 
    auto speed = 10.0; 
    auto xComponent = 0.0f; 
    auto yComponent = 0.0f; 

    glPushMatrix(); 
    { 
     glLoadIdentity(); 

     glRotatef(static_cast<GLfloat>(heading), 0, 1, 0); 
     glTranslatef(0, static_cast<GLfloat>(-speed), 0); 

     float modelviewMatrix[16]; 
     glGetFloatv(GL_MODELVIEW_MATRIX, modelviewMatrix); 

     xComponent = modelviewMatrix[2*4 + 0]; 
     yComponent = modelviewMatrix[0]; 
    } 
    glPopMatrix(); 
} 

그래서 궁금 해서요?

그래서 boost :: qvm 버전은 매우 유사해야하지만 OpenGL과 API가 상당히 다르기 때문에 회전 및 변환을 수행하는 방법을 잘 모르겠습니다.

void foo() 
{ 
    auto heading = 90.0; 
    auto speed = 10.0; 
    auto xComponent = 0.0f; 
    auto yComponent = 0.0f; 

    boost::qvm::mat<double, 4, 4> matrix; 
    boost::qvm::set_identity(matrix); 

    // rotate? 

    // translate? 

    // get components? 
} 

최종 코드 : 코드는이 질문 후이처럼 보이는 결국

:

#include <boost/qvm/mat.hpp> 
#include <boost/qvm/vec.hpp> 
#include <boost/qvm/mat_operations.hpp> 
#include <boost/qvm/map_vec_mat.hpp> 

// ... 

boost::qvm::mat<double, 4, 4> matrix; 
boost::qvm::set_identity(matrix); 
boost::qvm::mat<double, 4, 4> rotation = boost::qvm::roty_mat<4>(deg2rad(heading)); 
boost::qvm::vec<double, 3> v{{0.0, -speed, 0.0}}; 
boost::qvm::mat<double, 4, 4> translation = boost::qvm::translation_mat(v); 
+0

boost :: qvm이 필수입니까? [glm 라이브러리] (http://glm.g-truc.net/0.9.8/index.html)를 고려 했습니까? – Borgleader

+0

Boost는 다른 외부 종속성을 추가 할 필요가 없도록하는 유일한 요구 사항입니다. 나는 glm을 인식하지 못했지만 header 만있는 것으로 보이기 때문에 가능성이있을 수 있습니다. 나는 qvm 솔루션이 여기에 합당한지를보고 싶습니다. – DiB

답변

1

회전번역 행렬 부스트를 사용하여 얻을 수 있습니다 (예) :

boost::qvm::rotx_mat<4>(3.14159f); // rotation on x axis by PI radians 

vec<float,3> v={0,0,7}; 
mat<float,4,4> tr=translation_mat(v); // translation by 7 units on z axis 

결합 변환은 모델 뷰 매트릭스에 이러한 매트릭스를 곱하여 얻을 수 있습니다.

그런 다음, 점점 구성 요소이 모델 뷰 매트릭스에서 필요한 값을 읽기의 문제이다 (당신의 모델 뷰는 이미 선 boost::qvm::mat<double, 4, 4> matrix; 선언 한 행렬을 할 수있다).

1

view proxies의 중간 결과는 translation_mat 또는 roty_mat과 같이 mat<> 개체에 넣지 않는 것이 가장 좋습니다. 중간 결과를 auto const &으로 캡처하거나 아래에 표시된 것처럼 인라인으로 곱하면됩니다. 이렇게하면 임시 변수를 만들지 않아도됩니다.

auto heading = 90.0; 
auto speed = 10.0; 
auto xComponent = 0.0f; 
auto yComponent = 0.0f; 
{ 
    using namespace boost::qvm; 
    double const v[3] = {0,-speed,0}; 
    auto const & result = translation_mat(vref(v)) * roty_mat<4>(deg2rad(heading)); 
    xComponent = A02(result); //Not sure if this should be A20 instead 
    yComponent = A00(result); 
}