Sunday, July 20, 2008

This week in TP

This week, I finally figured out how to do proper camera rotation in 3d. The actual code turned out to be simple. At first, I wanted to use spherical coordinates to position the camera, as I had success with using polar coordinates for the radial menus. By storing the vertical and horizontal angles and treating radius as the zoom distance, I could convert them into 3d coordinates by applying some formulas. This worked only for rotations along the Z-axis (meaning that the world was "rolling", done by moving the mouse left and right). However, for rotations along the X-axis (pitch) it would refuse to rotate properly - upon reaching the horizon angle it would "bounce" back again.

In the end, I put the camera inside an OGRE scene node, and made it the child of another scene node which would act as the focus. Hopefully this tilted diagram isn't too confusing:

In the diagram, you can see the camera floating at a distance above the map, which contains several planets. The focus node is always level with the other map objects, while the camera node can zoom back and forth. As I mentioned, the camera node is a child of the focus node and by rotating the focus node directly, OGRE will apply any transformations to it's child nodes, causing the camera to rotate around the focus node.

Allowing the camera to look around freely posed a problem, mainly with the starry background as it was a flat field of stars. Here's a picture breaking the illusion:

Thankfully this was actually quite easy to fix. OGRE uses particle emitters, which spew out particles in various arrangements, and there was a Hollow Ellipsoid emitter which I could use to create a starfield surrounding the camera. The manual is not very clear on how to use the Hollow Ellipsoid, the inner_ parameters are actually numbers with a range from 0.0 to 1.0 specifying the percentage of inner volume which should be hollow.

There always seems to be a cluster of stars at roughly around the same location, I'm not sure why. Letting the camera roam also let a few more issues crop up, such as the planet rotation. Previously, they were facing the player who was looking from overhead, since otherwise all the player could see would be their polar caps so I had to rotate them back again. Another stickier problem is the panning of the camera. Since the camera can pan in any direction, it screws up the zoom if the player pans downwards or upwards.

Finally, the messages window layout has been changed to include a panel showing all the message headers. As I said in the previous post, the layout looks like it could do with some tweaking.
Next week, I will implement the ship design window, although I've not been able to create ship designs using the existing client yet, I should take a look at at least letting the player view the ship designs, or else he won't know how badass his fleets are. :)

Another thing will be the order queue management, which refers to deleting and editing existing orders.

There will be a turn update window, showing new events received upon a new turn.

Finally, I will create setup packages for Windows, Linux (with the help of fellow Thousand Parsec developers) and Mac (which I will be working with my mentor for - this may take longer due to issues with Python Ogre). Although not a real release yet, getting the build process done will be a load off my mind. No use working on a project if nobody can run it after all. :)

No comments: