The purpose of this sample is to demonstrate a specific concept in Direct2D for Windows 8.1. The example does *not* demonstrate correct design of Windows Store apps. If your goal is to rapidly write Windows Store Apps, then you should check out these great HTML/CSS3/JavaScript courses which are *currently* available *free* of charge at the Microsoft Virtual Academy:

  1. Developing in HTML5 with JavaScript and CSS3 Jump Start
  2. Developing Windows Store Apps with HTML5 Jump Start
  3. Gaming Engines for Windows 8 Jump Start

While I am personally a power freak and like playing with DirectX (when I can), you *may* be surprised at how easy it is to quickly write a fast, fluid, rich and immersive hardware accelerated Windows Store App using the ""web"" techniques that Jeremy Foster and Michael Palermo show off in the above mentioned classes :-)


Shows a way to perform collision testing between multiple Direct2D Geometries.

Building the Sample

Build with VS2013 and Windows 8.1 in the usual manner.


This sample uses the CreateTransformedGeometry method to transform two geometries into their display context and then uses the CompareWithGeometry function to perform hit testing.  While awkward, using the CompareWithGeometry function is more desirable for hit testing of geometries than using your own math since D2D Geometries can have complex shapes. 

Using ComareWithGeometry by itself may not be straightforward because it only seems to allow application of a transform to one of the two geometries.  On the other hand, if CreateTransformedGeometry is used in conjunction with
CompareWithGeometry a transform can be applied to both geometries *before* CompareWithGeometry is called and NULL can be passed in for the respective CompareWithGeometry parameter.


// See 
// ID2D1Factory::CreateTransformedGeometry 
// CD2DGeometry::CompareWithGeometry 
// and  
HRESULT TransformGeometry( 
    ID2D1Geometry *ipGeometryToTransform, 
    ID2D1Geometry **oppTranformedGeometry,  
    D2D1_MATRIX_3X2_F const & transform 
    HRESULT hr; 
    ID2D1Factory *pFactory = NULL; 
    ID2D1TransformedGeometry *pTransformedGeometry = NULL; 
    hr = pFactory->CreateTransformedGeometry( 
    // See Q&A Explanation from user treckle to understand why I should release the pFactory here 
    *oppTranformedGeometry = pTransformedGeometry; 
    return hr; 
void someHitTestingFuncPseudoCode() 
    D2D1_GEOMETRY_RELATION theRelation;  
    ID2D1Geometry * thisTGP;  
    TransformGeometry(thisGP, &thisTGP, thisTransform);  
    ID2D1Geometry * currentTGP;  
    TransformGeometry(curGP, &currentTGP, currentTransform);  
        (ID2D1Geometry *)currentTGP,  
    if (theRelation != D2D1_GEOMETRY_RELATION_DISJOINT) { 
        // A Collision has occured. 

Source Code Files

This sample used Microsoft's Direct2D Collision Sample as a template and then expanded it to create an animated collision demo.  You can find Microsoft's Direct2D Collision Sample here: