Showing posts with label planets. Show all posts
Showing posts with label planets. Show all posts

Wednesday, 16 February 2011

Week 21 - Rotation and Menus

This week I have been working on getting the planets rotating at the correct speeds and around their axis - quite difficult! - and implementing a pop up menu system, moving over some of the functionality I had coded into the keyboard controls.

Firstly, planet rotation. The first thing I had to do was work out a way to animate the rotation - this was fairly simple, and required a glRotatef call before drawing the planet in myDrawGLScene. For example, the Earth would rotate by "earthSpin" degrees every frame as the program runs. The variable earthSpin (there is a unique Spin variable for every planet) is updated in the method planetRot, which assigned the appropriate rotation value to each variable.

In order to calculate the correct rotation values, I needed a few things - firstly, how long it takes each planet to rotate 360 degrees, which I found at this website. Secondly, I needed to calculate how many frames it took the Julian day to increase by 1 as the program ran. Since the Julian day is currently set in the program to increase by 0.05 every frame, that means that it takes 20 frames for the day to increase by 1. Using this information I was able to work out the correct rotation values for each planet - the math is explained in more detail in the comments beside the code in the following screenshots of the planetRot function (click to expand):



each value has to be multipled by speedFactor, so that the rotation increases as the speed of orbit increases.

The next major problem was rotation around the axis of the planet. Each planet had already been rotated slightly by it's axis value - these rotations were all done around the Z axis of each planet, basically rotating around a vertical axis instead of the off centre one it needed to go around. This gave me a major headache, as opengl only allows for transformations around the X, Y and Z axes. I spent many hours reading information on matrix tranformations and aligning an axis to a vector but to be honest, I didn't really understand it too well. From the information and code examples I had come across, I developed the following function:


...which didn't work. It is meant to align the axis to a given vector, but I realised that the vector I was aligning it to (the vector position of the planet) would not be at the correct axis tilt anyway, and I have no idea how to get that vector. I have kept the method in the program for now, and it is something I will need to discuss with Rob tomorrow.

The solution I have been working on since that method failed is rotating by the axis value before the planet is drawn, then correcting that afterwards, like so:


This does seem to improve the look of the planets rotation, but I'm not sure if it's correct.

Now, onto opengl menus. The creation of the menu is all handled by a method called CreateMenus() in the main.cpp file. The handling of what each menu option does is taken care of by a method called myMenuResponder(int selection)  in the DrawSolarSystem class. The menu handles:

  • Listing the keyboard controls (submenu)
  • Controlling the scale of the distance between the planets and the Sun (submenu)
  • Controlling the scale of the planets (submenu)
  • Zooming into a view for each planet (submenu)
  • Changing the view between horitzontal and vertical
  • Switching to full screen mode
  • Resetting the scene to the load up config
  • Exiting the program
Here is the CreateMenus method that shows how all these options are programmed:



The very last line tells the program to call this menu whenever the right button of the mouse is clicked - this is how the user accesses it. Here is a small section of the myMenuResponder method. Each option in the above code is given a number, which is how these two methods are linked.


And finally, a couple of screenshots that demonstrate the program in vertical / horizontal view mode, and with the pop up menu up:



Note that the planets have been increased to their maximum scales, with the outer four planet's distances also decreased to their minimum value (as close as they can get to the Sun).

That's all for this week. Hopefully I'll be able to address the axis rotation and lighting/shadow issues for next week.

Sunday, 10 October 2010

Blog Week 1 - Direction

The first decision that I need to make in undertaking this project is which direction I would like to take the project in.

The coding language I have settled on is C++. Programming in this language means I can interact with OpenGL far easier than I could in other languages, such as Java. The orrery program should allow the user to view the planets orbiting the Sun initially from the furthest point out, with the option to zoom and view the other planets. Intial timescale should relate to a day passing every second, but the user will have the option to increase this in order to see the planets orbit at a higher speed. 

I am unsure yet as to how many moons I will include in this program. Initially I had thought to include only moons with a radius greater than 1000km - this gives me 16 planetary bodies in the system:
  • The Sun
  • Mercury
  • Venus
  • The Earth
    • The Moon 
  •  Mars
  • Jupiter
    • Io
    • Europa
    • Ganymede
    • Callisto
  • Saturn
    • Titan
  • Uranus
  • Neptune
    • Triton
This means that none of Mars' or Uranus' moons and only one of Saturn's and Neptune's would be included. This is something I will need to discuss further with my supervisor before making a cast iron decision. I do not think that the dwarf planets (such as Pluto) will be included, but as I say this is something I need to discuss and return to.


The following is a list of programs that I intend to use during this project:
  • Microsoft Visual Studio 2010 - for C++ programming
  • Autodesk 3Ds Max 2011 - for modelling of planets etc
  • Microsoft Word 2010 - any necessary word processing
  • Adobe Photoshop CS5 - texture editing etc


I will be using this blog to keep track of any links with useful information that I feel may prove useful in the future of the project. Here are a few that I have come across during my intial research this week:

http://nineplanets.org/ - comprehensive information site on the eight planets (despite the name), their moon, dwarf planets, and various other small bodies in the solar system.


http://star.arm.ac.uk/~dja/planets.html - orbital positions of the planets, dating from January 2000 to projected positons in December 2019.

http://www.etsu.edu/physics/etsuobs/starprty/22099dgl/planalign.htm - information on Planetary aligments. I had initially thought that a "planetary alignment" would make a perfect starting time for the program, yet this seems more complex than I had first realised.

http://www.easytorecall.co.uk/orrery_simulation.htm - A very basic Javascript 2D digital orrery. Shows orbits of Mercury, Venus, Earth and Mars and their moons around the Sun.

http://www.gifford.co.uk/~principia/orrery.htm - Another very simple digital orrery. Shows all planetary orbits, but no moons. Also shows current position of planets.