Pages

Tuesday, February 14, 2012

This is What I Do Instead of Having Normal Person Fun

I've decided to dedicate a blog post to some of the math/programming work I'm doing for MLPOnline. This should also help me remember why I'm still single on Valentine's Day so I can rant about the correct things when I drink myself into a gutter later.  Warning- this post has math. But its in the form of badly drawn Microsoft Paint pictures.  So, lets dig in!

Lets say that you have two objects- a box and a triangle.  You want to make sure the triangle can't stab into the box, especially if the box is made of concrete. The triangle should stay outside our box of concrete, unless our game is set in Alice's Wonderland.
This part comes right after the Caterpillar gets baked

Now, the question is: how do you keep that from happening?  Well, look at anything vaguely box-like in your room right now (books are good for this example).  Look at the corners- the only way for a book to be "inside" of our proverbial box is if one of the corners was inside the box.  There is no way to put the book inside the box without putting at least one corner in.

So, really, we just want to test if any of the corners of the book are inside our box.  In math, we call the corners of things vertices.  With a little imagination- perhaps with the help of Figment if you're a character on a Disney ride- you can see that each object is actually a collection of faces (the front of the book, the back of the book, the spine of the book, etc), and each of these faces each have a set of vertices.

Example: For the front of a book, the vertices would be the front bottom left corner, front bottom right corner, front top right corner and front top left corner.

So, really, the problem is: how do we check to see if one of these vertices is inside a bunch of other vertices?  Your answer is probably something along the lines of, "Um, by looking at it, numbskull".  You're also perfectly right- but computers are very retarded and can't look at objects.  All they see is a bunch of points in space that make up the objects we're talking about.  So, to a computer, our problem looks something like this:

Green dot- inside or outside the box?
Yeah.  The computer has no idea what inside or outside even mean.  If I gave you a sheet of random dots and told you to tell me if one dot was inside the others you'd tell me to lay off the drugs.  Remember how I said before that our objects are actually a collection of faces?  Well, time to use that to our advantage.  Sorta.

You see, there is another way to look at faces- as planes.  Planes are flat surfaces that extend out forever.  They're handy because they divide space in to two parts- the part on the left of the plane and the part on the right of the plane.

These two horribly drawn stick people can't see each other because there is a theoretical mathematic construct in the way.  This happens all the time in real life.

There are a few ways to describe planes, but the easiest to calculate (when we already have a bunch of points in the plane- the vertices that I rambled about before) is to have have a perpendicular arrow that points away from the plane and another point on the plane.  Or more simply- we can describe one of these great space dividers with nothing more than a point and an arrow we can get from a bunch of points.  Perfect!

Now, we finally have enough information to start to figure out our starting problem.  Some other very smart person figured out that a point is inside of a 2 dimensional shape if you could draw an arrow from somewhere outside the shape to the point and the number of intersections it made with the shape's sides was odd.

Thanks, dead smart person!
I need to generalize this to 3 dimensions, because apparently 2D graphics are lame.  Whatever.  So, I drafted up a test cube, picked a point I knew was going to be inside of the box, and picked a point that I knew was going to be outside of the box and made a line.  Then came the very unfortunate task of checking to see if the point intersected with any of the planes of my box.  There is a lot of linear algebra I'm going to ignore.  Unless, there is some demand to hear about it and or need for a sleep aid.

In a nutshell I got this:

I fail art forever. 
Which seems like a great success.  Until you start to look at more complicated shapes.  If one of those box sides was angled- like a ramp- then I would have had two plane intersections, and my algorithm would have mistakenly divided that the point was outside the box.  (Remember, planes extend infinitely out in two dimensions so they can divide 3-D space in two.  They don't have edges like the sides of a box would)

So, I also need to check each plane intersection point to make sure its in the face.  If it isn't, I need to throw it out.  To do that requires even dryer math (woo-hoo trigonometry!), but I have a solution that I think works.  Almost.  There are two problems that I still need to tackle.

1) My point in face check requires some order be imposed on the vertices.  They need to either be in clockwise or counter clockwise order.  I can either ask the developer working on generating our level geometry to impose this order on his stuff, or I can order them myself at the start of all this math mess.  Ordering them shouldn't be hard (which means I should be able to find out how someone else did it on the Internet), but there is a lot of computations happening already.  I'm beginning to get worried that it'll take too long to check this stuff, and that results in lag.  No one likes lag.

2)I've used some meta-knowledge here.  I know that my second point is outside the figure because I drew the figure up.  In our actual game, I my code won't be able to know any of that and will need to pick a secondary point all by itself.  And remember, all the computer knows about is a bunch of points- all this plane crap is done by my code in the middle of it.  The solution to this sucker is to use what smart people call a bounding sphere, which is the smallest sphere that encloses a set of points.

I just have to grab a point on that sphere (actually, I'll grab a point a little ways outside of the sphere, so I can avoid accidentally using a vertex) and I should be set.  The issue is that getting a sphere from the way the data is saved is going to be a pain.  I need to actually get a unique list of points that make up the object (which, when looking at how the data is saved right now is looking to take a lot of computational time) and then generate the sphere

In conclusion: video games are complicated.  Even ones about ponies.

Thursday, February 9, 2012

Another Postless Thursday

I'm a bit too busy with MLPOnline to write up a post.

I'll see about making it up tomorrow, but it really depends on how well I can do vector calculus at 3am.

If anyone tells you that making a game is easy, tell them to fucking suck it.  This shit is hard, but I work with some of the most awesome people on the planet (developer chat can randomly explode into pony references- it's hilariously awesome when it does).

Back to the ponies.

Tuesday, February 7, 2012

Internet Browsing And You

I sorta forget that other people don't always keep up with the latest trends when it comes to Internet browsing.  Hell, I don't even keep up with all the browsers. If you use Avant you're officially the sad nerdy version of a hipster.  And heaven forbid I run into someone using K-meleon- which is Firefox's shunned Windows-only cousin. 

The point is that there are more ways to view the Internet than the amount of licks it takes to get to the center of a Tootsie Pop.  That being said, I'm pretty sure all of you have the same picture when it comes to your choice of Internet browser.  This:


So... that's the kid from Up fighting with a furry?

Now, I'm not here to defend everyone's favorite browser for getting another browser.  If you don't know which one that is, have a hint: the one eating glue.  I use Firefox on my main computer because it has several add-ons I need to function (LeechBlock, FireBug and Chatzilla are the big three I use almost every day).  I've got Chrome on my netbook because it was shiny and new back then and I wanted to try it.

So, why does everyone hate IE?  Well, you probably first started avoiding it when your "computer" friend told you it was the worst thing ever.  This video sums it up fairly well:



It's a two minute video, but the important part is in the last stretch when he rants about IE.  You see, for a long time, Internet Explorer didn't play by the same rules as everyone else when it came to browsing the web.  Writing an application that worked for all browsers sucked because IE did things differently, so you'd have to tack on a lot of extra IE only code.

Then Microsoft pulled the stick out of their ass with IE 8 and 9, and made their browser Document Object Model compliant.  Or DOM compliant to cut down on typing, but don't confuse this with Marcus' gay lover in Gears of War.

Also known as the overcompensation duo
 So, in today's great world, developing for IE is just as easy as Firefox, Chrome, or Opera, as all of these browsers now follow the same rules (DOM).  I hope I just ruined some pretentious asshole's day with that one.  Wait, if that didn't do it, this will: as a programmer, you have no excuse anymore to say that developing for IE sucks.

Well, no one gives a shit about what's easy to write code on.   If that was the case, we'd have converted you people over to Linux a while ago.  And I know that- so I asked my Facebook feed, also known as the most fair distribution of people on the planet, why they thought IE sucked.

Almost everyone that replied complained about IE's speed.  Valid point.  Aside from the fact that IE recently beat Chrome in speed tests, and has historically beaten up on Firefox.  In fact, if speed was the only thing we judged browsers by, Opera would be launching nukes while everyone else was still working on gunpowder in the Civilization series.

What does this mean?  Not much.  IE still sucks at loading CSS style sheets (which is how 90% of graphics are done on the web) and recently has started taking close to 11 seconds to boot from a cold start.  Those are the two things that come to mind when you think about browser speed, so IE still feels slow.

But IE does a damn good job at dealing with multiple tabs (better than Chrome and Firefox in that regard) and running JavaScript (also known as animation on the web).  Is it any better than Firefox or Chrome?  Probably not- but its definitely comparable and not a glue huffing castoff from another age.

Also, (for your enjoyment) here are a few other reasons I got as to why people don't use IE:
"It's not as pretty as Firefox."
"I use Safari because [I'm not allowed to use] non-native browsers."
"BECAUSE IE WAS INVENTED BY THE MAN!!!!"

Thanks to everyone who answered my random Facebook poll.  Please don't flame me to hard.

Thursday, February 2, 2012

Hilarity: Insanty + Illegality

First for all my Bronies in the audience (if you're not down with ponies, then scroll down till you hit this: ***):

I'm now a developer for MLPOnline, a fan made pony mmo.  It's pretty awesome.  It has a website and everything: www.mlponline.net (click on demos to see some of the things we've got going on).  The website is a little dead- there is more action going on at the DA page.

My grand total sum of work has been to eat up bandwidth like a worm from Dune getting all the source code and web development tools.  However, if you want to follow it through development, go right ahead.  If you want to advertise it, go ahead even more.

If you want to help, well, that's up to the people actually running the show to decide, but the only time it ever hurts to ask is with your significant other.

Why am I developing an mmo?  More than just because I goddamn can and ponies rock.  I never turn down reasonable opportunities to write code, ever.  Game development and design is something I've always wanted to dabble in.  But, I was never able to get my shit together enough to try to do a game on my own.  This gives me a chance to learn how games are made, it'll actually look good on a resume (or as something to bring up during an interview) when it's done, and I do actually care about the subject material.

At any rate, I'm excited.  And if you're judging me, you can goddamn suck it.  Because you're reading my blog.

***

There are a verity of reasons why people might want to break the law- shits and giggles, revenge, greed, or because their neighbor's "No Trespassing" was goddamn asking for someone to streak naked on his lawn while singing "Peanut Butter Jelly Time".

I dig that.  Not you naked.  Dear God not that.  Put some clothes on, you're embarrassing yourself.
 
But I always do my online shopping without clothes!

All things considered, there are some times when breaking the law not only makes no sense, but also proves that you need help.  Lots and lots of help.  Also, it's hilarious.

For example, lightsabers are a physical impossibility.  They're just too bad ass to possibly exist in this universe.  If anyone actually figured out how to get a beam of light to 7 quadrillion degrees and make it about "yeh" long, a comet would come out of the sky and murder him.

Mother Nature can't handle lightsabers up in her shit.

So, when you want to go on a mass murder spree with a lightsaber, it turns into you running around Toys 'R' Us hitting people with plastic toy sabers instead.  True Story.  It gets better when you learn that the man in question- dual wielding lightsabers like a boss- actually had a show down with the police and managed to deflect two taser shots.

Damn.  That's just impressive.  The force may have very well been with him.

No one knows for sure if he was trained by the Star Wars Kid

Of course, other types of crime can be just as fun.  We've all heard jokes about retarded people passing school because they got a nerdy friend (read as: victim) to hack into the computer system and change all the grades in return for not getting a swirly that week.

Turns out that happens in real life, but the nerds make a goddamn killing to the tune of $300 to change an overall B to an A and $50 to change a test score.  I almost want to give them more props than the Jedi in training up there.  Not for hacking a high school computer system, I used to break the firewalls in my high school's system just to show that they could be broken.

But, having the balls to charge that much of fellow high school students?  Wow.  In high school, when I got enough money to eat out at McDonalds, I was freaking loaded.

And sometimes, its not the crime itself, but who commits the crime that's amazing.  For example, take Beezow Doo-Doo Zopittybop-Bop-Bop.

Yes, that's an actual name and not something I stole from Bill Cosby.  I know this because he has an arrest record.  What makes it even better is that his bizarre name is not the combination of a pair of hippie parents and an unfortunately timed hell of an acid trip, he chose that name himself.  He changed it from Jeffery, which isn't honestly that bad.

I guess he's stickin' it to the man somehow?  Or something?