Put a Auto-cam in Top Position

Unregistered

Post: #1
Hello every one...

Any function to:
put automaticaly and exactly a camera (or a view) in top viewer ( in a any model)?
I have some models of a city.. now I want a function o put a camera "exactely" in a top viewer?

Thanks....
Member
Posts: 321
Joined: 2004.10
Post: #2
I'd take a look first at the gluLookAt() function. The aruguments
I believe are:

gluLookAt( camera.placedAt.x,
camera.placedAt.y,
camera.placedAt.z, // Camera Position
camera.looksAt.x,
camera.looksAt.y,
camera.looksAt.z, // Where Camera is Aimed
camera.orientation.x,
camera.orientation.y,
camera.orientation.z ); // How Camera is held

but check the Read book on web documentation for details.

Assuming your city is centered around coordinates: 0.0, 0.0, 0.0,

Looking down would be gluLookAt(0.0, variableY, 0.0, 0,0, 0,0, 0,0, 0,0, 1.0, 0.0)

where variableY would be some value > 0.0 which would be the equivalent
of the camera zoom. This should at least get you started.
Moderator
Posts: 1,563
Joined: 2003.10
Post: #3
WhatMeWorry Wrote:Looking down would be gluLookAt(0.0, variableY, 0.0, 0,0, 0,0, 0,0, 0,0, 1.0, 0.0)

This wouldn't quite work, as your up vector is parallel to your look vector. The last three arguments would have to be a vector pointing somewhere on the X and/or Z axis, not the Y axis.

- Alex Diener
Unregistered

Post: #4
ok... I now the "gluLookAt" command ...
but, every time i have a new model in a new position i have to redefine the code.. right?
I really need a rotine or function that analize the model, their cordinates and put automaticaly and exactly a camera (or a view) in top viewer!!!!!
Unregistered

Post: #5
But Thaks .....
Oldtimer
Posts: 834
Joined: 2002.09
Post: #6
To find the center of a model, add all the vertices together and divide that new vector by the number of vertices in the model.
For instance: you have the vertices: (0, 1, 3), (0, -1, 3), (1, 0, 3). Add them together, and you get: (0+0+1, 1+(-1)+0, 3+3+3) = (1, 0, 3). Divide that vector by three and you get (1/3, 0, 1) which is the center of that model.

Now, you want to use this to position the camera right above the model. To do that, you place it at the same X and Z coordinates as the center of your model. Now you only need to find a suitable Y coordinate to set the height of the camera above your model. This is hard to do, since you need to think about the camera's field of view and so on, but a quick hack is to position the camera at twice the distance to the top-most vertex in the model. To do this, just look through the model's vertices, find the highest (or lowest) Y and place the camera at twice that coordinate. Now you can use the gluLookAt trick above, using the position we've calculated as the camera position.
Hope this helps!