Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera position in Post-Perspective Space

Started by maxest Oct 17, 2008 at 10:29 AM 1 replies 1.2k views
Original Post
maxest
maxest
I'll start with some piece of code:

	D3DXMatrixLookAtLH(&matView, &cameraPosition, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 800.0f/600.0f, 1.0f, 10000.0f);

	matrixWVP = matView * matProj;

	D3DXVECTOR4 lightPosPPS(cameraPosition.x, cameraPosition.y, cameraPosition.z, 1.0f);
	D3DXVec4Transform(&lightPosPPS, &lightPosPPS, &matrixWVP);
The code above computes camera position in PPS's unit cube. I thought I will get some X, Y, Z values == 0.0 and to my surprise I got something like (0.0, -7.3, -1.0). Why is it so?
clb
clb
Since the post-perspective transform unit cube is the image of all the points inside the capped frustum volume (capped by near and far planes) after projection. The camera point lies outside the camera frustum, because it is clipped by the front plane, and thus does not lie inside the post-transformed unit cube.

I'm not sure if this is what you meant or if you're after something else?
maxest
maxest
Of course you're right :). Camera point lies outside frustum clipping. When I changed near plane of my persp. matrix to 10, I got -10 as the Z value so it's alright. However I still don't know why the Y value is -7.3. I though this should be set to 0

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.