How to make sure that the object does not go out of the visible range opengl-> c

Suppose you have a polygon in the center of the screen (let’s say a square, given the 2D world), and you have a function to redraw this polygon from a central point. Each time you press up, down, left or right on the keyboard, the form will be redrawn taking into account the keystroke (the y-coordinates will be updated up or down, and the coordinates will be updated on the left and right). Given that you have: glutInitWindowSize (400400); glutInitWindowPosition (400200);

and I use glMatrixMode (GL_MODELVIEW), how can I prevent the form from exiting the camera view?

PS: So far, I can only prevent, so as not to leave the left and lower levels, I check when updating coords when redrawing, if y or x are negative (if they are, the form will be redrawn in the same position), but I do not I can get a way to do the same with the right and top edges of the window.

+3
source share
3 answers

It seems that you need to either set the far clipping plane of the camera to a greater distance, or make sure that your object does not go beyond the properties of the far clip of the camera.

+3
source

After reading your comments on another answer, I thought. I'm not sure if this will be convenient, but may be useful.

, , , , , , , . , ( ).

, , , . , , , , ( , ). , . (, )

, , , , , . , , , , , 1/2, . , , , . , (1/2 ) . 1/2, , , , , .

, - openGL, , , , .

, , , .

+3

it sounds like you need to track the width and height of a graphic, and then use some subtraction to calculate the maximum x and y positions that will be allowed.

Is this a btw school assignment?

+1
source

Source: https://habr.com/ru/post/1783767/


All Articles