This week was the deadline I had set myself to complete the program, so - have I managed it?
Just about! I still have a couple of tweaks I want to make, and clean up some code, but effectively the program is now fully functional and as advanced as I am going to make it.
I've changed quite a bit this week, cleaning a few things up - I've implemented arrays in several places where I had lists of variables for each planet, and completely reworked my planet rotation method to fix an error where the planet would stop if the speed became too great. The main addition this week though is the implementation of "planet views", an option on the menu which allows the user to focus the camera on one planet, and the camera will follow along as the planet orbits the Sun.
Firstly, the arrays I've implemented. I've replaced four variable lists with arrays:
Previously there was a model variable for each planet, a size variable for each planet etc, but using an array instead cleans things up greatly, and hopefully improves the program speed a little as well. Example: mercSize is now size[0], venSize is now size[1] etc.
Now, onto the planet rotation. The problem was that the rotation value is given by the rotation amount times the speed factor. When that equals 360, the planet stops spinning. Example: Earths rotation amount is 18 degrees. When the speed factor is increased to 20, the rotation amount is 18x20 = 360, so the planet appears to be still when the speed of the program is at 20 times. Since each planet reaches it's fastest speed when the rotation amount = 180 degrees, I simply worked out when this was for each planet and stopped increasing the rotation amount at that point. It's all explained in the method comments, here it is:
Finally, the planet views. To implement these I had to create 8 new methods in the DrawSolarSystem class - one for each planet, called mercuryView(), venusView etc. I also had to modify the camera controls to use gluLookAt, so I could focus the camera on a position.
So, in each view method I set the camera's position, and the camera's focus, using the X,Y,Z coordinates of each planet. For the cameras position, I had to move it slightly off the X,Y,Z of the planet so you could see it - I perfected each position by assigning a 'test' variable to be added or subtracted to the Y or Z, and controlled the increments with the keyboard. These keyboard controls are now commented out, and I replaced the test variables with an actual number once I'd gotten the best camera position. I also had to set certain booleans to false so they did not affect the camera. Here is an example of the mercuryView method:
The next step was to add this method into the DrawGLScene method. Since i wanted this view to be activated when a menu option is selected, a boolean trigger is required to be set to 'true' in order for the view to be shown.
Finally, in the menu responder I simply set the boolean for the planet view I want implemented to true (in this case Mercury), and all the rest to false.
I've also included an option to return to the default view, which simply resets the camera and loops through the planetView array, setting all the booleans to false.
I'm going to post a blog following this one, with screenshots of all the planet views.
Save for some minor tweaks, thats the program pretty much finished. I'm really pleased with the end result, and delighted I've been able to implement all the features I wanted to in the desired timeframe. Onto the report!
Showing posts with label speed control. Show all posts
Showing posts with label speed control. Show all posts
Wednesday, 2 March 2011
Wednesday, 9 February 2011
Week 20 - User Interaction
Following a short break, it's back to work on the Honours Project. I'm aiming to have the program fully finished by the end of February, the features I'm aiming to improve/add are:
The second piece of functionality that has been added is the ability for the user to increase the size of the individual planets. This was something discussed in my last meeting with Rob, and I decided that in order for the user to get a good look at the models (especially the smaller inner four planets) without lots of zooming and panning, this would be a great feature to implement. At the moment, only the planet Earth has this fucntionality coded, and it is controlled by the 'u' (to increase size to a max of 8x the original) and 'i' (to decrease size) keys. This is a feature I intend to move to the menu system, simply for the reason that I will run out of keyboard keys if I use two per planet. In order to code this, I introduced a variable earthSize, which is controlled in a similar way to the speed variable, increasing or decreasing the variable on a key press. I had to move the scaling function for the model from InitGL, where it was located in the display list, into myDrawGLScene, in order for it to update correctly whilst the program is running.
The final piece of functionality that I added this week was scaling the distances from the Sun. There are two options for the user in this case - they can increase/decrease the distance of the inner four planets from the Sun (currently using the 'f' and 'g' keys) or increase/decrease the distance of the outer four planets from the Sun. This gives the user the option to see the planets bunched in much more closely than the correct scale that the program launches in. This is controlled by two variables - innerScale and outerScale, with a default setting of 16 (purely for aesthetic reasons, although this could change). The positions of the planets that are defined in earth Update..Position method are multiplied by these variables, which are increased or decreased by a key press. The increase value for both variables is limited to 20, whilst different limits are applied for the inner and outer decrease values - in the inner case, so Mercury does not disappear into the Sun model, and in the outer case, so Jupiter and Mars' orbits don't collide.
The image below shows the outer planets decreased to their lower limit, Jupiter appearing very close to the inner four planets.
That's all for this week.
- More user interaction. This has been partly addressed this week.
- Improve lighting and shadows. Currently the planets don't have a 'dark side' where the Suns light doesn't hit them. I've no idea why this is as the lights are set up in the centre of the Sun, so I may not be able to solve this.
- Implement pop up menus. All the user interaction is keyboard and mouse based at the moment, and there's too many functions going on to have them all implemented by a key press - I want to move some stuff over to menus, and also include a pop up with control details for the keyboard functions.
- Rotate planets as they orbit. Currently the planets aren't rotating as they move, and implementing this has proved more difficult than I first thought it would be.
- Improve movement controls. This is the least important update, so it may get cast aside if I run out of time, but I would like to improve the way the user moves around the 3D solar system - it's not brilliant but it works, so I wouldn't be too worried about leaving it if need be.
So onto the improvements in the user interaction that have been added this week. The major cosmetic change is the addition of a speed control. I had previously attempted to add this in using a variable called speedFactor which was adjusted everytime the user pressed a key - but could not get it to work. I solved this by moving the code which updates the julian date:
julDate += (0.1 * speedFactor);
from the updateMercPosition function that it was in, into the main myDrawGLScene method, which fixed the issue of the speedFactor variable not being updated by a user key press. Now whenever the user presses 'm' the speed is increased (to a maximum of 25x), with n decreasing the speed (minimum of 1x). The program launches in 1x speed, and can be increased by the user to 25 times the launch speed. The speed is displayed on screen, beneath the two date displays like so:
julDate += (0.1 * speedFactor);
from the updateMercPosition function that it was in, into the main myDrawGLScene method, which fixed the issue of the speedFactor variable not being updated by a user key press. Now whenever the user presses 'm' the speed is increased (to a maximum of 25x), with n decreasing the speed (minimum of 1x). The program launches in 1x speed, and can be increased by the user to 25 times the launch speed. The speed is displayed on screen, beneath the two date displays like so:
The second piece of functionality that has been added is the ability for the user to increase the size of the individual planets. This was something discussed in my last meeting with Rob, and I decided that in order for the user to get a good look at the models (especially the smaller inner four planets) without lots of zooming and panning, this would be a great feature to implement. At the moment, only the planet Earth has this fucntionality coded, and it is controlled by the 'u' (to increase size to a max of 8x the original) and 'i' (to decrease size) keys. This is a feature I intend to move to the menu system, simply for the reason that I will run out of keyboard keys if I use two per planet. In order to code this, I introduced a variable earthSize, which is controlled in a similar way to the speed variable, increasing or decreasing the variable on a key press. I had to move the scaling function for the model from InitGL, where it was located in the display list, into myDrawGLScene, in order for it to update correctly whilst the program is running.
The final piece of functionality that I added this week was scaling the distances from the Sun. There are two options for the user in this case - they can increase/decrease the distance of the inner four planets from the Sun (currently using the 'f' and 'g' keys) or increase/decrease the distance of the outer four planets from the Sun. This gives the user the option to see the planets bunched in much more closely than the correct scale that the program launches in. This is controlled by two variables - innerScale and outerScale, with a default setting of 16 (purely for aesthetic reasons, although this could change). The positions of the planets that are defined in earth Update..Position method are multiplied by these variables, which are increased or decreased by a key press. The increase value for both variables is limited to 20, whilst different limits are applied for the inner and outer decrease values - in the inner case, so Mercury does not disappear into the Sun model, and in the outer case, so Jupiter and Mars' orbits don't collide.
The image below shows the outer planets decreased to their lower limit, Jupiter appearing very close to the inner four planets.
That's all for this week.
Labels:
3D,
C++,
controls,
distances,
interaction,
julian date,
menu,
opengl,
orbit,
orrery,
program,
rotation,
scale,
shadows,
size,
speed control,
text,
user interaction
Subscribe to:
Posts (Atom)