Sign in to follow this  
ForestMaster

Camera pos/dir + rot == right RTS view

Recommended Posts

ForestMaster    164
Hello, I'm sorry, I've figured out that i posted in the wrong section, so I post again here(sorry again for my dumbness). Here's the deal: I want to set camera and everything right so that i get my look on a trapezium, as in classic RTS(ie "Age of Mythology"); I don't know what to do, I've tryed many ways but the answer is prolly too easy for me to be got :S I'd be grateful if you can try at least to understand what I'm explaining :P a noOb.

Share this post


Link to post
Share on other sites
Calin    419
It's all about manipulatin your camera. In a RTS usually you have a top-down view with a slight inclination. Once you have a working camera adjusting the position is a child`s play.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hmm.. Are you looking for an isometric camera, perhaps? (I think that trapezium might == the familiar flattened diamond shape of yore.) If so, try googling for isometric and parallel projections; it's very possible to implement these in a modern 3D pipeline, and the results can be interesting.

Share this post


Link to post
Share on other sites
ForestMaster    164
I don't want isometric(thanks anyway).
I can't understand how to manipulate my camera to make its view field a trapezium: this way I mean to see no perspective distorsions on the terrain(ie)

Share this post


Link to post
Share on other sites
Quote:
Original post by ForestMaster
I don't want isometric(thanks anyway).
I can't understand how to manipulate my camera to make its view field a trapezium: this way I mean to see no perspective distorsions on the terrain(ie)


You can use an orthogonal projection to eliminate perspective distortion. As for acheiving a view of a trapezium-shaped region of terrain, you would probably want your camera at a small offset from a straight-down view angle.

- Mike

Share this post


Link to post
Share on other sites
ForestMaster    164
Quote:
Original post by doctorsixstring

You can use an orthogonal projection to eliminate perspective distortion. As for acheiving a view of a trapezium-shaped region of terrain, you would probably want your camera at a small offset from a straight-down view angle.

- Mike


Sorry for my noobshitness but.. How do I achieve the camera offset from a straight-down view angle? :S

Share this post


Link to post
Share on other sites
haegarr    7372
An orthogonal projection has a rectangular box as view volume. If such a box cuts a plane (as the simplest ground) a rectangle is yielded regardless of the inclination angle (as long as the front/back of the box are not cut). You will need to use a perspective projection if an actual trapezium should be yielded.

Your camera should have an own co-ordinate frame (that is a combination of a position and an orientation in your case) that defines the camera inside the world. Use a translation to move the camera upwards by an amount, and a rotation around the x axis for inclination. A 90° rotation will yield in a straight down look, so you may use a e.g. 75° rotation if you want a nearly straight down look.

Share this post


Link to post
Share on other sites
ForestMaster    164
Quote:
Original post by haegarr
Your camera should have an own co-ordinate frame (that is a combination of a position and an orientation in your case) that defines the camera inside the world. Use a translation to move the camera upwards by an amount, and a rotation around the x axis for inclination. A 90° rotation will yield in a straight down look, so you may use a e.g. 75° rotation if you want a nearly straight down look.


Thanks a lot, yes I have my own camera class ready to fire
So:(OGL)

camera.look();
glRotatef(75,1,0,0);
/*DrawAnythingYouWant*/


Am I on the right track?

Share this post


Link to post
Share on other sites
haegarr    7372
Quote:
Original post by ForestMaster
Am I on the right track?

In principal yes, but the stuff around the glRotate may have an influence. Be aware of the following (sorry, but here comes a bunch of theory):

(1) If camera.look() changes the heading of the camera (say it rotates around the cardinal y axis) then using glRotate(angle,1,0,0) may suffer. Perhaps you want to rotate around the _local_ x axis for camera inclination.

(2) The camera is given in global space. Rendering models (like the ground) appears also in global space. However, what you want to see on your monitor is in _view_ space. To reach this, you have to set-up the VIEW portion of the MODELVIEW matrix in OGL (you already know this, right?) Since one comes from VIEW space to global space by applying the camera's transformation, but wants the transformation vice-versa (from global to VIEW space), the VIEW transformation is just the inverse of the camera transformation. So I assume you have (regardless of point (1) here) do a
glRotate(-75°,1,0,0)
what is the said inverse. Please check this.

Share this post


Link to post
Share on other sites
ForestMaster    164
Quote:
Original post by haegarr
(1) If camera.look() changes the heading of the camera (say it rotates around the cardinal y axis) then using glRotate(angle,1,0,0) may suffer. Perhaps you want to rotate around the _local_ x axis for camera inclination.


camera.look() simply uses gluLookAt passing the position, view and up vectors of the camera. I still don't well understand Where to place the rotation /_\

Share this post


Link to post
Share on other sites
haegarr    7372
gluLookAt already does a heading (y axis rotation) as well as a pitching (x axis rotation). Hence you could try to place the point to look-at appropriately and drop performing your own x axis rotation. It may become difficult to implement the wanted inclination angle.

On the other hand, gluLookAt performs internally a sequence of
glMultMatrixf(M);
glTransled(-eye.x,-eye.y,-eye.z);
[please notice the negative signs and the order of transformations what both result from using the inverse, I mentioned that in my previous reply] where M is computed as rotation matrix. Normally one performs Euler rotations in the order heading first, than pitching, and at last rolling (you don't use rolling). Since the VIEW matrix is the inverse of the camera matrix, gluLookAt does something like
glMultMatrixf(pitching);
glMultMatrixf(heading);
glTransled(-eye.x,-eye.y,-eye.z);
[it doesn't do so really but one can image so].

So, if you want to do a pitching yourself you could see that you have to do it before gluLookAt if you wan't to see an appropriate effect anyhow. To make it work well it seems me senseful to guarantee that the pitching gluLookAt does it an identity operation (i.e. let the look-at point be on the same height as the camera is).

IMHO the overall structure has to be something like this (but don't hate me if I'm wrong ;)
glMatrixMode(GL_MODELVIEW);
glLoadIndentity();
glRotate(-75,1,0,0);
...
gluLookAt(...);
... transforming and rendering of models

Hope this makes sense...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this