Put a Autocam in Top Position
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....
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....
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.
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.
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
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!!!!!
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!!!!!
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 topmost 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!
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 topmost 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!
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
SDL. Current music position  e40pud  0  3,369 
Mar 9, 2010 08:46 AM Last Post: e40pud 

Cube autorotate  sakrist  2  4,252 
May 5, 2009 03:31 AM Last Post: Ingemar 

Object position after rotation  charon  11  9,939 
Mar 2, 2005 11:33 AM Last Post: hangt5 

Mouse Position In Fullscreen...  thaeez  6  5,775 
Nov 5, 2004 02:38 PM Last Post: thaeez 

Getting position after transformation without drawing?  hyn  19  10,002 
Aug 6, 2004 02:02 PM Last Post: kberg 