L ECTURE 5 Announcements. Tou II Feedback handins look varied and fun! write a Range or Interval class – makes math code easier to write read modify –

Slides:



Advertisements
Similar presentations
AP Physics C Mechanics Review.
Advertisements

2.5. B ASIC P RIMITIVE I NTERSECTION Details of common forms of primitive intersection test.
Rigid Body Dynamics Jim Van Verth
Object Oriented Programming
MOMENTUM AND COLLISIONS
Torque, Equilibrium, and Stability
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
C12, Polymorphism “many forms” (greek: poly = many, morphos = form)
L ECTURE 4 Announcements. Notes About Retries the TAs when you want a retry graded – Otherwise it will not be graded until after next assignment.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Inheritance and Polymorphism.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
Physics 218, Lecture XVII1 Physics 218 Lecture 17 Dr. David Toback.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
Collisions & Center of Mass Lecturer: Professor Stephen T. Thornton
Inheritance Part II. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
L ECTURE 5 Announcements. Notes About Retries the TAs when you want a retry graded – Will try to grade it before the next due date, but no guarantees.
Lecture 8 Applications of Newton’s Laws (Chapter 6)
L ECTURE 6 Announcements. Tou II Feedback handins look varied and fun! Write a Range or Interval class – makes math code easier to read write modify –
Computer graphics & visualization Collision Detection – Narrow Phase.
12/4/2001CS 638, Fall 2001 Today Using separating planes/axes for collision testing Collision detection packages.
Vectors 1D kinematics 2D kinematics Newton’s laws of motion
Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Internet Software Development Classes and Inheritance Paul J Krause.
Week 13 - Friday.  What did we talk about last time?  Ray/sphere intersection  Ray/box intersection  Slabs method  Line segment/box overlap test.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,
Problem of the Day  Why are manhole covers round?
Best Practices. Contents Bad Practices Good Practices.
Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003.
L ECTURE 6 Announcements. Next week will be great! Three major things are happening next week: – Zynga guest lecture – Your game pitches (more details.
Introduction to Particle Simulations Daniel Playne.
Chipmunk Physics Remember that we talked about this a bit when we did collision handlers for the space ship integration task (SpritesActionsPhysicsSound).
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
Chapter 7: Rotational Motion and the Law of Gravity Angular Speed & Acceleration  A unit of angular measure: radian y x P r  s = r  where s,r in m,
Linear Momentum. Units of Momentum Momentum and Its Relation to Force Conservation of Momentum Collisions and Impulse Conservation of Energy and Momentum.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
CS274 Spring 01 Lecture 7 Copyright © Mark Meyer Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
1 Sage Demo 4 Collisions SAGE Lecture Notes Ian Parberry University of North Texas.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
Lecture 12 Implementation Issues with Polymorphism.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Problem of the Day  Why are manhole covers round?
Tou II Feedback Handins look varied and fun! Write a Range or Interval class – Makes math code easier to: read write modify – Makes M I easier to build.
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Lecture 3 Announcements.
Chapter 7 Linear Momentum.
Lecture 2 Announcements.
Generic programming in Java
Physics 218 Lecture 15 Dr. David Toback Physics 218, Lecture XV.
Lecture 3 Announcements.
Lecture 5 Announcements.
Polymorphism Polymorphism - Greek for “many forms”
Computer Animation Algorithms and Techniques
Chapter 14 Abstract Classes and Interfaces
Java Programming Language
Lecture 13: Subtyping Rules Killer Bear Climber
3.3: Rectangle Collisions
GPAT – Chapter 7 Physics.
Separating Axis Theorem (SAT)
Presentation transcript:

L ECTURE 5 Announcements

Tou II Feedback handins look varied and fun! write a Range or Interval class – makes math code easier to write read modify – makes M I easier to build on top of Tou

Limbo playthrough Saturday 8pm, CIT 506 hosted by BGD

Zynga Guest Lecture October 24th

QUESTIONS? Announcements

L ECTURE 5 Physics I

INTEGRATION Physics I

Velocity

Acceleration

Which order to update? Position first (Euler) pos = pos + vel*time vel = vel + acc*time Velocity first (“Symplectic Euler”) vel = vel + acc*time pos = pos + vel*time

Which order to update? Position first (Euler) pos = pos + vel*time vel = vel + acc*time Velocity first (“Symplectic Euler”) vel = vel + acc*time pos = pos + vel*time stabler than Euler; use this

COLLISION RESPONSE Physics I

Collision response you know how to detect whether 2 objects collide how do we make objects respond in a physically believable way? general strategy: 1.move objects out of collision 2.change their velocities

Moving out of collision many ways to move the ball out of the wall we want the minimum “minimum translation vector” (MTV) same as overlap for now, assume we can find MTV

Changing velocity for collision

2-moving-object collisions reverse both velocities? doesn’t always work apply equal and opposite forces an instantaneous force is called an impulse

Units without mass with mass

Implementing force and impulse applyForce(…) accumulates force applyImpulse(…) accumulates impulse onTick(…) applies force and impulse, clearing them for next frame applyForce(…) and applyImpulse(…) only take effect on next onTick(…) “static” (immovable) objects can override applyForce (…) and applyImpulse (…) and make them noops class Entity { float mass; Vec2f pos, vel; Vec2f impulse, force; void applyForce(Vec2f f) { force += f; } void applyImpulse(Vec2f p) { impulse += p; } void onTick(float t) { vel += t*force/m + impulse/m; pos += t*vel; force = impulse = 0; } }

Impulse collision response translate objects out of collision – each by MTV/2 – or proportional to velocity in direction of MTV apply some impulse proportional to MTV to each object – how much? – this week: guess/hack – next week: more realistic

Collision callbacks pass in other Entity separate CollisionInfo object pass in the MTV maybe pass in which shapes collided – enemies with weak points maybe allow callback to prevent solid collision response – one-way platforms class Entity { boolean onCollide(Collision); } class Collision { final Entity other; final Vec2f mtv; final Shape thisShape; final Shape otherShape; } void onCollide(Entity); void onCollide(Collision);

MINIMUM TRANSLATION VECTOR Physics I

MTV in one dimension in 1D, convex shapes are line segments (intervals) these have a 1D MTV – similar to overlap – but it has a sign write a method that computes this use it to find shapes’ MTV

Computing MTV 1.for each (normalized!) axis, find 1D MTV of shapes’ projections 2.find the axis giving minimum 1D MTV 3.2D MTV is 1D MTV times that (normalized) axis

MTV interactive demo same as last week arrows are potential MTVs for box against triangle purple arrows are the actual MTV SAT guarantees that MTV is on a separating axis

Computing intervals’ MTV Float intervalMTV(Interval a, Interval b) Float aRight = b.max - a.min Float aLeft = a.max - b.min if aLeft < 0 || aRight < 0 return null if aRight < aLeft return aRight else return -aLeft

Computing polygons’ MTV Vec shapeMTV(Shape a, Shape b) Float minMagnitude = +infinity Vec mtv = null for Vec axis in allAxes Float mtv1d = intervalMTV(a.proj(axis), b.proj(axis)) if mtv1d is null return null if abs(mtv1d) < minMagnitude minMagnitude = abs(mtv1d) mtv = axis.smult(mtv1d) return mtv

Computing circles’ MTV Circle vs Circle – compare dist(center1, center2) and sum of radii – MTV is parallel to line connecting centers Circle vs Poly – use the same set of axes you did last week: Poly’s edge normals vector from circle center to closest vertex

Computing circles’ MTV (ctd) Circle vs Box – if Box contains circle center use Box’s axes – otherwise clamp circle center to Box compare dist(center, clampedPoint) and radius MTV is parallel to line connecting

Computing boxes’ MTV easy but inefficient way: – Box converts itself to a Poly efficient way: – use (0, 1) and (1, 0) as the only 2 axes

MTV pitfalls be careful with signs and argument order – especially when reversing args for double dispatch can use asserts: – MTV of shape A to move it out of shape B should point from B to A – assert dot(MTV, A.center – B.center) > 0

QUESTIONS? Physics I

L ECTURE 5 Tips for M I

Gravity on each tick, for each entity e, e.applyForce(g.smult(e.mass)) static objects’ applyForce does nothing

Player motion set velocity while left or right is held? – too sudden – can interact badly with other physics apply force while left or right is held? – asteroids!

Goal velocity

QUESTIONS? Tips for M I

JAVA TIP OF THE WEEK Annotations

Pitfalls of inheritance Entity onTick(long) PhysicsEntity onTick(long) Player onTick(long) Enemy onTick(long) Bullet onTick(long) what if you change name? change arg types? might forget to change a subclass subclass’ method no longer overrides anything! how to avoid? onTick(float)

annotation whenever you override a method, mark if superclass changes, you get a compile error Eclipse can insert these for you public class Entity { public void onTick(float t) { //... } public class Bullet extends PhysicsEntity public void onTick(long t) { //... } Bullet.java:2: method does not override or implement a method from a supertype

Other standard annotations annotations can mark – classes – methods – fields – variables – parameters can create your own… – see Oracle’s tutorial if you’re – alternative to removing a method entirely – compile warning when marked method is – tells the compiler not to catch you when you fall – avoid if at all possible

QUESTIONS? Annotations

T OU 2 PLAYTESTING ! Hooray!