Link: Higher-Order Fun

Higher-Order Fun

Higher-Order Fun

So, my blog’s concept is nothing new: Games, programming, tutorials, the works. But everyone’s a little different and post up different content, and recently I found this blog, by Rodrigo Monteiro, where he not only posts up tutorials, game design, and even 3D game math, but he also gives his 2 cents on games and game design ideas. It’s a real great blog, and definitely one to bookmark. Here, I have a few pages of interest for you:

 

Advertisements

Quick Code Tip: Fix Precision with Floating Points

Let’s say you have a floating point value of 200.21, and you convert it to an int, like so:

int amount = (int)(famount * 100);

Depending on processor, libraries, compiler and tons of other stuff, your value may APPEAR to be 200.21, but when you do your conversion the value comes out to 20020. What happened to that extra 1?!

Well, though you may see 200.21, the computer is actually storing 200.209999999… (because, you know, 0.999… == 1).

This doesn’t happen all the time, but when it does, it’s a pain. So how do we fix this?

Just add 0.5. Seriously.

int amount = (int)((famount * 100) + 0.5f));

Bam. Let’s break this down, PEMDAS style.

(famount * 100)
Ok, so we know that famount is not 200.21, but 200.2099999… This now brings us to 20020.99999…

((20020.999…) + 0.5f)
The 0.5 now brings us to 20021.49999… Like magic.

int amount = (int)(20021.4999…)
Saving all the pennies.

Good job. You just saved the world from mathematical inaccuracy.

Until next time, take care. (After that, do whatever the heck you want.)

Math Magician: Much Ado About 3D Math

Illustration of the right-hand rule for the cr...
Image via Wikipedia

You know what irks me? Going online to look up something simple, like Dot Product or Cross Product, and getting nailed in the face with calculus proofs and discrete mathematics on why this and that happens, but never getting a simplified answer on what I’m looking up!

Well, I have a website, and now it’s time I delivered the simple answers. Open wide for a study guide. Continue reading Math Magician: Much Ado About 3D Math

Code Snippet Quick Reference

I have created a quick way to find the code snippets you’re looking for! The Code Snippet Quick Reference under the Code tab at the top. Now you can find all the snippets for C/C++, Unity, and even the Math Algorithms all in one easy place (OK, technically 3, but shut up; I’m trying to do you a favor, here!).

Unity 3D Code Snippet – Inheriting Parent Velocity

Imagine that you’re running at 10 MPH. While you’re running, you throw a ball at 5 MPH. Now, imagine the laws of physics are screwed up and the ball, instead of adding your running velocity to its own, only moves at its 5 MPH. Imagine the look on your face when you try to figure out how the heck you just did that. Imagine the towns’ people accusing you of being a witch and burning you at the stake. Gruesome.

This is (sorta) what happened to me. I instantiated particles, but they didn’t pick up the instantiators’ velocity. Well, here’s a handy script I found, and now I am sharing it to help get your game up to speed (Ugh. I rather just be burned at the stake than to hear another corny pun).

Continue reading Unity 3D Code Snippet – Inheriting Parent Velocity

Unity 3D Code Snippet – Flight Script

Roll, yaw and pitch axis definition for an air...

Flying is a simple concept in games. An object that can move in 3 dimensions? I am all over that! But how about rotating to the forward vector? How about a constant velocity? Here is a quick way to get your game object up in the air (that joke hurt to type).

Continue reading Unity 3D Code Snippet – Flight Script

Math Magician – Lerp, Slerp, and Nlerp

Illustration of linear interpolation on a data...
Illustration of linear interpolation on a data set. The same data set is used for other interpolation methods in the interpolation article. (Photo credit: Wikipedia)

Man, I wish I had this blog going through school, because this place has become my online notebook. Game development is like riding a bike – but math, for me, can have a hard time stickin’. I’ve been working in databases so long that I have a lot of bit-shifting down, but my matrix and vector math is starting to lack. So, a creative way for me to remember all these algorithms is to try to explain them. Today, I’m going through Linear Interpolation, Sphereical Linear Interpolation, and Normalized Linear Interpolation. Continue reading Math Magician – Lerp, Slerp, and Nlerp