The Glulookat function of OpenGL [go]

Source: Internet
Author: User

void glulookat(gldouble Eyex, gldouble eyey, gldouble Eyez, gldouble CenterX, gldouble centery, gldouble Centerz, gldouble upx, gldouble upy, gldouble upz);The function defines a view matrix and multiplies it with the current matrix. The first set of Eyex, the Eyey,eyez camera in the world coordinates the position of the second group of Centerx,centery,centerz Camera lens aligned objects in the third group of world coordinates Upx,upy,upz Orientation of the camera upward in world coordinates you think of the camera as your own head: The first set of data is the position of the head. The second set of data is the position of the object that the eye looks at. The third group is the direction of the head (because you can look at the same object askew).
1#include"stdafx.h"2#include <GL/glut.h>3#include <stdlib.h>4 5 voidInitvoid)6 {7Glclearcolor (0.0,0.0,0.0,0.0);//Black Background8 }9 Ten voidDisplayvoid) One { A glclear (gl_color_buffer_bit); -GLCOLOR3F (1.0,1.0,1.0);//White Brush -      theGlloadidentity ();//Load Unit matrix -      -Glulookat (0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0); -Glutwireteapot (2); + glutswapbuffers (); - } +  A voidReshape (intWinth) at { -Glviewport (0,0, (Glsizei) W, (Glsizei) h); - Glmatrixmode (gl_projection); - glloadidentity (); -Gluperspective (60.0, (Glfloat) w/(glfloat) H,1.0,20.0); - Glmatrixmode (gl_modelview); in glloadidentity (); -Glulookat (0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0); to } +  - intMainintargcChar**argv) the { *Glutinit (&argc, argv); $Glutinitdisplaymode (glut_double |Glut_rgb);Panax NotoginsengGlutinitwindowsize ( -, -); -Glutinitwindowposition ( -, -); theGlutcreatewindow (argv[0]); +      A init (); the Glutdisplayfunc (display); + Glutreshapefunc (reshape); - Glutmainloop (); $     return 0; $}

First, the above display () function: Glulookat (0.0,0.0,5.0, 0.0,0.0,0.0, 0.0,1.0,0.0); The equivalent of our head position at (0.0,0.0,5.0), the eyes looking at (0.0,0.0,0.0), that is, the origin. The following three parameters (0.0,1.0,0.0), the y-axis is 1, the remaining 0, the head upward, is the normal situation. See the situation such as: spout in the right, the pot handle in the seat, the bottom of the pot under, lid on. Second, if the Glulookat three parameters are set to (0.0,-1.0,0.0), that is, the y-axis is 1, the remaining 0. This means that the head downward, that is, the human eye upside down, see the effect such as: three, again modify the Glulookat after three parameters (1.0,0.0,0.0); x axis is 1, The rest is 0. That is, the human head like the right 90 degrees, that is, clockwise turn 90 degrees (change angle of thinking is the kettle counter-clockwise to 90 degrees), guess see the result should be the spout on the top, lid in the right, the bottom of the pot in the left, the pot handle under. For example, if Glulookat () is not called, then the camera is set to the default position and orientation. by default, the camera is at the origin point, pointing to the negative direction of the z axis and the upward vector (0,1,0). You can modify the original code. Change the view transform function Glulookat () function to the model transform function Gltranslatef () and use the parameter (0.0,0.0,-5.0). The effect of this function is identical to the effect of using the Glulookat () function, because the Glulookat () function is to observe the cube by moving the camera (using an attempt to transform), while the Gltranslatef () function is moved by the teapot (using the model transform). Also note: View transformations are performed before the model transforms. Go to: http://blog.csdn.net/wangqinghao/article/details/14002077

Glulookat function of OpenGL [go]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.