One of the most important things in this section is to allow the field of view to pan + rotate + zoom (like a CS game to observe objects in the first person view, if possible w,s,a,d four keys to control the movement of the characters, as well as the mouse control perspective), the most important concept in this section is to set the viewing angle of view (GL. LookAt function, this function a total of nine parameters, we can be divided into three groups, the first set of XYZ represents the position of the eye, the second set of XYZ represents the object's XYZ, the third group represents the direction of the eye, Normal (0,1,0), if not the eyes but with the camera analogy, the camera normal installation, can also pour 180 degrees of installation placement, the corresponding parameter is (0,-1,0), can also be placed diagonally, in short, three parameters can describe the camera placement method)
?
Before testing these nine parameters, we still have to do some initialization work (in the Openglinitialized method to do more typical) there is a function perspective, there is a function Matricxmode, the first copy, The meaning is roughly set to the first person observation mode
?
When the program is loaded, to set the initial nine parameter values (in order to compare the test results, we just let the eye Z has a value, the others remain 1, except up_y is 1, the last three parameters are generally set to 0,1,0)
?
Just modify the three values of the eye, at the same time the position of the eye with a small ball drawn out, the observation point is also used to draw the small ball (the current observation point is unchanged, maintain 0), feel (your people in the pan, no turn, bow, head, note just position in the pan, your eyes always stare at the green ball)
?
To do a simple test, what if we let Vieweyex and viewobjectx move at the same time? It can be found that panning motion is really achievable (just as you're panning the view)
?
If Y is checked, move the motion in another direction
?
Z Participate in the effect is scaling (you can imagine the green ball at the beginning of the z=0 position of the canvas, and the bottom plane is also z=0 position, you put the eye and angle of view of the coordinates of the forward push, the green ball ran to the bottom plane behind, so see, and your eyes are still moving forward, So see the bottom plane getting bigger, feel in the scale), of course, if you do not let Z participate, just move eye_z, also can achieve scaling, and zoom effect is more obvious, because the point of observation is not changed, people are moving forward, like you would have a line of words on the wall can not see clearly, You go up to see (and tick Z participation in the effect more like a line of words on the wall, you go forward to see, this line of words also back, you just see the wall is getting closer), specifically whether to check the z parameter to set the scale after the introduction.
?
Think again about a question, if we never modify the nine parameters of LookAt, just add a translation + a rotating variable before the actual drawing, what happens? (Your eyes and observation points remain the same, but in fact the start point of the drawing is changing every time), you need to define a very important concept before this. OpenGL if the Pushmatrix and Popmatrix wrapped up is not to affect the outside (for example, I did not draw before the translation with this package, it will affect all the painting behind, but I draw the bottom plane, the ball and other things, just use this package up, The part I wrap, no matter how I pan + rotate, is equal to the position and posture of the brush without changing it externally.
?
Can prove to be able to translate, zoom, rotate, note in fact the essence is the same (you want to see a bigger effect, either you come closer to see, or you move the canvas closer to see, you have to look at the canvas to flip, either you walk around the canvas, or you put the canvas around him in the middle of a circle, etc.). Note Do not modify the value of the up_x,up_y,up_z, the general camera installation position is fixed, the parameters should be fixed, you changed the three parameters, then the previous argument is not established (for example, I gave a up_x is not zero value, I test trans_ x when it is not the standard X-direction translation), actually changed after the camera exactly what kind of effect is not good to say (the more awesome software Maya,3dmax will give a picture of the camera, tell you that the current camera is so installed, we do not do particularly complex applications, will not be used to adjust the camera parameters of the problem)
?
Undoubtedly, the center of our drawing is the center point of the coordinate system of the translation and rotation (front and back, left and right, around the z-axis, and can see the majority of the view we need is sufficient, this method is more simple than the previous analysis of nine parameters)
?
In the reference code of the attachment there is a camerarove example program, he summed up a similar to CS first-person perspective, but the implementation is not complete, interested readers can own in-depth study of the principle of implementation, I can only understand a part (I have his nine parameters are collected in a text box, In fact, when the view is modified only m_viewx and M_viewz are moving, how to move the feeling is very complex.
?
?
For more instructional videos and downloads, please pay attention to the following information:
My Youku Space:
Http://i.youku.com/acetaohai123
?
My online forum:
http://csrobot.gz01.bdysite.com/
?
Problem Exchange:
qq:910358960
Email:[email protected]
?
?
C # application Video Tutorial 2.3 OpenGL Virtual Simulation Introduction