Let’s Bounce! or Physics of Collisions Part 1 Games Fundamentals © by Jarek Francik Kingston University, London 2007 - 2013.

Slides:



Advertisements
Similar presentations
Impulse Momentum, and Collisions
Advertisements

Linear Impulse − Momentum
L-8 (M-7) I. Collisions II. Work and Energy Momentum: an object of mass m, moving with velocity v has a momentum p = m v. Momentum is an important and.
1Notes  Reference  Witkin and Baraff, “Physically Based Modelling” course, SIGGRAPH 2001  Link on the course website.
PHYS16 – Lecture 14 Momentum and Collisions October 8, 2010.
AP Physics Impulse and Momentum. Which do you think has more momentum?
Newton’s Third Law of Motion
Copyright © by Holt, Rinehart and Winston. All rights reserved. ResourcesChapter menu Momentum and Collisions Chapter 6 Table of Contents Section 1 Momentum.
Chapter 6 Momentum and Collisions. Chapter Objectives Define linear momentum Compare the momentum of different objects Describe impulse Conservation of.
Chapter 6 Preview Objectives Linear Momentum
Momentum and Impulse Vectorman productions present: A Nick enterprise: this product is intended for the serious physics student, if you are not a serious.
L-8 (M-7) I. Collisions II. Work and Energy
Introduction to Collisions Unit 5, Presentation 2.
Momentum and Its Conservation
Collisions.
REVISION MOMENTUM. the product of an object's mass and its velocity a vector quantity with the same direction as the velocity of the object. MOMENTUM.
Momentum and Collisions
1.To understand what momentum is 2.To understand conservation of momentum and to be able to complete related calculations 3.To understand different types.
THINGS YOU WANTED TO KNOW, BUT WERE AFRAID TO ASK. IMPULSE AND MOMENTUM.
IB Physics 12 Mr. Jean September 11 th, The plan: Video clip of the day Momentum Ballistic Pendulums Bouncing collisions.
Chapter 8 Impulse and Momentum THE LINEAR MOMENTUM  Momentum = mass times velocity  “Think of it as inertia in motion” Units - kg m/s or sl ft/s.
Momentum Momentum is inertia in motion Momentum is inertia in motion What is Inertia? What is Inertia? …think Newton’s 1 st Law …think Newton’s 1 st Law.
© Houghton Mifflin Harcourt Publishing Company The student is expected to: Chapter 6 Section 1 Momentum and Impulse TEKS 6C calculate the mechanical energy.
Preview Objectives Linear Momentum Chapter 6 Section 1 Momentum and Impulse.
Physics 11 Advanced Mr. Jean May 8th, The plan: Video clip of the day Review of yesterday Perfectly Elastic Bouncing Balls Not perfectly Elastic.
Calculations in Physics and Game Engines Games Fundamentals © by Jarek Francik Kingston University, London
Momentum.
Momentum.
Momentum.
Recoil and Collisions 8.01 W07D1
Momentum (p) equals mass (m) times velocity (v). p=mv * The symbol for “p” came from the word progress which is defined as “the quantity of motion with.
Chapter 6 Momentum and Collisions. 6.1 Momentum and Impulse Linear Momentum After a bowling ball strikes the pins, its speed and direction change. So.
Unit 2 Momentum and Impulse An Introduction to Momentum.
Impulse, Momentum and Collisions. momentum = mass x velocity p = mv units: kgm/s or Ns.
Chapter 7 Linear Momentum. Objectives: Students will be able to: Explain that a conserved quantity is a quantity that remains numerically constant. Define.
Physics Section 6.3 Apply the physics of collisions Inelastic collision – two objects stick together after colliding. The two objects become one object.
Physics 1D03 - Lecture 26 Collisions Conservation of Momentum Elastic and inelastic collisions.
Momentum and Collisions. Conservation of Momentum.
Topic 2.2 Extended E – Elastic and inelastic collisions.
Conservation of Momentum Physics Chapter 6 Section 2 (Pages )
CHAPTER 9 Momentum. Momentum is a vector quantity defined as the product of an objects mass and velocity Momentum describes an object’s motion Symbol.
6-3: Elastic and Inelastic Collisions Objectives: Identify different types of collisions Determine the decrease in kinetic energy during perfectly inelastic.
Momentum and Its Conservation Review. Momentum is a ___ quantity scalar 2.vector
© Houghton Mifflin Harcourt Publishing Company Preview Objectives Linear Momentum Chapter 6 Section 1 Momentum and Impulse.
DO NOW CLEAN UP EVERYBODY EVERYWHERE CLEAN UP EVERYBODY DO YOUR SHARE.
Conservation of Momentum Elastic & Inelastic Collisions.
Impulse & Momentum Physics 11. Momentum  The product of a particle’s mass and velocity is called the momentum of the particle:  Momentum is a vector,
Sect. 9.2: Impulse & Momentum
Chapter-7 Momentum and Impulse 1Momentum 2Impulse 3 Conservation of Momentum 4 Recoil 5 Elastic and Inelastic Collisions 6 Collisions at an Angle: An Automobile.
PHY 101: Lecture The Impulse-Momentum Theorem 7.2 The Principle of Conservation of Linear Momentum 7.3 Collision in One Dimension 7.4 Collisions.
Chapter 9:Linear Momentum
Elastic and Inelastic Collisions
UNIT 7 MOMENTUM & COLLISIONS. MOMENTUM The linear momentum of an object of mass m moving with a velocity v is defined as the product of the mass and the.
Chapter 6 Momentum. Linear Momentum Momentum = p Momentum = mass x velocity p = mv Units are kilogram-meters per second (kg·m/s)
Chapter 6 Preview Objectives Linear Momentum
a) More on Elastic Collisions
Collisions: Elastic & Inelastic
Conservation of Momentum
Car Crash Video
THIS IS JEOPARDY.
Things you wanted to know, but were afraid to ask.
Center of Mass & Linear Momentum
Collisions.
Momentum Conservation: Review
Linear Momentum.
Unit 7 &.
Momentum Ch. 6.
Chapter 6 Momentum and Collisions
Warm-up Checking HW (Conservation of Momentum Practice)
Presentation transcript:

Let’s Bounce! or Physics of Collisions Part 1 Games Fundamentals © by Jarek Francik Kingston University, London

What’s on the Agenda? Collisions: Elastic vs. Inelastic Essential Physics: Momentum, Impulse, Kinematic Energy, Conservation Rules Perfectly Inelastic Collision Elastic Collisions –Collision with a Stationary Object –Collision between Bills Coefficient of Restitution Implementation Remarks

Elastic vs. Inelastic Collisions Physicists classify collisions as: –perfectly inelastic: –perfectly elastic:

Elastic vs. Inelastic Collisions Real collisions are neither perfectly elastic nor inelastic: they are somewhere in-between Marbles, bills and many other hard objects may be quite well simulated as perfectly elastic collisions

Elastic Collisions Equal mass marbles exchange their velocities: v‘ A = v B v’ B = v A

Elastic Collisions Maths behind the marbles of different mass is a bit more complex

Elastic Collisions But hitting a stationary obstacle, again, is very simple: v’ = -v

Essential Physics

Momentum, Impulse, Energy Momentum m – mass v – velocity Impulse Kinematic Energy

2 nd Newton’s Law Two equivalent formulas: F = am F =  p / t = J / t J = Ft this is how it is widely known today this is what Isaac Newton originally wrote

Conservation of Momentum F1 = -F2(3rd Newton’s law)  p 1 / t =  p 2 / t  p 1 =  p 2

Conservation of Energy In an Isolated System ENERGY is constant but may be converted, for example into heat Only perfectly elastic collisions conserve the Kinematic Energy. In all real collisions part of Kinematic Energy is lost as colliding objects become hot.

Physics of Perfectly Inelastic Collision

Perfectly Inelastic Collision before the collision: applying momentum conservation: after the collision:

Physics of Perfectly Elastic Collision

Perfectly Elastic Collision

applying momentum conservation: after the collision: before the collision:

Elastic collision Two unknown velocities Momentum equation is not enough, we need something more! Definition: Elastic colision is a colision in which the kinematic energy is conserved

Elastic collision

Elastic collision of equal masses source:

Elastic Collisions collision with a stationary object: marbles bouncing from the walls bills bouncing from each other : billiard (or snooker) game

Collision with a Stationary Object

x’ v y’ v v’  Collision with a Stationary Object xvxv yvyv v    vv’

Collision with a Stationary Object x’ v y’ v v’  xvxv yvyv v    NOTICE: CHANGE OF SYMBOLS

Collision with a Stationary Object v’  v’ || v’  vv v || v    xvxv x’ v yvyv y’ v n c n: normal vector c: collision vector

n c Collision with a Stationary Object v’  v’ || v’  vv v || v    xvxv x’ v yvyv y’ v n: normal vector c: collision vector

Collision with a Stationary Object v’  v’ || v’  vv v    xvxv x’ v yvyv y’ v n v || c

Collision with a Stationary Object

double xv = ball.GetXVelocity(); double yv = ball.GetYVelocity(); double xn = sin(DEG2RAD(obj.GetRotation())); double yn = cos(DEG2RAD(obj.GetRotation())); double xc = -yn; double yc = xn; double vdotn = xv * xn + yv * yn; double vdotc = xv * xc + yv * yc; ball.SetVelocity(xc * vdotc - xn * vdotn, yc * vdotc - yn * vdotn);

Physics of the Billiard/Snooker Game

Billiard Game t v c n vv v ||

Billiard Game // distance vector (t) and radius double xt = ball2.GetPrecX() - ball1.GetPrecX(); double yt = ball2.GetPrecY() - ball1.GetPrecY(); double R = ball1.GetWidth(); // normal and collision vectors double xn = xt / 2 / R; double yn = yt / 2 / R; double xc = -yn; double yc = xn; // velocity vectors double xv1 = ball1.GetXVelocity(); double yv1 = -ball1.GetYVelocity(); double xv2 = ball2.GetXVelocity(); double yv2 = -ball2.GetYVelocity(); // dot products double v1dotn = xv1 * xn + yv1 * yn; double v1dotc = xv1 * xc + yv1 * yc; double v2dotn = xv2 * xn + yv2 * yn; double v2dotc = xv2 * xc + yv2 * yc; ball1.SetVelocity(xn * v2dotn + xc * v1dotc, -(yn * v2dotn + yc * v1dotc)); ball2.SetVelocity(xn * v1dotn + xc * v2dotc, -(yn * v1dotn + yc * v2dotc));

Billiard Game Life Demo

Coefficient of Restitution

General Case Newton’s Law of Restitution e – coefficient of restitution Notice that we use relative velocity and relative normal velocity:

Implementation Remarks 1.Ball Sinking 2. Bouncing & Sinking: a simple solution for balls and boxes

Ball Sinking in the Floor In the real world: beforehit!after

Ball Sinking in the Floor In the simulated world: beforehit!after

Ball Sinking in the Floor or even a worse scenario: beforehit!after WRONG Bounce condition may be wrongly detected! SOLUTION: only bounce when moving DOWN

Ball Sinking in the Floor General solution: only apply the bounce if v n > 0 v n

Ball Sinking in Another Ball

In the real world: beforehit!after

Ball Sinking in Another Ball In the simulated world: beforehit!after

Ball Sinking in Another Ball In the nasty case: #1#2#3 In frame #3 the balls still overlap. This may lead to repeated application of the ‘bounce’ effect. The balls may end up ‘glued’!

Ball Sinking in Another Ball In the nasty case: no collision yet frame #1

Ball Sinking in Another Ball In the nasty case: collision detected frame #2

Ball Sinking in Another Ball In the nasty case: collision detected bouncing applied frame #2

Ball Sinking in Another Ball In the nasty case: collision detected (again!) frame #3

Ball Sinking in Another Ball In the nasty case: collision detected (again!) bouncing applied frame #3 WRONG

Ball Sinking in Another Ball Solution: Take: -t: position vector (of the other ball) -v: velocity vector if (v ∙ t < 0) don’t bounce! frame #3 t v

Ball Sinking in Another Ball Solution: frame #3 Take: -t: position vector (of the other ball) -v: velocity vector if (v ∙ t < 0) don’t bounce! // distance vector (t) and radius double xt = ball2.GetPrecX() - ball1.GetPrecX(); double yt = ball2.GetPrecY() - ball1.GetPrecY(); double R = ball1.GetWidth(); // normal and collision vectors double xn = xt / 2 / R; double yn = yt / 2 / R; double xc = -yn; double yc = xn; // velocity vectors double xv1 = ball1.GetXVelocity(); double yv1 = -ball1.GetYVelocity(); double xv2 = ball2.GetXVelocity(); double yv2 = -ball2.GetYVelocity(); // dot products double v1dotn = xv1 * xn + yv1 * yn; double v1dotc = xv1 * xc + yv1 * yc; double v2dotn = xv2 * xn + yv2 * yn; double v2dotc = xv2 * xc + yv2 * yc; ball1.SetVelocity(xn * v2dotn + xc * v1dotc, -(yn * v2dotn + yc * v1dotc)); ball2.SetVelocity(xn * v1dotn + xc * v2dotc, -(yn * v1dotn + yc * v2dotc)); t v

Ball Sinking in Another Ball Solution: frame #3 Take: -t: position vector (of the other ball) -v: velocity vector if (v ∙ t < 0) don’t bounce! // distance vector (t) and radius double xt = ball2.GetPrecX() - ball1.GetPrecX(); double yt = ball2.GetPrecY() - ball1.GetPrecY(); double R = ball1.GetWidth(); // normal and collision vectors double xn = xt / 2 / R; double yn = yt / 2 / R; double xc = -yn; double yc = xn; // velocity vectors double xv1 = ball1.GetXVelocity(); double yv1 = -ball1.GetYVelocity(); double xv2 = ball2.GetXVelocity(); double yv2 = -ball2.GetYVelocity(); // check velocity dot position double vx = xv1 - xv2; double vy = yv1 - yv2; if (vx * xt + vy * yt < 0) return; // dot products double v1dotn = xv1 * xn + yv1 * yn; double v1dotc = xv1 * xc + yv1 * yc; double v2dotn = xv2 * xn + yv2 * yn; double v2dotc = xv2 * xc + yv2 * yc; ball1.SetVelocity(xn * v2dotn + xc * v1dotc, -(yn * v2dotn + yc * v1dotc)); ball2.SetVelocity(xn * v1dotn + xc * v2dotc, -(yn * v1dotn + yc * v2dotc)); t v

Bouncing from boxes and walls is quite common in games – simple and advanced a scene from the Marble, a workshop task for today... Bouncing & Sinking: a simple solution for balls & boxes

GFC offers an effective hit test function for rectangular sprites against circular shapes, for which position and radius are known: rect.HitTest(pos, radius); Bouncing & Sinking: a simple solution for balls & boxes

Problem: when the ball is overlapping the box it is too late to determine which side it entered (why?) Bouncing & Sinking: a simple solution for balls & boxes

Solution: track the previous frame position. Bouncing & Sinking: a simple solution for balls & boxes

Example: the ball is hitting the left hand edge of the box if: –there is a hit in frame #n –it was to the left of the box in frame #n-1 Bouncing & Sinking: a simple solution for balls & boxes

Solution Draft: 1.Store in a safe place the position of the ball before the update. This should be the position after the previous frame, before the current one – (x 0, y 0 ) 2.Just after update, check the HitTest. If there is no collision there is no bounce. 3.Now, when we know there is a hit: Assume there was no hit with (x 0, y 0 )* Check on which side of the box the ball was (in the prev frame) Apply the appropriate bounce Amend the position of the ball so that to prevent sinking * this assumption will be satisfied if you prevent sinking! Bouncing & Sinking: a simple solution for balls & boxes

Here is the solution: 1.Store in a safe place the position of the ball before the update. This should be the position after the previous frame, before the current one – (x 0, y 0 ) 2.Just after update, check the HitTest. If there is no collision there is no bounce. 3.Now, when we know there is a hit: Assume there was no hit with (x 0, y 0 )*. Check on which side of the box the ball was. Apply the appropriate bounce. Amend the position of the ball so that to prevent sinking. * this assumption will be satisfied if you prevent sinking! let’s have a look at this point in greater detail... Bouncing & Sinking: a simple solution for balls & boxes

Decompose ball’s velocity into v x and v y if v x > 0 the ball was travelling rightwards and we only check the left side of the box if v x < 0 the ball was travelling leftwards and we only check the right side of the box if v y > 0 the ball was travelling upwards and we only check the bottom side of the box if v y < 0 the ball was travelling downwards and we only check the upper side of the box Bouncing & Sinking: a simple solution for balls & boxes

Decompose ball’s velocity into v x and v y if v x > 0 the ball was travelling rightwards and we only check the left side of the box if v x < 0 the ball was travelling rightwards and we only check the left side of the box if v y > 0 the ball was travelling upwards and we only check the bottom side of the box if v y < 0 the ball was travelling downwards and we only check the upper side of the box Bouncing & Sinking: a simple solution for balls & boxes

Decompose ball’s velocity into v x and v y if v x > 0 the ball was travelling rightwards and we only check the left side of the box if (vx > 0 && x0 + r GetLeft()) { vx *= -damp;// bounce with damping x1 = pWall->GetLeft() - r;// amend the position // (to prevent sinking) } // Repeat for remaining three sides... // and, finally, apply all the changes theBall.SetVelocity(vx, vy); theBall.SetPosition(x1, y1); Bouncing & Sinking: a simple solution for balls & boxes