CS 488: Lab 7 – Camera

Welcome to lab, which is a place where you and your peers complete exercises designed to help you learn the ideas discussed in the preceding lectures. It is intended to be a time where you encounter holes in your understanding and talk out loud with your peers and instructor.

Your instructor will bounce around between breakout rooms to check in with you. However, you are encouraged to request assistance if you find your progress blocked.

Designate one of your group to be the host. This individual will be responsible for setting up a Live Share session in Visual Studio Code and submitting your work. No team member should dominate or be expected to carry the group. All members should be writing code and contributing ideas.

Setup

Host, follow these steps:

  1. Open Visual Studio Code.
  2. Click File / Open Folder, create a new folder, and open it.
  3. With the Live Share extension installed, select View / Command Palette, and choose Live Share: Start Collaborative Session.
  4. Copy the invitation link to your chat.

Non-hosts, join the session.

Task

Your task in this lab is to add a camera to your library of graphics repertoire and to explore a mechanism for animation in JavaScript. Follow these steps to complete this lab:

  • Implement the Camera class in camera.js. Focus on the constructor and orient. If you finish early, come back and implement strafe, advance, yaw, and pitch.
  • Add an instance of Camera to one of your renderers. Keep the object centered at the world’s origin. Place the camera somewhere else, looking at the origin.
  • Send just two matrices to the vertex shader: clipFromEye and eyeFromModel.
  • Add a setFromTo method to the camera that can be used to reposition and redirect the camera. Have it behave similar to the constructor, computing the camera’s forward vector. Assume the world’s up vector hasn’t changed.
  • When the user clicks down on the mouse, start animating the camera around the model. You’ll need to track the camera’s current location. On every frame, apply a rotation to this location and update the camera using your setFromTo method. Follow this general pattern in your renderer to animate:
    function someEventHandler(event)
      // ...
      if (doesEventTriggerAnimation) {
        requestAnimationFrame(animateFrame);
      }
    }
    
    function animateFrame() {
      // update state
      render();
      if (isStillAnimating) {
        requestAnimationFrame(animateFrame);
      } 
    }
    
    Adjust the conditional logic so that the user can toggle the animation on and off. There are other ways to perform animations, like calling setTimeout and setInterval. Unlike these other other functions, animation requests scheduled through requestAnimationFrame will be paused when the browser is in the background or the tab is not visible.
  • Submit your camera.js on Crowdsource. Enter the eIDs for your team members. If you need to make changes after you’ve already submitted, just reload the page and resubmit. If you haven’t finished by the end of the scheduled lab time, you are free to continue working. However, the submission must be made before the end of the day to receive credit.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *