Saturday, April 26, 2008
Farseer Physics
The only gripe i have is that it has basically zero documentation. And since this code has been around since 2006, I'm gonna guess no documentation is coming any time soon. The good news is they provide quite a bit of sample code, and the guy who wrote it seems to reply to just about every question people can think of on the codeplex boards.
Either way, i'm having some fun. I'll post some code when I get there.
Tuesday, April 8, 2008
Playing with OpenGL - Mouse Interaction
Anyways, I remember in the class I never ended up with an OpenGL app that would allow for proper mouse rotation of a 3d object. Mouse interaction was never really assigned in that class, and I remember spending a lot of my time trying to figure out the math the teacher was having us do instead.
So I thought now that I'm jumping back into OpenGL related stuff, my first project should be revisiting that very simple, yet often overlooked bit of code that handles mouse interaction. I reviewed some of the code I had written in the class, and it had the basic idea right, but not enough thought put into it.
So I started fresh. I've learned some interesting things:
ROTATION
If you rotate the camera about your scene, then you won't be able to spin a translated object in place (what you get is a big swing around the object, rather than watching the object spin). So it seems one wants to rotate the the whole scene before drawing it. This is, of course, to mimic what is seen in 3ds Max.
TRANSLATION
This is probably the easiest part of the math involved. Since translation from this projects point of view is moving about the screen plane, then we only have to move in two dimensions (The third dimension is zoom). All that needs be done is move our eyeball AND the point we're looking at in parallel.
ZOOM
This one is a bit tricky. The effect we want is to move our eye closer to the point we're looking at. This point is not necessarily the object. Imagine you have an eye location E and a focus point F. Moving our eye towards F involves a little bit of vector math. If we create a vector from E to F, we are half way there. To do that, subtract F from E in each dimension:
Vx = Fx - Ex;
Vy = Fy - Ey;
Vz = Fz - Ez;
Now we simple move our Eye point along this vector. Multiple the vector by some scaling factor and add
newEye = E + V*scale;
or
newEyex = Ex + Vx*scale;
newEyey = Ey + Vy*scale;
newEyez = Ez + Vz*scale;
When you think about the math, it makes sense. When you look at the math, it's easy to get confused.
At any rate, here's my program. I've tried to put it together so you don't need to modify your paths to get it to build (the glut library is included).
Saturday, April 5, 2008
Finished with Conway's game of life
Thursday, April 3, 2008
My First 3ds Max
1. 3ds max is a power tool for graphics.
2. There is a TON of functionality in 3ds Max.
3. The 3ds Max developers have made a custom UI so they can fit all the functionality in. For example, scroll bars are about 4 pixels wide.
4. Even with all the functionality, 3ds Max is actually pretty easy to use (so far).
The Quick start has you create a Greek structure with some columns and stairs. You then animate a camera along a line, and render a video. My camera skills need a lot of work, so I won't post the video I created. But here are a couple renderings of the structure itself to give you an idea.

and holy cow. I just closed 3ds Max, and instead of saying "Yes, I'd like to save", I clicked the no button on accident :(. Oh well, if I need to make that temple again later, I'll probably know way more and be able to make it even better.
Saturday, March 29, 2008
New Menu Code
Okay, It's been busy at home lately. I've been moving it. But I've been trying to find a little time every day to work on my XNA stuff, and I've got a much more complete menu system now.
I've made some changes:
- The menu now shows a default "Return" choice at the bottom of each list. This can be turned off by setting the "showBackChoice" boolean.
- The menu now has two types of choices, Normal and LeftRight. Normal choice will show their child choices as a separate menu when they are executed. LeftRight choices will show their child choices as a list to the left of the parent choice when they are SELECTED.
I've also made the sample code show a bit more info in the console as you are viewing the menu. The sample code initializes the menu as follows:
mainMenu.AddChoice("Choice 1");
MenuChoice choice = mainMenu.AddChoice("LR Choice");
choice.AddLeftRightChoices(new string[] { "one", "two", "three" });
choice = mainMenu.AddChoice("Sub Menu");
choice.AddChoice("Sub choice 1");
choice.AddChoice("Sub choice 2");
mainMenu.ChoiceExecuted += new Menu.ChoiceExecutedHandler(ChoiceExecuted);
mainMenu.ChoiceSelected += new Menu.ChoiceSelectedHandler(ChoiceSelected);
mainMenu.ChoiceDeselected += new Menu.ChoiceDeselectedHandler(ChoiceDeselected);
So there you go. Pretty simple. If I make any more changes, I'll be sure to post them. Possible changes could be:
- using a proper spriteFont to display the text (so we could use something besides Times new Roman).
- making background images actually work.
- something I overlooked....
I've realized as I've been working on this that is might have been easier to just implement it using a full on tree, rather than a bunch of sneaky lists.
Sunday, March 16, 2008
Basic Menu
Menu mainMenu;
Then, in LoadContent(), initialize the menu, it's choices, and any handlers you want to catch.
mainMenu = new GameMenu.Menu(this);
mainMenu.AddChoice("Show Sprite");
mainMenu.AddChoice("Return");
mainMenu.ChoiceExecuted += new Menu.ChoiceExecutedHandler(ChoiceExecuted);
Of course, ChoiceExecuted should be defined somewhere. I'll get to that at the end. In your Update() method, call the game menu's update function:
mainMenu.Update(gameTime);
And in the Draw() method, call the menu's draw function:
mainMenu.Draw(gameTime);
If the menu isn't visible, those functions will do nothing. To show the menu, you set the visible property to true. I do this in the Update method when the user pressed escape:
if (keyboardState.IsKeyDown(Keys.Escape) && !prevKeyBoardState.IsKeyDown(Keys.Escape))
{
mainMenu.visible = !mainMenu.visible;
}
And finally, when a menu choice is executed, you handle it as follows:
public void ChoiceExecuted(object source, Menu.MenuEvent e)
{
if (e.choiceString == "Show Sprite")
{
mainMenu.visible = false;
}
else if (e.choiceString == "Return")
{
mainMenu.visible = false;
}
}
All I'm doing in the sample code is hiding the menu, but you can do anything in there. There are also choiceSelected and choiceDeselected events, and they get fired in the current code.
My next update to this code should have the ability to navigate through menu pages, and the ability to give the user some left/right choices as far as options go (a "Sound On Off" menu choice, for example).
Tuesday, March 11, 2008
Quick Update
I was looking at some other XNA code yesterday, and I think I need to look into spriteFonts. I might be able to use those instead of the bitmap font class I'm using now. spriteFonts are built in to XNA, so they might be faster. I'll have an easier time modifying the font type, that's for sure. More later this week...