Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

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:

  • 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:




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.

Tuesday, 7 December 2010

Week 9 - Text

Just a short update this week - I'm slightly ahead of plan at the moment for the honours project, so I've been focusing more on my other courseworks. What I have done this week though, is implement some rendering of text on the screen, to display the Julian date and regular date. This is not as simple as it sounds in OpenGL!

The first thing I did however, was to increase the size of the objects. In the last blog there are some screenshots of the scalings I used - values like 0.005. I did this so I could zoom out far enough without the objects disappearing out of the matrix. I've done some experimenting with making the matrix larger though, and now the objects are scaled to a size easier to manage.

As a result I have implemented a seperate distance scale for the outer planets - this was done simply by adding another scalefactor variable. I'm not sure how I'm going to use these two seperate scales yet, but it's useful to have the option.

Finally, the main thing I've been working on is getting some text to display the Julian date. This should increase as the planets move around. I've also worked on converting the Julian date back into a regular (Gregorian) date format, and displaying that too.

The text strings that will be output are defined at the top of the DrawSolarSystem class. They're pretty simple, and look like this:


Now in order to render them on screen, a few things need to be done in the DrawGLScene method. Firstly, the view needs to be switched from perspective to orthographic, as the text is 2D, and won't be manipulated in 3D with the mouse controls etc. Then a for loop using the text string is defined to render the text. This looks like:


Drawing numbers that update, like the julian date and regular date, is a slightly different process, to start with anyway. Defined at the top of the DrawGLScene method, I used a function called gcvt to convert the numbered variables into strings, so that they can be displayed in the same way as the text strings. Here's the code:



Then, they are rendered to the screen much the same way as before. The example here is for the "year" number. Finally, the view is switched back to perspective.


And here is a screenshot of what the screen looks like:



Very fetching text I'm sure you'll agree! The Julian date updates nicely, although the more observant may notice that the julian date and regular date don't match. Only the year seems to be updating in the date. There seems to be a problem somewhere in the date calculations, but I'm not sure where yet. The program seems to be starting on the 2nd of December 2004, despite being coded to start on the 1st January 2004, so there's obviously a problem somewhere. I'll try and address this before next weeks blog.

That's all for this week. I've got lots of other coursework due in for next week, so I can't see next weeks blog being all that long either!