首页 > 其他 > 详细

GAMES 101 Assignment 1

时间:2021-08-25 23:25:10      阅读:9      评论:0      收藏:0      [点我收藏+]
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.

    //my code start
    rotation_angle=rotation_angle/180*MY_PI;
    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;
    //end   
    
    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.
    
    //my code
    Eigen::Matrix4f Mortho_translate=Eigen::Matrix4f::Identity();
    Eigen::Matrix4f Mortho_scale=Eigen::Matrix4f::Identity();
    Eigen::Matrix4f Mo=Eigen::Matrix4f::Identity();
    Eigen::Matrix4f Mpo=Eigen::Matrix4f::Identity();
    float r,l,t,b;
    float halfAngle=eye_fov/2/180*MY_PI;
    t=std::tan(halfAngle)*zNear;
    r=aspect_ratio*t;
    l=-r;
    b=-t;
    Mortho_translate<<1,0,0,-(r+l)/2,
                        0,1,0,-(t+b)/2,
                        0,0,1,-(zNear+zFar)/2,
                        0,0,0,1;  //ping yi
    Mortho_scale<<2/(r-l),0,0,0,
                    0,2/(t-b),0,0,
                    0,0,0,2/(zNear-zFar),
                    0,0,0,1;    //suo fang        
    Mo=Mortho_scale*Mortho_translate;        
    Mpo<<zNear,0,0,0,
        0,zNear,0,0,
        0,0,zNear+zFar,-zNear*zFar,
        0,0,1,0;
    projection=Mo*Mpo;
    //end
    return projection;
}

GAMES 101 Assignment 1

原文:https://www.cnblogs.com/Los1r/p/15186534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!