Sunday, 14 June 2009

Random post

Well, I dunno what else to post, so I shall post some "numbers" again! Whee!

Seriously, if you hate maths, just don't look.

Remember a few posts ago, I talked about the so-called Axial Billboarding? It's a billboard aligned with an axis! Yay!

So far, I only manage to figure out how to orientate the billboard along an axis that is aligned to either the x-y plane or z-axis, assuming z is the "up" on the Cartesian Plane.

Before I continue on with Axial Billboarding, I should start with a normal billboard. A billboard is just a sprite that faces the camera wherever the camera goes.

Here, you can see the damage display (highlighted with blue circle). It's actually a billboard, because wherever I move the camera, it will face it.

So, how does the math go for this normal billboarding? Alright, we need to know 2 very important info, well, actually, 2 angles to be more precise.
Let's assume point A represents the position of the quadrilateral (usually a rectangle) that is going to be "billboard-ed".

Now, let's place the camera. Let's call the camera position, B.
Oh crap! So complicated! So many lines! Anyway, to put things in simpler terms,

Oh, I forgot to mention that line h and line d are perpendicular to each other. L is the distance from A to B.

Would you believe that from those 3 variables, we can solve for angles x and y, well, at least for x? Haha, here comes the magic of trigonometry (oh boy...)!

To solve for angle x, we can choose to use sin, cos or tan. It doesn't matter since we have all 3 sides of the triangle. But I would recommend using sin or cos because tan reaches infinity when the angle is equal to 90, 270, ...

Ok, let's use sin just because I had committed a lot of sins. Haha, get it? sine, sin! Lol! Ok, I shall stop.

So,

We got x! Now for y.

Angle y is basically the direction of B from A.


It's very simple to get y. See the "u"? u is the difference in x between A and B.

You can use the difference in y as well, but for that, you'll have to use sin instead of cos, which I'll be using.

Anyway,


We got x, and we got y!

With these 2 variables, we can finally turn the quad to face the camera. Now, it's very important to draw the quadrilateral with its centre as its origin to make it look good, unless, of course, you have your own reasons otherwise.

And, the quadrilateral should be facing the x-axis.

So, this will be how you'll draw your quadrilateral in a 3D game:



Next, you want to rotate it around the y-axis at x angle. Followed by a rotation around the z-axis at y angle. After all that, translate it to the object's position.

And that's all for the normal billboard. I won't go on with Axial Billboarding now because I'm just lazy to draw all the diagrams and blah. Maybe later.

Well, have a nice day!

0 comments: