Put a Auto-cam in Top Position - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: Put a Auto-cam in Top Position (/thread-6032.html) Put a Auto-cam in Top Position - alert - Dec 13, 2004 05:05 AM 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.... Put a Auto-cam in Top Position - WhatMeWorry - Dec 14, 2004 11:49 AM 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. Put a Auto-cam in Top Position - ThemsAllTook - Dec 14, 2004 12:22 PM 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 Put a Auto-cam in Top Position - alert - Dec 15, 2004 05:02 AM 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!!!!! Put a Auto-cam in Top Position - alert - Dec 15, 2004 05:11 AM But Thaks ..... Put a Auto-cam in Top Position - Fenris - Dec 15, 2004 05:37 AM 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!