The Cardinal Codez

Friday, June 8, 2007

Vectors


Here's a little refresher course on Maths: Vectors in 3d dimensions. =D

The following code creates a 3d plane that will always be facing the viewer [camera]. With a little guesswork on how computer languages work, but knowledge of Maths, this should be easy to figure out.

Now we just need a Maths question to come out for the CTs regarding finding the points of a 3d plane facing a guy standing at a specified coordinates and we're set. =D

BTW, Vector3D.Normalize() refers to finding the Unit Vector. It's NOT finding the normal vector. 'Cause, Statistics, Normal distribution, normalization means setting mean to 0 and standard deviation to 1, which is basic units. So Normalization, in Vectors, means finding the Unit Vector.


C# code for letting a 4 vertex Mesh face the user at all times
X
 
_


Vector3D campos = camera.AbsolutePosition;
Vector3D target = camera.Target;
Vector3D up = camera.UpVector;
Vector3D view = target - campos;
view.Normalize();

Vector3D horizontal = up.CrossProduct(view);
if ( horizontal.Length == 0 )
{
horizontal.Set(up.Y,up.X,up.Z);
}
horizontal.Normalize();
horizontal *= 0.5f * Size.Width;

Vector3D vertical = horizontal.CrossProduct(view);
vertical.Normalize();
vertical *= 0.5f * Size.Height;

view *= -1.0f;

for (int i=0; i<4; ++i)
vertices[i].Normal = view;

vertices[0].Position = horizontal + vertical;
vertices[1].Position = horizontal - vertical;
vertices[2].Position = - horizontal - vertical;
vertices[3].Position = - horizontal + vertical;

Cool Code design by Cardin.
I can't help myself. XD

Yup.




Dang I give up. I was trying to code something that looks like the top of the windows title bar. But it's just damn tedious, keep having to move each thing pixel by pixel and see if they fit nicely together.

Wait, there's more trouble. Browsers don't display pixels the same. And that's gonna be affected by your computer's pixel resolution as well. So you can spend hrs tweaking it to look super nice, then another guy who's using resolution 1024x1280 comes along and everything is wrecked. CSS coding is so awesomely frustrating.

Algorithm coding is way more fun. You actually see results. And those results can be so much more impressive than a nicely designed page. Depending on what algo you're coding, the fun varies. I'd just finished coding, as seen above, a 3D plane that follows the user around. And there's also an option to turn that following system off as well. Flying around a 3d board is definitely much more fun than pushing 2d blocks onto one another in XHTML...

Though I'm kinda surprised my XHTML/CSS skills haven't gotten at all much rusty since a few years ago, when i coded a dynamic changing site design. =D


Gash is on crack.
Konjiki no Gash Bell rocks!! Don't say it ain't.


1. Konjiki no Gash Bell OP3 [Mienai Tsubasa] - Tanimoto Takayashi
2. Bad Day - David Powter
3. Bleach OP1 [Alones] - Aqua Timerz

No comments: