当前位置:网站首页>OpenGL - Coordinate Systems
OpenGL - Coordinate Systems
2022-07-05 09:18:00 【Farmer er】
From the vertex coordinates to the effect we finally see , There are many coordinate system transformations in the middle :
For us , Just focus on three matrices :Vclip=Mprojection⋅Mview⋅Mmodel⋅Vlocal
Mmodel
: A matrix that converts local coordinates into world coordinates , Note that the translation at this time is based on the coordinate system of the object itselfMview
: Convert the world coordinates from the perspective of the camera , For example, shift to the right , The view will actually pan to the leftMprojection
: Project the observation coordinates
Camera/View space
adopt view matrix
, Convert the position and direction of the world coordinate system relative to the camera , You can get view space
. The position of the camera in the world coordinate system is defined as follows :
glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f);
glm::vec3 cameraTarget = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 cameraDirection = glm::normalize(cameraPos - cameraTarget);
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraRight = glm::normalize(glm::cross(up, cameraDirection));
glm::vec3 cameraUp = glm::cross(cameraDirection, cameraRight);
With the location information , You can calculate that LookAt matrix
:
utilize glm
This matrix can be constructed more conveniently :
glm::mat4 view;
// Position Target Up
view = glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f),
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
Walk around
Moving the view is actually changing the position of the camera , The specific code can refer to ->
Look around
Euler angles
Pitch angle (pitch)
It's a corner that describes how we look up or down , You can see in the first picture . The second picture shows Yaw angle (yaw)
, Indicates the degree to which we look left and right . Roll angle (roll)
Represents how we roll the camera , Usually used in spacecraft Cameras .
Moving the mouse left and right changes yaw
, Moving up and down changes pitch
, The transformed coordinates can be calculated as :
glm::vec3 direction;
// yaw stay xz Plane , pitch stay yz Plane
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
Zoom
The effect of enlargement and reduction can be achieved by transmission projection , The specific code can refer to ->
Camera Class
Easy to use , We can encapsulate the functions of the camera -> , Usage method ->
边栏推荐
- 2310. The number of bits is the sum of integers of K
- 嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
- Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
- Global configuration tabbar
- Wxss template syntax
- Transfer learning and domain adaptation
- Kotlin introductory notes (I) kotlin variables and non variables
- [beauty of algebra] solution method of linear equations ax=0
- uni-app 实现全局变量
- My life
猜你喜欢
22-07-04 西安 尚好房-项目经验总结(01)
Applet data attribute method
Kotlin introductory notes (VIII) collection and traversal
Confusion matrix
牛顿迭代法(解非线性方程)
Huber Loss
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
What is a firewall? Explanation of basic knowledge of firewall
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
Wxss template syntax
随机推荐
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
Svg optimization by svgo
Applet data attribute method
Alibaba cloud sends SMS verification code
Blue Bridge Cup provincial match simulation question 9 (MST)
Talking about label smoothing technology
Svgo v3.9.0+
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
nodejs_ fs. writeFile
STM32简易多级菜单(数组查表法)
Greendao reported an error in qigsaw, could not init daoconfig
np.allclose
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Rebuild my 3D world [open source] [serialization-2]
nodejs_ 01_ fs. readFile
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
File server migration scheme of a company
Blogger article navigation (classified, real-time update, permanent top)