PDA

View Full Version : Lines are not parallel when they should be



mrjjj
04-17-2009, 03:11 PM
I have a camera that can move around space and turn. It looks at a box ( whoopie ).


Here are some screen shots where you can see the problem.

http://www.killersmurf.com/static/front_view.png
http://www.killersmurf.com/static/camera_moved_right.png
http://www.killersmurf.com/static/camera_moved_left.png

Here is the source code http://www.killersmurf.com/static/hmmmcube.cpp
( btw, I DO know I should like, free memory, but considering these objects are the only ones the program ever uses, well... )

As you can see, when the camera moves right ( ie, the box on the screen moves left ) the lines making up the left hand side of the box ( and I mean stage left - the viewer's right ) are at a tighter angle than the lines on the other side.

This applies with opposite effects when the camera is translated in the opposite direction.

As you've probably guessed, I'm really new to this, and I'm not sure if this is a problem with the way I use perspective. So here's the initialization code.

glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
gluPerspective( 45 , SCREEN_WIDTH / SCREEN_HEIGHT , 0.1 , 100 );

Also, I use SDL, but I'm guessing that's not significant.

Jan
04-17-2009, 03:29 PM
It's called "perspective" and it's meant to be like that ;)

Seriously, when you only have a single cube, perspective distortion often seems "wrong" though it isn't. When you have a more complex scene, like a whole room, it will appear correct, there is just too few information in a single cube, so the brain thinks there's got to be something wrong (had that problem myself several times).

Other than that, your field-of-view is a bit low (45), set to 60 or even higher (up to 90, more becomes unnatural). It might look better, but the math is the same, those angles will not be parallel, because that's not how perspective works. If you want to understand it better, you might look up the term "vanishing point".

Hope that helps,
Jan.

mrjjj
04-17-2009, 03:33 PM
Ahh, cheers. I honestly sat with a rubik's cube for ages, trying to work out if the lines would look like that. I was on the verge of getting some wire and sticky tack. See, I even got my mate over and he told me that it was ok, but I didn't listen, hah. :-)

remdul
04-18-2009, 06:34 AM
You may want to check out glOrtho, if you're after isometric views (like 2d strategy games).

http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml