# data[].attributes.body
// main.cpp
// 5820658 전형진, 2025-10-15
// Calculate the point-conversion of model in world space

#define GLM_ENABLE_EXPERIMENTAL

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


#define VEC3_AXIS_X glm::vec3(1.0f, 0.0f, 0.0f)
#define VEC3_AXIS_Y glm::vec3(0.0f, 1.0f, 0.0f)
#define VEC3_AXIS_Z glm::vec3(0.0f, 0.0f, 1.0f)
#define MAT4X4_ID glm::mat4x4(1.0f)


float modRot[3]; // rotations of model
glm::mat4x4 rotMat; // rotation matrix of model
glm::vec3 vec_modSc, vec_modTrans; // scale vector & translation vector of model
glm::vec4 point_local, point_worldSpace;
glm::mat4x4 modMat; // final matrix of model


// program entry point
int main()
{
	modRot[0] = 40.0f; modRot[1] = 56.0f; modRot[2] = 0.0f; // assign rotations of model; X,Y,Z
	vec_modSc = glm::vec3(1.3f, 1.3f, 1.3f); // assign the scale vector of model
	vec_modTrans = glm::vec3(0.0f, 5.0f, 0.0f); // assign the translation vector of model

	// get the rotation matrix of model
	rotMat = glm::rotate(MAT4X4_ID, glm::radians(modRot[0]), VEC3_AXIS_X);
	rotMat = glm::rotate(rotMat, glm::radians(modRot[1]), VEC3_AXIS_Y);
	rotMat = glm::rotate(rotMat, glm::radians(modRot[2]), VEC3_AXIS_Z);

	glm::mat4x4 scaleMat = glm::scale(MAT4X4_ID, vec_modSc); // get the scale matrix of model
	glm::mat4x4 transMat = glm::translate(MAT4X4_ID, vec_modTrans); // get the translation matrix of model

	glm::mat4x4 modMat = (transMat *scaleMat *rotMat); // get the final matrix of model

	point_local = glm::vec4(4.0f, 5.0f, 3.0f, 1.0f); // assign the local point of model
	std::cout << "\nPoint of model in world space: " << glm::to_string(modMat *point_local); // print the final answer

	// END OF PROGRAM
	std::cout << "\n5820658 전형진 과제 끝." << std::endl; // E.O.P. printing identifier
	return 0; // end program
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/matrix_transform.hpp>

int main()

{

glm::vec4 local_point(4.0f, 5.0f, 3.0f, 1.0f);

// Transform 구성요소

glm::mat4 trans = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

// 회전 행렬 (X, Y, Z 순서)

glm::mat4 rotX = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));

glm::mat4 rotY = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1, 0));

glm::mat4 rotZ = glm::rotate(glm::mat4(1.0f), glm::radians(0.0f), glm::vec3(0, 0, 1));

glm::mat4 rot = rotZ rotY rotX;

// 모델 행렬 (S >R >T 순 적용)

glm::mat4 model = trans rot scale;

// 로컬 좌표를 월드 좌표로 변환

glm::vec4 world_point = model * local_point;

std::cout << glm::to_string(world_point) << 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 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

//glm::mat4 unitVector = { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} };

glm::vec3 zAxis = glm::normalize(campos - look);

glm::vec3 xAxis = glm::normalize(glm::cross(up, zAxis));

glm::vec3 yAxis = glm::normalize(glm::cross(zAxis, xAxis));

glm::vec4 col1 = { xAxis.x,yAxis.x,zAxis.x,0 };

glm::vec4 col2 = { xAxis.y,yAxis.y,zAxis.y,0 };

glm::vec4 col3 = { xAxis.z,yAxis.z,zAxis.z,0 };

glm::mat4 translation = glm::translate(glm::mat4(1.0), -campos);

glm::mat4 rotate = { col1,col2,col3,{0,0,0,1 } };

return rotate * translation;

}

int main()

