projection matrix

This article is to move the math of perspective matrix here so that I(or you if you get interested && you have the same problem as me) can review it once I forget it. Yes, I'll put everything I'm frequently referencing to this blog space. Here we go:


1. depth intepolation, linear by 1/z

 suppose the line to be projected is "ax+bz=c", to research the depth intepolation, let's suppose a point (x3, z3) in the middle way between (x1, z1) and (x2, z2), and it's projected to the plane (p3, -n), and we have

(1) n/-z = p/x

(2)ax+bz=c

remove the x we have:

x = -pz/n

-apz/n+bz=c

1/z = (-ap)/(cn) + b/c

And let's linearly interpolate p, we have

1/z3 = t/z1 + (1-t)/z2

For other vertex attributes, let's suppose it's b, we would expect the interpolated value to form the same proportion with the total difference as does the z:

(b3-b1)/(b2-b1)=(z3-z1)/(z2-z1)

b3=z3(b3(1-t)/z1+b2t/z2)

2. homogeneous clip sace, place the -z in the w position

the -z value in w position has two functions:

(1)to serve the z1,z2 value in the above equation to interpolate vertex attributes

(2)to divide the result of Mp*P, as the z was stripped out so that the Mp is possible to be constructed

2n/(r-l)      0         (r+l)/(r-l)         0

0            2n/(t-b)   (t+b)/(t-b)      0

0                0        -(f+n)/(f-n)    -2nf/(f-n)

0                0                -1             0

3. glFrustum, glPerspective

void glFrustum(GLdouble  left,  GLdouble  right,  GLdouble  bottom,  GLdouble  top,  GLdouble  nearVal,  GLdouble  farVal);

it's totally the same what we're talking about here:)

void gluPerspective(GLdouble  fovy,  GLdouble  aspect,  GLdouble  zNear,  GLdouble  zFar);

the zNear and zFar is still the same. This function suppose r=-l, and the fovy and aspect is equivalent in this way:

2n/(r-l)

=n/r

aspect=r/t

r=aspect*t

n/r

=n/(aspect*t)

=ctan(fovy/2) / aspect

4. orthographic projection(glOrtho)

      

detailed content coming soon...


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值