January 14th, 2008
It’s time to put a milestone on the XNA project, something to show what I’ve been doing these days. So far I’ve learned about making a terrain (2D grid – heightmap – lightning – multitexturing), camera handling (moving and zooming), drawing the interface (mouse cursor and hud display) and some interaction (picking the cursor target).
The project is called “Ball roller”. A ball model is loaded somewhere on the terrain. When the user clicks somewhere on the terrain, the ball will roll to that point. Such a project will put everything I’ve done so far with XNA to the test and add some new concepts: loading a model from and external resource and heightmap collision. The loaded model is the ball which can be rolled around, and heightmap collision is used for the ball to follow a terrain contour.
I’ve added a new class: xBall. It keeps data about the ball model and its position in the world. Its most important function is MoveTo(). When that function is called, the ball will start rolling in the direction of the mouse click. For every position change it will ask the terrain what the height is at that point. The terrain has a function GetHeight() where it calculates the height of the point by looking at its heightmap and using bilinear interpolation.
The ball is rolled over the terrain following its contour:
All in all, I had some fun in figuring how all of this works.
Terrain generation was the most complicated part and i spent most of my project time on it. As somebody put it: “Shaders make you feel… powerful, or very stupid”. I hope I can use it further and turn it into a base for some simulation.
The camera, object picking and ball rolling are all about math. It took me some time to refresh my knowledge about vectors and matrices but in the end, it was quality time.
Here’s the completed VS solution and executables. The solution can be opened with Visual Studio Express 2005 and XNA Game Studio 2.0.
