Linear Transform From 3D Space To 2D Space

Linear Transform From 3D Space To 2D Space

Author: Kagula

Date: 2010-03-23

简介:

    本文是文章后半部分所列教材的学习笔记。

Introduction

  How a point from the 3d cartesian space project to window space. I  explanation it used  Matlab language symantics.I assume the reader be familiar with matlab and linear algebra.

World Space To Camera Space

  Here I suppose a point is in the 3d cartesian space,other words is in the world space. It’s already undergo the linear transform of some rotation , translation , uniform scales and the  shear.

  Now I stand in the original point and want view the star in the sky, how can I see it.

  Assume the star is a point in the world space I call it Xworld. The same point I see with my eye is in my view space(also name it camera space).How to transform the point from world space to camera space. 

  First I assume the point in the 4d tuple.The coordinate I defined here is, A Axis Left to right is positive direction I call it x axis. Down to up and perpendicular to x axis is y axis. Another axis perpendicular with x and y axis is z axis,From your eye to the monitor is positive direction. Where they cross is original point,I assigned it to(0,0,0). The fourth component of the point I defined  1,why be 1 I discuss later.

  Xworld=[x1,y1,z1,1]’

  Xview =[x2,y2,z2,1]’

  Mview=[a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34]

  So the identity should be like this

Xview=Mview*Xworld.   (1-1)

Mview is a function how to evaluate it.

  You can imagine you stand in the world center of 2d cartesian but how about if you stand left offset 1 unit distance from the original of the x axis. Yes the object like move to right a one unit distance. So x component of the Xview should plus one unit.

I define E is where you stand, So the equality should be like it

     Xview = Xworld – E    (1-2)

 

  Now I think the matrix Mview=[eye(3)  -eye(3)*E;0 1],which from the reference [2].Substituting the symbol with you particular value,you will find it equal to (1-2)

Below snippet is the example,where Ex、Ey、Ez is component of the E

-[1 0 0;0 1 0;0 0 1]*[Ex Ey Ez]’=-[Ex Ey Ez]’

[eye(3)  –[Ex Ey Ez]’;0 0 0 1]=[ 1 0 0 –Ex; 0 1 0 –Ey;0 0 1 –Ez;0 0 0 1]=Mview    (1-3)                   

Also show (1-1) with substituting Mview with (1-3) equal to (1-2) left the fourth component of the Xview is 1.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

Camera Space To Clip Space(Perspective Projection)

  Before dive the paragraph you should know what is the view frustum and what is the orthographic projection,about it reference [2] Page94 Figure 4.19,Page 89.

  Step1: Projection

   Assume a point P in the view frustum, P project to the point q in the view plane(near plane),we can get the below equation

qx/px = qz/pz => qx = qz*(px/pz)  (2-1) then we get the matrix below

Mproj=[ 1 0 0 0;0 1 0 0;0 0 1 0;0 0 1/qz 0]  (2-2) OpenGL

Mproj’=[1 0 0 0; 0 1 0 0;0 0 1 1/qz;0 0 0 0]  (2-3) DirectX

 

  Step2: To normalized device coordinate

  I express it in terms of the six-tuple(l,r,b,t,n,f),denoting the left,right,bottom,top,near and far.l is you can see the most left edge,r is you can see the most right edge,the other is so on.

  Before projection,[input-1]we determined the depth we see is near plane from the far plane. [input-2] fovy ,Field of view in the y direction, in radians. [input-3]As                                                                                                                                                                                                                                                                                                                                                                                                                   pect ratio, The ratio defined as view space width divided by height.

  Then we evaluated [Output](l,r,b,t,n,f)

 

Reference《D3DXMatrixPerspectiveFovLH Functionhttp://msdn.microsoft.com/en-us/library/bb205350(VS.85).aspx

 

Because

  X_output = 2/(l-r)(n*x_input)    (2-4)

  Y_output = 2/(b-t)(n*y_input)    (2-5)

  Z_output = ( n/(f-n) )*(z_input-n)  (2-6)

So the matrix is which D3DXMatrixPerspectiveFovLH is.Detail see R1P55Equation(2.68)

  The R1P55Equation(2.67) have some complicate,You should be familiar with “Lines Project to Lines

  Below matlab code will show the relationship about the concept

  %begin

  S=0:1/100:1;

  W0 = 0.1;w1=1; %w0 is Near,w1 is Far

  S2=(W1.*s)./(w0+(w1-w0).*s)  %R1P37Equation(2.44)

  Plot(s,s2,’-r’,s,s,’-b’);

  Xlabel(‘s’),ylabel(‘s2’);

  Axis(‘square’)

  grid

  %end

  Now the objects is in the unit cube,left to right is 1 to -1,top from bottum is 1 to -1,near to far is 0 to 1(DirectX) or -1 to 1(OpenGL)

  After perspective divide (Reference 2-1 )the point in 3d space can project to 2d space(also can be windows coordinate)

 

  I have not considered the view frustum screw,because I can not understand it now, whatever in directX9 is no concern.

Reference

[1]《3D Game Engine Design-Apractical Approach to Real-Time Computer Graphics》(Second Edition) David H. Eberly  2007

[2]《Real-Time Rendering》(Third Edition) Tomas Akenine-Moller ,Eric Haines,Naty Hoffman 2008

[3]《Linear Algebra:An Interactive Approach》Jain,S.K. , Gunawardena,A.D.  2003

[4]《DirectX Documentation for C++》(Microsoft DirectX SDK (November 2008))45ret

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kagula086

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值