Colors and bitwise operators

I found this very interesting post called “Hex colors & bitwise operators” on www.tracestatement.com a while back and I’ve been meaning to blog about it.

ActionScript

  1. // From hex value to r,g,b values
  2. var hex:uint = 0xFF8811;
  3. var r:uint = rgb >> 16;
  4. var g:uint = rgb >> 8 & 0xFF;
  5. var b:uint = rgb & 0xFF;
  6.  
  7. //From r,g,b values to hex value
  8. hex = (r << 16) | (g << 8) | b;

This tiny bit of code allows you to rapidly subtract the Red, Green and Blue values from a hexadecimal colour code. Once you have the R, G, B bits you can then manipulate them and once done convert them back to a single Hex value.

An important thing to remember is bitmasking, this can be used to switch a set of bits either on or off.

More messing around with Unity3D

Last week I spent some more time experimenting with Unity3D. My friend Erik is a 3D artist and give me this German tank to use for my experimenting. I couldn’t resist and build a completely politically incorrect scene with this, so – as I live in London – I decided to recreate the Big Ben, Parliament and Westminster Abbey.

Tank

[Click the image to play]
Controls:
Move: w,a,s,d
Toggle camera: c

Drive around, enjoy the view and then destroy it! 😀

I must say Unity3D is absolutely amazing! This whole thing took me about 16 hours to build and most of that time was spent in getting to know the GUI. This demo includes some physics, particles and a whooping total of two scripts. It only took two very small scripts to get that whole thing to work, how awesome is that?!

Links:
Tank demo: http://ansuz.nl/toys/unity3d/tank/
Move script: http://ansuz.nl/toys/unity3d/tank/Move.js
Toggle Cam Script: http://ansuz.nl/toys/unity3d/tank/SwitchCamera.js
Erik’s portfolio: http://pilsje.net/erik/

First Unity3D experiment

I started doing some experimenting with Unity3D and I must say I love it so far! 😀
As a first test I wanted to be able ‘drive’ a simple car and have some collision detection.
One problem I ran into was being able to switch cameras. There is no method available at the moment to retrieve all cameras in a scene, what you can do is retrieve all enabled cameras. What most people, including myself, end up doing is creating a script that allows you to set an X number of cameras and you toggle between those.

My first Unity3D test

Click the image to see my first test running.

Controls:
Move: w,a,s,d
Toggle camera: c

Augmented Reality

This seems to be the new buzz word on the web.

After seeing a couple of examples from Boffswana and Toyota I wasn’t that convinced. The response usually isn’t too good and the quality seems to lack a lot.

I printed out the markers on A4 and gave it a try. Since A4 isn’t that sturdy the marker got distorted and both examples had a lot of trouble picking it up. Also I tried it at night in the study with a single light on. This resulted in a glare on the marker and of course this interfered with the recognition. The low light conditions didn’t help much either, it seems a low(er) contrast really throws the marker recognition off. All in all AR software seems to be quite sensitive to imperfections.

Of course this could stop me from trying something myself and see why exactly it is so sensitive.
So what I did is combine the FLARToolkit with Flint particles.

Augmented Reality test

[Click the image above to run the example, I’ve used the same marker as the Boffswana example.]

If you run my test, you’ll see that it’s quite sluggish as well, you’re lucky if you get 6+ frames per second. This is due to the marker detection method ( FLARSingleMarkerDetector.detectMarkerLite() ). Sometimes this method takes up to 1300 ms to detect the marker, on average it takes about 150 ms.

The Flash community has always been really fast on picking new technolgy up, but I’m afraid this is a little bit too high end for Flash at the moment.

Some possible solutions:

  • Glue the printed marker to a piece of cardboard to get it a bit more steady so it won’t be bent as much and is easier to pick up by the AR software.
  • Marker detection doesn’t work that well with low light conditions. When I was at FlashCamp Seb (from PV3D) had a good idea. Just process the camera image, make it black and white and crank up the brightness and contrast.
  • As for processing speed, maybe something clever with pixel bender? Could Alchemy help?

Web Games

Since a colleague and some blog post on Drawlogic have sparked my interest in Unity3D I haven been noticing more and more games that run in or from the browser.

There is Battlefield Heroes that is meant to be released somewhere this year.
Last Friday I discovered Quake Live (I kinda feel ashamed not knowing about that one earlier)
Combine this with Unity3D and you can clearly see a change is going to happen in the world of web (browser) games.

Before there were only Flash games, some of which are excellent! But now you can have a full blown 3D engine running in your browser, how awesome is that!

Flash Camp London

13.30 – 14.00 Keynote
Serge Jespers (Adobe)

14.00 – 14.30 Work / Play
Seb Lee-Delisle (Plugin Media / PV3D)

15.45 – 16.30 Scripting with AS3
Mike Chambers (Adobe)

16.30 – 17.00 Spore Microsite
Richard Dean (Creative Lead – Lightmaker)

17.00 – 17.30 Custom Chrome in AIR
James Whittaker (Front-end technical architect / Adobe Community Expert)

18.15 – 19.00 Flash CS4
Lee Brimlow (Adobe)

19.00 – 19.45 Flex workflows in CS4
Serge Jespers (Adobe)