# data[].attributes.body
// main.cpp

// 5820658 전형진, 2025-10-29

// get projection-matrix in perspective-view camera

#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

/* ================ /

fovY(field-of-view y): vertical-directional viewing-angle, unit in degree

aspectRatio: aspect-ratio, equivalent to (width/height)

nearZ: distance in z-axis, from camera to near-plane

farZ: distance in z-axis, from camera to far-plane

/ ================ */

float width, height, aspectRatio, fovY, nearZ, farZ;

glm::mat4x4 resultMatrix;

// convert angle in degree to radian

static float degToRad(float angle_degree)

{ return (angle_degree *(glm::pi<float>() /180.0f)); }

// convert angle in radian to degree

static float radToDeg(float angle_radian)

{ return ( angle_radian *(180.0f /glm::pi<float>()) ); }

// calculate and return the projection-matrix of perspective-view camera

static glm::mat4x4 getPerspective(float fov, float aspect, float near, float far)

{

glm::mat4x4 mat_result(0.0f);

float _calculations[4];

float _tanHalfFov = tan(degToRad(fov) /2);

calculations[0] = (1 /(aspect *tanHalfFov));

calculations[1] = (1 /tanHalfFov);

_calculations[2] = ( -((far +near) /(far -near)) );

_calculations[3] = ( -( ((far near) /(far -near)) 2 ) );

mat_result[0][0] = _calculations[0];

mat_result[1][1] = _calculations[1];

mat_result[2][2] = _calculations[2];

mat_result[2][3] = (-1.0f);

mat_result[3][2] = _calculations[3];

return mat_result; // return the result of calculations, perspective projection-matrix

}

// program entry point

int main()

{

// set-up initial values

width = 780.0f;

height = 750.0f;

aspectRatio = (width /height); // calculate the aspect-ratio

fovY = 45.0f; // unit in degree

nearZ = 0.1f;

farZ = 500.0f;

// perform the calculation & print the answer

resultMatrix = getPerspective(fovY, aspectRatio, nearZ, farZ);

std::cout << "\nProjection matrix in perspective-view camera: " << glm::to_string(resultMatrix); // print the answer

// END OF PROGRAM

std::cout << "\n5820658 전형진 과제 끝." << std::endl; // program-finished identifier

return 0; // exit the program

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/matrix_transform.hpp>

//using namespace glm;

glm::mat4 MyPerspective(float fovY, float width, float height, float nearZ, float farZ) {

glm::mat4 result(0.0f);

const float aspect = width / height;

const float halfFovYRadians = (fovY * glm::pi<float>() / 180.0f) / 2.0f;

const float tanHalfFovY = tan(halfFovYRadians);

result[0][0] = 1.0f / (aspect * tanHalfFovY);

result[1][1] = 1.0f / tanHalfFovY;

result[2][2] = -(farZ + nearZ) / (farZ - nearZ);

result[2][3] = -1.0f;

result[3][2] = -(2.0f farZ nearZ) / (farZ - nearZ);

return result;

}

int main() {

const float width = 780.0f;

const float height = 750.0f;

const float fovY = 45.0f;

const float nearZ = 0.1f;

const float farZ = 500.0f;

glm::mat4 Mat_P = MyPerspective(fovY, width, height, nearZ, farZ);

std::cout << glm::to_string(Mat_P) << std::endl;

return 0;

}

# data[].attributes.body
//Computer_Graphcis(6)
//park_jihyeon(Nyancode1)
#define GLM_ENABLE_EXPERIMENTAL
#define GLM_SWIZZLE
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/matrix_transform.hpp>

//using namespace glm;

glm::mat4 MyPerspective(float fovY, float width, float height, float nearZ, float farZ){
  glm::mat4 result(0.0f);
  const float aspect = width / height;
  const float halfFovYRadians = (fovY * glm::pi<float>() / 180.0f) / 2.0f;
  const float tanHalfFovY = tan(halfFovYRadians);

  result[0][0] = 1.0f / (aspect * tanHalfFovY);
  result[1][1] = 1.0f / tanHalfFovY;
  result[2][2] = -(farZ + nearZ) / (farZ - nearZ);
  result[2][3] = -1.0f;
  result[3][2] = -(2.0f * farZ * nearZ) / (farZ - nearZ);
  return result;

}

int main(){
  const float width = 780.0f;
  const float height = 750.0f;
  const float fovY = 45.0f;
  const float nearZ = 0.1f;
  const float farZ = 500.0f;
  glm::mat4 Mat_P = MyPerspective(fovY, width, height, nearZ, farZ);
  std::cout << "Projection Matrix:\n" << glm::to_string(Mat_P) << std::endl;
  return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <glm/gtx/dual_quaternion.hpp>

#include<iostream>

#include<glm/glm.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include<glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include<glm/mat4x4.hpp>

#include<glm/mat2x2.hpp>

#include<glm/mat3x2.hpp>

#include<glm/mat3x3.hpp>

glm::mat4 Perspective(float fov_y, float aspect, float near, float far);

int main()

{

float width = 780.0f;

float height = 750.0f;

float fov_y = 45.0f;

float near_z = 0.1f;

float far_z = 500.0f;

float aspect = width / height;

glm::mat4 pro_mat = Perspective(fov_y, aspect, near_z, far_z);

std::cout << glm::to_string(pro_mat) << std::endl;

return 0;

}

glm::mat4 Perspective(float fov_y, float aspect, float near, float far)

{

fov_y = glm::radians(fov_y);

glm::mat4 pro_mat(0);

pro_mat[0][0] = 1.0f / (aspect * glm::tan(fov_y / 2.0f));

pro_mat[1][1] = 1.0f / (glm::tan(fov_y / 2.0f));

pro_mat[2][2] = -(far + near) / (far - near);

pro_mat[2][3] = -1.0f;

pro_mat[3][2] = -(2.0f far near) / (far - near);

return pro_mat;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

glm::mat4 CreatePerspectiveMatrix(float fovY, float width, float height, float nearZ, float _farZ)

{

glm::mat4 result(0.0f);

float aspectRatio = width / height;

const float tanHalfFovY = tan(glm::radians(_fovY) / 2.0f);

result[0][0] = 1.0f / (aspectRatio * tanHalfFovY);

result[1][1] = 1.0f / tanHalfFovY;

result[2][2] = -(_farZ + nearZ) / (farZ - _nearZ);

result[2][3] = -1.0f;

result[3][2] = -(2.0f farZ nearZ) / (_farZ - _nearZ);

return result;

}

int main()

{

const float WIDTH = 780.0f;

const float HEIGHT = 750.0f;

const float FOV_Y = 45.0f;

const float NEAR_Z = 0.1f;

const float FAR_Z = 500.0f;

glm::mat4 perspectiveMatrix = CreatePerspectiveMatrix(FOV_Y, WIDTH, HEIGHT, NEAR_Z, FAR_Z);

std::cout << "투영 행렬:\n" << glm::to_string(perspectiveMatrix) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/mat4x4.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <cmath>

glm::mat4 perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 projection(0.0f);

float a = 1.0f / (aspect * std::tan(fovy / 2.0f));

float b = 1.0f / std::tan(fovy / 2.0f);

float c = -((far + near) / (far - near));

float d = -(2.0f * far * near / (far - near));

projection[0][0] = a;

projection[1][1] = b;

projection[2][2] = c;

projection[2][3] = -1.0f;

projection[3][2] = d;

return projection;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = glm::pi<float>() / 4.0f;

float nearz = 0.1f;

float farz = 500.0f;

float aspect = width / height;

glm::mat4 perspectiveMat = perspective(fovY, aspect, nearz, farz);

std::cout << glm::to_string(perspectiveMat) << std::endl;

return 0;

}

# data[].attributes.attachment_caption
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/mat4x4.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat3x2.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspective(float fovy, float aspect, float near, float far)
{
	glm::mat4 projectionMatrix(0.0f);

	projectionMatrix[0][0] = 1.0f / (aspect * tan(glm::radians(fovy) / 2.0f));
	projectionMatrix[1][1] = 1.0f / tan(glm::radians(fovy) / 2.0f);
	projectionMatrix[2][2] = -(far + near) / (far - near);
	projectionMatrix[2][3] = -1;
	projectionMatrix[3][2] = -(2 * far * near) / (far - near);

	return projectionMatrix;
}

int main()
{
	float width = 780.0f;
	float height = 750.0f;
	float fovy = 45.0f;
	float nearz = 0.1f;
	float farz = 500.0f;
	float aspect = width / height;

	std::cout << glm::to_string(perspective(fovy, aspect, nearz, farz)) << std::endl;

	return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <cmath> // tan 함수 사용

// 가로 : 780

// 높이 : 750

// fied of view y : 45

// NearZ : 0.1

// FarZ : 500

glm::mat4 custom_perspective(float fovy, float aspect, float nearZ, float farZ)

{

// x scale matrix

float tan_half_fovy = std::tan(fovy / 2.0f); // tan(fovy/2)

float x_scale = 1.0f / (aspect tan_half_fovy); // 1/(aspecttan(fovy/2))

// y scale matrix

float y_scale = 1.0f / tan_half_fovy; // 1/tan(fovy/2);

// z scale matrix

float diff_z = farZ - nearZ; // f - n

float Z1 = -(farZ + nearZ) / diff_z; // - (f + n) / (f - n)

float Z2 = -(2.0f farZ nearZ) / diff_z; // -2 ( f * n ) / ( f - n )

glm::mat4 Result(0.0f); // 결과값 matrix를 0으로 초기화

Result[0][0] = x_scale;

Result[1][1] = y_scale;

Result[2][2] = Z1;

Result[3][2] = Z2;

Result[2][3] = -1.0f;

return Result;

}

int main()

{

// 설정 값

float width = 780.0f;

float height = 750.0f;

float fov_y = 45.0f;

float near_z = 0.1f;

float far_z = 500.0f;

// aspect ratio 계산

float aspect = width / height;

// perspective 함수는 radian으로 받음.

// fov_y degree -> radian 으로 변환

fov_y = glm::radians(fov_y);

// custom_perspective 함수 사용

// projectionmatrix에 custom_perspective 행렬 저장

glm::mat4 projectionmatrix = custom_perspective(fov_y, aspect, near_z, far_z);

std::cout << glm::to_string(projectionmatrix) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat2x3.hpp> //개념적으론 2x3임

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspec(float fovy, float aspect, float nearz, float farz)

{

glm::mat4 result(0.0f);

result[0][0] = 1.0f / (tan(fovy / 2.0f) * aspect);

result[1][1] = 1.0f / tan(fovy / 2.0f);

result[2][2] = -(farz + nearz) / (farz - nearz);

result[2][3] = (- 2.0f farz nearz) / (farz - nearz);

result[3][2] = -1.0f;

return result;

}

int main()

{

float width = 780.0f;;

float height = 750.0f;

float fovy = glm::radians(45.0f);

float nearz = 0.1f;

float farz = 500.0f;

float aspect = width / height;

glm::mat4 projection = perspec(fovy, aspect, nearz, farz);

std::cout << "직접 만든 perspective 함수 : " << glm::to_string(projection) << std::endl << std::endl;

glm::mat4 x = glm::perspective(fovy, aspect, nearz, farz);

std::cout <<"glm에 내장된 perspective 함수 : " << glm::to_string(x) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;

const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::mat4 Perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 projection =

{

{1 / (aspect tan(DEGREES_TO_RADIANS (fovy / 2))),0,0,0},

{0,1 / tan(DEGREES_TO_RADIANS * (fovy / 2)),0,0},

{0,0,-1 (far + near) / (far - near),-2 (far * near) / (far - near)},

{0,0,-1,0}

};

return projection;

}

int main()

{

float width = 780;

float height = 750;

float fovY = 45.0f;

float nearZ = 0.1f;

float farZ = 500.f;

float aspect = width / height;

glm::mat4 perspectiveProjection = Perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(perspectiveProjection)<<std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include<iostream>

#include<glm/glm.hpp>

#include<glm/gtx/string_cast.hpp>

#include<glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspective(float fovY, float aspect, float near, float far);

int main() {

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 ppmat = perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(ppmat) << std::endl;

return 0;

}

glm::mat4 perspective(float fovY, float aspect, float near, float far) {

glm::mat4 projection_matrix(0.0f);

projection_matrix[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

projection_matrix[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

projection_matrix[2][2] = -(far + near) / (far - near);

projection_matrix[2][3] = -1.0f;

projection_matrix[3][2] = -(2.0f far near) / (far - near);

return projection_matrix;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <glm/gtx/dual_quaternion.hpp>

#include<iostream>

#include<glm/glm.hpp>

#include<glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include<glm/mat4x4.hpp>

#include<glm/mat2x2.hpp>

#include<glm/mat3x2.hpp>

#include<glm/mat3x3.hpp>

glm::mat4 Perspective(float fov, float n, float f, float aspect);

int main()

{

float width = 780;

float height = 750;

float fov = 45;

float near_z = 0.1f;

float far_z = 500;

float aspect = width / height;

glm::mat4 pers = Perspective(fov, near_z, far_z, aspect);

std::cout << glm::to_string(pers);

return 0;

}

glm::mat4 Perspective(float fov, float n, float f, float aspect)

{

glm::mat4 mat(0);

float fov_y = glm::radians(fov);

mat[0][0] = 1 / (aspect * glm::tan(fov_y / 2));

mat[1][1] = 1 / glm::tan(fov_y / 2);

mat[2][2] = -((f + n) / (f - n));

mat[2][3] = -(2 ((f n) / (f - n)));

mat[3][2] = -1;

return mat;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat3x2.hpp> //개념적으로 2x3

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/gtx/dual_quaternion.hpp>

glm::mat4 PersPective(float fovY, float aspect, float near, float far)

{

fovY = glm::radians(fovY);

glm::mat4 PS(0.0f);

PS[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

PS[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

PS[2][2] = -(far + near) / (far - near);

PS[2][3] = -1.0f;

PS[3][2] = -(2.0f far near / (far - near));

return PS;

}

int main()

{

float w = 780.0f;

float h = 750.0f;

float forY = 45.0f;

forY = glm::radians(forY);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = w / h;

glm::mat4 PS = PersPective(forY, aspect, nearZ, farZ);

std::cout << glm::to_string(PS) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <glm/glm.hpp>

#include <glm/gtc/matrix_transform.hpp>

#include <glm/gtc/type_ptr.hpp>

#include <iostream>

#include <iomanip>

int main() {

float Width = 780.0f;

float Height = 750.0f;

float FovY = 45.0f;

float NearZ = 0.1f;

float FarZ = 500.0f;

float aspectRatio = Width / Height;

glm::mat4 projection = glm::perspective(glm::radians(FovY), aspectRatio, NearZ, FarZ);

std::cout << std::fixed << std::setprecision(6);

std::cout << "mat4x4(("

<< projection[0][0] << ", " << projection[0][1] << ", " << projection[0][2] << ", " << projection[0][3] << "), "

<< "(" << projection[1][0] << ", " << projection[1][1] << ", " << projection[1][2] << ", " << projection[1][3] << "), "

<< "(" << projection[2][0] << ", " << projection[2][1] << ", " << projection[2][2] << ", " << projection[2][3] << "), "

<< "(" << projection[3][0] << ", " << projection[3][1] << ", " << projection[3][2] << ", " << projection[3][3] << "))"

<< std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/mat4x4.hpp>

glm::mat4 PersPective(float fovY, float aspect, float near, float far)

{

//fovY는 이 함수 안에서 라디안으로 바꿔서 사용한다.

fovY = glm::radians(fovY);

glm::mat4 ps_arr(0.0f);

ps_arr[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

ps_arr[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

ps_arr[2][2] = -(far + near) / (far - near);

ps_arr[2][3] = -1.0f;

ps_arr[3][2] = -(2.0f far near) / (far - near);

return ps_arr;

}

int main()

{

float w = 780.0f;

float h = 750.0f;

float fovY = 45.0f;

//fovY = glm::radians(fovY);

float Znear = 0.1f;

float Zfar = 500.0f;

float aspect = w / h;

glm::mat4 ps = PersPective(fovY, aspect, Znear, Zfar);

std::cout << glm::to_string(ps);

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/mat4x4.hpp>

glm::mat4 Perspective(float fovy, float aspect, float near, float far) {

glm::mat4 ps_arr(0.0f);

ps_arr[0][0] = 1.0f / (aspect * tan(fovy / 2.0f));

ps_arr[1][1] = 1.0f / (tan(fovy / 2.0f));

ps_arr[2][2] = -(far + near) / (far - near);

ps_arr[2][3] = -1.0f;

ps_arr[3][2] = -(2.0f far near) / (far - near);

return ps_arr;

}

int main() {

float w = 780;

float h = 750;

float fovy = 45.0f;

fovy = glm::radians(fovy);

float nearz = 0.1f;

float farz = 500.0f;

float aspect = w / h;

glm::mat4 ps = Perspective(fovy, aspect, nearz, farz);

std::cout << glm::to_string (ps);

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/mat4x4.hpp>

//PDF p.71 perspective projection matrix - 4x4

//fovY 는 dgree 로 들어가니, main 에 radiant 를 추가할것

glm::mat4 Perspective(float fovY, float aspect, float near, float far) {

glm::mat4 Pmat(0.0f);

Pmat[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

Pmat[1][1] = 1.0f / glm::tan(fovY / 2);

Pmat[2][2] = -(far + near) / (far - near);

Pmat[2][3] = -1.0f;

Pmat[3][2] = -(2.0f far near) / (far - near);

return Pmat;

}

int main() {

//width - 780.0f height - 750.0f

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY); //fovY 를 dgree 로 받기에 radiant 사용할 것: 교수님

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 perspective_projection_metrix = Perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(perspective_projection_metrix) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/matrix_transform.hpp>

// 가로 : 780

// 높이 : 750

// fied of view y : 45

// NearZ : 0.1

// FarZ : 500

int main()

{

float aspect = 780.0 / 750.0;

float fov_y = 45.0;

float Near_Z = 0.1;

float Far_Z = 500.0;

// perspective 함수는 radian으로 받음.

// fov_y는 degree이기 때문에 radian으로 변환해야함.

// mat perspective ( fov_y, 종횡비, near, far );

glm::mat4 projectionMatrix = glm::perspective

(

glm::radians(fov_y),

aspect,

Near_Z,

Far_Z

);

std::cout << glm::to_string(projectionMatrix) << std::endl;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspective(float fovY, float aspect, float near, float far);

int main() {

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 ppmat = perspective(fovY, aspect, nearZ, farZ);

std::cout << "Projection Matrix:\n" << glm::to_string(ppmat) << std::endl;

return 0;

}

glm::mat4 perspective(float fovY, float aspect, float near, float far) {

glm::mat4 projection_matrix(0.0f);

// 도를 라디안으로 내부에서 변환하도록 수정 적용

float rad = glm::radians(fovY);

float t = glm::tan(rad * 0.5f);

float range = far - near;

projection_matrix[0][0] = 1.0f / (aspect * t);

projection_matrix[1][1] = 1.0f / t;

projection_matrix[2][2] = -(far + near) / range;

projection_matrix[2][3] = -1.0f;

projection_matrix[3][2] = -(2.0f far near) / range;

return projection_matrix;

}

# data[].attributes.body
#include <iostream>

#define GLM_ENABLE_EXPERIMENTAL

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/mat3x2.hpp>

//perspective 행렬

glm::mat4 perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 pers(0.0f);

pers[0][0] = 1.0f / (aspect * tan(glm::radians(fovy) / 2.0f));

pers[1][1] = 1.0f / tan(glm::radians(fovy) / 2.0f);

pers[2][2] = -(fovy + near / fovy - near);

pers[2][3] = -1.0f;

pers[3][2] = -2 (fovy near / fovy - near);

return pers;

}

int main()

{

float degree=45.0f;

float Width = 780.0f;

float Height = 750.0f;

float FovY = degree;

float NearZ = 0.1f;

float FarZ = 500.0f;

float aspect = Width / Height;

glm::mat4 perspectiveMat= perspective(FovY, aspect, NearZ, FarZ);

std::cout << glm::to_string(perspectiveMat) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include<iostream>

#include<glm/glm.hpp>

#include<glm/gtx/string_cast.hpp>

#include<glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspective(float fovY, float aspect, float near, float far);

int main() {

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 ppmat = perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(ppmat) << std::endl;

return 0;

}

glm::mat4 perspective(float fovY, float aspect, float near, float far) {

glm::mat4 projection_matrix(0.0f);

projection_matrix[0][0] = 1.0f / (aspect * glm::tan(glm::radians(fovY) / 2.0f));

projection_matrix[1][1] = 1.0f / (glm::tan(glm::radians(fovY) / 2.0f));

projection_matrix[2][2] = -(far + near) / (far - near);

projection_matrix[2][3] = -1.0f;

projection_matrix[3][2] = -(2.0f far near) / (far - near);

return projection_matrix;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SIWZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/vec3.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat2x3.hpp>

glm::mat4 perspective(float fovy, float aspect, float near, float far) {

glm::mat4 projection(0.0f);

projection[0][0] = 1.0f / (aspect * glm::tan(fovy / 2.0f));

projection[1][1] = 1.0f / glm::tan(fovy / 2);

projection[2][2] = -(far + near) / (far - near);

projection[2][3] = -1.0f;

projection[3][2] = -(2.0f far near) / (far - near);

return projection;

};

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 projection_metrix = perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(projection_metrix) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/mat4x4.hpp>

glm::mat4 MakePerspective(float fovY, float aspect, float zNear, float zFar)

{

glm::mat4 mat(0.0f);

float tanHalf = glm::tan(fovY * 0.5f);

float invTan = 1.0f / tanHalf;

mat[0][0] = invTan / aspect;

mat[1][1] = invTan;

mat[2][2] = -(zFar + zNear) / (zFar - zNear);

mat[2][3] = -1.0f;

mat[3][2] = -(2.0f zFar zNear) / (zFar - zNear);

return mat;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = glm::radians(45.0f);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 proj = MakePerspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(proj) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include<iostream>

#include <glm/gtx/dual_quaternion.hpp>

#include<glm/glm.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include<glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include<glm/mat4x4.hpp>

#include<glm/mat2x2.hpp>

#include<glm/mat3x2.hpp>

#include<glm/mat3x3.hpp>

glm::mat4 perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 projection(0.0f);

float a = 1.0f / (aspect * tan(glm::radians(fovy) / 2.0f));

float b = 1.0f / tan(glm::radians(fovy) / 2.0f);

float c = -((far + near) / (far - near));

float d = -(2.0f far near / (far - near));

projection[0][0] = a;

projection[1][1] = b;

projection[2][2] = c;

projection[2][3] = -1.0f;

projection[3][2] = d;

return projection;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

float nearz = 0.1f;

float farz = 500.0f;

float aspect = width / height;

glm::mat4 perspectiveMat = perspective(fovY, aspect, nearz, farz);

std::cout << glm::to_string(perspectiveMat) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/mat4x4.hpp>

glm::mat4 PersPective(float fovY, float aspect, float near, float far)

{

glm::mat4 ps_arr(0.0f);

ps_arr[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

ps_arr[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

ps_arr[2][2] = -(far + near) / (far - near);

ps_arr[2][3] = -1.0f;

ps_arr[3][2] = -(2.0f far near) / (far - near);

return ps_arr;

}

int main()

{

float w = 780.0f;

float h = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY);

float Znear = 0.1f;

float Zfar = 500.0f;

float aspect = w / h;

glm::mat4 ps = PersPective(fovY, aspect, Znear, Zfar);

std::cout << glm::to_string(ps);

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <glm/gtx/dual_quaternion.hpp>

#include<iostream>

#include<glm/glm.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include<glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include<glm/mat4x4.hpp>

#include<glm/mat2x2.hpp>

#include<glm/mat3x2.hpp>

#include<glm/mat3x3.hpp>

glm::mat4 Perspective(float fov_y, float aspect, float near, float far);

int main()

{

float width = 780.0f;

float height = 750.0f;

float fov_y = 45.0f;

fov_y = glm::radians(fov_y);

float near_z = 0.1f;

float far_z = 500.0f;

float aspect = width / height;

glm::mat4 pro_mat = Perspective(fov_y, aspect, near_z, far_z);

std::cout << glm::to_string(pro_mat) << std::endl;

return 0;

}

glm::mat4 Perspective(float fov_y, float aspect, float near, float far)

{

glm::mat4 pro_mat(0);

pro_mat[0][0] = 1.0f / (aspect * glm::tan(fov_y / 2.0f));

pro_mat[1][1] = 1.0f / (glm::tan(fov_y / 2.0f));

pro_mat[2][2] = -(far + near) / (far - near);

pro_mat[2][3] = -1.0f;

pro_mat[3][2] = -(2.0f far near) / (far - near);

return pro_mat;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/transform.hpp>

glm::mat4 perspective(float fovY, float aspect, float near, float far) {

glm::mat4 p(0.0f);

p[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

p[1][1] = 1.0f / glm::tan(fovY / 2.0f);

p[2][2] = -((far + near) / (far - near));

p[3][2] = -2.0f ((far near) / (far - near));

p[2][3] = -1.0f;

return p;

}

int main()

{

float width = 780.0;

float height = 750.0;

float fovy = 45.0;

float near = 0.1;

float far = 500.0;

float aspect = width / height;

float fovY = glm::radians(fovy);

glm::mat4 projection = perspective(fovY, aspect, near, far);

std::cout << glm::to_string(projection) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/matrix.hpp>

#include <glm/gtx/transform.hpp>

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0f; //glm::radians()

const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>(); //glm::degrees()

glm::mat4 perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 pro_mat(0.0f);

pro_mat[0][0] = 1.0f / (aspect * tan(glm::radians(fovy) / 2.0f));

pro_mat[1][1] = 1.0f / tan(glm::radians(fovy) / 2.0f);

pro_mat[2][2] = -(far + near) / (far - near);

pro_mat[2][3] = -1.0f;

pro_mat[3][2] = -2.0f * (far * near) / (far - near);

return pro_mat;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 p_mat = perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(p_mat) << std::endl;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/matrix_transform.hpp>

#include <glm/gtc/type_ptr.hpp>

using namespace std;

glm::mat4 Perspective(float fovY, float aspect, float nearZ, float farZ)

{

float f = 1.0f / tan(fovY / 2.0f);

glm::mat4 result(0.0f);

result[0][0] = f / aspect;

result[1][1] = f;

result[2][2] = (farZ + nearZ) / (nearZ - farZ);

result[2][3] = -1.0f;

result[3][2] = (2.0f farZ nearZ) / (nearZ - farZ);

return result;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = glm::radians(45.0f);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 proj = Perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(proj) << std::endl;

return 0;

}

# data[].attributes.body
glm::mat4 perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 projection_matrix(0.0f);

projection_matrix[0][0] = 1.0f / (aspect * tan(glm::radians(fovy) / 2.0f));

projection_matrix[1][1] = 1.0f / tan(glm::radians(fovy) / 2.0f);

projection_matrix[2][2] = -((far + near) / (far - near));

projection_matrix[2][3] = -1.0f;

projection_matrix[3][2] = -(2.0f far near / (far - near));

return projection_matrix;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

float nearz = 0.1f;

float farz = 500.0f;

float aspect = width / height;

glm::mat4 pm = perspective(fovY, aspect, nearz, farz);

std::cout << glm::to_string(pm) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include<iostream>

#include<glm/glm.hpp>

#include<glm/gtx/string_cast.hpp>

#include<glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspective(float fovY, float aspect, float near, float far);

int main() {

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 ppmat = perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(ppmat) << std::endl;

return 0;

}

glm::mat4 perspective(float fovY, float aspect, float near, float far) {

glm::mat4 projection_matrix(0.0f);

projection_matrix[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

projection_matrix[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

projection_matrix[2][2] = -(far + near) / (far - near);

projection_matrix[2][3] = -1.0f;

projection_matrix[3][2] = -(2.0f far near) / (far - near);

return projection_matrix;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

glm::mat4 Perspective(float fovy, float aspect, float near, float far) {

return glm::mat4{ {1 / (aspect glm::tan(glm::radians(fovy / 2))),0,0,0},{0,1 / tan(glm::radians(fovy / 2)),0,0},{0,0,-(far + near) / (far - near),-1},{0,0,-2 (far * near) / (far - near),0} };

}

int main()

{

std::cout << glm::to_string(Perspective(45.f, 780.f / 750.f, 0.1f, 500.f)) << std::endl;

}

# data[].attributes.body
#include <iostream>

#define GLM_ENABLE_EXPERIMENTAL

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/mat3x2.hpp>

/*

width = 780

height = 750

fovY = 45

nearz = 0.1

farz = 500

*/

glm::mat4 perspective(float fovy, float aspect, float near, float far)

{

glm::mat4 projection(0.0f);

float a = 1.0f / (aspect * tan(glm::radians(fovy) / 2.0f));

float b = 1.0f / tan(glm::radians(fovy) / 2.0f);

float c = -((far + near) / (far - near));

float d = -(2.0f far near / (far - near));

projection[0][0] = a;

projection[1][1] = b;

projection[2][2] = c;

projection[2][3] = -1.0f;

projection[3][2] = d;

return projection;

}

int main()

{

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

float nearz = 0.1f;

float farz = 500.0f;

float aspect = width / height;

glm::mat4 perspectiveMat = perspective(fovY, aspect, nearz, farz);

std::cout << glm::to_string(perspectiveMat) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

#include <glm/gtx/dual_quaternion.hpp>

#include <glm/mat4x4.hpp>

glm::mat4 PersPective(float fovY, float aspect, float near, float far)

{

glm::mat4 ps_arr(0.0f);

ps_arr[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

ps_arr[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

ps_arr[2][2] = -(far + near) / (far - near);

ps_arr[2][3] = -1.0f;

ps_arr[3][2] = -(2.0f far near) / (far - near);

return ps_arr;

}

int main()

{

float w = 780.0f;

float h = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY);

float Znear = 0.1f;

float Zfar = 500.0f;

float aspect = w / h;

glm::mat4 ps = PersPective(fovY, aspect, Znear, Zfar);

std::cout << glm::to_string(ps);

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include<iostream>

#include<glm/glm.hpp>

#include<glm/gtx/string_cast.hpp>

#include<glm/gtx/matrix_transform_2d.hpp>

glm::mat4 perspective(float fovY, float aspect, float near, float far);

int main() {

float width = 780.0f;

float height = 750.0f;

float fovY = 45.0f;

fovY = glm::radians(fovY);

float nearZ = 0.1f;

float farZ = 500.0f;

float aspect = width / height;

glm::mat4 ppmat = perspective(fovY, aspect, nearZ, farZ);

std::cout << glm::to_string(ppmat) << std::endl;

return 0;

}

glm::mat4 perspective(float fovY, float aspect, float near, float far) {

glm::mat4 projection_matrix(0.0f);

projection_matrix[0][0] = 1.0f / (aspect * glm::tan(fovY / 2.0f));

projection_matrix[1][1] = 1.0f / (glm::tan(fovY / 2.0f));

projection_matrix[2][2] = -(far + near) / (far - near);

projection_matrix[2][3] = -1.0f;

projection_matrix[3][2] = -(2.0f far near) / (far - near);

return projection_matrix;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

/*
Width = 780
Height = 750
FovY = 45.0f
NearZ = 0.1f;
FarZ = 500.0f;
*/

glm::mat4 perspective(float fovy, float aspect, float near, float far);

int main()
{
	float width = 780, height = 750, fov_y = 45.0f, near_z = 0.1f, far_z = 500.0f;

	glm::mat4 projection_matrix = perspective(fov_y, width/height, near_z, far_z);

	std::cout << glm::to_string(projection_matrix) << "\n";

	return 0;
}

glm::mat4 perspective(float fovy, float aspect, float near, float far)
{
	glm::mat4 pro_matrix =
	{
		{ 1/(aspect * std::tan(glm::radians(fovy/2))), 0, 0, 0 },
		{ 0, 1 / std::tan(glm::radians(fovy/2)), 0, 0 },
		{ 0 , 0, -((far + near) / (far - near)), -1 },
		{ 0, 0, -2.0f*((far*near)/(far-near)), 0 }
	};
	return pro_matrix;
}