Archived

This topic is now archived and is closed to further replies.

d000hg

Building a frustum, AAAAAAAAAAAAAGHH!!

Recommended Posts

This is so frustrating! I want to build the planes for a frustum to do boundary-box viewing tests. I want to use the same information I give D3D to create a view-matrix (FOV, aspect ratio, near and far z values), to create planes which fit the boundary of where stuff stops being on-screen. Just having the camera centred at the origin pointing wherever it does without rotation (along z-axis?) would do. I''ve done this before but thi time it just WON''T work! Then I want to transform the planes, firstly to keep up with the camera moving, then for the world matrix of the object being looked at. Why do I have to use transpose inverse matrices - is this still needed if the matrices only do rotation and no translation?
Read about my game, project #1 NEW (13th August): A new screenshot is up, plus diaries for week #3
John 3:16

Share this post


Link to post
Share on other sites
Thanks for that, but still problems. Should I be doing projection matrix, followed my view or the other way round. View, followed by projection is just crap, the other way round gives almost correct results - this is it working ok and this is it screwing up. Can someone tell me how to test a boundary box against the frustum please?



Read about my game, project #1
NEW (13th August): A new screenshot is up, plus diaries for week #3


John 3:16


[edited by - d000hg on September 2, 2002 8:06:25 AM]

Share this post


Link to post
Share on other sites
to test a bounding box against the planes: (pseudocode only)
(assumes that the normals for the frustum planes point INWARDS
so that stuff is inside the frustum, only if it is INFRONT of
ALL the frustum planes (is reversed for outward facing normals))

int count1 = [number of points in bounding box]
for each point p in the bounding box{
int count2 = [number of frustum planes];
for each plane in the frustum{
if (DotProduct(p,plane.Normal) - plane.PointOnPlane) > 0)
count2--;
}
if (count2==0)
count1--;
}
if (count1 == 0){
// this bounding box lies completely in the frustum
}else if (count1 < [number of points in bounding box]){
// part of this bounding box is inside the frustum but
// not all of it
}else{
// the bounding box lies completely outside the frustum
}


thats just as I was going along, but basically we test to see that every point in the bounding box lies inside every plane
of the frustum.
if so then the box is inside the frustum.
if some of the points lie completely in the frustum, then the box is partially inside the frustum.
otherwise, its completely out of the frustum.

HTH and that there''s no big errors in the above code.
Toby
if (

Gobsmacked - by Toby Murray

Share this post


Link to post
Share on other sites
Got it fixed, all my original code was fine I think, but in loading the map I used sscanf, reading an int to a short variable which screwed it up!



Read about my game, project #1
NEW (13th August): A new screenshot is up, plus diaries for week #3


John 3:16

Share this post


Link to post
Share on other sites
quote:
Original post by tobymurray
thats just as I was going along, but basically we test to see that every point in the bounding box lies inside every plane
of the frustum.
if so then the box is inside the frustum.
if some of the points lie completely in the frustum, then the box is partially inside the frustum.
otherwise, its completely out of the frustum.



Is this true? Imagine if a corner of the frustum intersected a face of the bounding box ... this would give a false negative, wouldn''t it?

Share this post


Link to post
Share on other sites
quote:

Is this true? Imagine if a corner of the frustum intersected a face of the bounding box ... this would give a false negative, wouldn''t it?



I think that, besides checking for the vertices, a box can intersect the frustum even if there are no vertices inside the frustum, so I suppose there would be another kind of checking more.

I''m stuck in the same, so if anyone knows a good way to check if a box intersect the frustum, please post it here.

Share this post


Link to post
Share on other sites
A perfect test, that is always right, is quite complicated. However one that always tells what''s in correctly but may rarely give a false positive is very simple.
For each camera plate, check all the vertices of the bounding box. If all of them are outside then the box is out of view. If after checking all the planes no vertices were outside any plane then the box is completely in. Otherwise it should be drawn but is not completely inside (if it''s a quadtree/octree you want to test the sub-nodes)

Does this help?



Read about my game, project #1
NEW (13th August): A new screenshot is up, plus diaries for week #3


John 3:16

Share this post


Link to post
Share on other sites