Making Visual Studio Intellisense work with QT

Disclaimer: This solution worked for Visual Studio 2013 with Qt 5.3

One of the reasons if your Qt program runs fine but the Visual Studio Intellisense does not detect Qt specific variables can be due to the necessary header files not being included. You will notice if you go to Project Properties->C/C++->Additional Include Directories, that there are several include entries defined with using QTDIR as an environment variable.

I’m sure you have figured out the solution now. You have to define this system variable to make Intellisense work. Add a new system variable called QTDIR, and point it to the QT installation with the version you are working with, ex: C:\Qt\5.3\msvc2012_opengl. This should solve your problem.

Note: There seems to be other problems that can cause Intellisense to not work with Qt, and they are pointed out in:

Finding a normal (perpendicular) vector on a 2d plane

There are plenty of times when we need a normal vector in game dev and graphics programming (or if we are simply just learning vector math). It is relatively simple for you to find a normal (perpendicular) vector on a 2D plane. Swap the vector components and negate one, i.e. if the vector components are (u, v) swap it (-v, u) or (v, -u). Negating the first component will make the normal vector counter clock wise to the initial vector. Negating the 2nd term will make the normal clockwise to the initial vector.

Normal Vector illustration

Normal Vector Illustration

Solving the Error 127 from Make when cross compiling to raspberry pi

I was following the excellent tutorial from Alessio on cross compiling to raspberry pi from Windows 7. Then, I hit the the dreaded ‘Error 127’ from make. Now, after hours of searching I couldn’t find how to solve this. Then, Bryan has mentioned that you need to install the 32 bit cygwin version and that would work, and works it does.

If you already installed cygwin 64 bit version like me and wondering how to install it,here are some steps:

  1. download the 32 bit setup to a new directory(ex: C:\cygwin32) and run the setup. Make sure you make every path point to this new directory during the setup process.
  2. Now, copy the crosstools directory to this new directory. So, it will be at C:\cygwin32\opt\cross\x-tools\arm-unknown-linux-gnueabi
  3. Change all paths created in Eclipse in the ‘Path’ variable (and Windows Environment variables too, if you added cygwin there) to point to this new location
  4. Now, clean and build the project and it should compile for you!

Another error I ran across is this:

Could not determine GDB version after sending: C:\cygwin32\opt\cross\x-tools\arm-unknown-linux-gnueabi\bin\arm-unknown-linux-gnueabi-gdb.exe –version

If you ran across this you installed python 2.7 instead of 2.6. Re-run the cygwin setup and change the python version to 2.6.x.x and install this python version. Re-run your program and it should be working.

I wrote this so it helps someone else to save a ton of time. HTH.

world space vs node space on cocos2d

If you are doing a game that will use up maps, or large views that goes beyond the size of the screen you will run into issues like me. These issues will most likely be due to your lack of knowledge of world space vs node space.

Let me try to give an example. You have a character sprite, in a large map at position (60,10). Now, think you move you move the map to the right of the current screen by dragging your finger (think Angry birds). Say, you move it by 10 points. So, now your character is at (50, 10) (if you move your map to the right, the character moves to the left by 10 points). Now, if you want to detect a touch on the sprite will it work? Well, if it does then you already must’ve configured it to work with node space coordinates. So, the answer is no. It will not work.

Why did it not work? Now, if you touch the screen at (50, 10) and try to detect that on the sprite (using the bounding box, or a virtual rectangle around the sprite), you will be not get any result. This is because you are using the world space for the touch. The world space will mean the screen coordinates. So, on the screen you touch (50, 10), that’s all right. But, where is the sprite on the underlying map. We just moved the map, not the character. So, on the underlying map, the character is still at (60, 10). So, what you have to do is convert the world space coordinates to the node space coordinates of the map. Now, when you do this, the touch coordinates will get converted to (60, 10) and we will get a hit on the sprite touch detection.

The convenience methods that does this are:

convertToNodeSpace(CCTouch* touchPoint)
convertToNodeSpace(CCPoint point)

Mastering copy paste with vim

When your yanking and deleting, sometimes you come across “oh, shit” situations, where you replaced the text that you yanked with something you deleted or vice versa. Fear not, these two commands will save your day.

What you yanked (or copied) will be saved in “0 register, so to paste what you yanked, the key sequence is: “0p

What you deleted (or cut) will be saved in the “1 register, so to paste what you deleted, the key sequence is: “1p

Of course, the generic version of this is for yanking to the “x register: “xy and pasting is: “xp

The generic version of deleting is kept as an exercise 😛

Building Axis2/C on Mac OS X Mountain Lion 10.8.4

This should work on other Mountain Lion versions as well, but I have not tested it. First of all, let’s install a set of dependencies required for the building process.

The easiest way (at least for me) was to install them through macports.

Note: You need to install Xcode and the Xcode command lilne tools for macports to work. Xcode is a (very) large download. So, it will take some time to install. But, an advantage is many tools ask you to install Xcode since it brings in a lot of useful dependencies useful for dev. provided by Apple itself. So, you’ll need it anyway if you’re planning to do some C development 🙂

After installing macports, you need to install automake, autoconf, libtool, libxml2 and pkgconfig. Type in the following command:

sudo port install automake autoconf libtool libxml2 pkgconfig

Now, we are set to build the source. Check it out using the following command:

svn co axis2-c-trunk

This will checkout the source code the a directory named axis2-c-trunk. Now, we need to apply this patch that fixes a constants issue. Download it and put it inside the directory axis2-c-trunk. Now execute the following commands to patch the source:

cd axis2-c-trunk

patch -p0 < unavailable_constants_macosx_fix.patch

Now, you are ready to build the source. Just execute the with the following command:


That should create a successful build in the axis2-c-trunk/deploy directory. If it didn’t you probably would need this patch as well. Patch your source the same way as above, and try running the build script again:

patch -p0 < mac_os_build_fix.patch


Converting all educational institutions to use open source software in Sri Lanka

Recently, I read this post about Richard Stallman’s (RMS) visit to India. I then decided to educate myself about how RMS’s visit impacted India. I read this very, very interesting thing that happened in Kerala. An excerpt from wikipedia:

In August 2006 at his meetings with the government of the Indian State of Kerala, he persuaded officials to discard proprietary software, such as Microsoft’s, at state-run schools. This has resulted in a landmark decision to switch all school computers in 12,500 high schools from Windows to a free software operating system.[45]

Then, I was wondering why this did not happen in Sri Lanka? If it did I’ve never heard about this. All open source Operating Systems are now usable enough for even novices to use it, and most of the software available for it is free.

This would be a brilliant move, not just to cut costs but to ‘fix’ our future generations. Every school child that is above 13 is able to program with his knowledge of basic algebra and such, if he or she has proper guidance. The use of Open Source Operating Systems allows all these children to have access to all development tools for free (Eclipse, vim, emacs, etc.), thus forming a generation with a high computer literacy rate. The other advantage of this is the low barrier to entry in the software world. How cool would it be to see a 15 year old in Sri Lanka creating this amazing app for Android and making a multi-million dollar business out of it? This move would not just make children more computer literate but also allow talented kids to build their entrepreneurial skills as well.

I hope that the leadership in this country grabs this opportunity.