PDA

View Full Version : Easy GLUT Cameras?

Bitwize
01-04-2011, 03:34 PM
I recently created a thread (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=288556&amp;#Post288 556) asking whether or not to use GLUT to create a model of the solar system

Anyway, I now have the calculations and output drawn for all the objects, only I have an issue. I originally created my project through using a portion of canned code for the viewing area and - despite looking up minor tutorials on cameras and viewports - i lack an understanding of it.
I am reading this OpenGL Camera Tutorial (http://www.opengl.org/resources/faq/technical/viewing.htm), and though I have tried code like:

glMatrixMode(GL_PROJECTION); // Set projection parameters.
gluLookAt(0, 0, 100, /* look from camera XYZ */
0, 0, 0, /* look at the origin */
0, 1, 0); /* positive Y up vector */
I am getting blackness as an output. I require the camera being far away, as the scale of the models are up to 109 (due to the sun being scaled by the radius of the earth), and of course the scaled distances between the planets.

My question is how do I set up a camera with a distance that would incorporate all the units of that distance, while still maintaining visibility?
I'd really appreciate either a detailed explanation (that helps a bit better than the tutorial), a better tutorial, or even ideally a few snippets of code I could work off of to figure out how to use cameras and views (Not that I mean I wish to cheat my understanding, but I work better with reading code snippets and deciphering what it means myself than reading tutorials most of the time).

EDIT:
I forgot to also ask; how could I make the view not stretch or compress the models when the window is reshaped?
I currently use this function:

void computeLocation()
{
double x = 2 * cos(user_theta); // my x-, y-, and z-coordinates
double y = 2 * sin(user_theta);
double z = user_height;
double d = sqrt(x * x + y * y + z * z); // distance to origin

glMatrixMode(GL_PROJECTION); // Set projection parameters.
glFrustum(-d * 0.5, d * 0.5, -d * 0.5, d * 0.5, d - 1.1, d + 1.1);
gluLookAt(x, y, z, 0, 0, 0, 0, 0, 1);
}
The user_theta is from canned code and calculates the position of the camera for a slight angular movement
I think my issue revolves around my lack of understanding of glFrostum; but even the tutorials of that only confuse me. I'm not looking for in depth work with it, just as simplified as possible to make a camera.
I apologize for my ignorance, but I am a bit rushed now and so I am looking for the simplest method available

Bitwize
01-05-2011, 03:52 PM
Bump.

I don't suppose anyone has a simple explanation that may help me?

Bitwize
01-06-2011, 03:20 PM
Bump again

i've been trying to figure out the damn frustum, and I only make more mistakes every time I try. All I need is to be explained how the frustum/lookat works, and how I can change it so that when the program is being run it no longer stretches the graphics to the screen (if that's possible)

I'm really in a rush now

Bitwize
01-07-2011, 08:33 PM
Okay, so far I have managed to design this:

camera(double radius, double x_pos, double y_pos, double z_pos)
{
double x = x_pos * scale;
double y = y_pos * scale;
double z = z_pos * scale;
double x_cam = x + (3 * radius )*cos(user_theta); //
double y_cam = y + (3 * radius )*sin(user_theta); //
double z_cam = z + (3 * radius );
double d = sqrt(x_cam*x_cam + y_cam*y_cam+z_cam*z_cam);
glMatrixMode(GL_PROJECTION);
glFrustum(-d * 0.5*zoomFactor, d * 0.5*zoomFactor,
-d * 0.5*zoomFactor, d * 0.5*zoomFactor,
d - 1.1, 100000);
gluLookAt( x_cam, y_cam, z_cam, x, y, z, 0, 0, 1 );
}
What this is -supposed- to do is look at whatever planet I tell it to, and keep it a distance of 3 times it's radius away from it. The only issue is sometimes it shows, sometimes it does not. For instance, if the zNear value is changed to just 1.0, it will show the planets, yet not the sun (perhaps due to the radius of the sun?) but yet if it stays d - 1.1, it shows the sun, but not the planets.
I really lack an understanding of it, and would really appreciate any help before Monday.
EDIT: I forgot to mention; scale is a global variable that is used to scale the planet's distances so it's not TOO massive

ugluk
01-08-2011, 04:28 AM
Go here:

http://library.nu/

search for "opengl math" and read, then if you don't understand something, ask here.

Bitwize
01-08-2011, 01:01 PM
Go here:

http://library.nu/