GAMES101-Homework0&Homework1

Homework0

Homework0

#include <cmath>
#include <Eigen/Dense>
#include <Eigen/Core>
#include <iostream>
using namespace std;
using namespace Eigen;
#define  pi 3.1415926

int main()
{
	Vector3d p(2.0f, 1.0f, 1.0f);
	double th = (45.0 / 180.0) * pi;
	Matrix3d rotate,trans;
	rotate << cos(th), -1 * sin(th), 0,
		      sin(th), cos(th),      0,
		      0,       0,            1;

	trans << 1, 0, 1,
		     0, 1, 2,
		     0, 0, 1;
	p = trans * rotate * p;
	cout << p.head(2) << endl;
	return 0;
}

知识点:
在这里插入图片描述
在这里插入图片描述

图片来自这里

Homework1

Eigen::Matrix4f get_model_matrix(float rotation_angle)
{
    Eigen::Matrix4f model = Eigen::Matrix4f::Identity();
    rotation_angle=rotation_angle/180.0f*MY_PI;
    // TODO: Implement this function
    // Create the model matrix for rotating the triangle around the Z axis.
    // Then return it.
    model<<cos(rotation_angle),-sin(rotation_angle),0,0,
           sin(rotation_angle),cos(rotation_angle),0,0,
           0,0,1,0,
           0,0,0,1;
    return model;
}

//提高项代码如下段
Eigen::Matrix4f get_rotation(Vector3f axis,float angle)
{
    angle=angle/180.0f*MY_PI;
    Eigen::Matrix4f Result = Eigen::Matrix4f::Identity();
    Eigen::Matrix3f E = Eigen::Matrix3f::Identity();
    Eigen::Matrix3f N = Eigen::Matrix3f::Identity();
    Eigen::Matrix3f ResultMat3 = Eigen::Matrix3f::Identity();
    N<< 0,-axis[2],axis[1],
        axis[2],0,-axis[0],
        -axis[1],axis[0],0;
    ResultMat3 = E*cos(angle) +(1-cos(angle))*axis*axis.transpose()+ sin(angle)*N;
    Result<<ResultMat3(0,0),ResultMat3(0,1),ResultMat3(0,2),0,
            ResultMat3(1,0),ResultMat3(1,1),ResultMat3(1,2),0,
            ResultMat3(2,0),ResultMat3(2,1),ResultMat3(2,2),0,
            0,0,0,1;
    
    return Result;
}

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.
    eye_fov=eye_fov/180*MY_PI;
    projection<<1/(aspect_ratio*tan(eye_fov/2.0f)) ,0,0,0,
                0,1/tan(eye_fov/2.0f),0,0,
                0,0,-(zFar+zNear)/(zFar-zNear),2*zFar*zNear/(zNear-zFar),
                0,0,-1,0;
    return projection;
}
//https://zhuanlan.zhihu.com/p/448904350
//理解过程见上诉博客,我直接带的透视投影公式

知识点:
正交投影
正交投影
透视投影:
在这里插入图片描述
补充:我使用的本地的VS,作业中的文件如下图所示。
在这里插入图片描述

Homework2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值