0

基本上,我需要在按下左键(将视图向右)时正确地改变眼睛和向上的向量。我的实现如下,但似乎没有通过测试。任何人都可以帮忙吗?

// Transforms the camera left around the "crystal ball" interface
void Transform::left(float degrees, vec3& eye, vec3& up) {
    // YOUR CODE FOR HW1 HERE
    eye = rotate(degrees, vec3(0, 1, 0)) * eye;
    up = rotate(degrees, vec3(0, 1, 0)) * up;
}

旋转函数有两个参数 degree 和 axis,并返回旋转矩阵,它是一个 3 x 3 矩阵:

mat3 Transform::rotate(const float degrees, const vec3& axis) {
    // YOUR CODE FOR HW1 HERE

    mat3 rot, I(1.0);
    mat3 a_x;
    a_x[0][0] = 0;
    a_x[0][1] = -axis[2];
    a_x[0][2] = axis[1];
    a_x[1][0] = axis[2];
    a_x[1][1] = 0;
    a_x[1][2] = -axis[0];
    a_x[2][0] = -axis[1];
    a_x[2][1] = axis[0];
    a_x[2][2] = 0;
    float theta = degrees / 180 * pi;
    rot = I * cos(theta) + glm::outerProduct(axis, axis) *(1-cos(theta)) + a_x*sin(theta);
    return rot;
}  
4

2 回答 2

0

试试这样的东西是否可以解决它:

glm::mat3 Transform::rotate(float angle, const glm::vec3& axis) {
    glm::mat3 a_x(   0.0f,  axis.z, -axis.y,
                  -axis.z,    0.0f,  axis.x,
                   axis.y, -axis.x,    0.0f);
    angle = glm::radians(angle);
    return glm::mat3() * cos(angle) + sin(angle) * a_x
        + (1.0f - cos(angle)) * glm::outerProduct(axis, axis);
}
于 2013-10-05T11:04:31.410 回答
0

我四处搜索并找到解决方案:

// Transforms the camera left around the "crystal ball" interface
void Transform::left(float degrees, vec3& eye, vec3& up) {
    // YOUR CODE FOR HW1 HERE
    eye = eye * rotate(degrees, up);
}

旋转功能是正确的。

于 2013-10-06T02:16:48.623 回答