当前位置:网站首页>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 ->
边栏推荐
- Transfer learning and domain adaptation
- Creation and reference of applet
- c语言指针深入理解
- Greendao reported an error in qigsaw, could not init daoconfig
- Multiple linear regression (sklearn method)
- Generate confrontation network
- 一文详解图对比学习(GNN+CL)的一般流程和最新研究趋势
- Shutter uses overlay to realize global pop-up
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- 2309. 兼具大小写的最好英文字母
猜你喜欢
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
Applet data attribute method
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Kotlin introductory notes (VII) data class and singleton class
Introduction Guide to stereo vision (7): stereo matching
My experience from technology to product manager
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Applet network data request
图神经网络+对比学习,下一步去哪?
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
随机推荐
牛顿迭代法(解非线性方程)
Priority queue (heap)
Analysis of eventbus source code
notepad++
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
OpenFeign
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Svg optimization by svgo
Codeworks round 639 (Div. 2) cute new problem solution
迁移学习和域自适应
Mengxin summary of LCs (longest identical subsequence) topics
Editor use of VI and VIM
C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea
2310. 个位数字为 K 的整数之和
编辑器-vi、vim的使用
My life
np. allclose
Kotlin introductory notes (IV) circular statements (simple explanation of while, for)
Using request headers to develop multi terminal applications
C # draw Bezier curve with control points for lattice images and vector graphics