Saturday, 28 February 2009

Games without maths will never exist

I've been asked many times

"Do games need add math?"

Actually, some of my friends wanna try learning programming. So, yeah, I gave them the link to Microsoft's Visual Studio Express programs, if they are really interested in it. Then suddenly, they ask that question.

The answer, of course would be yes. You may not know it when you play games like DOTA, or Red Alert 3 or Maple, but behind the scenes, a lot of Math is going on. Mathematic is the driving force behind computer games.

There are simple math, like deducting the player's HP, and super-complicated math like path finding (for AI).

And in 3D games, selecting a unit by clicking on them is also quite complicated. Sure, you can just click on the screen, but in 3D environment, the game must perform a lot of calculations just to get what object you're trying to click.

So, remember, the next time you play computer games, don't ever forget the efforts the game developers had to put in to give you the best entertaining experience.

If you want to know an example of how math is applied in a game, you can check out the Circle-Line Intersection. How is that helpful in the gaming world? Well, let's say you have a circular object, and you fired a bullet at it. Assuming that the bullet will travel in a straight line, the question is, will the bullet hit the object? Yeah, so, as you can see, game development isn't just "code typing", it is also a gigantic mathematical problem, that you have to solve. Well, sort of. Ok, fine, my analogy isn't that good, but you get the idea, right?

But don't let that bring your hopes down on becoming a professional game developer. It's a very fun thing to do, seeing people play the game that you made. Some more, you can see them and laugh as they suffer from the hard levels you give them. Playing computer games is a fun hobby, but creating them is even more fun. I mean, you are like a God, planning what you want to do in your very own universe, and controlling everything. You want the player to suffer, well, why not fill the whole world with boiling hot lava? Ok, that'll just be plain evil. Anyway, all I want to say is, creativity is another important aspect in creating a game. Go wild! It's your world after all.

So, if you aspire to be a pro game programmer, I wish you Ganbatte! Trust me, game programming is fun, if you have the passion for it.

Thursday, 26 February 2009

Triangle, 3 angles of despair

Oh, sorry for the weird title. Anyway, the other day when I was walking back home with David Mosiun after the can rings hunt, he suggested to me about making the triangle a little bit more complicated. Yeah, so I wondered, why not?

Here's what I've done.

WARNING: If you an uncontrollable hatred towards Maths, I suggest you should look away.

First, let's place a triangle in the cartesian plane:

Simple enough? It's important that the labels for the vertices are in clockwise order. I'm gonna use vectors here, since vectors are so fun! No trigonometry will be involved (well, except for Pythagoras' Theorem)

First, run a line from point C down to line AB so that it is perpendicular to line AB.

That line (h) will divide line AB into 2 sections, a and b. What I'm gonna do now is find a, b and h. From there, I will be able to get the area of the triangle. Remember, I'm gonna do this without the help of trigo, since I'm on a trigo-hiatus. Hahaha.

We'll need the vector for line AB, so, it'll be

A-B.

Then, we'll need to normalize it.

W=(A-B)/(|A-B|)

Right, now, that'll be called W. To get the length of section a, we're gonna have to project line AC onto W. That's where dot product comes in handy. Because dot products can give negative numbers, which we don't really need, let's get the absolute value of it.

a=|(A-C) ּ W|

Same goes for section b, instead, it'll involve line BC.

b=|(B-C) ּ W|

Now for h. Since we know b. And c is just equal to |B-C|, we can get h:

h=sqrt(c²-b²)
h=sqrt[ (|B-C|)² - ((B-C) ּ W)² ]
Actually, since we are squaring those numbers, the absolute value sign is actually quite redundant, since squares are always positive. That's why I took out the absolute value sign. But note that I didn't touch the modulus sign for B-C in the (|B-C|) because that sign there represents the magnitude of vector (B-C).

Now we have a,b and h, let's put them together:

Area of triangle=1/2 x base x height

so,

Area of triangle
=1/2 (a+b) h
=1/2 (|(A-C) ּ W| + |(B-C) ּ W|) sqrt[ (|B-C|)² - ((B-C) ּ W)² ]

or, if you like a better view of this equation:

where,


Ok, so there's your "area of triangle" being turned into a garbled mess! Now, I don't guarantee that the equation above will be 100% accurate. There may be errors in there which I may have overlooked. You won't be seeing that equation in your textbooks anytime soon, so don't worry too much about it and blah. It's just for fun.

Wednesday, 25 February 2009

Gayness!!

In The Sims series, your options for true love are not limited to only the opposite sex. Yesterday, I made a guy sim love my sim (who is also a guy).OMG! I MADE THEM KISS!!

Well, anyway, proposing to him was not very successful though. He rejected my sim a couple of times. That bastard!!

Anyway, I'm gonna play a bit more The Sims 2 now before I start doing my homework. Sigh... Form 4 life is tough.

Right, here are a few videos:

My sim (who is the guy. I'll call him Bilsa from now, since I named him Bilsa) wanted to leap into the girl's (Jan) arms, but because the chemistry between them isn't that good, the girl refused to hold him. Lol!


Then here, Bilsa is proposing to Jan, but due to poor chemistry, she declined it. Poor Bilsa.


So, off with Jan and on to a new girlfriend. Yeah, here, you can see Bilsa's second wife knocking over a snow man. Yes, they got married.

Tuesday, 24 February 2009

...

Once I'm satisfied with learning gesture recognition, I shall get on to making Mr Ball. I think I might start making it next month or so.

But for now, I should continue Red Alert 3. hahaha!

Monday, 23 February 2009

The Sims 2!!

I'm replaying The Sims 2 again, and I've got to say, I'm too pro at managing my own shop already (in The Sims 2), hahaha! Ok, ok, I shouldn't be bragging.

It's freaking amusing, especially when I made my Sim to propose to another Sim. He got rejected twice, lol! Then the third time's the charm! Hahaha!

In the end, I made the couples argue with each other until they slap each other (lol!) and finally they broke up. I just hate managing two Sims. Hahaha! Me gonna play some more.

Saturday, 21 February 2009

Blah!

Tracking an object is another difficult task to do. I tried to do that, but my program failed miserably. All because of bad lighting. See, my calculator is slightly reflective, because of the smooth surface. So, at some angle, it reflects a little more of the ambient light into the camera. Because of that, it picks up different colour values. If these values do not lie in the range of colour values that I want, the program will discard that particular pixel.

The usual colour space that we use everyday is the RGB (Red Green Blue) colour space. Different amount of these 3 colours can create a variety of colours. The bad thing is, different lighting can change these values significantly. Not good for my program, so I didn't use it. Instead, I tried with YCbCr colour space, which is actually quite a new thing for me. It's better than RGB actually. But then again, lighting 1, program 0.

I'm currently searching for better colour spaces, which aren't really influenced by lighting conditions.

Friday, 20 February 2009

Yesh! Finally!

At last! I successfully connected to my webcam through programming! It wasn't an easy task. Right, now I have to think of a way to track objects. I'm not going to use my hand because it's kinda hard for my level.