1 / 13

Overview

Overview. Today: - MAT 594CM Forums ( Ritesh ) - Problem Set #1 online, due April 15th - Need to move to lower-level coding environment - Dot product, Vector product - Calculating n ormals for lighting - 6 DOF camera - Blend modes, Depth testing

efia
Download Presentation

Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview Today: - MAT 594CM Forums (Ritesh) - Problem Set #1 online, due April 15th - Need to move to lower-level coding environment - Dot product, Vector product - Calculating normals for lighting - 6 DOF camera - Blend modes, Depth testing - Object “picking”, project/unproject methods - Simple animation

  2. Dot Product 1 The dot product lets us calculate the difference in direction between two vectors. Given two three-dimensional vectors P and Q, we calculate the dot product like so: PQ = PxQx + PyQy + PzQz Example: if P = (5, 4, 3) and Q = (2, 2, 4), PQ = (5 * 2) + (4 * 2) + (3 * 4) = 10 + 8 + 12 = 30

  3. Dot Product 2 PQ= |P||Q| cosθ or (PQ) / (|P||Q|) = cosθ Example: if P = (0, 6, 0) and Q = (0, 3, 4), PQ = (0 * 0) + (6 * 3) + (0 * 4) = 18 |P||Q| = (√02 + 62 + 02 ) * (√02 + 32 + 42 ) = √36 * √25 = 30 So, cosθ = 18/30 Solve for θ by taking the inverse cosine of both sides θ = cos-1 (.6) = .9273 radians = 53 degrees

  4. Cross Product The cross product lets us calculate a vector perpendicular to two vectors. It is used to calculate a surface normal, which is needed for lighting. It’s also needed for creating cameras with 6 DOF. PxQ= (PyQz - PzQy , PzQx- PxQz , PxQy - PyQz) Example: P = (0, 6, 0) and Q = (0, 3, 4) PxQ= (6*4 - 0*3, 0*0 - 0*4, 0*3 - 6*4) = (24, -4, -24) = V our new vector, or normal, can be normalized by dividing each component by the length of the vector: Example, |V| = √(242 + (-4)2 +(-24)2) = 34.176 so our normalized vector Vn = (24/34.176, -4/34.176, -24/34.176) = (.7022, -.117, -.7022), and |Vn| = 1

  5. Cross Product to generate normals For each face (eg, a triangle or quad) you need 3 points that are not collinear. define a vector P from point A to point B, and a second vector Q from point A to point C P = (Bx - Ax, By - Ay, Bz - Az) Q = (Cx- Ax, Cy- Ay,Cz- Az) find V = PxQ and then normalize V to get the normalized normal N. All 4 points in a quad will use the same normal, which will be specified before calling the vertex commands. glBegin(GL_QUADS) glNormal3f(Nx, Ny, Nz); glVertex3f(Ax, Ay,Az); glVertex3f(Bx, By,Bz); glVertex3f(Cx, Cy,Cz); glVertex3f(Dx,Dy,Dz); glEnd();

  6. Animation Although the frame rate of the OpenGL display loop attempts to run in sync with the refresh rate of the screen, you cannot count on this timing when animating your scene. - The OS can pause the display - Loading resources dynamically may take time - Different systems may have different refresh rates - You may be computing/drawing too much for your video card

  7. Animation A better way to do animation is to keep track of the current time and its position along a timeline defined by the start and end times of the movement. Then translate or rotate objects based on the percentage of time that has passed. May be problematic: void myDisplayLoop() { setUpCamera(); rotateObjectAroundYAxis(1f); //will be jittery & unpredictable drawObject(); }

  8. Animation Simple example: animating a 5-second translation 3 units along the Z axis void myInit(){ //normal stuff... //define animation long startTime = now(); long endTime = startTime + 5000ms; float distZ = 3f; } void myDisplayLoop() { //normal stuff... //handle animation current = now(); glTranslatef(0f, 0f, (current - start)/(end - start)*distZ); drawCoolShape(); }

  9. Animation Can also add “easing” interpolation functions to control the smoothness of the animation. The above psuedocode defined two “keyframes” and two different points in time, and did a linear interpolation between them to map the current to time to a current position along the z-axis. Easing functions provide a simple way to effect the interpolation between two points. Ex. float easedPerc = sin(origPerc * PI/2);

  10. gluPerspectivepseudocode gluPerspective(fovy, aspect,zNear,zFar) { ymax = zNear * tan(fovy * PI / 360.0); ymin = -ymax; xmin = ymin * aspect; xmax = ymax * aspect; glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); }

  11. glFrustumpseudocode glFrustum(xmin, xmax, ymin, ymax, zNear, zFar) { top = near_dist * tanf(fov * 0.5f); right = top * aspect; bottom = -top; left = -right; two_near_dist= 2.0f * near_dist; right_minus_left= right - left; top_minus_bottom= top - bottom; far_minus_near= far_dist - near_dist; m00 = two_near_dist / right_minus_left; m02 = (right + left) / right_minus_left; m11 = two_near_dist / top_minus_bottom; m12 = (top + bottom) / top_minus_bottom; m22 = -(far_dist + near_dist) / far_minus_near; m23 = -(2.0f * far_dist * near_dist) / far_minus_near; m32 = -1.0f; Projection.row0 =(m00, 0.0f, m02, 0.0f); Projection.row1 =(0.0f, m11, m12, 0.0f); Projection.row2 =(0.0f, 0.0f, m22, m23); Projection.row3 =(0.0f, 0.0f, m32, 0.0f); }

  12. Projection Matrix 3 The Projection Matrix encoding the perspective transform looks likes this: ( 2n / (r – l) , 0 , -(r + l) / (r - l), 0 ) ( 0 2n / ( t - b) , (t + b) / (t - b) , 0 ) ( 0 0 , (f + n) / (f - n) , - (2fn) / ( f - n) ) ( 0 0 , 1, 0 ) Where n and f are the near and far planes, t and b are defined by the fovy And l and r are further defined by the aspect ratio

More Related