{

glm::vec4 local_point(4, 5, 3, 1);

glm::mat4 Trans = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 rotate=glm::rotate(glm::mat4(1.0f),glm::radians(40.f),glm::vec3(1.0f,0.f,0.f));

rotate= glm::rotate(rotate, glm::radians(56.f), glm::vec3(0.0f, 1.f, 0.f));

rotate = glm::rotate(rotate, glm::radians(0.f), glm::vec3(0.0f, 0.f, 1.f));

glm::mat4 model = Trans* rotate *scale;

glm::vec4 world_point = model * local_point;

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

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

/*

scale 1.3 all

translate 0 5 0

rotate 40 56 0

*/

int main()

{

glm::vec4 local(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 trans = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 rx = glm::rotate(glm::radians(40.0f), glm::vec3(1.0f, 0.0f, 0.0f)); // X축 회전 40도

glm::mat4 ry = glm::rotate(glm::radians(56.0f), glm::vec3(0.0f, 1.0f, 0.0f)); // Y축 회전 56도

glm::mat4 rz = glm::rotate(glm::radians(0.0f), glm::vec3(0.0f, 0.0f, 1.0f)); // Z축 회전 0도

//glm::mat4 model = rz ry rx trans scale;

glm::mat4 model = trans scale rx ry rz;

//glm::mat4 model = trans rz ry rx scale;

glm::vec4 world = model * local;

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

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()

int main()

{

glm::vec4 localpoint(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0.0f, 0.0f));

rotation = glm::rotate(rotation, glm::radians(56.0f), glm::vec3(0.0f, 1.0f, 0.0f));

rotation = glm::rotate(rotation, glm::radians(0.0f), glm::vec3(0.0f, 0.0f, 1.0f));

glm::mat4 model = translate rotation scale;

glm::vec4 point = model * localpoint;

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

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/vec3.hpp>

#include <glm/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat2x3.hpp>

int main()

{

glm::vec4 m(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 rx = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0, 0));

glm::mat4 ry = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1.0f, 0));

glm::mat4 rz = glm::rotate(glm::mat4(1.0f), glm::radians(0.0f), glm::vec3(0, 0, 1.0f));

glm::mat4 rot = rx ry rz;

glm::mat4 trans = glm::translate(glm::mat4(1.0f), glm::vec3(0, 5.0f, 0));

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 model = trans scale rot;

std::cout << glm::to_string(model*m) << std::endl;

return 0;

}

# data[].attributes.body
//Computer_Graphcis(5)
//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;



int main() {
    glm::vec4 loc_p(4, 5, 3, 1);

    glm::mat4 rot = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));
    rot = glm::rotate(rot, glm::radians(56.0f), glm::vec3(0, 1, 0));
    rot = glm::rotate(rot, glm::radians(0.0f), glm::vec3(0, 0, 1));

    glm::mat4 Trans = glm::translate(glm::mat4(1.0f), glm::vec3(0, 5, 0));

    glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

    glm::mat4 model = Trans * scale * rot;

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

    glm::vec4 result2 = model * loc_p;
    std::cout << glm::to_string(result2) << 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/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat3x2.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

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

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

int main() {

glm::vec4 local_point(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 trans = glm::translate(glm::mat4(1.0f), glm::vec3(0, 5, 0));

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 rotX = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));

glm::mat4 rotY = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1, 0));

glm::mat4 rotZ = glm::rotate(glm::mat4(1.0f), glm::radians(0.0f), glm::vec3(0, 0, 1));

glm::mat4 rot = rotX * rotY ;

glm::mat4 model = trans rot scale;

glm::vec4 world_point = model * local_point;

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

}

# data[].attributes.body
int main()

{

glm::vec4 v(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 s = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 t = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));

rotate = glm::rotate(rotate, glm::radians(56.0f), glm::vec3(0, 1, 0));

rotate = glm::rotate(rotate, glm::radians(0.0f), glm::vec3(0, 0, 1));

//SRT

glm::mat4 m = t rotate s;

glm::vec4 wp = m * v;

std::cout << glm::to_string(wp) << 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/matrix_transform_2d.hpp>

#include <glm/gtx/transform.hpp>

int main()

{

glm::vec4 local_point(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 m(1.0f);

glm::mat4 s = glm::scale(m, glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 t = glm::translate(m, glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 xr = glm::rotate(m, glm::radians(40.0f), glm::vec3(1.0f, 0.0f, 0.0f));

glm::mat4 yr = glm::rotate(m, glm::radians(56.0f), glm::vec3(0.0f, 0.1f, 0.0f));

glm::mat4 zr = glm::rotate(m, glm::radians(0.0f), glm::vec3(0.0f, 0.0f, 0.1f));

glm::mat4 model = t xr yr zr s;

glm::vec4 world_point = model * local_point;

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

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/geometric.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

float x_translation = 0.0f;

float y_translation = 5.0f;

float z_translation = 0.0f;

float x_rotation = 40.0f; // degrees

float y_rotation = 56.0f; // degrees

float z_rotation = 0.0f; // degrees

float scale_value = 1.3f;

glm::vec4 local_point(4,5,3,1);

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(scale_value, scale_value, scale_value));

glm::mat4 trans = glm::translate(glm::mat4(1.0f), glm::vec3(x_translation, y_translation, z_translation));

glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), glm::radians(x_rotation), glm::vec3(1,0,0));

rotate = glm::rotate(rotate, glm::radians(y_rotation), glm::vec3(0,1,0));

rotate = glm::rotate(rotate, glm::radians(z_rotation), glm::vec3(0,0,1));

glm::mat4 model = trans rotate scale;

glm::vec4 world_point = model * local_point;

std::cout << glm::to_string(world_point) << 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>

int main() {

glm::vec4 local_point(4, 5, 3, 1);

glm::mat4 s = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 t = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 x = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0.0f, 0.0f));

glm::mat4 y = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0.0f, 1.0f, 0.0f));

glm::mat4 z = glm::mat4(1.0f);

glm::mat4 r = x y z;

glm::mat4 model = t r s;

