I am a beginner with OpenGL, so I will very much appreciate some help
I am using this project as a basis for the work I am trying to do. I suppose pasting all that code in the thread is not the best idea, but if needed I can do it.
I have a set of coordinates of satellites (in kilometers) that I will draw around the gluSphere (Earth). I have problems with rendering when I want to make the radius of the sphere equal to that of Earth in kilometers (6371 km), which I need to do if I want to use the satellite coordinates that I have. I don’t see the “Earth” being drawn on the scene even when I try various translations with “glTranslatef(0.0f, 0.0f, -X)”.
What do I need to change in code in order to be able to use “real” kilometeres for distance units in the simulation and see the Earth rendered properly ?
Thank you very much and kind regards,
My first guess is that your far plane is too close. That example uses
gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
So if your units are km, anything more than 200 km from the viewpoint will be clipped.
As well as increasing the far distance, you’ll also need to increase the near distance if you don’t want the depth resolution to be very coarse for almost the entire scene. Make the near distance as high as you can get away with. If you need to support extreme variations in distance (e.g. having a satellite ten metres in front of the viewpoint, with the earth in the background), you’ll need to use multiple passes.
I have a set of coordinates of satellites (in kilometers) that I will draw around the gluSphere (Earth). I have problems with rendering when I want to make the radius of the sphere equal to that of Earth in kilometers (6371 km), which I need to do if I want to use the satellite coordinates that I have.
I do a lot of orbital graphics. I strongly suggest you start with a sphere of radius = 1.0 (they use 2.0 in the example). Then scale the satellite cords down by r = 1/6371. An easy way to do this would be to call glScalef (r, r, r) just after the earth sphere is drawn. Put your Draw_Satellites routine after the glScalef call.
This way you don’t have to fuss with the clipping planes. Also, it will be very easy to change the program to adapt to any system of units (nm, ft, etc). All you’d have to do is change the value of r.
Thank you both for answers, your suggestion worked GClements.
Carmine, the scaling idea sounds good but I wonder, will there be no loss of quality and accuracy on image for using such small units ? I somehow imagine that OpenGL will have a harder time drawing with such small numbers and keeping the orbit “lines” nice and in proper ratios. But I don’t understand OpenGL too well so of course I may be off course.
If you’re specifying coordinates using floating-point, the magnitude doesn’t matter unless you start approaching the range of a single-precision floating-point value (roughly 1.2e-38 to 3.4e+38)
If you’re using fixed-point, the coordinates should be scaled and translated such that the bounds just fit into the fixed-point range, then the inverse transformation applied to convert them back to the original values.