Alex Popescu's Bloghttp://www.alexandrupopescu.com
Just another WordPress siteWed, 22 May 2013 09:14:39 +0000en-UShourly1https://wordpress.org/?v=4.9.8Free graphicshttp://www.alexandrupopescu.com/?p=102
Thu, 08 Dec 2011 23:31:41 +0000http://blog.alexandrupopescu.com/?p=102I am a programmer at core and, I guess like most programmers, I am not a very good or proficient artist (even if I did some web design in Photoshop or Flash, games are different). Therefore, when I want to do some game programming, I always struggle to have something to display and I always end up searching online for resources (preferably free).

In this post I would like to mention a couple of sites that helped me a lot when experimenting with ideas and prototypes and when needing some graphics resources.

First of all there is http://www.reinerstilesets.de/ which is just great. This guy, Reiner Prokein, just put on his site, for free, a ridiculous amount of graphics both 2D and 3D for people to use. The image on the side is a screenshot from a project that uses map tiles, vegetation and character sprites from his website and they are just great.

Then there is http://opengameart.org/ which is a great initiative in that it attempts to bring together artists to create a community that donates graphics for the “helpless” programmers like me. And the result is impressive: they have a huge collection and lots of them are licensed under some sort of creative commons license.

And last but not least, the impressive work of Daniel Cook on http://www.lostgarden.com/. He gives away not only graphics collections but even full game designs and ideas for others to do and all he wants in return is… glory

Well, it looks like there is hope for hobby game programmers after all. Check out these sites if you didn’t know them already and prepare to be amazed.

]]>Pathfinding shouldn’t care about the maphttp://www.alexandrupopescu.com/?p=96
Sun, 04 Dec 2011 12:18:01 +0000http://blog.alexandrupopescu.com/?p=96Back to posting on the blog… after a long while. Lack of time is the only issue that stops me from publishing the piling up stuff I want to share. But, as I am wrapping up the last couple of courses for my Master’s degree right now I hope to find a little bit of extra time to write.

One of those last projects I am doing is for the “Game Programming” course. This one will give me a chance to improve my XNA library of reusable classes and components that I hope to use in a real game someday.
In short, this project will be a small strategy game where some human knights battle monsters (not sure what kind yet) such as orcs (that’s new ). It’s an excuse to implement some of the basic game AI techniques such as: procedural generation, pathfinding, finite state machines and maybe, time permitting, some emotional computing.

A few days ago I was working on the pathfinding part and, as usual, I first search online to see what is already out there, so I came across THIS very nice implementation by Roy Triesscheijn. It is quite well done, but what I started thinking about was “how to make this even more generic?”. And the answer was: duh… generics. So, in order to make it work with both 2D and 3D nodes I would pass the type of the node position as a generic type. I further reduced the implementation by merging the original World class into the PathFinder and making the PathFinder non static.

this is pretty straight-forward and looks like any normal linked list node with the position that is basically the content of the node being generic. This means you can use for the position any class you want such as Point or Vector2 for 2D maps or Vector3 for 3D maps. You can even create your own class such as Point3.

Then the code for the PathFinder class, which becomes a non static abstract class is:

This uses the same generic to specify which type of positioning it is using. The idea is, based on the specific needs of the map, to have a path finder class that inherits from this one and implements the needed abstract methods:

GetPositionIndex: gets a position and returns the int index for it. This is used because the blocked array is a 1-dimensional array and all positions need to be mapped to an index in that array. Needless to say, each specific position needs to be mapped to a single specific index.

GetSquaredDistance: calculates the distance between 2 positions

GetSurrounding: returns all possible next steps based on the current position

And these two classes are the very portable part of it. Now on the specific side, a child path finder needs to be implemented, and it looks like this (this is the one I am using for a simple 2D tile based map):

that’s it. There is one change needed that I thought of: if you want to use it with sparse nodes instead of a simple grid, then the way it specifies the size needs to change. Right now the size is just a position but in case of a graph that would not work. I don’t need that right now so I can’t be bothered to come up with a solution for the moment. If you do, let me know.

]]>Transaction Indexerhttp://www.alexandrupopescu.com/?p=83
Mon, 25 Oct 2010 23:25:06 +0000http://blog.alexandrupopescu.com/?p=83When you do web mining, you usually take into account several documents (or transactions) and try to find connections between words in these documents. A practical example of this is finding connected products in people’s shopping carts, used by Amazon for example to suggest new products. To achieve this, Association rules are extracted from the shopping carts history in the database using some algorithm. The most successful and popular algorithm for this is the Apriori algorithm.

Now, in order to start implementing the algorithm the data should be ordered and the number of transactions that contains each specific term needs to be computed. I chose to implement this in a separate mini-project and to publish the C++ source code here.

This transaction indexer (as I called it) will receive as input a text file with the following form:

And will output two files, a dictionary file containing all items (alphabetically ordered) and the transaction count for each item and an indexed transaction file that contains the item indexes instead of the actual items. They will look like this:
dictionary file:

bread 2
butter 2
eggs 2
milk 2
potatoes 1
tomatoes 1

and the indexed transaction file:

1 2 3 4
2 4 6
1 3 5

The program uses a Binary search tree to sort the dictionary and calculates the outputs recursively.

More information about specific methods can be found in the documentation file generated with Doxygen and included in the attached zip archive.

If I will have time I will also put on the rest of the implementation later. Download file here.

For some XNA experiments of mine, I wanted to generate the XML asset files automatically and so I started exploring different possibilities. After searching for a while, both paid solutions like TorqueX 2D or freely available ones, I was quite unhappy with the solutions out there. So, I decided to start working on my own. This is how XEdit2D started, and then became my first published open source project.

My ideas were simple: import images, transform them into animations or tilesets, combine animations into a character sheet, use tilesets as starting point for a map editor. Now, making choices for the interface was not as simple. I want the user to be able to do many things and at the same time have a simple interface. The first attempt can be seen above.

So, there is an image tab, the user can load images into an image list and see them as thumbnails. One or more images will be selected and can be transformed into animations. After choosing how many frames are there per image, each image will be transformed into an animation and displayed into the Animations tab. A similar workflow would be followed to add animations to a character.

After doing this I had an interesting idea: why would I use a traditional interface (image lists, toolbars, icons and tabs) when I could do much better than that?! I think a more visual interface could be more useful and fun at the same time. So I started shifting my ideas towards a Diagram-like interface (something similar to a UML editor), where the user would build a graph and connect nodes to build and combine data.

I started working on it and what came out can be seen below:

I think this is a much better design, since each node would be a standalone UserControl and the main Diagram manager would handle them and the connections between them. The nodes can contain all the functionality to process inputs and offer subcontrols to see the data and interact with it.

I still need to figure out some issues with the design, such as: how to fit more animations inside a single node or how to add functionality (like an option panel) to arrows. I will post a demo video later about it. For now the project can be found on google code at: http://code.google.com/p/xedit2d/

]]>My first object trackerhttp://www.alexandrupopescu.com/?p=37
Sun, 14 Mar 2010 23:21:22 +0000http://blog.alexandrupopescu.com/?p=37In December I completed my first simple object tracker as a project for the “Intelligent Multimedia Systems” course. It wasn’t a very advanced one but it is based on very simple ideas and technologies and very effective given the right environment. The tracker was a mean-shift one, which, as opposed to a brute-force tracker does not search for the object in all pixels around last known position. The mean-shift applies a gradient to the last known position thus determining what is the most probable direction the object just moved and shifting the gradient until the object is re-centred. This results in way less calculations being made and better performance.

The whole process goes like this in short:

We have a set of frames (either as a movie or as a sequence of images) and we choose an object to be tracked in the first frame. This can be done either by giving the coordinates of a rectangle or any other location. I chose to pick the object completely by having a mask for the first frame. Below is an example of first frame and mask:

This is the input data. Then the processing starts. Based on the given mask, the object will be retrieved from the first frame, its histogram will be computed and used throughout the whole application as a reference. The histogram reflects the set of colours in the given object. Now the complicated math comes in: to find the same object in the next frame, a kernel will be multiplied with the pixels of the second frame corresponding to the position of the object in the first frame.

The kernel I used is the Epanechnikov Kernel and it is a weighted function that looks like this:

What it means is that points in the middle of the object are more important than points on the sides or corners. When multiplying this function by the values of the pixels and comparing to the colour histogram, we will see a change in the values towards the direction our object is moving and then we will need to re-centre our position to maximize the result.

It is a very effective way provided the colour is not confusing, for example the object might have a very similar colour to the background. Below are some examples of final movies with objects tracked. Two of them are from the set everybody received, a football match, and the third one I had to find myself. For that I used a set of images from the PETS 2006 International Workshop. The purpose of that workshop was to track people that left their luggage unattended for more than 30 seconds, so most of them are from stations or airports CCTV footage but it suited me just fine.

First Football match tracking clip:

Second Football match tracking clip:

CCTV tracking clip:

