1

Possible Duplicate:
Collision detection between two general hexahedrons

Right now I do collision detection by finding the min and max and doing bounding box check. Unfortunately, my player cube rotates with the camera and this makes for some annoying results when the player is at a 45 degree angle. The constraints are that each cube is axis alligned and has 8 verticies, but the player one might be rotated (basically I do sin, cos, to each vertex and rotate about the cube's center. Given this, how can I do accurate collision detection since my player is rotated?

Thanks

Community
  • 1
  • 1
jmasterx
  • 52,639
  • 96
  • 311
  • 557
  • 2
    Am I missing something or are you asking the same question over and over again? – Eiko Sep 06 '10 at 13:20
  • This may not be an exact duplicate. Milo is using a non-standard vocabulary: by "cube" he means hexahedron (i.e. six faced solid figure), and "axis aligned" is not perfectly clear to me but may mean "opposite faces are parallel". He is not distinguishing clearly between the many classes of regularity and right-angledness that are available. This question may be slightly more constrained that the most recent one, but he was presented with two working algorithms for the general case. In any case, I can no longer be bothered. – dmckee --- ex-moderator kitten Sep 06 '10 at 16:37
  • "Axis aligned" in game development vernacular means that the faces are all parallel to the three major axis planes, i.e. those at X=0, Y=0, and Z=0. Where I went to school, "cube" is defined as a hexahedron with right angles between all edges and all edges the same length. – dash-tom-bang Sep 07 '10 at 21:48

3 Answers3

1

Find the intersection line of each pair of planes, and then determine if that intersection line is at least partly within both of the polygons.

Or, for a simpler solution, pretend that the player is a sphere.

erikkallen
  • 33,800
  • 13
  • 85
  • 120
  • Okay how can I do sphere-AABB cube collision detection? – jmasterx Sep 06 '10 at 13:04
  • Sometimes cylinder might be better than sphere. This is how collision detection was done in Quake I for example. – mip Sep 06 '10 at 13:06
  • Which ever one is simplest to implement – jmasterx Sep 06 '10 at 13:07
  • Cynlinder collisions should be pretty darned easy. You basically take the distance between the centers and check that it is larger than the sum of the radiuses. – Gian Sep 06 '10 at 13:09
  • doesnt that mean the cube is treated like a cylinder too? I want cylinder->cube – jmasterx Sep 06 '10 at 13:15
  • For collision detection or intersection detection between a rotated box and a sphere or a cylinder, you can transform both objects so that the box is a unit AABB (or just any AABB). That should make it easier. – fingerprint211b Sep 06 '10 at 13:18
1

Perhaps the Separating axis theorem is applicable in 3-dimension for your problem.

Gian
  • 13,735
  • 44
  • 51
-2

If one of the cubes is not rotated then its easy to check if a single point is within the cube (with bounds checks). So take each of the 8-nodes of the rotated cube and check to see if it falls within the unrotated cube.

John Alexiou
  • 28,472
  • 11
  • 77
  • 133