Archive for February 11, 2013

The Thing About Raycasts

Raycasts are extremely versatile. With raycasts you can see if there is something under the mouse, in the path of a straight shooting object, or just about anything else regarding something being in the path of something else. As far as calculations go, raycasts are probably one of the most expensive (in terms of computational time) things that you can do. But how expensive are they? Well, let's put things into perspective about just how expensive raycasts are. We'll look at the basics of raycasting and how it is used with great frequency in a standard setting.

Raycast Basics

What exactly is a raycast, how does it work, why is it so expensive? A raycast has an origin and a direction, like any vector, and is literally cast, or thrown if you will, into the scene. The process basically involves going through every object, then checking ever vertex, face, and edge, for an intersection. Even with rigorous optimization this can be checking against hundreds of elements, and this is what makes it computationally expensive.

How it's Used

While it is relatively expensive, it is exactly how the scene is rendered. On my desktop that means 1680 x 1050 = 1,764,000 raycasts per frame just to display what is going on. On my tablet it's 1920 x 1200 = 2,304,000 raycasts per frame and 960 x 540 = 518,400 for my phone. So while it is an expensive calculation, remember that it is happening half a million to two million times a frame just to render, so doing it another 30 or so times is no worse than a 6 x 5 grid of extra pixels.

Unity Android Key Mappings

If you are using Unity to develop for Android platforms, you may be wondering what keys the different buttons map to. I happened to find the answer in a location unrelated to Unity, but the information is still valid. In order to make touch devices generally compatible, touch and key inputs are directly mapped to mouse and keyboard buttons respectively. Below is a short table snagged from a Google Group

  • One finger tap = left mouse button
  • Two finger tap = right mouse button
  • Menu key =
    • Middle mouse
    • Windows key
  • Home button = HOME key
  • Back button = ESC key
  • Power button = END key

Note:

After testing with my tablet, I could not confirm any other keys besides the back button. The menu key did not even show up.

The Importance of Humor

Many people say that having a good sense of humor is beneficial. This is the case with coding as well. Having a good sense of humor will make your code more readable as it will provide a little chuckle here and there, as well as keep you in a good mood. Working while happier is a great way to avoid lots of little errors. Not only that but, since you are in a good mood, you will be less tempted to distraction making you more efficient. Who doesn't want to complete "8 hours of work" in 5 or 6? Below is a little snippet of some good humor that I put in my code that may or may not be funny, but is of non-detrimental nature, and gave me a bit of a smile.

Coding Humor

Why yes, public health is important.