February 24th, 2007 by Sharky

kick it on GameDevKicks.com 

I have just updated the source Code with some optimizations. (they’ll be incorporated in my next game release soon too)

I haven’t updated the tutorials to reflect these enhancements yet, but the general concept is still the same.

The main changes are these:

  • When constructing a BoundingPart you now additionally pass the original ModelMesh’s original BoundingSphere. This is used as a general proximity test, so the rest of the BoundingSphere’s don’t need to be transformed and tested on every frame.
  • This behavior is optional. When calling Transform() there is a bool “optimize? parameter. Pass false and the behavior is as it was before.
  • Re factored a little. The List stuff is now encapsulated into a class.
  • When you run the sample, you will notice the BoundingSpheres often don’t move with the model. This is deliberate, and demonstrates the optimizations working. It means they didn’t need to get transformed on each frame because nothing (i.e. the 3D Mouse Cursor) is in the general proximity of their BoundingPart.
  • the XBOX 360 controller now rumbles when the 3D Mouse cursor collides. ;)

The old “tutorial” code is still available in the usual place, but you can get the new optimized version here also. (just scroll down the page further to find the updated version)

Average Rating: 4.7 out of 5 based on 271 user reviews.

9 Responses to “”

  1. zygote Says:

    Nice! I cant wait to check it out :)

  2. Alfons Says:

    I like your tutorial a lot.

    But I’m not sure it’s the right version that’s up for download. Because I downloaded it and when I tried it the Xbox360 controller didn’t rumble and all of the spheres moved even if the cursor was far far away.

    Will you update the tutorial as well?

  3. Alfons Says:

    my bad…didn’t follow the instruction. “…(just scroll down a little to the “update?)”

  4. Sharky Says:

    hehe. No worries, and thanks. :)

  5. Sharky Says:

    I’ve updated the text to be a bit clearer.

  6. Ultrahead Says:

    Hi, man! Nice update. Glad to see the proximity test implementation …

  7. XNAtutorial.com » Weekly Update - Chronological Order Today Says:

    [...] Lawrence updated his 3D Collision Detection source code and tutorials, especially focusing on proximity tests. He updated Sharky’s Air Legends in the process. (tutorial) (Sharky) [...]

  8. A Says:


    I am just a newbie here. I just tried out your code to use on my FPS style game (basically in Half life style). The problem I got is my 3D model mesh is not properly allocating in the boundingspheres. The coordinate is not right the scaling also wrong. How could I make this spheres to world coordinate?

    Any suggestion?


  9. Sharky Says:

    I’m not really sure.

    Before I finished my tutorial and sample, I had originally resorted to a bit of a magic number hack when my XNA generated bounding spheres appeared too small. I just experimented with multiplying by different numbers until it looked about right for the model. As it turned out though, it was because my rendering code originally didn’t take into consideration any Bone Transforms. Once I implemented those things came right with no magic number required.

    Another thing to consider, is within the modelling tool itself. When you adjust various pieces of your model in whatever tool you use, they can remain as transformations that potentially effect the exported model. Each tool will have it’s own way of committing these transforms. In XSI I believe you have to “Freeze all transforms”.

    Your mileage may vary. I’m really no expert at any of the above. It’s just been trial and error experience for me. I could be talking bollocks, but this is what worked for me in the end.

Leave a Reply