glm::vec4 world_point = model * local_point;

std::cout << to_string(world_point) << std::endl;

return 0;

}

# data[].attributes.body
glm::vec4 modelP(4, 5, 3, 1);

glm::mat4 scaleMat = glm::scale(glm::mat4(1), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 transMat = glm::translate(glm::mat4(1), glm::vec3(0, 5, 0));

glm::mat4 xrotMat = glm::rotate(glm::mat4(1), glm::radians(40.f), glm::vec3(1, 0, 0));

glm::mat4 yrotMat = glm::rotate(glm::mat4(1), glm::radians(56.f), glm::vec3(0, 1, 0));

glm::mat4 modelMat = transMat scaleMat xrotMat * yrotMat;

glm::vec4 worldP = modelMat * modelP;

std::cout << to_string(modelMat) << std::endl;

std::cout << to_string(worldP) << 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>

int main()

{

glm::vec4 point(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 s = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 t = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 rx = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0, 0));

glm::mat4 ry = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1.0f, 0));

glm::mat4 model = t s rx * ry;

glm::vec4 worldPoint = model * point;

std::cout << glm::to_string(worldPoint) << 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>

int main()

{

glm::vec4 point = { 4.0f, 5.0f, 3.0f, 1.0f};

glm::mat4 rotx = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0, 0)); //x축

glm::mat4 roty = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1.0f, 0)); //y축

glm::mat4 Trans = glm::translate(glm::mat4(1.0f), glm::vec3(0, 5.0f, 0));

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 model = Trans scale rotx * roty;

glm::vec4 p = model * point;

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

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

glm::vec4 point = { 4.0f,5.0f,3.0f,1.0f };

glm::mat4 scale = glm::scale (glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 rotateX = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));

glm::mat4 rotateY = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1, 0));

glm::mat4 model = translate scale rotateX * rotateY;

std::cout << to_string(model*point) << std::endl;

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

int main()

{

glm::vec4 local(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 sca = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 tan = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 roty = glm::rotate(glm::radians(56.0f), glm::vec3(0, 1, 0));

glm::mat4 rotz = glm::rotate(glm::radians(40.0f), glm::vec3(1, 0, 0));

glm::mat4 model = tan * sca * rotz * roty;

glm::vec4 wsp = model * local;

std::cout << glm::to_string(wsp) << 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/matrix_transform.hpp>

int main() {

glm::mat4 s = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 t = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 rx = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));

glm::mat4 ry = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0, 1, 0));

glm::mat4 rz = glm::rotate(glm::mat4(1.0f), glm::radians(0.0f), glm::vec3(0, 0, 1));

glm::mat4 model = t s rx ry rz;

glm::vec4 lacal_point(4, 5, 3, 1);

glm::vec4 world_point = model * lacal_point;

std::cout << glm::to_string(world_point) << 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/matrix_transform.hpp>

#include <glm/gtc/type_ptr.hpp>

using namespace std;

int main() {

glm::vec4 local(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 rotX = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0.0f, 0.0f));

glm::mat4 rotY = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0.0f, 1.0f, 0.0f));

glm::mat4 Trans = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 mod = Trans scale rotX * rotY;

glm::vec4 world = mod * local;

cout << glm::to_string(world) << 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>

int main() {

glm::vec4 m(4.0f, 5.0f, 3.0f, 1.0f);

//로테이트

glm::mat4 rx = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1.0f, 0.0f, 0.0f));

glm::mat4 rz= glm::rotate(glm::mat4(1.0f), glm::radians(0.0f), glm::vec3(0.0f, 0.0f, 1.0f));

glm::mat4 ry = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0.0f, 1.0f, 0.0f));

glm::mat4 rot = rx ry rz;

//트렌스

glm::vec3 offset(0.0f, 5.0f, 0.0f);

glm::mat4 trans = glm::translate(glm::mat4(1.0f), offset);

//스케일

glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 modle = trans rot scale;

std::cout << to_string(modle*m) << 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>

int main()

{

glm::vec4 local(4.0f, 5.0f, 3.0f, 1.0f);

glm::mat4 sca = glm::scale(glm::mat4(1.0f), glm::vec3(1.3f, 1.3f, 1.3f));

glm::mat4 tan = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 5.0f, 0.0f));

glm::mat4 roty = glm::rotate(glm::mat4(1.0f), glm::radians(56.0f), glm::vec3(0,1,0));

glm::mat4 rotx = glm::rotate(glm::mat4(1.0f), glm::radians(40.0f), glm::vec3(1, 0, 0));

glm::mat4 mod = tan sca rotx * roty;

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

glm::vec4 wsp = mod * local;

std::cout << glm::to_string(wsp) << 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>

#include <glm/gtx/matrix_transform_2d.hpp>

glm::mat4 MyLookAt(const glm::vec3& camPos, const glm::vec3& look, const glm::vec3& up);

