Wednesday, 30 January 2013

Current State Of Play with my C++ Engine

So, I have been quite for a long time, life has a habit of getting in the way like that though, I am sure if you are a regular follower of my blog(s), you know I have a tendency to pop in and out.

That said, I am doing a few things, still working on an XNA game (Killer Core) with Mark, have also been participating in an 8WeekGame competition, as well as try and port my existing XNA engine to MonoGame, and I hope this year to, again, be contributing to the fantastic Star Trek fan project ST:Excalibur.

So, where does that leave my C++ stuff, well on the back burner to be honest, but that said, it’s not dead, back in November last year, I mailed someone the source for the engine (warts and all), have not heard if they have found it of much use, but it was nice to know people still have an interest in it. This year my good friend Ed has asked if I would post about what I have done with it so far, and so that’s what I intend to do.

If you are interested in accessing my code directly then let me know I currently have it set up on Assembla.com, so if you are a member, let me know and I can add you and you can get the latest code as it changes.

What am I going to post about then?

Well, I thought I would tell you about the classes I have created in the engine, and explain a little about what they are trying to do. As you probably know, my background for graphics engines is in XNA, so I have tried to create an engine that reflects XNA so it’s easy for me to transition to C++ and DX11, and also means that a lot of the work I have done in my XNA engine I can bring with me to C++.

We have covered the creation of devices and a window in earlier posts, so I am going to skip over that here and just go to the classes. I’ll probably do a post for each class that way I can put a bit more detail into the posts (hope enough for you).

Monday, 24 December 2012

Merry Xmas 2012 & a Happy New Year!

Just wanted to drop you all a note with some festive cheer, also so you know I have not totally dropped off the grid. I seem to go through times when I just stop posting, then Ill go mad again and put a load of stuff out, I guess it’s all down to the ebb and flow of my life. At the moment I have been evolved in the 3rd 8 Week Game Competition and I’m having a load of fun creating my game for it called Road Rumble. I have posted a few vids of progress, you can see my first few weeks here:

Week 1

This is my first weeks progress writing a game for the 8 Week Game competition. This is there 3rd competition, but my first time entering.

I thought with the time span,a 2D game would be nice and quick to do, so that's what I have gone with. I have used Farseer for the physics & collision detection, also in their samples I have taken there 2D camera too :S

Week 2

This is my second weeks development update, as you can see now have a bit of a HUD, fuel and damage, some explosions and a particle system.

Week 3 (rushed as it’s Xmas)

So, this is my third week update, it's a bit rushed as it's not really a full third weeks work, I put it up quick so I had something to show for the third week seeing as it was Xmas I really didn't think I would get anything done that holiday week.

So we have a better HUD and some more explosive stuff :D Oh, and a crappy story line I knocked up in about 5 minutes, was at the time of the Mayan Apocalypse so made sense to me at the time :P

Music sourced from here : rizm.ikaduchi.com

So, merry Xmas one and all, hope you have a great new year too, stay tuned, you never know I may just post some more stuff :D

Regards,

Charles.

Friday, 21 September 2012

Killer Core–Reloaded

So, I have been quiet for a bit, and this is why, Killer Core. Way back when I was first getting into XNA I started this game, based on an old classic ZX Spectrum game called Starquake and I loved that old game.

I have to say a big thanks to Mark Neale as he has taken on the mantle of Physic programmer on this project and without his input, I/we would be no where near this stage.

We are still a long, long way off making this a game, but I just wanted to post what we are up to and where we are with it. I just hope this time around the game gets finished :)

Wednesday, 8 August 2012

Axis Aligned Rectangles

So, what are you looking at in that clip?

Exactly what the title of this post is eluding to, a Rectangle structure that can be used to detect collision like the one we have in XNA. I have kept it Axis Aligned just like the intrinsic XNA one. If you don’t know what I mean by Axis Aligned, then have a Google or a Bing for it, it basically means that the collision detection is done based on the rectangle not being rotated.

In the clip we see RED rectangles, these show up when two rectangles intersect, a BLUE rectangle is the Union rectangle that holds both of the colliding rectangles, the GREEN rectangle is shown when a rectangle is Contained by another and the WHITE rectangle is the Intersect rectangle.

I have been working on trying to get a C++ framework together so I can start writing about some GPU elements, ad realize that I am skimping on the code snippets, so, here is how I have constructed the RCRectangle structure.

My header file looks like this:

struct RCRectangle
{
protected:
public:

    float X;
    float Y;
    float Width;
    float Height;

    DECLDIR RCRectangle(void);
    DECLDIR RCRectangle(XMFLOAT4 dimensions);
    DECLDIR virtual ~RCRectangle(void);


    DECLDIR static RCRectangle Intersect(RCRectangle rectangle1, RCRectangle rectangle2);
    DECLDIR static void Intersect(RCRectangle rectangle1, RCRectangle rectangle2, OUT RCRectangle rectangle3);

    DECLDIR virtual bool Intersects(RCRectangle rectangle);

    DECLDIR virtual bool Contains(RCRectangle rectangle);

    DECLDIR static RCRectangle Union(RCRectangle rectangle1, RCRectangle rectangle2);
    DECLDIR static void Union(RCRectangle rectangle1,RCRectangle rectangle2, OUT RCRectangle rectangle3);
    
};

So, we have an X and Y to give us our top left corner and a Width and a Height to give us the opposing corner.

I have also put in the same methods we have in XNA, so Intersect to get the rectangle where the two rectangles overlap, Intersects to detect rectangle intersection, Contains for when a rectangle contains another and Union used to create a rectangle that will contain the two rectangles.

The RCRectangle.cpp file has the function bodies and they look like this:

RCRectangle::RCRectangle(void)
{

}

RCRectangle::RCRectangle(XMFLOAT4  dimensions)
{
    X = dimensions.x;
    Y = dimensions.y;
    Width = dimensions.z;
    Height = dimensions.w;
}

RCRectangle::~RCRectangle(void)
{

}

void RCRectangle::Intersect(RCRectangle rectangle1, RCRectangle rectangle2,OUT RCRectangle rectangleOut)
{
    if(rectangle1.Intersects(rectangle2))
    {
        float x,y,w,h = 0;

        if(rectangle1.X >= rectangle2.X)
            x = rectangle1.X;
        else
            x = rectangle2.X;

        if(rectangle1.Y >= rectangle2.Y)
            y = rectangle1.Y;
        else
            y = rectangle2.Y;

        if(rectangle1.X + rectangle1.Width <= rectangle2.X + rectangle2.Width)
            w = (rectangle1.X + rectangle1.Width) - x;
        else
            w = (rectangle2.X + rectangle2.Width) - x;

        if(rectangle1.Y + rectangle1.Height <= rectangle2.Y + rectangle2.Height)
            h = (rectangle1.Y + rectangle1.Height) - y;
        else
            h = (rectangle2.Y + rectangle2.Height) - y;

        rectangleOut = RCRectangle(XMFLOAT4(x,y,w,h));
    }
}
RCRectangle RCRectangle::Intersect(RCRectangle rectangle1, RCRectangle rectangle2)
{
    RCRectangle retVal(XMFLOAT4(0,0,0,0));

    if(rectangle1.Intersects(rectangle2))
    {
        float x,y,w,h = 0;

        if(rectangle1.X >= rectangle2.X)
            x = rectangle1.X;
        else
            x = rectangle2.X;

        if(rectangle1.Y >= rectangle2.Y)
            y = rectangle1.Y;
        else
            y = rectangle2.Y;

        if(rectangle1.X + rectangle1.Width <= rectangle2.X + rectangle2.Width)
            w = (rectangle1.X + rectangle1.Width) - x;
        else
            w = (rectangle2.X + rectangle2.Width) - x;

        if(rectangle1.Y + rectangle1.Height <= rectangle2.Y + rectangle2.Height)
            h = (rectangle1.Y + rectangle1.Height) - y;
        else
            h = (rectangle2.Y + rectangle2.Height) - y;

        retVal = RCRectangle(XMFLOAT4(x,y,w,h));
    }

    return retVal;
}

bool RCRectangle::Intersects(RCRectangle rectangle)
{
    bool retVal = true;

    // AA Check.
    if(
        X > rectangle.X + rectangle.Width ||
        Y > rectangle.Y + rectangle.Height ||
        X + Width < rectangle.X ||
        Y + Height < rectangle.Y)
    {
        // Can't possibly have overlap
        retVal = false;
    }
    else
    {
        retVal = true;
    }


    return retVal;
}

bool RCRectangle::Contains(RCRectangle rectangle)
{
    bool retVal = false;

    if(X <= rectangle.X && X + Width >= rectangle.X + rectangle.Width &&
        Y <= rectangle.Y && Y + Height >= rectangle.Y + rectangle.Height)
        retVal = true;

    return retVal;
}

