GAMES101 作业 00:虚拟机的使用

作业 00 的实现代码:Assignment00

1. assignment

const float PI = 3.1415927;

void scale(Eigen::Vector3f &p, float sx, float sy) {
    Eigen::Matrix3f matrix3f;
    matrix3f <<
        sx, 0.0, 0.0,
        0.0, sy, 0.0,
        0.0, 0.0, 1.0;
    p = matrix3f * p;
}

void rotate(Eigen::Vector3f &p, float angle, bool clockwise) {
    if (clockwise) {
        angle *= -1.0;
    }
    float radian = angle * PI / 180.0;
    Eigen::Matrix3f matrix3f;
    matrix3f <<
        cos(radian), -sin(radian), 0.0,
        sin(radian), cos(radian), 0.0,
        0.0, 0.0, 1.0;
    p = matrix3f * p;
}

void translate(Eigen::Vector3f &p, float tx, float ty) {
    Eigen::Matrix3f matrix3f;
    matrix3f <<
        1.0, 0.0, tx,
        0.0, 1.0, ty,
        0.0, 0.0, 1.0;
    p = matrix3f * p;
}

void assignment() {
    Eigen::Vector3f p(2.0, 1.0, 1.0);
    std::cout << "assignment of input" << std::endl;
    std::cout << p << std::endl;
    rotate(p, 45.0, false),
    translate(p, 1.0, 2.0);
    std::cout << "assignment of output" << std::endl;
    std::cout << p << std::endl;
}

2. 运行结果

运行结果

posted @ 2020-11-27 18:44  virgilwjj  阅读(482)  评论(0编辑  收藏  举报