Welcome, Unregistered.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Reply
Old 29-May-2009, 16:28   #1
maxest
Registered
 
Join Date: Oct 2008
Posts: 7
Default Extracting frustum planes from orthographic projection

I extract perspective-frustum planes by first extracting the corners, which are computed in this manner:
Code:
		viewFrustumCorners[0] = CVector3(-1.0f, 1.0f, 0.0f);
		viewFrustumCorners[1] = CVector3(1.0f, 1.0f, 0.0f);
		viewFrustumCorners[2] = CVector3(1.0f, -1.0f, 0.0f);
		viewFrustumCorners[3] = CVector3(-1.0f, -1.0f, 0.0f);
		viewFrustumCorners[4] = CVector3(-1.0f, 1.0f, 1.0f);
		viewFrustumCorners[5] = CVector3(1.0f, 1.0f, 1.0f);
		viewFrustumCorners[6] = CVector3(1.0f, -1.0f, 1.0f);
		viewFrustumCorners[7] = CVector3(-1.0f, -1.0f, 1.0f);

		for (int i = 0; i < 8; i++)
		{
			viewFrustumCorners[i] = (CVector4)viewFrustumCorners[i] * viewProjTransformInversed;
		}
So I start with clip-space and go back to world-space. Now I need to do the same thing but for frustum that is not perpsective, but orthographic. So I tried do it in the same way. Unfortunately I don't get proper results. Could you give me some clues on how to extract the ortho-frustum corners?
maxest is offline   Reply With Quote
Old 01-Jun-2009, 23:23   #2
Nick
Senior Member
 
Join Date: Jan 2003
Location: Ottawa, Ontario
Posts: 1,783
Default

They are homogeneous coordinates, so they have 4 components. To go from 4D vectors to 3D vectors, just divide the first three component by the last one. Conversion from 3D to 4D is done by setting the last component to 1.
Code:
CVector4 viewFrustumCorners[8];

viewFrustumCorners[0] = CVector4(-1.0f, 1.0f, 0.0f, 1.0f);
viewFrustumCorners[1] = CVector4(1.0f, 1.0f, 0.0f, 1.0f);
viewFrustumCorners[2] = CVector4(1.0f, -1.0f, 0.0f, 1.0f);
viewFrustumCorners[3] = CVector4(-1.0f, -1.0f, 0.0f, 1.0f);
viewFrustumCorners[4] = CVector4(-1.0f, 1.0f, 1.0f, 1.0f);
viewFrustumCorners[5] = CVector4(1.0f, 1.0f, 1.0f, 1.0f);
viewFrustumCorners[6] = CVector4(1.0f, -1.0f, 1.0f, 1.0f);
viewFrustumCorners[7] = CVector4(-1.0f, -1.0f, 1.0f, 1.0f);

for (int i = 0; i < 8; i++)
{
	viewFrustumCorners[i] = viewFrustumCorners[i] * viewProjTransformInversed;

	viewFrustumCorners[i].x /= viewFrustumCorners[i].w;
	viewFrustumCorners[i].y /= viewFrustumCorners[i].w;
	viewFrustumCorners[i].z /= viewFrustumCorners[i].w;
}
That should do it.
Nick is offline   Reply With Quote
Old 03-Jun-2009, 12:00   #3
maxest
Registered
 
Join Date: Oct 2008
Posts: 7
Default

Yes, I know that. And my overloaded * operator does that automatically. As I said, it works for perspective projections, but doesn't want for ortho
maxest is offline   Reply With Quote
Old 03-Jun-2009, 15:31   #4
Nick
Senior Member
 
Join Date: Jan 2003
Location: Ottawa, Ontario
Posts: 1,783
Default

Then just set a simple orthographic projection matrix for which you know the frustum planes, and check the calculations by hand. Somewhere something is not working the way you expect it to work. So verify things step by step at a lower level.
Nick is offline   Reply With Quote
Old 03-Jun-2009, 16:12   #5
maxest
Registered
 
Join Date: Oct 2008
Posts: 7
Default

I guess I've just found the problem. My function which calculates the inverse of a matrix returned the same matrix. It didn't compute the inverse because determinant of ortho matrix is near 0, and I have an "if" which says that in this case the computations are to be skipped, because it is not possible to compute inverse matrix from a singular input matrix. Yet ortho isn't singular (althought it's determinant is very small)
maxest is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:22.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.