Notes for Assignment 3
The following are suggestions for how to implement Assignment #3:
- Having the following variables makes it easier to implement the assignment:
- Speed a scalar of the current speed of your tank. controlled by the Y mouse pos.
- TankPosition the current position of your tank - a vector in x,y,z.
- ViewDirection the vector for the direction your tank is looking.
- ViewMatrix A useful 4x4 matrix for the current View Matrix
- Pixels the pixel values for the texture to use as the height map. An array in size of 4*image.width*image.height. Data is in R,G,B,A bytes.
- Implement a function to extract pixels from a texture.
- Modify drawScene() function to set the View matrix from a common View Matrix variable.
- Initialize key variables in the startup function of your program.
- Your mouseDown handler should adjust a speed variable based on the change in the Y position of the mouse.
- Your mouseDown handler should rotate a view direction vector based on changes in X position of the mouse.
- Implement a function getTexHeight(x,z) that returns the height of the Terrain at the specified x,z position.
- Implement a getTriNormal(x,z) that returns a normal for the given x,z coordinates.
- Implement a function getViewMatrix that generates the correct view matrix giving view position, orientation and up vector. Us the speed, view direction, and Terrain Height and triangle normal to generate this view matrix. You can use the mat4.lookAt function to generate the View Matrix.