Tuesday, November 16, 2010

Node Box Transformations

Well hello again everybody! So I got to Wikipedia browsing, ended up in Artificial intelligence, and found something called Scene Graphs. Which are basically giant linked list structures, much like what I used before in various programs. I had no idea they had a name! Where you basically have a grid of linked structures, and those nodes point to things that are instantiated. While I always had them stored in arrays. My ideas were similar. But to represent an entire graph as a bunch of linked nodes never occurred to me as something that would be efficient at all!

3x3 Node box
So I got to thinking how I could use this type of structure. And decided to have a box, that could take inputs and translate them into box movements. As you can see in the picture to the right. It's pretty simple looking. Now obviously, when you apply force to the middle node on any side, it should shift the entire box if the force is sufficient. But, when you apply force to any of the corners of the box. Then, as my friend pointed out, the box should rotate. Right?

A corner node
Unfortunately, this complicates my coding quite a bit. At first I thought to try to use the fact that the angle between corner nodes and their adjacent nodes should be 90 degrees, or 180,270,360. Whichever one was necessary for the corner. But, I couldn't find, or remember how to get the angle between two lines easily. Without using dot notation for vectors, which I didn't want to do at all. So it was back to the thinking board for a bit.



Translating rotation
 to adjacent nodes
Luckily for me, as I was drawing out right triangles and trying to find some relationship. My brain clicked and got the image to the right. The red lines are how much the node moves in x coordinates, and then on the bottom part of the image, that same amount is translated to it's adjacent nodes! I'm not sure if this identity is completely true. But eyeballing objects that I moved in experimentation, And drawing out triangles with a ruler seem to confirm it. Observations were good enough for old school physicists, so I'm going with them on this one!

So I've been coding this bad boy up, and have reached the point where I have my node's behavior coded in. Though I have yet to actually test it and create a node box. Once I do that, then hopefully, I won't have to rework too much code. The overall goal of this little project is to create swarm-like AI structures that will attempt to push a block from one location to another, but they have to have enough of themselves pushing in the right directions to move the box. Their mass and force, must be greater than the inertial mass of the box itself. If they're not enough swarm-creatures to push the box, they can breed to make more.

It's very very basic AI coding with an implementation of an odd node box. This should be interesting! Maybe if it's easier than I think it will be, I can rig up some directX code to display a box going through what the node box is having done to it.

No comments:

Post a Comment