3D世界中,在计算各个物体位置的时候是以世界坐标为主的,但是最终却是所有3D模型都需要转换到视野空间中的(view space),这样才能在屏幕中显示出来。
我们可以想象3D空间中有很多模型(人物,汽车,枪等),同时也一直都存在一个摄像头,而我们就是通过这个摄像头去看我们创造的3D世界的。
这个时候,只要我们知道摄像头在3D世界中的位置,即摄像头的世界坐标,那么就可以通过位置变换操作(Transformation)计算出一个矩阵V,表示乘以这个矩阵就可以把摄像头放到需要的位置。
这个时候,只要计算矩阵V的逆矩阵(V的负一次方)用view表示,就可以把世界空间中的所有物体的位置乘以这个矩阵view,那么就是这些物体在视野空间中(view space)的相对位置了。
原理是这样的,但是到了D3D中,要求这个view matrix是有现成的函数XMMatrixLookAtLH(...),代码如下:
float x = radius*sinf(phi)*cosf(theta);
float y = radius*sinf(phi)*sinf(theta);
float z = radius*cosf(phi);
XMVECTOR camera_pos = XMVectorSet(x, y, z, 1.0f);
XMVECTOR focus_pos = XMVectorZero();
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
view = XMMatrixLookAtLH(camera_pos, focus_pos, up);
这个函数是根据三个参数来计算出最终的矩阵的,分别是:摄像头的位置camera_pos, 镜头聚焦点focus_pos; 和垂直方向up,一般是垂直向上。
当然其中的数学计算过程还是挺复杂的,不过了解了原理,用起这个函数就不会觉得那么神秘了,也不过是利用数学计算出一个矩阵罢了。否则我总觉得会害怕碰这些函数的,尤其是一有错的时候,就会猜测会不会这些神秘函数的问题呢?
分享到:
相关推荐
introduction-computer-graphics-3rd 计算机图形学-基于opengl 和java 英文第三版,2023年最新
computer graphics, from an educational point of view, students will be well versed in many essential algorithms useful to understanding in-depth, more ad- vanced algorithms. The book will also be ...
Springer - Geometric Algebra For Computer Graphics - 2008
Interactive Computer Graphics A Top-Down Approach with WebGL(7th) 英文无水印pdf 第7版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除...
中国大学Mooc视频课程--计算机图形学[万琳]配套实验源码 目前上线实验 * 实验一:绘制窗体 * 实验二:绘制三角形 * 实验三:绘制四边形 * 实验四:绘制球 * 实验五:绘制模型 * 实验六:旋转立方体 ...
Computer Graphics - Principles and Practice 3rd edition 2014,pdf格式,适合学习
Interactive Computer Graphics:A.Top-Down Approach with Shader-Based OpenGL(6th.2011)
Hands-On-GPU-Accelerated-Computer-Vision-with-OpenCV-and-CUDA-master源代码
Vince - Geometry for Computer Graphics Vince - Geometry for Computer Graphics Vince - Geometry for Computer Graphics
Advanced Methods in Computer Graphics - With Examples in OpenGL
计算机图形学国外经典教材,英文第二版,老虎书
3d_computer_graphics_-_a_mathematical_introduction_with_opengl
3D Computer Graphics - A Mathematical Introduction with OpenGL
Fundamentals of Computer Graphics-CRC (2016) 英文原版PDF下载 备份一下
This book is an introduction to 3-D computer graphics with particular emphasis on fundamentals and the mathematics underlying computer graphics. It includes descriptions of how to use the cross-...
COS 426计算机图形学比赛参赛作品作为COS 426计算机图形学的一部分,这是2020年Spring开设的普林斯顿计算机科学高级课程,邀请学生在课程分配的基础上进行思考,设计和实施其他功能,以提交给全职员工评判的全班竞赛...
Lengyel E.-Mathematics for 3D game programming and computer graphics-PTR (2011) 3D游戏与计算机图形学中的数学方法 英文版
深度学习,用opencv处理视频,英文版书籍,适合计算机视觉人员学习
Title: Computer Graphics Through OpenGL: From Theory to Experiments, 3rd Edition--true PDF Author: Sumanta Guha Length: 760 pages Edition: 3 Language: English Publisher: Chapman and Hall/CRC ...