int main() {

glm::vec3 camPos = { 5.0f, 5.0f, 5.0f };

glm::vec3 look = { 0.0f, 0.0f, 0.0f };

glm::vec3 up = { 0.0f, 1.0f, 0.0f };

glm::mat4 view = MyLookAt(camPos, look, up);

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

return 0;

}

glm::mat4 MyLookAt(const glm::vec3& camPos, const glm::vec3& look, const glm::vec3& up) {

glm::vec3 zaxis = glm::normalize(camPos - look);

glm::vec3 xaxis = glm::normalize(glm::cross(up, zaxis));

glm::vec3 yaxis = glm::cross(zaxis, xaxis);

glm::mat4 rotation(1.0f);

rotation[0][0] = xaxis.x; rotation[1][0] = xaxis.y; rotation[2][0] = xaxis.z;

rotation[0][1] = yaxis.x; rotation[1][1] = yaxis.y; rotation[2][1] = yaxis.z;

rotation[0][2] = zaxis.x; rotation[1][2] = zaxis.y; rotation[2][2] = zaxis.z;

glm::mat4 translation = glm::translate(glm::mat4(1.0f), -camPos);

return rotation * translation;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/geometric.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 trans = glm::translate(glm::mat4(1), -campos);

glm::mat4 rot

{

glm::vec4(x.x, y.x, z.x, 0),

glm::vec4(x.y, y.y, z.y, 0),

glm::vec4(x.z, y.z, z.z, 0),

glm::vec4(0, 0, 0, 1)

};

return rot * trans;

}

int main()

{

glm::vec3 camPos(5, 5, 5);

glm::vec3 Look(0, 0, 0);

glm::vec3 Up(0, 1, 0);

glm::mat4 temp = lookAt(camPos, Look, Up);

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

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

glm::vec3 camPos = { 5,5,5 };

glm::vec3 look = { 0,0,0 };

glm::vec3 up = { 0,1,0 };

glm::mat4 m = lookAt( camPos, look, up );

std::cout << to_string(m) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t = glm::translate(glm::mat4(1), -campos);

glm::mat4 r({ x.x,y.x,z.x,0 }, { x.y,y.y,z.y,0 }, { x.z,y.z,z.z,0 }, { 0,0,0,1 });

return t * r;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

glm::vec3 camPos = { 5,5,5 };

glm::vec3 look = { 0,0,0 };

glm::vec3 up = { 0,1,0 };

glm::mat4 m = lookAt( camPos, look, up );

std::cout << to_string(m) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t = glm::translate(glm::mat4(1), -campos);

glm::mat4 r({ x.x,y.x,z.x,0 }, { x.y,y.y,z.y,0 }, { x.z,y.z,z.z,0 }, { 0,0,0,1 });

return t * r;

}

# data[].attributes.body
#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/mat2x3.hpp>

glm::mat4 lookAt(glm::vec3 camPos, glm::vec3 look, glm::vec3 upVector)

{

glm::vec3 z = glm::normalize(camPos - look);

glm::vec3 x = glm::normalize(glm::cross(upVector, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 trans = glm::translate(glm::mat4(1), -camPos);

glm::mat4 rota = {

glm::vec4(x.x, y.x, z.x, 0.0f),

glm::vec4(x.y, y.y, z.y, 0.0f),

glm::vec4(x.z, y.z, z.z, 0.0f),

glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),

};

return rota * trans;

}

int main()

{

glm::vec3 camPos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

glm::mat4 view = lookAt(camPos, look, up);

std::cout << glm::to_string(view) << 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.0f;

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

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up);

int main() {

glm::vec3 campos = { 5.0f, 5.0f, 5.0f };

glm::vec3 look = { 0.0f, 0.0f, 0.0f };

glm::vec3 up = { 0.0f,1.0f, 0.0f };

std::cout << glm::to_string(lookAt(campos, look, up)) << std::endl;;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t(1.0);

glm::mat4 trans = glm::translate(t, -campos);

glm::mat4 rota = { glm::vec4(x.x, y.x, z.x, 0.0f), glm::vec4(x.y, y.y, z.y, 0.0f), glm::vec4(x.z, y.z, z.z, 0.0f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f) };

return rota * trans;

}

# 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/transform.hpp>

using namespace glm;

// lookat 함수 없이 lookat 함수 구현하기

mat4 makeViewMatrix(const vec3& eye, const vec3& target, const vec3& worldUp)

{

vec3 forward = normalize(eye - target);

vec3 right = normalize(cross(worldUp, forward));

vec3 up = cross(forward, right);

mat4 rotation(

vec4(right.x, up.x, forward.x, 0.0f),

vec4(right.y, up.y, forward.y, 0.0f),

vec4(right.z, up.z, forward.z, 0.0f),

vec4(0.0f, 0.0f, 0.0f, 1.0f)

);

mat4 translation = translate(mat4(1.0f), -eye);

return rotation * translation;

}

int main()

{

vec3 camPos(5.0f, 5.0f, 5.0f);

vec3 lookAtPoint(0.0f, 0.0f, 0.0f);

vec3 upDir(0.0f, 1.0f, 0.0f);

mat4 view = makeViewMatrix(camPos, lookAtPoint, upDir);

std::cout << glm::to_string(view) << 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/matrix_transform_2d.hpp>

#include<glm/mat4x4.hpp>

glm::mat4 lookAt(glm::vec3 pos, glm::vec3 look, glm::vec3 up) {

glm::vec3 Z = glm::normalize(pos - look);

glm::vec3 X = glm::normalize(glm::cross(up, Z));

glm::vec3 Y = glm::cross(Z, X);

glm::mat4 T = glm::translate(glm::mat4(1.0f), -pos);

glm::mat4 R(1.0f);

for (int i = 0; i < 3; i++) R[i][0] = X[i];

for (int i = 0; i < 3; i++) R[i][1] = Y[i];

for (int i = 0; i < 3; i++) R[i][2] = Z[i];

R[3] = { glm::vec4(0,0,0,1) };

return R * T;

}

int main() {

glm::vec3 pos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

glm::mat4 view = lookAt(pos, look, up);

std::cout << glm::to_string(view) << 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.0f;

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

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up);

//glm mat4 반환

int main() {

glm::vec3 campos = { 5.0f, 5.0f, 5.0f };

glm::vec3 look = { 0.0f, 0.0f, 0.0f };

glm::vec3 up = { 0.0f,1.0f, 0.0f };

std::cout << glm::to_string(lookAt(campos, look, up)) << std::endl;;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look); //pdf 47

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t(1.0);

glm::mat4 trans = glm::translate(t, -campos);

glm::mat4 rota = { glm::vec4(x.x, y.x, z.x, 0.0f), glm::vec4(x.y, y.y, z.y, 0.0f), glm::vec4(x.z, y.z, z.z, 0.0f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f) }; //x, y, z, w

return rota * trans;

}

# 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 lookat(glm::vec3 campos, glm::vec3 look, glm::vec3 up);

int main() {

std::cout << to_string(lookat({ 5, 5, 5 }, { 0, 0, 0 }, { 0, 1, 0 })) << std::endl;

return 0;

}

glm::mat4 lookat(glm::vec3 camPos, glm::vec3 Look, glm::vec3 Up) {

glm::vec3 z = glm::normalize(camPos - Look);

glm::vec3 x = glm::normalize(glm::cross(Up, z));

glm::vec3 y = glm::cross(z, x);

glm::mat4 t = glm::translate(glm::mat4(1.0f), -camPos);

glm::mat4 r({ x.x, y.x, z.x, 0 }, { x.y, y.y, z.y, 0 }, { x.z, y.z, z.z, 0 }, { 0, 0, 0, 1 });

return r * t;

}

# 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::cross = 외적, glm::dot = 내적

glm::mat4 lookAt(glm::vec3 camPos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 z = glm::normalize(camPos - look);

glm::vec3 x = glm::normalize(glm::cross(up,z)); //외적

glm::vec3 y = glm::normalize(glm::cross(z,x)); //외적

glm::mat4 c = glm::translate(glm::mat4(1), -camPos);

//원점으로 이동

//3개의 새로운 축 구함

glm::mat4 rotate = {

glm::vec4(x.x, y.x, z.x, 0.0f),

glm::vec4(x.y, y.y, z.y, 0.0f),

glm::vec4(x.z, y.z, z.z, 0.0f),

glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),

};

//회전행렬

//glm::vec4 c4(glm::dot(x, -camPos), glm::dot(y, -camPos), glm::dot(z, -camPos),1.0f); //내적

//trans = -ex,-ey,-ez,1.0f

//같은 오브젝트 상의 한 점의 좌표값은 새로운 좌표축과의 내적을 이용해서 구함

//카메라는 항상 -z방향을 본다고 가정

return rotate *c;

}

int main()

{

glm::vec3 camPos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

glm::mat4 view = lookAt(camPos, look, up);

std::cout << glm::to_string(view) << 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/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat3x2.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

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

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

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up);

int main() {

glm::vec3 camPos = { 5.0f, 5.0f, 5.0f };

glm::vec3 look = { 0.0f, 0.0f, 0.0f };

glm::vec3 up = { 0.0f, 1.0f, 0.0f };

glm::mat4 lookat = lookAt(camPos, look, up);

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

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::cross(z, x);

glm::mat4 t(1.0);

glm::mat4 trans = glm::translate(t, -campos);

glm::mat4 rot = {

glm::vec4(x.x, y.x, z.x, 0.0f),

glm::vec4(x.y, y.y, z.y, 0.0f),

glm::vec4(x.z, y.z, z.z, 0.0f),

glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)

};

return rot * trans;

}

# 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>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

int main()

{

glm::vec3 campos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

std::cout << to_string(lookAt(campos, look, up)) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z , x));

glm::mat4 T = glm::translate(glm::mat4 (1),-campos);

glm::mat4 R {glm::vec4(x.x, y.x, z.x, 0), glm::vec4(x.y, y.y, z.y, 0), glm::vec4(x.z, y.z, z.z, 0), glm::vec4(0, 0, 0, 1)};

