## Explanation of the Translation MethodOnce your OpenGL window is made, and you compile and open it, you're staring at a black screen. OpenGL is a 3D rendering engine, which I'm sure you know if you're trying to learn it. So where exactly are you if you're just staring into blackness, or whiteness, depending on what color you put into glClearColor. Well, imagine a grid. The grid is 20 units long, and 20 units wide. Now in reality of OpenGL, there is no limit to the space you have. But for this idea, imagine it being 20x20. Your camera is sitting in the very center of the grid, at 10 units up, 10 units in. This is the center, just like in math, and it is divided into four quadrants. Imagine you're above the grid, an aerial view, and your camera is facing south. Any objects in front of the camera, or south of the camera, have a negative Z value. Any objects behind the camera have a positive value, and the camera is sitting on 0. Now, any objects to the east of the camera, which would be left in the viewing area since you're looking south, would have a negative X value. Any objects to the right, or on the west side of the camera would have a positive X value. Any objects above the camera, would have a positive Y value, and any below would have a negative Y value. Some tips to remember: X Axis: Left (negative) and Right (positive) Here is a drawing of the aerial view. You're the blue arrow, and the direction it is pointing is the direction you would be facing if you were standing there. The camera itself is exactly on (0, 0, 0) Now that you know where things are in relation to the center point, (0,0,0) I will explain how the translation method works. First off, when you use glTranslatef, it does not mean you're moving the camera. What glTranslate does is set up a central axis, a starting point in the 3D grid where other things will be drawn. So if you set up a starting point, a central axis, at X=3, and Y=2, and Z=-5, you would be 3 units to the right, 2 units up, and 5 units away from the camera. Then, if you used any glVertex commands, they would all be based around X=3, Y=2 and Z=-5, but to them, that would be their center. So if you rotated them, they would rotate around that point. Now, if you drew a triangle at (0, 1, 0) (-1, 0, 0) and (1, 0, 0), with it being (X,Y,Z), it would really be compared to the camera at coordinates (3, 3, -5) (2, 2, -5) and (4, 2, -5). You created an axis at (3, 2, -5) and drew a triangle according to it being the (0,0,0) point. Now you could just create a triangle using the coordinates compared to the camera, but the only problem with doing this is if you tried to rotate it, it would rotate around the camera axis, not the axis you signified at (3, 2,-5). Therefore, using glTranslate is necessary if you plan to do any rotating. If you rotate around the camera axis, it would be like attaching a string from the camera to the triangle, then spinning it like that. It would rotate off and on the screen as it would go around the camera. |