![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
This is a function i have spent quite a lot of time to fine tune, it is an exact frustum / AABB culling function.
You can substitute Node->BoxP1 , Node->BoxP2 with Min and Max of your aabb , this functions needs some external data, you can easily replace , and frustum planes need to be computed before calling it. I have yet to find some case this function doesn't catch. Note: it uses an external class called Vec3f , which supports vector operations Pts is a vector of 8 integers d is a vector of 8 floats storing signs P is a vector of 8 Vec3f classes functions returns 0 -> box is out 1 -> box is in 2 -> box is intersecting the frustum Code:
|
|
|
|
|
|
#2 |
|
Valued Member
Join Date: Dec 2007
Posts: 107
|
errate corrige :
for ( i=0; i<5; i++ ) is for ( i=0; i<4; i++ ) |
|
|
|
|
|
#3 |
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
It sounds awfully complicated. Especially with the divides. Why not use a seperating axis test, together with some precomputed values of the frustum (tightest aabb around the frustum, the crossproduct of each frustum edge with each basis vector, projection distances of the frustum on it's planes and those vectors)? You'll only need 23 planetests in the worst case, with lots of early out oppertunities if they don't intersect.
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. |
|
|
|
|
|
#4 |
|
New Member
Join Date: Nov 2008
Location: Netherland
Posts: 1
|
Sounds like a lot of work. Check out Mark Morley's page on frustum culling. His site is down these days but you can see a copy on http://www.racer.nl/reference/vfc_markmorley.htm for example.
These days I'm using bits to get 2^3 directions for the box (AABB) I want to test; I then only check the 2 outer vertices on the AABB versus each of the 6 planes. Slightly faster. |
|
|
|
|
|
#5 |
|
DevMaster Staff
Join Date: Sep 2005
Location: The Netherlands
Posts: 1,442
|
If you use all the 6 planes you only need to test 1 vertex per plane, not 2. But it is not exact, which is what the topicstarter wanted.
___________________________________________
C++ addict - Currently working on: the 3D engine for Tomb Raider: Underworld and Deus Ex 3. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|