Of course problems can appear when using this technique if colours of other objects are similar. For example there is a spike in the second clip when the tracked player passes behind another one and both contain some black color in their histogram. But, all in all it is a very powerful way of tracking and doesn’t use a lot of processing power.

]]>.Net exception listhttp://www.alexandrupopescu.com/?p=34
Wed, 03 Feb 2010 10:57:42 +0000http://blog.alexandrupopescu.com/?p=34I’ve been looking for a complete list of all possible .Net exceptions because I like to throw the appropriate exception type when needed. MSDN doesn’t offer anything like that but I found a blog post on Mike Vallotton’s blog that was exactly what I was looking for. Here it is: .Net exceptions (all of them).
]]>3D sphere from photoshttp://www.alexandrupopescu.com/?p=27
http://www.alexandrupopescu.com/?p=27#commentsMon, 01 Feb 2010 22:10:56 +0000http://blog.alexandrupopescu.com/?p=27I just presented my demo at the end of last week so now I have some more time to write about it. As I was saying, the purpose was building a multi-touch interface using infrared lights. I also needed to have something to demonstrate on. After thinking about and talking to my coordinator, Frank, the decision was to implement some sort of 3D image selection interface.

A short specification would be this: we have a set of photos (a few thousand for example), out of these we select a random number (for example 500) and display them in a sphere. The images always face the camera and the user can interact with this sphere in a multi-touch way. To make it look nicer the images will be placed on the sphere by using image features such as hue or luminosity. The user will be able to rotate or resize the sphere and will select images that are relevant or non relevant to his search. Then the images will be re-sorted and the whole process repeats.

My first test was creating some numbered images (see the PHP Script) and position them randomly in a sphere shape. Spherical Coordinates are specified by 3 coordinates: the radius, the azimuth angle and the elevation angle. Since I want to use only the surface of the sphere the radius will be constant, which means I will need 2 circular features to order the images by. For the first test I used random angles:

As a second step I decided to use the HUE angles as specified by Frank Preucil to use for his famous hue circle. This proved to be a very nice choice because it is circular and you can see the difference on the screen:

Then I tried other features. Some very interesting options were general line features (for example by using a Gabor Filter), brightness, intensity and others. Unfortunately none of them is circular and they were challenging to implement. Due to the looks of it (below an example of a sphere using hue as azimuth angle and intensity as elevation angle) and the short time available, I decided to scrap them and use random as the elevation angle.

now that this was decided I needed to go on with the Gesture implementation…

]]>http://www.alexandrupopescu.com/?feed=rss2&p=273Impressive photographyhttp://www.alexandrupopescu.com/?p=25
Sat, 23 Jan 2010 20:58:44 +0000http://blog.alexandrupopescu.com/?p=25While looking for images for my new “Query by example” project, I came across what I believe to be very nice photography work by Li Wei.

]]>PHP script to generate numbered imageshttp://www.alexandrupopescu.com/?p=20
http://www.alexandrupopescu.com/?p=20#commentsTue, 19 Jan 2010 22:41:01 +0000http://blog.alexandrupopescu.com/?p=20When I need small utilities or helping scripts I turn to a scripting language such as PHP not only because it is very easy to write quick code with it but also because it doesn’t need anything else besides a text file to run from command line. This was the case a few days ago when I suddenly needed a few hundred images to test an application but I also needed them to be numbered so I would know where each one of them is exactly.

]]>http://www.alexandrupopescu.com/?feed=rss2&p=201Multitouch 2 – Infrared lighthttp://www.alexandrupopescu.com/?p=14
Mon, 18 Jan 2010 17:16:46 +0000http://blog.alexandrupopescu.com/?p=14For the project mentioned before I needed an infrared light to be able to reflect light off the fingers to the WiiMote camera. I started building this myself but being my first electronics job ever I needed some help. After reading and asking around for tips, the circuit I needed to create looked something like this:Basically two infrared serial LEDs + a 68 ohm resistor for each pair. What I wanted to do next was to power the whole thing off USB to make it more portable. This meant I needed to keep it under 500 mA not to create a power surge. So, in the end my project included 16 LEDs and 8 resistors. Below you can see the result of my work:

I am not very proud of my soldering skills yet so I will not show the backside

At this point I started testing it. I connected it to USB, I connected the WiiMote to Bluetooth and downloaded the WiiMote Multitouch example written using DirectX to display and manipulate a grid on the screen. The whole thing is not precise at this moment and I can spot two main problems with it:

I didn’t do the whole in the middle yet, which means I positioned the WiiMote on top and the light is not reflected at a convenient angle.

I didn’t get reflective tape yet and my fingers create too many points to track. Out of all these, the WiiMote is only capable of tracking 4 which means they keep changing all the time, making it impossible to control.

I ordered reflective tape on eBay UK, it will take a few days but it’s very hard to find in the Netherlands. Meanwhile I will start developing other features and get back here when possible. To be continued…