A full update on all the work I've done over the Christmas break will come at the end of the week, but I just wanted to post the model of the Planet Earth I've just completed:
I'm quite pleased with it. However, it should be noted that this is a render in 3Ds Max - it won't look as good as this in the program. I've managed to get it to load in the program, but it seems to be causing a lot of speed issues - a bit worrying when theres 8 other models to go!
Full update on the date system and hopefully more models to come at the end of the week.
Edit:
I've just implemented a sky box to give a starry background, and here is what the Earth model looks like in the openGL program:
Not quite as good as the render, but still pretty nice!
Showing posts with label render. Show all posts
Showing posts with label render. Show all posts
Tuesday, 4 January 2011
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!
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:
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:
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!
Labels:
C++,
gcvt,
gregorian date,
julian date,
opengl,
print,
program,
render,
string,
text
Monday, 22 November 2010
Week 7 - More Programming
This week I have been working further upon the OrbitalCalculations class - namely, trying to prove that the figures being generated are correct by following through an example from a trustworthy source. The source I used was the following from Utrecht University - http://www.astro.uu.nl/~strous/AA/en/reken/hemelpositie. In getting this result, I have edited the class quite a bit, and will detail those changes later. I have also worked on getting a proper import code, that will allow my program to read in 3Ds max models and their materials.
Firstly, the changes to the orbital calculations class;
Firstly, the changes to the orbital calculations class;
- getV has been replaced with getTrueAnomaly, and the variables likewise - so double v is now double trueAnomaly. This was mainly to help myself, I had not realised initially that the variable v that I was calculating was the true anomaly. I also changed the code, to give a more accurate result. I adapted the code from the same resource as the eccentric anomaly code - http://www.jgiesen.de/kepler/kepler.html.
- variable perihelionTime has been removed. After discussions with Rob it became clear that the current method of calculating the mean anomaly could not work, as there was very little to no data available on the date of perihelion passage for any planet other than Earth. The new method requires a start time which the orbital elements are valid for (01/01/2000) and the current date.
- Using the method of calculation detailed in the Utrecht University website, it is no longer necessary to calculate the X,Y,Z values in two parts, so x1, y1, z1, x2, y2, z2 and their associated methods have been removed and merged into one for calculating x, y and z on their own.
Now onto the big problem I had in getting the numbers my program output to equal the ones that website said I should be getting - radians and degrees. You see, the computer computes sin/cos/tan functions in radians, and the data I input and want output is in degrees. This gave me quite some trouble, but essentially each variable which is an angle had to be converted into radians before the calculation is carried out, then converted back into degrees if it is returning an angle. What I did was create a variable called k, and make it equal to Pi / 180. This means that multiplying an angle by k will convert it from degrees to radians, and dividing an angle by k will convert an angle from radians to degrees.
I'd like to run through the example on the Utrecht University website for calculating the X,Y,Z position of Jupiter.
The first step is to calculate the mean anomaly. Here is a screenshot of my new mean anomaly calculation:
The UU website states the result should be: 141.324°
Next, the true anomaly. Here's my new code to calculate the true anomaly:
The result for the true anomaly should be: 144.637°
Next up, the distance to the sun, which is r. My code to calculate r hasn't changed actually, but I did have to convert the true anomaly used in the calculation into radians first.
The result for r should be: 5.40406 AU
Finally, the x,y,z coordinates. I'll post an image of my code to calculate X, the other two are similar. Notice that each angle has to be multiplied by k - this is not shown on the website, and gave me lots of trouble!
The x,y,z coordinates for Jupiter should be: −5.04289, 1.93965, 0.10478
Now, here's a screenshot of my results:
and a side by side comparison. Target results in red, my results in blue.
Mean Anomaly: 141.324° | 141.365°
True Anomaly: 144.637° | 144.036°
r: 5.40406 | 5.40417
x: −5.04289 | -5.04431
y: 1.93965 | 1.93624
z: 0.10478 | 0.104829
Pretty close! I'm very happy with how the calculations are working.
The second part of what I was working on this week was importing a basic model from 3Ds Max and getting it displayed on screen. This proved quite difficult! The code I was planning to use from last semester proved instantly unusable - it requires models to be of .txt format, and 3Ds Max does not export to this format.
I spent many hours trying and testing different loaders, and eventually settled on an object loader (it loads models of type .obj) called GLM from this website: http://www.3dcodingtutorial.com/Working-with-3D-models/Getting-GLM.html. I imported the files into my project and put them in a seperate folder - this means that the ImportModel and point classes I had made are no longer needed.
With a bit of tweaking, I've managed to get a geosphere with a material of an alien's face that I created in 3Ds Max, to display in my viewport window. Here's a screenshot:
All in all, some good progress made.
More next week.
Labels:
calculations,
comparison,
degrees,
Earth,
glm,
import,
Jupiter,
loader,
material,
mean anomaly,
obj,
orbit,
OrbitalCalculations,
radians,
render,
true anomaly,
Utrecht University,
x,
y,
z
Subscribe to:
Posts (Atom)