[Solved] How to render a mesh that has passed across the view plane?

Started by
14 comments, last by Bunker 9 years, 10 months ago

Now I can see what you meant :)

What you are actually doing is rendering the scene from the point of view of the person sitting in front of your monitor, and then projecting that rendered image onto the window coordinates. That actually doesn't have to be messed up by the clipping planes, since you can just use your clipping plane close to the actual viewer (and hence it wouldn't get anywhere near your teapot...).

Advertisement

Demo.jpg

Thanks for telling me.This link should be okay.

I did something very similar 5 years ago (picture) and all the magic with projection was done very simply by using D3DXMatrixPerspectiveOffCenterLH to create the projection matrix. Try to look at this D3DX function ;)

I thought the concepts of the near clipping plane and the view plane(or projection plane) are unified in DirectX's world before?but they're not actually. The view plane are set to z = 1 while the near clipping plane are adjustable. So it's possible to adjust the near clipping plane while keeping the view plane unmoved.

I searched MSDN for the functions that can be used for generating projection matrix, there are two of them:

The first one is commonly used. The second one is which I am using because the point of view is movable in my projection model so the matrix will be offcenter.

Details as follows:


D3DXMATRIX* D3DXMatrixPerspectiveFovLH(
  _Inout_  D3DXMATRIX *pOut,
  _In_     FLOAT fovy,
  _In_     FLOAT Aspect,
  _In_     FLOAT zn,
  _In_     FLOAT zf
);


D3DXMATRIX* D3DXMatrixPerspectiveOffCenterLH(
  _Inout_  D3DXMATRIX *pOut,
  _In_     FLOAT l,
  _In_     FLOAT r,
  _In_     FLOAT b,
  _In_     FLOAT t,
  _In_     FLOAT zn,
  _In_     FLOAT zf
);

These two functions compute the returned matrices as shown:

  • D3DXMatrixPerspectiveFovLH

xScale     0          0               0
0        yScale       0               0
0          0       zf/(zf-zn)         1
0          0       -zn*zf/(zf-zn)     0
where:
yScale = cot(fovY/2)

xScale = yScale / aspect ratio 

Parameter zn represents the position of the near clipping plane,while FOV is determined by fovy.

  • D3DXMatrixPerspectiveOffCenterLH

2*zn/(r-l)   0            0              0
0            2*zn/(t-b)   0              0
(l+r)/(l-r)  (t+b)/(b-t)  zf/(zf-zn)     1
0            0            zn*zf/(zn-zf)  0

In this matrix, zn determines both the near clipping plane and FOV. To keep FOV unchanged while zn is changing, I have to adjust the size of the view volume at the same time.

Tell me if I am wrong.


Thanks. That's really cool. How are you tracking the eye?

Well?I use a Kinect to track the eye.

 


Demo.jpg
 
Thanks for telling me.This link should be okay.

 
I did something very similar 5 years ago (picture) and all the magic with projection was done very simply by using D3DXMatrixPerspectiveOffCenterLH to create the projection matrix. Try to look at this D3DX function ;)
 

That's awesome.It could be better if the cup is "outside" the screen.
I must confess, I thought this was another raving lunatic post when I read the OP. We have had a spate of them recently.

Glad I was wrong. This stuff looks fascinating.
Problem Solved! After calling D3DXMatrixPerspectiveOffCenterLH?I simply divide the elements M(0,0) and M(1,1) by zn in the output matrix to make the view plane come back to z=1. Now it looks just fine! Maybe I didn't describe my problem properly since it's my first time to post in English. Anyway,thank you guys here for helping so much :)

This topic is closed to new replies.

Advertisement