Author Topic: 3D-Bounding Box Collision-detection?  (Read 4474 times)

0 Members and 1 Guest are viewing this topic.

Offline ScottyBrosious

  • C= 64
  • **
  • Posts: 25
  • Karma: 3
    • View Profile
3D-Bounding Box Collision-detection?
« on: January 26, 2007 »
O.k. I have this city where each building is only a
3D-Box.

Would anyone know how I could do collision-detection
on 3D-Box?

That is a 3D-Bounding Box collision-detection.
So I will not (won't) be able to walk right through a building.

Some code would be useful.
Please help me if you can.
Thanks
 

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 3D-Bounding Box Collision-detection?
« Reply #1 on: January 26, 2007 »
Most 3D games use sphere to sphere collision, but for buildings bounding box would work better.

Just test the three attributes of each point against those of your square building, if any of the points lie inside there is a collision.

If you want some specific source code, please post what you have done so far.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: 3D-Bounding Box Collision-detection?
« Reply #2 on: January 26, 2007 »
here you go mate  ;) the basics are all there you might want to change the code to suite though.

http://dbfinteractive.com/index.php?PHPSESSID=ed99002dcfd6e4a0dcdbb5217ac2eefb&topic=690.0
Challenge Trophies Won:

Offline gerarmajax

  • ZX 81
  • *
  • Posts: 2
  • Karma: 1
    • View Profile
Re: 3D-Bounding Box Collision-detection?
« Reply #3 on: January 27, 2007 »
in your case you can easily forget the 3rd dimension and do all your tests in 2D ;)
Also when the squares are all axis-aligned, the math are ridiculously simple. You end up checking that the absolute of the distance ( respectively in X and Y ) between the unit and the building is > half the side of the unit + half the side of the building

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 3D-Bounding Box Collision-detection?
« Reply #4 on: January 28, 2007 »
Hi gerarmajax, welcome to the forum!  And thanks for your input.

A bit more on bounding box collision here too
http://dbfinteractive.com/index.php?topic=658.msg9787#msg9787

Jim
Challenge Trophies Won:

Offline gerarmajax

  • ZX 81
  • *
  • Posts: 2
  • Karma: 1
    • View Profile
Re: 3D-Bounding Box Collision-detection?
« Reply #5 on: January 28, 2007 »
Thanks.
Checking the min/max is also very efficient. Then it depends how the data are stored. In a test I did a while ago, I checked the collision between squares of changing size. Storing the center position and the (half)side was more practical.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 3D-Bounding Box Collision-detection?
« Reply #6 on: January 28, 2007 »
Whoops, forgot to say hello to you, so a warm welcome to the forum. Thanks for chipping in with some help. Have your first good Karma for that.  :)
Shockwave ^ Codigos
Challenge Trophies Won: