14 if (fov == 0.0f || aspect == 0.0f || near_ == 0.0f || far_ == 0.0f ||
19 float f = 1.0f / tan(fov / 2.0f);
20 projectionMatrix[0][0] = f / aspect;
21 projectionMatrix[1][1] = f;
22 projectionMatrix[2][2] = (far_ + near_) / (near_ - far_);
23 projectionMatrix[3][2] = 2.0f * far_ * near_ / (near_ - far_);
24 projectionMatrix[2][3] = -1.0f;
26 return projectionMatrix;
57TEST(GraphicsTest, Projection) {
60 glm::mat4 glmProjectionMatrix =
61 glm::perspective(glm::radians(55.0f), 1.321f, 0.1f, 1000.0f);
62 std::cout << projectionMatrix << std::endl;
63 for (
int i = 0; i < 4; i++) {
64 for (
int j = 0; j < 4; j++) {
65 std::cout << glmProjectionMatrix[i][j] <<
" ";
67 std::cout << std::endl;
69 for (
size_t i; i < 16; i++) {
70 EXPECT_FLOAT_EQ(((&projectionMatrix[0][0]))[i],
71 (&glmProjectionMatrix[0][0])[i]);
75TEST(GraphicsTest, LookAt) {
79 glm::mat4 glmViewMatrix =
80 glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3(0.0f, 0.0f, 1.0f),
81 glm::vec3(0.0f, 1.0f, 0.0f));
83 std::cout << viewMatrix << std::endl;
84 for (
int i = 0; i < 4; i++) {
85 for (
int j = 0; j < 4; j++) {
86 std::cout << glmViewMatrix[i][j] <<
" ";
88 std::cout << std::endl;