pwn't.
Samapico - Wed May 19, 2010 5:10 pm
Post subject:
I hate you all, immature Internet people!
Blocks - Tue May 25, 2010 1:55 am
Post subject:
The two times I've come across bounding boxes and collision detection, cylinders have always been approximated as regular right prisms. Octagonal is actually pretty good (4 boxes), 16agonal is very good (8 boxes). It's a lot simpler just to keep all your bounding boxes as ... boxes.
K' - Tue May 25, 2010 5:07 pm
Post subject:
3D is just cpu taxing heavy. Stick to 2D. Elipses and rectangles. Work best.
Anonymous - Tue May 25, 2010 5:35 pm
Post subject:
... What if I need that 3rd dimension?
Computing the 2D cross-section / intersection would be just as hard
And as I said, this isn't a game or anything, I don't care if it takes a millisecond to compute (OH NOES, I HAS A SQUARE ROOT)
Also... I found a way to do it in the Programming Gems book, but it's actually to quickly eliminate non-visible cylinders in a frustum (truncated square-based pyramid Field of View), and it gives some false-positives in some cases... But I think I could add a check with a plane vs axis-aligned box check
That one's probably much easier, but my day at work is done, so... if you want to have fun, find me a plane vs box intersect test
To quickly explain the solution I'm using:
Take the 2 endpoints of the cylinder;
For each of the 6 box planes:
-Adjust the plane with the 'effective radius', which is the dot product of the cylinder's axis and the plane's normal, multiplied by the actual radius.
-Test both endpoints with each of these planes
It works fine except when the cylinder is near a corner, where you kind of detect a "collision" with both adjusted planes... But I want to add a condition that the cylinder's cap plane must also intersect with the box.
I'll show images when I have some time.
Anonymous - Wed May 26, 2010 11:28 am
Post subject:
Just found this... Seems like a pretty simple cylinder vs plane test... And if I just test against 6 planes, it should work
template <typename Real>
bool IntrPlane3Cylinder3<Real>::Test ()
{
// Compute extremes of signed distance Dot(N,X)-d for points on the
// cylinder. These are
// min = (Dot(N,C)-d) - r*sqrt(1-Dot(N,W)^2) - (h/2)*|Dot(N,W)|
// max = (Dot(N,C)-d) + r*sqrt(1-Dot(N,W)^2) + (h/2)*|Dot(N,W)|
Real sDist = mPlane->DistanceTo(mCylinder->Axis.Origin);
Real absNdW = Math<Real>::FAbs(mPlane->Normal.Dot(
mCylinder->Axis.Direction));
Real root = Math<Real>::Sqrt(Math<Real>::FAbs((Real)1 - absNdW*absNdW));
Real term = mCylinder->Radius*root +
((Real)0.5)*mCylinder->Height*absNdW;
// Intersection occurs if and only if 0 is in the interval [min,max].
return Math<Real>::FAbs(sDist) <= term;
} |
Though I'd have to tweak it cause I want it to be anywhere inside all of the 6 planes, while this (I think) checks if a cylinder really intersects the plane. If my cylinder is completely below a plane, I want it to consider it as an intersection
L.C. - Tue Jun 01, 2010 3:43 pm
Post subject:
Useless information, but for a sphere:
Origin + Radius + Direction its heading = Single test to see if it's colliding
Learned that from a buddy. You probably know it.
Samapico - Tue Jun 01, 2010 5:36 pm
Post subject:
Spheres are obviously easy...
But anyway, I went the easy road and generated N oriented bounding boxes to estimate my cylinder, it works just fine.
There are 2 ways to surround the cylinder with OBB's... one is to form a regular polygon around it (image 1):
length = 2*r
width = r*tan(pi/(2n))
The other way allows to reduce slightly the "wasted" space by reducing the width of each box so two adjacent boxes will have a junction right on the perimeter of the cylinder (image 2):
length = 2*r
width = r*sin(pi/(2n))
When n grows higher (4 boxes and more), the difference between the 2 is so small it doesn't matter much. But if you're using only 2 boxes, having a regular polygon around the cylinder would mean the 2 boxes would have a square base and would be completely overlapping, while if you use the 2nd way, both boxes would be forming a + kind of thing.
As for the OBB/AABB collision test code, I translated this guy's library:
http://www.geometrictools.com/LibMathematics/Intersection/Intersection.html
(well, just the few functions I needed)