计算机图形学学习日志2

1.Rodrigues 旋转公式的矩阵形式

在这里插入图片描述
在这里插入图片描述
例如:
在这里插入图片描述
在这里插入图片描述
于是我们有任意向量 A 绕着轴n旋转就等同于R * A的结果。

2.世界坐标系转化到相机坐标系

在这里插入图片描述
总而言之,只要把相机的右(g叉乘t),上方向(t),g方向按列排放并且在最后一列放上平移的数字就得到了将世界坐标系变换到相机坐标系的旋转变化复合矩阵。
在这里插入图片描述

3.正交投影矩阵

将一个立方体,中点平移到原点上,并且将长宽高映射到Range(-1,1)成为一个立方体。
在这里插入图片描述

4.透视投影

在这里插入图片描述

作业0答案

#include <bits/stdc++.h>
#include "E:\Desktop\Cscript\Computer Graphics\eigen-3.4.0\Eigen\Dense"
using Eigen::MatrixXd;
using Eigen::VectorXd;
using namespace std;

int main() {
    Eigen::Matrix3f i;
    Eigen::Vector3f p(2.0f, 1.0f, 1.0f);
    i << cos(45), -sin(45), 1.0f,
         sin(45),  cos(45), 2.0f,
         0.0f,     0.0f,    1.0f;

    Eigen::Vector3f ans = i * p;
    cout << ans; 
    return 0;
}

Output:
在这里插入图片描述
作业1:

Eigen::Matrix4f get_model_matrix(float rotation_angle)
{
    Eigen::Matrix4f model = Eigen::Matrix4f::Identity();

    // TODO: Implement this function
    // Create the model matrix for rotating the triangle around the Z axis.
    // Then return it.
    float angle = rotation_angle * (MY_PI / 180);

    Matrix4f i;
    i << cos(angle), -sin(angle), 0, 0,
        sin(angle), cos(angle), 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1;
    model = model * i;
    return model;
}

Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio,
                                      float zNear, float zFar)
{
    // Students will implement this function

    Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();

    // TODO: Implement this function
    // Create the projection matrix for the given parameters.
    // Then return it.
    float tempeye = eye_fov * (MY_PI / 180);
    float n = zNear;
    float f = zFar;
    Matrix4f i;
    i << 1 / (tan(tempeye / 2) * aspect_ratio), 0, 0, 0,
        0, 1 / tan(tempeye / 2), 0, 0,
        0, 0, (f + n) / (f - n), -2 * f * n / (f - n),
        0, 0, 1, 0;
    projection = i * projection;
    



    return projection;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值