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 :P

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 https://svn.apache.org/repos/asf/axis/axis2/c/core/trunk 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 build.sh with the following command:


./build.sh

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
./build.sh

 

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.

Solving the NameNotFoundException when connecting to IBM MQ through JMS

If you are facing an exception like the one at [0], then the problem might be hard to figure out. Because, if you look at the Queues in the MQ explorer, the queu named FOOQ will be there.

So, the missing part here is the JMS binding of that queue. This takes 10 minutes to solve. Right click on the queue, and select ‘create JMS queue’. Pick the JNDI Context you have created (creating this is out of scope of this post), and just click next, next and finish. Now re-generate the JNDI bindings by running IVTSetup.bat, and copy it over to the client machine and use it.

Your problem should be solved by now and you will be happily putting messages to IBM MQ Queues.

[0] –

TID: [0] [ESB] [2013-03-20 19:01:11,515] ERROR {org.apache.axis2.transport.jms.JMSConnectionFactory} -  Error looking up the JMS destination with name FOOQ of type generic {org.apache.axis2.transport.jms.JMSConnectionFactory}
javax.naming.NameNotFoundException: dynamicQueues/FOOQ
    at com.sun.jndi.fscontext.RefFSContext.getObjectFromBindings(RefFSContext.java:400)
    at com.sun.jndi.fscontext.RefFSContext.lookupObject(RefFSContext.java:327)
    at com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:146)
    at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:127)
    at org.wso2.carbon.context.internal.CarbonContextDataHolder$CarbonInitialJNDIContext.lookup(CarbonContextDataHolder.java:1030)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at org.apache.axis2.transport.jms.JMSUtils.lookup(JMSUtils.java:509)
    at org.apache.axis2.transport.jms.JMSUtils.lookupDestination(JMSUtils.java:718)
    at org.apache.axis2.transport.jms.JMSConnectionFactory.getDestination(JMSConnectionFactory.java:198)
    at org.apache.axis2.transport.jms.JMSMessageSender.<init>(JMSMessageSender.java:88)
    at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:120)
    at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
    at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:297)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
    at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:456)
    at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:57)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:316)
    at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:329)
    at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:175)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:367)
    at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:408)
    at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:219)

    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
TID: [0] [ESB] [2013-03-20 19:01:12,045] ERROR {org.apache.synapse.core.axis2.Axis2Sender} -  Unexpected error during sending message out {org.apache.synapse.core.axis2.Axis2Sender}
org.apache.axis2.transport.jms.AxisJMSException: Error looking up the JMS destination with name FOOQ of type generic
    at org.apache.axis2.transport.jms.JMSConnectionFactory.handleException(JMSConnectionFactory.java:228)
    at org.apache.axis2.transport.jms.JMSConnectionFactory.getDestination(JMSConnectionFactory.java:200)
    at org.apache.axis2.transport.jms.JMSMessageSender.<init>(JMSMessageSender.java:88)
    at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:120)
    at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
    at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:297)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
    at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:456)
    at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:57)
    at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:316)
    at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:329)
    at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:59)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:175)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:367)
    at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:408)
    at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:219)

    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: javax.naming.NameNotFoundException: dynamicQueues/FOOQ
    at com.sun.jndi.fscontext.RefFSContext.getObjectFromBindings(RefFSContext.java:400)
    at com.sun.jndi.fscontext.RefFSContext.lookupObject(RefFSContext.java:327)
    at com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:146)
    at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:127)
    at org.wso2.carbon.context.internal.CarbonContextDataHolder$CarbonInitialJNDIContext.lookup(CarbonContextDataHolder.java:1030)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at org.apache.axis2.transport.jms.JMSUtils.lookup(JMSUtils.java:509)
    at org.apache.axis2.transport.jms.JMSUtils.lookupDestination(JMSUtils.java:718)
    at org.apache.axis2.transport.jms.JMSConnectionFactory.getDestination(JMSConnectionFactory.java:198)
    ... 20 more