# CSCI 420 week 02 input and interaction & transformation ###### tags: `CSCI 420` * **Input and Interaction** (setup glut) * primitives: **vertices, lines, polygons** * one strength of modern consumer GPU: vertices attributes are abstract entities(a bunch of numbers), which why machine learning could work on GPUs * CPU $\Leftrightarrow$ GPU: like client server architecture * object vertices is sent to GPU once and never modify again for efficiency * read back from GPU would choke the pipeline * display list * aspect of instancing, render things repeatly with high efficiency * don't put variable in display list * graphics hardware is optimized to do 4x4 matrix multiplication * vertex array * list all points, and triangle array indexes into vertex array * don't have to duplicate data * **vertex buffer objects(VBOS)**: modern way to move data to gpu and render, fast / flexible * **display list**: fast / inflexible * **Immediate mode**(GL_begin, GL_end): slowest / flexible * **vertex array**: slow / flexible * hidden surface removal * **object space**: depth sort (painter's algorithm) * **image space**: z-buffer algorithm(for each object), raycasting(do inverse of z-buufer, for every pixels) * z-buffer algorithm: using depth buffer, if farer, discard, otherwise, draw and update * glOrtho() for parallel viewing, glPerspective() for perspective viewing * **Tranformation** * 2 matrix stacks in opengl, modeling and viewing transformation matrix, projection matrix * **object coordinate $\to$ world coordinate $\to$ camera coordinate** * model-view matrix: move everything in front of camera * modern openGL: compute transformation matrix yourself * glLoadIdentity() create a 4x4 matrix and push on top of matrix stack, very common use * glRotate: rotate about object coordinate system, not world coordinate system * follow this sequence on openGL: **translate $\to$ rotate $\to$ scale**, or result will be mayhem * gl{Push, Pop}Matrix to save previous state(**now deprecated**) * **Linear Algebra** * use square length for comparison instead of square root for performance reason * a x b \begin{align} \begin{pmatrix} a_1\\ a_2\\ a_3\\ \end{pmatrix} \times \begin{pmatrix} b_1\\ b_2\\ b_3\\ \end{pmatrix} = \begin{pmatrix} a_2b_3-a_3b_2\\ a_3b_1-a_1b_3\\ a_1b_2-a_2b_1\\ \end{pmatrix} \end{align} * coordinate system changing: express vector u in terms of vector v: \begin{gather} u_1=\gamma_1v_1+\gamma_2v_2+\gamma_3v_3\\ u_2=\gamma_4v_1+\gamma_5v_2+\gamma_6v_3\\ u_3=\gamma_7v_1+\gamma_8v_2+\gamma_9v_3 \end{gather} \begin{align} \begin{bmatrix} a_1\\ a_2\\ a_3\\ \end{bmatrix} = M \begin{bmatrix} b_1\\ b_2\\ b_3\\ \end{bmatrix} ,\ M = \begin{bmatrix} \gamma_1&\gamma_2&\gamma_3\\ \gamma_4&\gamma_5&\gamma_6\\ \gamma_7&\gamma_8&\gamma_9\\ \end{bmatrix} \end{align} * affine transformation \begin{bmatrix} \alpha_1& \alpha_2 & \alpha_3 & 1 \end{bmatrix} * if fourth coordinate(homogeneous coordinate) is non zero, it's point, actual point is other 3 values divided by fourth value * it's 1 unless in projection * rotation in 2D (determinant is 1, and is a orthogonal matrix, because $\sin^2\theta+\cos^2\theta=1$) \begin{align} \begin{bmatrix} x^\prime\\ y^\prime\\ \end{bmatrix} = \begin{bmatrix} \cos\theta&-\sin\theta\\ \sin\theta&\cos\theta\\ \end{bmatrix} \begin{bmatrix} x\\ y\\ \end{bmatrix} \end{align}