//****************************************************************************// //************** Viewing Transformation - January 25th, 2019 ****************// //**************************************************************************// - Okay, people have some questions about project 1A, which is due tonight: - "After I do a rotation, one of my coordinates is 8.97*10^-9?" - that's close enough to 0 for me! - (...everything else is pretty straightforward) - "Most common matrix multiplication error I've seen is accidentally altering one of the matrices as you multiply - you want to COPY the values, otherwise you'll end up affecting your results" ---------------------------------------------------------------------- - Alright, remember how we did some arbitrary rotation stuff on Wednesday? Where we rotated the coordinates, rotated the stuff, then rotated the camera back? That'll be important for doing our viewing transformations - Now, Processing (for the viewing transformation function, called "camera()") will ask us for 9 numbers: - 3 specifying the camera position - 3 specifying the point we're looking at (?) - 3 specifying the "up" vector - OpenGL does basically the same thing, but with a different function (called "glnLookUp") - Most of what we'll talk about today will assume the perspective projection, since we're specifying the EXACT location of our camera - "Parallel projection is a bit more loose, since we have a viewing box instead of any specific point" - In Processing, if we were to invoke the command: camera(0,0,8, 0,0,0, 0,1,0) - This means the camera will be positioned at (0,0,8), should look at the point (0,0,0), all with the up direction being straight-up in the Y direction - In this case, all it does is move the camera to the origin for us (?) - This command does the EXACT SAME THING as: translate(0,0,-8) - However, if we had a camera initially at the origin and pointed down the -Z direction, then camera(0,0,0, 1,0,0, 0,1,0) - Is equivalent to just saying: rotate(90, 0,1,0) // rotate on the y-axis - Mathematically, how does this work, though? - Well, let's say we know 3 vectors: - The position of our eye/camera "e" - The "gaze direction" of our camera "g" - The up vector for our camera, "t" - We want to pick up our camera, set it down at the origin, and then point it so it's facing the -Z direction (but everything else is shifted, so that's okay) - To do this, we need to do a translation, and THEN a rotation: Mview = R*T - The translation to the origin is pretty straightforward: T = Translate(-ex, -ey, -ez) - ...but the rotation is a little more complicated: w = -g/|g| - this is the opposite of our view direction u = (t x w)/|t x w| - this is pointing to the LEFT of our eye v = w x u - this is pointing to the right - These vertices leave us with 3 perpendicular UNIT vectors, so we now have a basis we can use to rotate, using our arbitrary rotation trick from last time! - This leads to a final rotation matrix of: R = [ux uy uz 0] [vx vy vz 0] [wx wy wz 0] [0 0 0 1] R*g = [0, 0, -1, 1] - yup, it's now pointing to -Z! - "...okay, that might not be the clearest explanation I've given, but here're the important things this camera transformation is actually doing that you should remember:" 1) It's moving a virtual camera position from SOMEWHERE in 3D space to the origin 2) It's rotating the camera's gaze direction to be parallel to the -Z axis - ...Okay, so now, somewhere in the middle of his many buried notes, Professor Turk is going to tell us about output devices - Specifically, we're going to talk about LCD screens and E-Ink (at a VERY high level) - First up, though, how does the CPU deal with output devices? - Well, if you stretch your minds back to CS 2200, the CPU is putting stuff onto the output bus, which then stores the image we're putting on the screen into the FRAME BUFFER - This buffer usually has several megabytes of memory, which used to be absolutely GINORMOUS by 1970s standards but is considered pretty trivial today - This buffer then sends the stored image to the "video controller," which then sends it out to whatever monitor is connected - "In graphics, we do something known as DOUBLE-BUFFERING: one buffer holds the image currently being displayed, while the other holds the next image that's ready-to-go" - Why can't we get away with just using 1 piece of memory? Well, imagine the screen is currently drawing your beautiful image. Suddenly, while it's 1/3 of the way through, you start overwriting that with a new image, and the screen starts drawing your NEW image the rest of the way! You've torn the image in two! - For that reason, this is called IMAGE TEARING - Occasionally, it can also result in a partially blank screen, if the buffer is flushed before you write to it - So, what actually happens in double buffering is that the frame buffer holds whatever's the latest and greatest image from the CPU, and the video controller will load that image AFTER it's done drawing the current one - "I'm going to put on my special glasses now, because we're talking about Liquid Crystal Displays" *Professor Turk puts on cardboard glasses, looks only slightly insane* - What're liquid crystals? They're these wonderful molecules that chemists came up with some decades ago that change their conformation in response to pressure, temperature, electric fields, etc. - Liquid crystal DISPLAYS use a specific type of liquid crystal that twists and untwists in response to voltage being put through them - In the monitor, a polarizing filter twists all the light so it's pointed in the exact same direction - If no voltage is being put through them, the crystals don't turn, and allow light to go through them - If there IS voltage applied, the crystals turn, blocking the polarized light for that pixel! - "...okay, let me explain the glasses now" - The glasses have 2 polarized lenses in them: 1 that's turned 90 degrees, and another turned the opposite way - Up front, if he holds them up to an LCD screen, 1 of the lenses is black (no light gets through), and the other is clear! If he rotates them, that reverses! - "These glasses were the old way of doing 3D films, where one eye would see the left image and the other would see the right. Nowadays, they use something called circular polarization, which is much weirder" - And with that, the day is done! You are free!...until Monday!