Geeks With Blogs

News Bob Taco Industries is an ISV focused on game and app development for Microsoft platforms headed up by Michael B. McLaughlin. Mike is a Microsoft Visual C++ MVP (previously an XNA/DirectX MVP from 2011-2013), a developer, a writer, a consultant, and a retired lawyer. If you're a developer who is just getting started, consider checking out the BTI website's section for developers for links to code samples and other helpful sites.
Bob Taco Industries Blogging Division

One of the more popular series of samples for XNA was the collision detection series. Especially the 2D pixel perfect collision and transformed pixel perfect collision. So as my first sample, I’ve replicated them. But since I don’t want to maintain more samples than I need to, they are all in a single sample. Everything is heavily commented and power just went out here for some reason but I’m happy to respond to questions about the sample, so feel free to ask away in the comments and I’ll get to them as soon as I can.

The sample can be downloaded here: . The key parts of the collision detection are in CollisionDetection2D.h . I also show how to use DirectXMath’s XMMATRIX to scale, rotate, and translate images. The Game class’s CreateDeviceResources, Update, and Render member functions have been updated accordingly (in Update and Render, non-transformed pixel perfect translation code is present but commented out).

While creating this sample I found a few bugs in my Windows Store DirectX C++ Sample Base (the Present method wasn’t checking for a null swap chain RTV and DSV which could cause a crash if a tablet was rotated at the wrong time and the CreateDeviceResources code had the potential to create a cross-threading D3D crash due to the possibility of accessing the device context from multiple threads at the same time). I fixed those up both in this sample and in the original base sample code. The original base sample has been updated in place so the original download link will give you the latest code. While I was fixing those bugs I also made a few cleanups and improvements since I was changing things anyway.

I haven’t yet decided which old XNA sample I want to replicate next so if there’s something you want to see, let me know. Ultimately I’d like to port the Platformer sample, but that is a fairly large sample with a lot of parts so it’ll be a little while before I have the time to do that. I’d like to complete more of the smaller, technique-oriented samples first. And I’d also like to do a few sample showing how to work with XAML including something that shows how to do game state (along the lines of XNA’s Game State Management sample but not necessarily a direct port of it). But for now I’m going to settle in with a book and wait for power to return.


Posted on Thursday, February 14, 2013 6:21 PM directx , C++ | Back to top

Comments on this post: C++ Pixel Perfect Collision Detection Sample (and Base Sample updated!)

Comments are closed.
Comments have been closed on this topic.
Copyright © Michael B. McLaughlin | Powered by: | Join free