当前位置:网站首页>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 ->
边栏推荐
- 优先级队列(堆)
- LeetCode 556. 下一个更大元素 III
- Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
- OpenGL - Model Loading
- nodejs_ fs. writeFile
- Solution to the problem of the 10th Programming Competition (synchronized competition) of Harbin University of technology "Colin Minglun Cup"
- 驾驶证体检医院(114---2 挂对应的医院司机体检)
- Newton iterative method (solving nonlinear equations)
- notepad++
- Node collaboration and publishing
猜你喜欢
OpenGL - Coordinate Systems
Composition of applet code
Applet network data request
[beauty of algebra] singular value decomposition (SVD) and its application to linear least squares solution ax=b
[code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
Wxml template syntax
Applet customization component
Priority queue (heap)
Introduction Guide to stereo vision (7): stereo matching
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
随机推荐
OpenGL - Coordinate Systems
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Introduction Guide to stereo vision (4): DLT direct linear transformation of camera calibration [recommended collection]
NIPS2021 | 超越GraphCL,GNN+对比学习的节点分类新SOTA
Applet (global data sharing)
利用请求头开发多端应用
Return of missing persons
C # image difference comparison: image subtraction (pointer method, high speed)
Rebuild my 3D world [open source] [serialization-1]
It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
Svgo v3.9.0+
The combination of deep learning model and wet experiment is expected to be used for metabolic flux analysis
Explain NN in pytorch in simple terms CrossEntropyLoss
Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time
Blue Bridge Cup provincial match simulation question 9 (MST)
信息与熵,你想知道的都在这里了
C#绘制带控制点的Bezier曲线,用于点阵图像及矢量图形
Characteristic Engineering
Editor use of VI and VIM