当前位置:网站首页>OpenGL - Coordinate Systems
OpenGL - Coordinate Systems
2022-07-05 09:12:00 【农场主er】
从顶点坐标到我们最终看到的效果,中间要经历多个坐标系的转换:
对于我们来讲,只需要关注三个矩阵即可:Vclip=Mprojection⋅Mview⋅Mmodel⋅Vlocal
Mmodel
:将局部坐标转为世界坐标的矩阵,注意此时的平移是以物体本身的坐标系为基准的Mview
:将世界坐标以摄像机的视角进行转换,比如向右平移,实际上视图会向左平移Mprojection
:对观察坐标进行投影
Camera/View space
通过view matrix
,将世界坐标系相对摄像机的位置和方向进行转换,就可以得到view space
。摄像机在世界坐标系的位置定义如下:
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);
有了位置信息之后,可以计算出LookAt matrix
:
利用glm
可以更便捷的构造出该矩阵:
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
Look around
Euler angles
俯仰角(pitch)
是描述我们如何往上或往下看的角,可以在第一张图中看到。第二张图展示了偏航角(yaw)
,表示我们往左和往右看的程度。滚转角(roll)
代表我们如何翻滚摄像机,通常在太空飞船的摄像机中使用。
鼠标左右移动改变了yaw
,上下移动改变了pitch
,变换的坐标可以计算为:
glm::vec3 direction;
// yaw 在xz平面, pitch 在yz平面
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
Camera Class
边栏推荐
- Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]
- Golang foundation - the time data inserted by golang into MySQL is inconsistent with the local time
- C [essential skills] use of configurationmanager class (use of file app.config)
- MPSoC QSPI flash upgrade method
- Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
- Editor use of VI and VIM
- 驾驶证体检医院(114---2 挂对应的医院司机体检)
- Beautiful soup parsing and extracting data
- Introduction Guide to stereo vision (7): stereo matching
- Illustrated network: what is gateway load balancing protocol GLBP?
猜你喜欢
利用请求头开发多端应用
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
Hi Fun Summer, play SQL planner with starrocks!
nodejs_ fs. writeFile
容易混淆的基本概念 成员变量 局部变量 全局变量
Introduction Guide to stereo vision (7): stereo matching
22-07-04 西安 尚好房-项目经验总结(01)
AUTOSAR from getting started to mastering 100 lectures (103) -dbc file format and creation details
Applet customization component
Use and programming method of ros-8 parameters
随机推荐
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]
Blue Bridge Cup provincial match simulation question 9 (MST)
.NET服务治理之限流中间件-FireflySoft.RateLimit
2309. 兼具大小写的最好英文字母
uni-app 实现全局变量
2309. The best English letters with both upper and lower case
Huber Loss
Talking about label smoothing technology
Editor use of VI and VIM
Svg optimization by svgo
Use and programming method of ros-8 parameters
[beauty of algebra] solution method of linear equations ax=0
C # compare the differences between the two images
2011-11-21 training record personal training (III)
Nodejs modularization
Applet data attribute method
Rebuild my 3D world [open source] [serialization-1]
Introduction Guide to stereo vision (1): coordinate system and camera parameters
Kubedm series-00-overview
利用请求头开发多端应用