IAT 167 Lecture Notes - Lecture 7: Arrow Keys, Atan2, Damping Ratio
Document Summary
Entity that has a magnitude and direction. Collection of values that holds position, velocity and acceleration (processing) E. g. float xpos, ypos, xspeed, yspeed, xacc, yacc. Mult(n): multiply a vector by a scalar. Div(n): divide a vector by a scalar. Mag(): calculates the magnitude (length) of the vector. Heading(): calculate the angle of the vector. Dist(v): calculate the distance between two vectors. Keycode: up, down, left right, alt, control, shift. Damping velocity: multiply velocity by dampening factor to ensure the object never gets too fast. Resolve collision by bouncing off: atan2(y-other. y, x-other. x) E. g. float avgspeed = (vel. mag() + other. vel. mag() /2); vel. x = avgspeed * cos(angle); vel. y = avgspeed * sin(angle); other. vel. x = avgspeed * cos(angle-pi); other. vel. y = avgspeed * sin(angle-pi); (distance along x) < sum (half widths) (distance along y) < sum (half lengths) Abs(x - other. x) < charwidth/2 + othercharwidth/2 && abs(pos. y - other. pos. y) < charheight/2 + other. charheight/2. Use nested-loops to compare objects against each other.