This week I was focusing on attempting to get the planets to rotate properly around their tilted axis, instead of around the global z axis. I have to admit, I didn't think I would be able to fix this - but in the end, I managed it!
I started by fixing the rotateToAxis method. The intention of the method was to rotate the axis that the planet spins around (the z axis) by the number of degrees of axis tilt. However, if you remember from the previous blog, I couldn't get this to work at all and the planets disappeared when I tried to use it. After last weeks meeting with Rob, he pointed out that the vector being used would have to first be normalised, or the whole thing wouldn't work - the major point I had missed. Here is the reworked version of this method:
The dot product and cross vector methods called here have also been slightly adapted - they now only require one vector to be passed down - this simplifies things from the previous technique.
Once I had this method working, I still had the same issue - what was the vector that needed to be passed to this method? I knew it would be the vector that ran at the angle of the axis tilt, but that was it. Then the lightbulb moment - the rotation_angle variable in this method was the axis tilt.
Once I had realised this, I removed the call in initGL that rotates the planet by its axis tilt - after all, the rotateToAxis method would take care of this.
If you look back to the rotateToAxis method, you will see that there are commented out "cout" calls - these print the variables like rotation_angle to the console, so I can see what each variable is at each part of the calculation. I knew that the vector was rotated around the Z axis, so the vector I needed to input would be of the form (1,1,?), with the question mark changing for each planet. I discovered that increasing this number decreased the rotation angle, and decreasing the number increased the angle. So, with a lot of trial and error, I matched up the rotation_angle with the axis tilt value by adjusting the z value of the input vector. It's difficult to explain, but here are the input vectors for each planet, that might help to clear things up:
Once I had done this, all I needed to do is add a call to rotateToAxis before each planet is drawn:
and Voila! Planet's that rotate about their own axis. I'm really pleased I got this fixed, it gives the program a much more authentic look to it. The only other thing I added this week was a simple boolean switch to remove or add the stars in the background. This is an option on the menu now (hopefully you can also see that the planets are correctly tilted!):
And finally... I let the program run for a while (check the date!) and managed to get a snapshot with all the planets on screen. I'm a little unsure if Uranus' ring spin is correct, but this will be an issue with the model not the calculations if it isn't, I need to check that with Rob.
That's all this week. I just need to implement the 'planet views' option that will zoom to a planet and move the camera with it's orbit, and the program is completed! If I manage that by the end of the month, then I'll have hit my deadline.
No comments:
Post a Comment