0

I want to render some stuff from a bird perspective with Pyopengl.

The "bird" camera should be able to move in X, Y a rotate around Z vector.

It works, but I would like to place the "bird" a the bottom of the screen, because the top of the screen should be in direction of movement.

However, this option is not pleasant. What I would really prefer, is to still look down (Z direction), but with some kind of offset.

In other words, it should look like I crop the lower part of screen and use only the upper part.

The problem is illustrated in the following figure:

enter image description here

(the original figure was taken from http://www.songho.ca/opengl/gl_projectionmatrix.html)

How can I achieve that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
matousc
  • 3,698
  • 10
  • 40
  • 65
  • It might help if you add some drawings or screenshots of what you are trying to visually achieve with this "bird's eye" view. This would help clarify what you mean by wanting an "offset" or "cropping" certain portions of the screen. – CodeSurgeon Apr 08 '18 at 20:12
  • @CodeSurgeon I tried to make it clearer. – matousc Apr 09 '18 at 05:34
  • Would using a function like `gluLookAt` work? That would allow you to specify the position of the camera as well as a target to look at. These functions, like `glRotate` are deprecated in OpenGL though. – CodeSurgeon Apr 09 '18 at 22:49

1 Answers1

0

Finally I find the solution. The magic trick is the following command:

glViewport (offset_X, offset_Y, screen_X, screen_Y)

where:

  • offset_X - offset of the camera in X axis
  • offset_Y - offset of the camera in Y axis
  • screen_X - screen resolution you use in X axis
  • screen_Y - screen resolution you use in Y axis

For case described in question (if the camera should be placed 25% of the screen height from the bottom of the screen):

gluPerspective(45, (screen_X / screen_Y), 0.1, 2000.0)
glViewport (0, -int(screen_Y*0.75), screen_X, int(screen_Y*1.75) )
matousc
  • 3,698
  • 10
  • 40
  • 65