1 / 63

Lecture 9

Lecture 9. Announcements. Congrats!. You are done with all the assignments in this class! From now on everything you work on is designed by you Good work so far!. Final Coding. Time to start coding for your final project Remember, you should be mostly finishing your engine this week

cael
Download Presentation

Lecture 9

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. Lecture 9 Announcements

  2. Congrats! • You are done with all the assignments in this class! • From now on everything you work on is designed by you • Good work so far!

  3. Final Coding • Time to start coding for your final project • Remember, you should be mostly finishing your engine this week • Don’t forget to set up a meeting with your mentor TA soon

  4. Announcements Questions?

  5. Lecture 9 Collision Detection III

  6. Point of Collision • We want to find out where shapes hit • In our simulation, colliding shapes are intersecting • Generally the intersection is small • So we choose a point that approximately represents where the intersection is

  7. Poly-Poly • When two polygons (AABs are polygons too!) collide, at least one vertex of one shape is inside the other • If there’s only one point, use that as the point of collision • If there’s more than one, average them!

  8. Circle-Circle • Circle-Circle is easy: • It’s on the line connecting the centers, with ratio of the radii • Remember this is in world (absolute) coordinates

  9. Circle-Poly • If vertices of the poly are within the circle, then average them • If not, then take the point along the MTV: • (Depends on MTV direction)

  10. Collision Detection III Questions?

  11. Lecture 9 Physics III

  12. Physics III Rotation

  13. Rotation • We currently have shapes that don’t rotate • First step is to be able to rotate shapes • Next step is to provide collision response for rotating entities

  14. Terminology ω • Let’s define some things: • Angle, θ (CCW) • Angular velocity, ω • Angular acceleration, α • Moment of Inertia, • Analogous to mass (inertia) for rotation θ

  15. Basics public class PhysicalEntity{ float angle, aVel, aAcc; void move(float time) { //integrate position aVel += aAcc*time; angle += aVel*time; aAcc = 0; rotate(aVel*time); } } • Your physical entities should have an angle, angular velocity, and angular acceleration • You should integrate these as before • But whenever you do this you have to physically rotate the shape

  16. Rotating Shapes • What shapes do we need to rotate? • AAB doesn’t rotate, by definition • Circles are circles • You still need angular values for the circle though, what if the hitbox is a circle? • Therefore only polygons need to rotate • Rotate polygons by rotating their vertices

  17. Centroid of Polygon • Every shape rotates around its centroid • The centroid of a polygon with vertices is: • Where • and are coordinates of vertices in CCW order

  18. Rotating Polygons • To rotate a polygon, rotate each vertex by the angle • These vectors are the vertices relative to the centroid! • Remember to update edges as well θ

  19. Inertia • We also need the moment of inertia of an object • You can define or calculate it • Circle: • Polygon:

  20. Rotation Questions?

  21. Physics III Rotational Physics

  22. Impulse and Forces • How can we cause shapes to rotate in the world? • Currently we are applying impulse/forces the centroids of entities • Apply impulse/force to object, but not at centroid

  23. Impulse and Forces • Now your impulses and forces have a magnitude and a point of application • is relative to the centroid • The magnitude is actually a vector • for impulse and for force from now on or

  24. Angular Impulse and Forces • In relation with angular velocity and acceleration: or

  25. Collision Response • We need to change the impulse we calculated in Physics II • It’s now a different value that is applied at some specific point • It’s applied to the point of collision!

  26. Some Definitions • More definitions: • , are the vectors from the centroids of the shapes to the collision point • , are the perpendiculars to , • is the normalized MTV

  27. Collision Response • Magnitude of the impulse • , are projections of velocities onto the • The impulse is in the direction of , determine the sign based on your MTV direction

  28. Fixed Rotation • Just like with static shapes, there should also be shapes that don’t rotate • Just like with the previous impulse equation, have a special case for non-rotating objects • Replace with if the entity doesn’t rotate • Note that if both objects don’t rotate, the equation reduces to the old equation

  29. Rotational Physics Questions?

  30. Physics III Friction

  31. Friction • We don’t want everything to be slippery • Friction slows things down • Give every physical entity a friction value greater than 0

  32. Frictional Force • The frictional force is parallel to the surface of contact • i.e. perpendicular to MTV • The direction is determined by the direction of the relative velocity (1D): a b a b

  33. Relative Velocity • Only velocity perpendicular to the MTV is relevant • Direction of the perpendicular () doesn’t matter • Consistency matters

  34. How Much Force? • From physics, the friction force on object A due to object B is proportional to the force exerted on object A by object B • We don’t really have that force… • But we did apply impulse to the objects!

  35. The Force • So we have • is the impulse applied in collision response • is a constant

  36. Disclaimer ω • This friction works for the case when the relative velocity is linear • With rotation, things become much more difficult • If you want to combine these, good luck!

  37. Friction Questions?

  38. Lecture 9 Networking

  39. Networking NETWORKING STRATEGIES

  40. The Illusion • All players are playing in realtime on the same machine • But of course this isn’t possible • We need to emulate this as much as possible

  41. Send the Entire World! • Players take turns modifying the game world and pass it back and forth • Works alright for turn-based games • …but usually it’s bad • RTS: there are a million units • FPS: there are a million players • Fighter: timing is crucial

  42. Send Commands • Each player sends the other all actions that alter shared game world • “Deterministic P2P Lockstep” • Problem: everything must evaluate the same • Or else there are desyncs • Problem: have to wait for all the other players’ commands • So everyone is limited by laggiest player

  43. Client-Server Model • One player is the authoritative server • Other player is a “dumb terminal” • Sends all input to server • Server updates the world and sends it back • Problem: client has to wait for server to respond to perform even basic actions

  44. Client-side Prediction • Client responds to player input immediately • When the server sends back the authoritative game state, client state is overwritten

  45. Rollback • But the server just sent a state that was 100ms in the past! • What if games have diverged since then? • For instance, both players think they’ve collected a single powerup • Client has to roll back the world and integrate commands since the last known good state

  46. Masking the Timewarp • Problem: laggy players experience this jump often • Solution: if the server usually sends states from 100ms ago, run the client 100ms behind • Turns a jumpy experience into a smooth, only slightly slow one

  47. Networking Strategies Questions?

  48. Networking IMPLEMENTATION

  49. TCP: Transmission Control Protocol • Abstracts over IP • All packets are guaranteed to be received and in the correct order • Good for sending important, permanent data (websites, databases, etc)

  50. UDP: User Datagram Protocol • A very thin shell around IP • Much faster than TCP, but no guarantees about reception or order • Good for information where only the most recent state matters (streaming, etc)

More Related