![]() We could define a simple 3D projection as follows:įrustumM(projectionMatrix, 0, -aspectRatio, aspectRatio, -1, 1, 1, 100) What about 3D projections? For those, we can use frustumM:įrustumM(float m, int offset, float left, float right, float bottom, float top, float near, float far) It just provides a way to adjust our coordinate space, so that we can see more of our scene if the screen is wider, and less if the screen is narrower. We shrink the width in order to compensate for the smaller screen.Īt the heart of things, the orthographic projection matrix will still convert things to the range, since that’s what OpenGL expects. This also works when we switch to portrait mode: OrthoM(projectionMatrix, 0, -1.333, 1.333, -1, 1, -1, 1) Īlthough the screen is wider than it’s tall, we automatically adjust the coordinate space to match by mapping -(800/600) to the left side and (800/600) to the right side. Let’s say that the screen dimensions are 800×600. OrthoM(projectionMatrix, 0, -aspectRatio, aspectRatio, -1, 1, -1, 1) To define a simple matrix that adjusts things for the screen’s aspect ratio, we might call orthoM as follows:įloat aspectRatio = (float) width / (float) height ![]() OrthoM(float m, int mOffset, float left, float right, float bottom, float top, float near, float far) Let’s take a closer look at Android’s method: Android has the orthoM method other platforms will have something similar. The first thing you can do to get around this problem is to define an orthographic projection. The first problem is that they always range from -1 to +1, so if you use these coordinates directly, your image might be stretched when switching from portrait mode to landscape mode. While OpenGL wants things to be in normalized device coordinates, it’s hard to work with these directly. The underlying operating system’s window manager will then map that viewport to the appropriate place on the screen. OpenGL will then map these coordinates onto the viewport that was configured with glViewport. The bottom left corner will be at (-1, -1), and the top right corner will be at (1, 1). These coordinates range from -1 to +1 on each axis, regardless of the shape or size of the actual screen. ![]() OpenGL only requires that when all of your transformations are done, things should be in normalized device coordinates. Normalized device coordinatesĪt the heart of things, OpenGL 2.0 doesn’t really know anything about your coordinate space or about the matrices that you’re using. To better understand OpenGL’s matrices, and how and why we use them, we first need to understand the OpenGL coordinate space. This is a topic that I have been frequently confused by, myself, and I feel that it warrants further explanation. I often get questions related to OpenGL’s matrices: how do they work, how do they get built, and so forth.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |