Is this for level designer, or for the engine?
For the level designer - you'll need that code to e.g. combine static objects. Research vector graphic APIs for the solution, the task sounds pretty common for SVG, PostScript, WMF, etc.. First try using CombineRgn Win32 API :-)
For the game engine - I'd suggest you don't do what you want..
You'll spend enormous amount of CPU combining your objects together. You'll spend enormous count of branch mispredictions checking the border conditions, testing whether 2 segments intersect or not, etc.. And, this process must be repeated every frame for the visible portion of your map.
Just do bounding box checks, then collide individual objects. If your object shapes are too complex - simplify them while exporting data into the engine, and use different shapes for collision and drawing.
Update: see my C# GDI+ code that does what you want. You can easily write the same in C++: the GraphicsPath class is merely a thin wrapper over the corresponding gdiplus.dll functions.
static class GraphicsPathExt
{
[DllImport( @"gdiplus.dll" )]
static extern int GdipWindingModeOutline( HandleRef path, IntPtr matrix, float flatness );
static HandleRef getPathHandle( GraphicsPath p )
{
return new HandleRef( p, (IntPtr)p.GetType().GetField( "nativePath", BindingFlags.NonPublic | BindingFlags.Instance ).GetValue( p ) );
}
public static void FlattenPath( this GraphicsPath p )
{
HandleRef h = getPathHandle( p );
int status = GdipWindingModeOutline( h, IntPtr.Zero, 0.25F );
// TODO: see http://msdn.microsoft.com/en-us/library/ms534175(VS.85).aspx and throw a correct exception.
if( 0 != status )
throw new ApplicationException( "GDI+ error " + status.ToString() );
}
}
class Program
{
static void Main( string[] args )
{
PointF[] fig1 =
{
new PointF(-50, 0),
new PointF(0, 50),
new PointF(50, 0),
};
PointF[] fig2 =
{
new PointF(-50, 25),
new PointF(50, 25),
new PointF(0, -25),
};
GraphicsPath path1 = new GraphicsPath();
path1.AddLines( fig1 );
path1.CloseAllFigures();
GraphicsPath path2 = new GraphicsPath();
path2.AddLines( fig2 );
path2.CloseAllFigures();
GraphicsPath combined = new GraphicsPath();
combined.AddPath( path1, true );
combined.AddPath( path2, true );
combined.FlattenPath();
foreach (var p in combined.PathPoints)
{
Console.WriteLine( "<{0}, {1}>", p.X, p.Y );
}
}
}