当前位置:网站首页>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 ->
边栏推荐
- Summary of "reversal" problem in challenge Programming Competition
- C # image difference comparison: image subtraction (pointer method, high speed)
- 基于STM32单片机的测温仪(带人脸检测)
- np. allclose
- Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
- Multiple linear regression (sklearn method)
- 信息与熵,你想知道的都在这里了
- Huber Loss
- Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value
- Introduction Guide to stereo vision (7): stereo matching
猜你喜欢
C语言-从键盘输入数组二维数组a,将a中3×5矩阵中第3列的元素左移到第0列,第3列以后的每列元素行依次左移,原来左边的各列依次绕到右边
高性能Spark_transformation性能
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Wxss template syntax
Rebuild my 3D world [open source] [serialization-1]
NIPS2021 | 超越GraphCL,GNN+对比学习的节点分类新SOTA
An article takes you into the world of cookies, sessions, and tokens
nodejs_ 01_ fs. readFile
信息与熵,你想知道的都在这里了
随机推荐
【ManageEngine】如何利用好OpManager的报表功能
[technical school] spatial accuracy of binocular stereo vision system: accurate quantitative analysis
驾驶证体检医院(114---2 挂对应的医院司机体检)
2309. 兼具大小写的最好英文字母
Applet network data request
阿里云发送短信验证码
Progressive JPEG pictures and related
Greendao reported an error in qigsaw, could not init daoconfig
3D reconstruction open source code summary [keep updated]
Svgo v3.9.0+
Svg optimization by svgo
STM32简易多级菜单(数组查表法)
Priority queue (heap)
What is a firewall? Explanation of basic knowledge of firewall
LeetCode 556. 下一个更大元素 III
Talking about the difference between unittest and pytest
迁移学习和域自适应
Kotlin introductory notes (VI) interface and function visibility modifiers
OpenGL - Model Loading
Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]