Presentation is loading. Please wait.

Presentation is loading. Please wait.

MP2 QUATERNION BASED CAMERA FOR FLIGHT SIM. Quaternions!  You need to have a good understanding of what they are, and a good grasp of how they work.

Similar presentations


Presentation on theme: "MP2 QUATERNION BASED CAMERA FOR FLIGHT SIM. Quaternions!  You need to have a good understanding of what they are, and a good grasp of how they work."— Presentation transcript:

1 MP2 QUATERNION BASED CAMERA FOR FLIGHT SIM

2 Quaternions!  You need to have a good understanding of what they are, and a good grasp of how they work.  Good places to start:  https://en.wikibooks.org/wiki/Guide_to_Game_Development/Theory/M athematics/Quaternions https://en.wikibooks.org/wiki/Guide_to_Game_Development/Theory/M athematics/Quaternions  https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

3 Making a non-rotating camera first.  You want mat4.perspective and mat4.lookAt.  mat4.perspective(out, fovy, aspect, near, far)  Out is the resultant matrix.  Fovy is the Vertical field of view in radians  Aspect ratio. typically viewport width/height  Near bound of the frustum  Far bound of the frustum  You may have already seen all this in class. This function will only need to be called once. You can pass the resultant matrix to the shaders without needing to update it at all.

4 Using Mat4.lookAt  This is the function that you will have to call with the right parameters. Eye, Center, Up are the arguments.  Eye – is the position of the viewer.  In the case of a non-moving camera, this will be constant.  In the case of a moving camera, this will change.  When the camera is moving, you have to ask yourself where the next eye position will be.  Hint: Imagine a plane flying. Where is the cockpit?

5 Using Mat4.lookAt  Center – the point the viewer is looking at.  You know a plane can rotate along any of the 3 axes. When does the point change?  Hint for implementation:  Does it really have to be that exact point in the distance?  What could you do to ensure that you always get a point such that you are looking the same way?

6 Using Mat4.lookAt  Up Vector!  Up Vector is local to the camera. Not the same as the Global Up Vector!  So, it changes as the flight rotates.  For instance, imagine you are changing the nose of the airplane to point more upwards. Is upwards always the same with respect to the Global and Local vectors?

7 Where to start?  Imagine how a plane starts on the runway. What are its axes?  Allow your flight-sim to always start with the same axes. Then, you know the initial values.  (Think about how the default OpenGL camera works. What are its axes?)

8 One way of doing it..  Assume the plane starts in with 0 rotation.  Keep one quaternion that represents the entire rotation so far.  Every time there is a new rotation, we can take it into account by changing that quaternion.  Then, at every frame, we apply this rotation to the initial state.  Then we make the lookAt matrix.  You could come up with another way if you want.

9 Tutorial:  http://content.gpwiki.org/OpenGL:Tutorials:Using_Quaternions_to_re present_rotation http://content.gpwiki.org/OpenGL:Tutorials:Using_Quaternions_to_re present_rotation

10 Passing the Matrices in.  The matrices generated from the glmatrix functions can be directly passed in by:  var projMatrixUniform = gl.getUniformLocation(ShaderProgram, "projectionMatrix"); //  gl.uniformMatrix4fv(projMatrixUniform, false, projectionMatrix); //  You want to use something like this to pass in your matrices to the shader pipeline.

11 Generating Terrain  You need to have something to fly over  Terrain can be implemented as a height map  result will only be semi-realistic, but good enough for now  Cover a rectangular area with triangles  Have x and z arranged in a grid pattern  Generate a y coordinate  Compute averaged per-vertex normals  You can use the diamond-square algorithm to generate a fractal terrain  https://en.wikipedia.org/wiki/Diamond-square_algorithm


Download ppt "MP2 QUATERNION BASED CAMERA FOR FLIGHT SIM. Quaternions!  You need to have a good understanding of what they are, and a good grasp of how they work."

Similar presentations


Ads by Google