RCRectangle RCRectangle::Union(RCRectangle rectangle1,RCRectangle rectangle2)
{
    float x = 0 ,y = 0,w = 0,h = 0;

    if(rectangle1.X <= rectangle2.X)
        x = rectangle1.X;
    else
        x = rectangle2.X;

    if(rectangle1.Y <= rectangle2.Y)
        y = rectangle1.Y;
    else
        y = rectangle2.Y;

    if(rectangle1.X + rectangle1.Width >= rectangle2.X + rectangle2.Width)
        w = (rectangle1.X + rectangle1.Width) - x;
    else
        w = (rectangle2.X + rectangle2.Width) - x;

    if(rectangle1.Y + rectangle1.Height >= rectangle2.Y + rectangle2.Height)
        h = (rectangle1.Y + rectangle1.Height) - y;
    else
        h = (rectangle2.Y + rectangle2.Height) - y;

    return RCRectangle(XMFLOAT4(x,y,w,h));
}

void RCRectangle::Union(RCRectangle rectangle1,RCRectangle rectangle2, OUT RCRectangle rectangle3)
{
    float x = 0 ,y = 0,w = 0,h = 0;

    if(rectangle1.X <= rectangle2.X)
        x = rectangle1.X;
    else
        x = rectangle2.X;

    if(rectangle1.Y <= rectangle2.Y)
        y = rectangle1.Y;
    else
        y = rectangle2.Y;

    if(rectangle1.X + rectangle1.Width >= rectangle2.X + rectangle2.Width)
        w = (rectangle1.X + rectangle1.Width) - x;
    else
        w = (rectangle2.X + rectangle2.Width) - x;

    if(rectangle1.Y + rectangle1.Height >= rectangle2.Y + rectangle2.Height)
        h = (rectangle1.Y + rectangle1.Height) - y;
    else
        h = (rectangle2.Y + rectangle2.Height) - y;

    rectangle3 = RCRectangle(XMFLOAT4(x,y,w,h));
}

 

If you are wondering what the DELDIR is, it’s a macro I am using so the methods can be accessed from out side the library when included in a project and it looks like this:

#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif

Hope you find this post useful, as ever C&C are welcome :D

Friday, 3 August 2012

Render Targets

So, done a bit more on my library, not only do I have a working SpriteBatch class, I have also given the option to be rendered instanced :), so once I got that all working, I decided the next thing for me to look at are Render Targets.

As you can see from the clip, I have it working, but there is an issue in there that I want to get sorted before I move on, I am not totally sure why it’s doing what it’s doing, but I hope to get to the bottom of it..

Good news for me, is once I have this sorted I can look at post processing and deferred lighting, which if you have followed any of my posts in the past, I love playing with both those elements.

Monday, 23 July 2012

XNA Samples in C++

So I was looking at one of the 2D samples on the creators club site, namely this one, where MS show how to use XNA to create a quick 2D shooter. I thought this would be a good test to see how far I am with my library as far as my sprite batch code goes, and hoped it would show up a few issues (which thankfully it did)

Now, due to my poor C++ I still have a number of issues, so I wont be putting this library up yet, but I plan to take take the existing creators club samples and use them and their assets (hope MS don’t mind) to do samples for my library.

I am also hoping to get working samples for Windows 8 Metro applications too, time willing.

In the mean time, take a look at where I am so far with this first sample. As you can see in the clip I have animated sprites now as well, still no sound, music is played by the clip and is not in game music, but that’s just another on the TODO list :P All assets in the clip are rendered using my C++ library, but all the assets are from the XNA sample as is.

As ever your comments are more than welcome :)

Thursday, 19 July 2012

RandomchaosDX11Lib & SpriteBatch

So, since the last post, I have started to create a XNA like library for me to use while learning all this new gubbins. I know Shawn has already started a DXToolKit, and I have to say I have lifted a tone of code from it to get my library working, but to get it working in what I had already written was proving to be difficult due to my total lack of C++ knowledge, but as this is for my experiments, it won’t hurt none me writing my own and learning from Shawn along the way.

So, as it stands at the moment, I have wrapped all I have covered so far in the library and you can now create a derived instance of RCGame (similar to our Game class in XNA) and start adding stuff to the Components list and now draw 2D using the SpriteBatch.

Some of you will be happy I am looking at the 2D stuff, it’s still a long way off done, and I am sure won’t be as robust as Shawn's stuff, but I am learning from it, and hope you guys can, as ever benefit from what I am picking up (or not in some cases :P)