return R * T;

}

# 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 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up);

int main() {

glm::vec3 campos = { 5.0f,5.0f,5.0f };

glm::vec3 look = { 0.0f,0.0f,0.0f };

glm::vec3 up = { 0.0f,1.0f,0.0f };

glm::mat4 lookatm = lookAt(campos, look, up);

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

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t(1.0);

glm::vec3 offset = glm::vec3(-campos.x, -campos.y, -campos.z);

glm::mat4 trans = glm::translate(t, offset);

glm::mat4 rota = { glm::vec4(x.x, y.x, z.x, 0.0f),

glm::vec4(x.y, y.y, z.y, 0.0f),

glm::vec4(x.z, y.z, z.z, 0.0f),

glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)};

return rota * trans;

}

# 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 myLookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 zaxis = glm::normalize(campos - look);

glm::vec3 xaxis = glm::normalize(glm::cross(up, zaxis));

glm::vec3 yaxis = glm::cross(zaxis, xaxis);

glm::mat4 view(1.0f);

view[0][0] = xaxis.x; view[1][0] = xaxis.y; view[2][0] = xaxis.z; view[3][0] = -glm::dot(xaxis, campos);

view[0][1] = yaxis.x; view[1][1] = yaxis.y; view[2][1] = yaxis.z; view[3][1] = -glm::dot(yaxis, campos);

view[0][2] = zaxis.x; view[1][2] = zaxis.y; view[2][2] = zaxis.z; view[3][2] = -glm::dot(zaxis, campos);

view[0][3] = 0.0f; view[1][3] = 0.0f; view[2][3] = 0.0f; view[3][3] = 1.0f;

return view;

}

void printMatrix(const glm::mat4& mat) {

for (int i = 0; i < 4; i++) {

for (int j = 0; j < 4; j++) {

cout << mat[i][j] << " ";

}

}

}

int main() {

glm::vec3 camPos(5.0f, 5.0f, 5.0f);

glm::vec3 look(0.0f, 0.0f, 0.0f);

glm::vec3 up(0.0f, 1.0f, 0.0f);

glm::mat4 view = myLookAt(camPos, look, up);

cout << "mat4x4";

for (int i = 0; i < 4; i++) {

cout << "(";

for (int j = 0; j < 4; j++) {

cout << view[i][j] << ", ";

}

cout << ")";

}

return 0;

}

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

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

#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

glm::vec3 camPos, Look, Up;

// return the view-matrix of camera

static glm::mat4x4 lookAt(glm::vec3 cameraPos, glm::vec3 targetPos, glm::vec3 upVec) {

// calculate the normal-vector of camera (z-axis of camera)

glm::vec3 camZ = glm::normalize(targetPos -cameraPos);

// calculate the normal-vector of the x-axis of camera

glm::vec3 camX = glm::normalize(glm::cross(glm::normalize(upVec), camZ));

glm::vec3 camY = glm::normalize(glm::cross(camZ, camX)); // get y-axis of camera

// get translation-matrix of camera, from origin to camera-point

glm::mat4x4 camTrsMat = glm::translate(glm::mat4x4(1), -cameraPos);

// get rotation-matrix of camera

glm::mat4x4 camRotMat = {

{ camX.x, camY.x, camZ.x, 0 },

{ camX.y, camY.y, camZ.y, 0 },

{ camX.z, camY.z, camZ.z, 0 },

{0,0,0,1}

};

return (camRotMat *camTrsMat); // return the view-matrix of camera

}

// program entry point

int main()

{

// Q1, matrix transform

camPos = glm::vec3(5,5,5);

Look = glm::vec3(0,0,0);

Up = glm::vec3(0,1,0);

std::cout << "\nView-Matrix of Camera : " << glm::to_string(lookAt(camPos, Look, Up));

// END OF PROGRAM

std::cout << "\n5820658 전형진 과제 끝." << std::endl;

return 0; // end program

}

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

//using namespace glm;

glm::mat4 lookat(glm::vec3 campos, glm::vec3 look, glm::vec3 upvec) {
    glm::vec3 R_cam_z = glm::normalize(campos - look);
    glm::vec3 R_cam_x = glm::normalize(glm::cross(upvec, R_cam_z));
    glm::vec3 R_cam_y = glm::normalize(glm::cross(R_cam_z, R_cam_x));
    glm::vec4 col1 = { R_cam_x.x, R_cam_y.x, R_cam_z.x, 0.f };
    glm::vec4 col2 = { R_cam_x.y, R_cam_y.y, R_cam_z.y, 0.f };
    glm::vec4 col3 = { R_cam_x.z, R_cam_y.z, R_cam_z.z, 0.f };
    glm::vec4 col4 = { 0.0f, 0.0f, 0.0f, 1.0f };
    glm::mat4 trans(1.0f); glm::mat4 m = {col1, col2, col3, col4};
    glm::mat4 result = m * translate(trans, -campos);
    return result;
}

int main() {
    glm::vec3 campos(5.f, 5.f, 5.f);
    glm::vec3 look(0.f, 0.f, 0.f);
    glm::vec3 up(0.f, 1.f, 0.f);
    glm::mat4 result = lookat(campos, look, up);
    std::cout << glm::to_string(result) << 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/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 LookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)
{
	//glm::mat4 unitVector = { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} };
	glm::vec3 zAxis = glm::normalize(campos - look);
	glm::vec3 xAxis = glm::normalize(glm::cross(up, zAxis));
	glm::vec3 yAxis = glm::normalize(glm::cross(zAxis, xAxis));

	glm::vec4 col1 = { xAxis.x,yAxis.x,zAxis.x,0 };
	glm::vec4 col2 = { xAxis.y,yAxis.y,zAxis.y,0 };
	glm::vec4 col3 = { xAxis.z,yAxis.z,zAxis.z,0 };
	glm::mat4 translation = glm::translate(glm::mat4(1.0),-campos);
	
	glm::mat4 rotate = { col1,col2,col3,{0,0,0,1 } };
	return rotate*translation;
	
	
}


int main()
{
	glm::vec3 campos = { 5,5,5 };
	glm::vec3 look = { 0,0,0 };
	glm::vec3 up = { 0,1,0 };
	std::cout<<glm::to_string(LookAt(campos, look, up));
	


	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/mat4x4.hpp>

#include <glm/mat2x2.hpp>

#include <glm/mat3x2.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

int main()

{

glm::vec3 campos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

std::cout << glm::to_string(lookAt(campos, look, up)) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 Trans = glm::translate(glm::mat4(1), -campos);

glm::mat4 rot({ x.x,y.x,z.x,0 }, { x.y,y.y,z.y,0 }, { x.z,y.z,z.z,0 }, { 0,0,0,1 });

return rot * Trans;

}

# 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()

int main()

{

glm::vec3 camPos(5.0f, 5.0f, 5.0f);

glm::vec3 look(0.0f, 0.0f, 0.0f);

glm::vec3 up(0.0f, 1.0f, 0.0f);

std::cout << glm::to_string(lookAt(camPos, look, up)) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 camPos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(camPos - look);

glm::vec3 x = glm::normalize(up * z);

glm::vec3 y = glm::normalize(z * x);

glm::mat4 trans = glm::translate(glm::mat4(1.0f), -camPos);

glm::mat4 rotate = { {x.x,y.x,z.x,0.0f},{x.y,y.y,z.y,0.0f},{x.z,y.z,z.z,0.0f},{0.0f,0.0f,0.0f,1.0f} };

return rotate * trans;

}

# data[].attributes.headline
제가 실수 한 부분 - 성만규

# data[].attributes.subject
제가 실수 한 부분 - 성만규

# data[].attributes.body
새로운 z축 구하는 부분하고 translaion하는 부분하고 제가 헷갈렸네요. 월드 좌표계 원점(0,0,0) 에서 새로운 카메라 위치(ex, ey, ez) 이기 때문에 translation을 위한 offset는 (-ex,-ey-ez)가 맞습니다.

그러므로 glm::translate(glm::mat4(1.0), glm::vec3(-ex,-ey,-ez))

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#define GLM_SWIZZLE

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

glm::vec3 camPos = { 5,5,5 };

glm::vec3 look = { 0,0,0 };

glm::vec3 up = { 0,1,0 };

glm::mat4 m = lookAt( camPos, look, up );

std::cout << to_string(m) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t = glm::translate(glm::mat4(1), -campos);

glm::mat4 r({ x.x,y.x,z.x,0 }, { x.y,y.y,z.y,0 }, { x.z,y.z,z.z,0 }, { 0,0,0,1 });

return t * r;

}

# 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>

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up) {

glm::vec3 zaxis = glm::normalize(campos - look);

glm::vec3 xaxis = glm::normalize(glm::cross(up, zaxis));

glm::vec3 yaxis = glm::normalize(glm::cross(zaxis, xaxis));

glm::vec4 c1 = { xaxis.x, yaxis.x, zaxis.x, 0.0f };

glm::vec4 c2 = { xaxis.y, yaxis.y, zaxis.y, 0.0f };

glm::vec4 c3 = { xaxis.z, yaxis.z, zaxis.z, 0.0f };

glm::vec4 c4 = { 0.0f, 0.0f, 0.0f, 1.0f };

glm::mat4 trans(1.0f);

glm::mat4 m = {c1, c2, c3, c4};

glm::mat4 res = m * translate(trans, -campos);

return res;

}

int main()

{

glm::vec3 campos(5.0f, 5.0f, 5.0f);

glm::vec3 look(0.0f, 0.0f, 0.0f);

glm::vec3 up(0.0f, 1.0f, 0.0f);

std::cout << glm::to_string(lookAt(campos, look, up)) << std::endl;

return 0;

}

# 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> // 2D 변환 함수 포함

#include <glm/mat3x2.hpp> // 개념적으로는 2x3 (pdf 참조)

int main()

{

glm::vec3 comPos(5, 5, 5);

glm::vec3 Look(0, 0, 0);

glm::vec3 Up(0, 1, 0);

glm::mat4 result = lookAt(comPos, Look, Up);

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

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 Look, glm::vec3 Up)

{

glm::vec3 z = glm::normalize(campos - Look);

glm::vec3 x = glm::normalize(glm::cross(Up, z));

glm::vec3 y = glm::cross(z, x);

glm::mat4 view = glm::mat4(1.0f);

view[0][0] = x.x; view[0][1] = x.y; view[0][2] = x.z;

view[1][0] = y.x; view[1][1] = y.y; view[1][2] = y.z;

view[2][0] = z.x; view[2][1] = z.y; view[2][2] = z.z;

glm::mat4 trans = glm::mat4(1.0f);

trans[3][0] = Look.x - campos.x; trans[3][1] = Look.y - campos.y; trans[3][2] = Look.z - campos.z;

glm::mat4 result = view * trans;

return result;

}

# 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>

#include <glm/gtx/matrix_transform_2d.hpp>

#include<glm/mat3x3.hpp>

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 rat = { {x.x, y.x, z.x, 0}, {x.y, y.y, z.y, 0}, {x.z, y.z, z.z, 0}, {0,0,0,1} };

glm::mat4 tr = glm::translate(glm::mat4(1), -campos);

return rat * tr;

}

int main()

{

glm::vec3 camPos = { 5.0f,5.0f,5.0f };

glm::vec3 Look = { 0.0f,0.0f,0.0f };

glm::vec3 Up = { 0.0f,1.0f,0.0f };

glm::mat4 looka = lookAt(camPos, Look, Up);

std::cout << to_string(looka);

return 0;

}

# data[].attributes.body
#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 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 zAxis = glm::normalize(campos - look);

glm::vec3 xAxis = glm::normalize(glm::cross(up, zAxis));

glm::vec3 yAxis = glm::normalize(glm::cross(zAxis, xAxis));

glm::mat4 trans = glm::translate(glm::mat4(1), -campos);

glm::mat4 rot

{

glm::vec4(xAxis.x, yAxis.x, zAxis.x, 0),

glm::vec4(xAxis.y, yAxis.y, zAxis.y, 0),

glm::vec4(xAxis.z, yAxis.z, zAxis.z, 0),

glm::vec4(0, 0, 0, 1)

};

return rot * trans;

}

int main()

{

glm::vec3 campos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

glm::mat4 viewMat = lookAt(campos, look, up);

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

return 0;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

glm::vec3 camPos(5, 5, 5);

glm::vec3 look(0, 0, 0);

glm::vec3 up(0, 1, 0);

std::cout << glm::to_string(lookAt(camPos, look, up)) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::mat4 tr = glm::translate(glm::mat4(1), -campos);

glm::vec3 z = glm::normalize(look - campos);

glm::vec3 x = glm::normalize(up * z);

glm::vec3 y = glm::normalize(z * x);

glm::vec4 c1(x[0], y[0], z[0], 0);

glm::vec4 c2(x[1], y[1], z[1], 0);

glm::vec4 c3(x[2], y[2], z[2], 0);

glm::vec4 c4(0, 0, 0, 1);

glm::mat4 ro(c1, c2, c3, c4);

return ro*tr;

}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

glm::vec3 camPos(5, 5, 5); // cameraPos

glm::vec3 Look(0, 0, 0); // cameraTarget

glm::vec3 Up(0, 1, 0); // Upvector

std::cout << glm::to_string(lookAt(camPos, Look, Up)) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 move = look - campos;

glm::vec3 NewZAxies = glm::normalize(look - campos);

glm::vec3 NewXAxies = glm::normalize(up * NewZAxies);

glm::vec3 NewYAxies = glm::normalize(up * NewXAxies);

glm::mat4 viewingMat =

{

{ NewXAxies.x, NewYAxies.x, NewZAxies.x, 0 },

{ NewXAxies.y, NewYAxies.y, NewZAxies.y, 0 },

{ NewXAxies.z, NewYAxies.z, NewZAxies.z, 0 },

{ 0 ,0, 0, 1}

};

return viewingMat;

}

# 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 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up);

int main()

{

std::cout << to_string(lookAt({ 5,5,5 }, { 0,0,0 }, { 0,1,0 })) << std::endl;

return 0;

}

glm::mat4 lookAt(glm::vec3 campos, glm::vec3 look, glm::vec3 up)

{

glm::vec3 z = glm::normalize(campos - look);

glm::vec3 x = glm::normalize(glm::cross(up, z));

glm::vec3 y = glm::normalize(glm::cross(z, x));

glm::mat4 t = glm::translate(glm::mat4(1), -campos);

glm::mat4 r({ x.x,y.x,z.x,0 }, { x.y,y.y,z.y,0 }, { x.z,y.z,z.z,0 }, { 0,0,0,1 });

return r*t;

}