1、二维及三维观察,回顾第三章讲的基本概念,Start from 3D object and finally displayed on the 2D screenThe objects are being transformed to various spaces, they include建模坐标系(局部坐标系)世界坐标系观察坐标系(Camera Space)规范化坐标系设备坐标系(屏幕坐标系),Different Spaces in Graphics,From Egon Raths Notes,Different Spaces in Graphics,To convert between sp
2、aces, different matrices are involvedModel Matrix (From object space to world space)View Matrix (From world space to camera space)Projection Matrix (From camera space to screen space),建模坐标系,Local coordinate system of the 3D geometrical objectsIn OpenGL, it is the space whenever the 3D geometry is be
3、ing createdE.g. a cube created about originThe vertices coordinates:(-1,1,1), (-1,-1,1), (1,-1,1), (1,1,1),(-1,1,-1), (1,1,-1), (1,-1,-1), (-1,-1,-1),世界坐标系,The space where all objects are positionedE.g. our cube are moved to the desired place in the world spaces coordinate frameWe can do this by mul
4、tiplying the vertices of the cube with the Model Matrix,World Space Frame,建模坐标系到世界坐标系的转换,A vertex (-1,1,1) in object space is going to transform into world space by the following Matrix Mmodel,Mmodel =,Mmodelv =,=,=,观察坐标系,The space where the camera is being the center (origin) Moving a Video Camera
5、Backward is the same as moving the filmed object forward,World Space Frame,Camera Space Frame,世界坐标系到观察坐标系,A vertex (9,-2,-5) in world space is going to transform into camera space by the following Matrix Mview,Mview =,Mviewv =,=,=,Camera Space / Eye Space,In some rendering engine, e.g. OpenGL, the C
6、amera is always set at the worlds centerSo, The Model and View Matrix are being combined to form the ModelView Matrix insteadUsing the examples above,Mmodelview = MmodelMview =,屏幕坐标系,In the camera space, we already have all vertices in a position viewing from the cameraThe last process is the projec
7、tion of 3D vertices to the 2D coordinates on the screen/film of a camera,World Space Frame,Camera Space Frame,裁减窗口与视口,裁减窗口二维场景中要显示的部分视口指定在输出位置的什么位置进行观察将不同尺寸的裁减窗口连续映射到固定尺寸的视口中,则可以得到“拉镜头”的效果通过将一个固定尺寸的裁减窗口移过场景中的不同位置,可以产生“移镜”的效果裁减窗口和视口一般是正则矩形,二维观察流水线,二维应用的观察坐标系和世界坐标系一致世界坐标系中指定一个观察坐标系规范化坐标系裁减工作通常在规范化设备坐标
8、系中进行规范化和视口变换,三维观察流水线,三维观察坐标系的设定,观察点观察方向观察向上方向投影平面使用一个标量参数设定观察平面沿z轴方向的位置对象到观察平面的投影与场景在输出设备的显示对应观察平面法向量图形系统中,如何确定观察平面法向量观察向上向量一般通过世界坐标系获取,但需调整到与z轴垂直的方向uvn观察坐标系通过观察平面法向量N及观察向上向量V来获得Y轴方向计算V和N的叉积可得到正确的U的方向并形成右手观察系统右手观察坐标的一组单位轴向量构成uvn观察坐标参考系统,三维观察坐标系,生成三维观察效果通过改变观察参数,可以得到场景中的多个视图广角视图立体视图移镜效果几何变换可达到改变观察参数的
9、效果世界坐标系到观察坐标系的变换观察坐标系原点移动到世界坐标系原点的矩阵观察坐标系叠加到世界坐标系的组合旋转变换矩阵,OpenGL观察变换函数,OpenGL实用库指定三维观察参数的函数设定对称透视投影变换的函数OpenGL基本库正交投影斜平行投影视口变换GLUT定义和管理显示窗口,OpenGL观察变换函数,glMatrixModel(GL_MODELVIEW)gluLookAt(x0, y0, z0, xref, yref, zref, Vx, Vy, Vz),投影变换,平行投影坐标位置沿平行线变换到观察平面保持对象有关比例不变计算机辅助绘画和设计生成比例工程图正投影斜投影透视投影对象位置沿会
10、聚到观察平面后一点的直线变换到投影坐标系不保持对象的相关比例透视投影的真实感较好,两种投影方式,In CG, 2 common view projections are Parallel/Orthographic projectionPerspective projectionBut we can still treat all projections the same wayagain by matrix multiplication,平行投影,All projection lines are orthogonal (perpendicular) to the projection plan
11、ePreserves both distances and anglesShapes preservedSuitable for measurements,Projection plane,平行投影,Commonly used in graphics design and Computer Aided Design (CAD)Frontal, Rear, Top views,正投影,对象描述沿与投影平面法向量N平行的方向到投影平面上的变换N称为正投影或正交投影OpenGL正交投影函数glMatrixModel(GL_PROJECTION)glOrtho(xwmin, xwmax, ywmin,
12、 ywmax, dnear, dfar),透视投影,All projection lines converge to a point : the center of projection (COP)COP is the aperture of camera,透视投影,Objects further from viewer are projected smaller than the same sized objects closer to the viewerLooks realisticFeeling of depthMore difficult to construct by hand than parallel projections (but not more difficult by computer),,特殊镜头效果,Lens flareSimulate the effect with the use of the flare textureMotion blurAccumulate the rendering result of several frames,Fast OpenGL-rendering of Lens Flares,Motion Blur - OpenGL projects in Delphi,