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!