Question: In Program 9.2, add the ability to move the camera around with the mouse or keyboard. To do this, you will need to utilize the

In Program 9.2, add the ability to move the camera around with the mouse or keyboard. To do this, you will need to utilize the code you developed earlier in Exercise 4.2 for constructing a view matrix. You’ll also need to assign mouse or keyboard actions to functions that move the camera forward and backward, and functions that rotate the camera on one or more of its axes (you’ll need to write these functions too). After doing this, you should be able to “fly around” in your scene, noting that the skybox always appears to remain at the distant horizon.

Program 9.2Java/JOGL application public void init(GLAuto Drawable drawable) { GL4 gl= (GL4) GLContext.getCurrentGL(); //public void display(GLAuto Drawable drawable) { // clear color and depth buffers, projection and camera view} // set up vertices buffer for cube (buffer for texture coordinates not necessary)public int loadCubeMap(String dirName) {GL4 gl = (GL4) GLContext.getCurrentGL(); // assumes that the six fileJava/JOGL application public void init(GLAutoDrawable drawable) { GL4 gl= (GL4) GLContext.getCurrentGL(); //Byte Buffer topWrapped RGBA = ByteBuffer.wrap(topRGBA); ByteBuffer leftWrapped RGBA =gl.glBind Texture(GL_TEXTURE_CUBE_MAP, textureID); gl.gl TexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, 1024,} // to help reduce seams gl.glTexParameteri(GL_TEXTURE_CUBE_MAP, gl.g|TexParameteri(GL_TEXTURE_CUBE_MAP,void main(void) { } tc = position; // texture coordinates are simply the vertex coordinates mat4 vrot_matrix

Exercise 4.2

In Program 4.1, the “view” matrix is defined in the display() function simply as the negative of the camera location:vMat.translation(-cameraX, -cameraY, -cameraZ);

Replace this code with an implementation of the computation shown in Figure 3.13. This will allow you to position the camera by specifying a camera position and three orientation axes. You will find it necessary to store the vectors U,V,N described in Section 3.7. Then, experiment with different camera viewpoints, and observe the resulting appearance of the rendered cube.

Program 4.1Java/JOGL Application import java.nio.*; import javax.swing.*; import java.lang.Math;import static com.jogamp.opengl.GL4.*; import com.jogamp.opengl.*; import com.jogamp.opengl.awt.GLCanvas;// allocate variables used in display() function, so that they won't need to be allocated during renderingpublic void init(GLAutoDrawable drawable) { GL4 gl= (GL4) GLContext.getCurrentGL(); rendering Program =public void display(GLAuto Drawable drawable) { GL4 gl = (GL4) GLContext.getCurrentGL();} // copy perspective and MV matrices to corresponding uniform variables gl.glUniformMatrix4fv(mvLoc, 1,private void setupVertices() { GL4 gl= (GL4) GLContext.getCurrentGL(); // 36 vertices of the 12 triangles} } -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f,

Figure 3.13(XC) Yc Zc 1 point Pc in eye space = - negative of camera rotation angles x Vx -Nx 0 y Vy Vz 0 - Ny -z 0 0 0

Section 3.7

So far, the transform matrices we have seen all operate in 3D space. Ultimately, however, we will want to display our 3D space—or a portion of it—on a 2D monitor. In order to do this, we need to decide on a vantage point. Just as we see our real world through our eyes from a particular point, in a particular direction, so too must we establish a position and orientation as the window into our virtual world. This vantage point is called “view” or “eye” space, or the “synthetic camera.”view volume projection plane objects in world space eye (camera) objects outside of view

Java/JOGL application public void init(GLAutoDrawable drawable) { GL4 gl= (GL4) GLContext.getCurrentGL(); // rendering programs and shaders for the torus, and for the cubemap rendering Program = Utils.createShader Program("vertShader.glsl", "fragShader.glsl"); rendering ProgramCubeMap = Utils.createShader Program("vertCShader.glsl", "fragCShader.gisl"); setup Vertices(); brick Texture = Utils.load Texture("brick1.jpg"); // texture for the torus in the scene gl.glBind Texture(GL_TEXTURE_2D, brick Texture); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); skyboxTexture = Utils.loadCubeMap("cubeMap"); gl.glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); // folder containing the skybox textures

Step by Step Solution

3.39 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Graphics Programming Questions!