3D Game World


I was able to get my models to display on the 3D game screen, and I was able to make it move around using the thumbstick for X/Y axis and the LT/RT triggers for Z axis.  Using an orthographic projection, I was able to make the model appear as a static image.  For now, my screen is mapped to 24×16 game world coordinates, since my player model is only two Blender units tall.  This will be really helpful when converting the game world coordinates to the 3D space, because I should be able to make a 1-to-1 correlation between the 2D bounding boxes and the rendered 3D objects.  Unfortunately, my model still displayed on its side, with the positive Z axis pointing out of the screen.  I spent quite a while playing with the FBX export settings, but I was unable to get it to display correctly.  Then I finally just rotated the model manually in Blender and exported, and still got the same result with the model on its side.  After multiple rebuilds and exports, I finally figured out that the object’s vertices must be rotated in edit mode for the rotation to take effect.  By doing this, I was able to get the player model to display correctly.  It is also important to note that all of the object’s coordinates are in relation to the orange anchor point in Blender, so it is best to move that anchor point to the origin first.  I think it may be better to go ahead and programmatically rotate the FBX object, just in case I get models from another source.  Other models will still have the same problem, and I don’t want to manually rotate the vertices of every model I use.  I also noticed that XNA does matrix operations in order when multiplying.  When rotating an object, it is important to apply the rotation matrix first before translating it.  I haven’t found an equivalent to pushing/popping matrices as in OpenGL.  It is also important to have the model in Blender centered on the rotation point.  This will prevent having to programmatically center it first.

After I got the blocks of the game world displaying correctly, I copied in all of the controller handling code from my existing GameScreen class.  All of the display code from the game objects such as enemies, collectibles, and blocks is the same, except that I have to divide all of the position location coordinates by the tile size (48 pixels) to covert the object’s location from screen coordinates to world coordinates.  The screen coordinates are 1280×720 and the world coordinates are 24×16.  I think the world coordinates are much easier to deal with, since one Blender unit is exactly one unit in the world space.  The only problem is that my collision boxes are Rectangle objects which are handled in screen coordinates.  I can’t convert these Rectangles to world coordinates because the Rectangle only accepts integers and doesn’t handle floats.  I could write my own collision box class and methods that accept floats, but that would be more work to do with no real benefit.  There may be a slight performance improvement, but I don’t think it would be noticeable.  On the other hand, it may be less efficient to do float based collision detection, since floating point operations are generally more expensive.


Using the models that I generated for the body, hands, boots, and helmet, I went ahead and updated the model on the equipment screen.  Currently, this is just a static image that I rendered by importing all of the armor pieces in Blender.  These pieces complete most of the player’s body, but I will probably need another player model to connect the pieces of equipment.  I’m hoping I can use the bone/armature information from the player to set the armor pieces in real time.  That way a player can have any combination of armor pieces equipped and have it display in real time on their game character.

One other change I made was to pull in all of the “model” (as in MVC) into its own class.  Since the World class already contained the data for the game objects, I used that class.  This just required me to add the Player class into the world class.  The reason for doing this was to have all of the non-graphical game information in one location.  This allows me to pass the “model” to the two different views that I have created, which are the 2D sprite view and the 3D view using the imported FBX models.  Ideally, I should be able to switch between the 2D view and 3D view instantaneously while playing the game, since they are both using the same data model.  I added an interface called GameWorldHandler that just has methods for handling the World object.  This allows me do determine if I should pass the World object to the current screen on each update.  The two game screens and the equipment screen implement this interface, since those require the game World (and the Player object) to display.  However, screens like the title screen and credits screen are not GameWorldHandlers, so those do not implement that interface.  I could have used an abstract class, but those screens already inherit from my ResistorKit Screen class.

helm02_screenFinally, I have started working on modeling the second armor set.  Currently, I just have the helmet done.  I may want to round out the edges some more, but I don’t want to add too may polygon faces because it could possibly impact performance.  Plus, the details of the model won’t be noticeable since the player is so small.  However, the details may be noticeable on the equipment screen where I plan to display the model in full size.

3 Replies to “3D Game World”

Comments are closed.