Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision...

62
Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire University

Transcript of Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision...

Page 1: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Further Programming for 3D applicationsCE00849-2

Motion, Fundamental Physics and Collision Detection

Bob Hobbs

Faculty of Computing, Engineering and Technology

Staffordshire University

Page 2: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Hierarchy of ModelsHierarchy of Models

Geometry

Physics

Bio-Mechanics

Behaviour

Page 3: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Transformations in OpenGLTransformations in OpenGL

► ModelingModeling TranslateTranslate RotateRotate ScaleScale ShearShear

► ViewingViewing orient cameraorient camera projectionprojection

► AnimationAnimation► Map to screenMap to screen

Page 4: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Camera paradigm for 3D Camera paradigm for 3D viewingviewing

3D scene

Camera

2D picture

Content of 2D picture will depend on: • camera parameters (position,

direction, field of view, ...), • properties of scene objects, • illumination, ...

► 3D viewing is similar to 3D viewing is similar to taking taking picture with camerapicture with camera:: 2D view 2D view ofof 3D scene 3D scene

Page 5: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Model descriptionModel description

►Models are used to represent the 3D Models are used to represent the 3D things we are simulatingthings we are simulating

►A standard way of defining models is A standard way of defining models is neededneeded

►Model made up of points and lines Model made up of points and lines joining the lines to form facesjoining the lines to form faces

►A co-ordinate system is used to A co-ordinate system is used to represent the pointsrepresent the points

Page 6: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Coordinate SystemsCoordinate Systems

► World coordinate systemWorld coordinate system: reference frame : reference frame for specification of (relative) for specification of (relative) positionposition / / orientationorientation of of viewerviewer and and scene objectsscene objects (size?)(size?)

xw

zw

yw

Scene (head looking at bird)

xm

zm

ymHead model

xm

zm

ym

Bird model

Page 7: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Coordinate SystemsCoordinate Systems

►Viewing coordinate systemViewing coordinate system: reference : reference frame for specification of scene from frame for specification of scene from viewpoint of camera / viewerviewpoint of camera / viewer

xw

zw

yw

xm

zm

ym

xm

zm

ym

Taking a view of scene (head looking at bird)

Camera

yv

zv

xv

Page 8: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

3D to 2D3D to 2D

►The next part of the process has to take The next part of the process has to take the image from viewpoint and calculate the image from viewpoint and calculate the way the 3D shapes that can be the way the 3D shapes that can be seen can be drawn on a 2D surface.seen can be drawn on a 2D surface.

►Any surfaces not seen are eliminated.Any surfaces not seen are eliminated.► Involves a mathematical process of Involves a mathematical process of

manipulating and generating resultant manipulating and generating resultant 2D vertices2D vertices

Page 9: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

xw

zw

yw

World coordinates

Viewing PipelineViewing Pipeline

Coordinate transformations: Coordinate transformations: generation of 3D view involves generation of 3D view involves

sequence (sequence (pipelinepipeline) of ) of coordinate coordinate transformationstransformations

Camera

Modelling coordinates

3D object

2D picture

Device coordinates

xm

zm

ym

xmzm

ym

xm

zm

ym

xvzv

yv

Viewing coordinates

Page 10: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Camera AnalogyCamera Analogy

►3D is just like taking a photograph 3D is just like taking a photograph (lots of photographs!)(lots of photographs!)

camera

tripod model

viewingvolume

Page 11: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Camera Analogy and Camera Analogy and TransformationsTransformations

► Projection transformationsProjection transformations adjust the lens of the cameraadjust the lens of the camera

► Viewing transformationsViewing transformations tripod–define position and orientation of the tripod–define position and orientation of the

viewing volume in the worldviewing volume in the world

► Modeling transformationsModeling transformations moving the modelmoving the model

► Viewport transformationsViewport transformations enlarge or reduce the physical photographenlarge or reduce the physical photograph

Page 12: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Coordinate Systems and Coordinate Systems and TransformationsTransformations

► Steps in Forming an ImageSteps in Forming an Image specify geometry (world coordinates)specify geometry (world coordinates) specify camera (camera coordinates)specify camera (camera coordinates) project (window coordinates)project (window coordinates) map to viewport (screen coordinates)map to viewport (screen coordinates)

► Each step uses transformationsEach step uses transformations► Every transformation is equivalent to a Every transformation is equivalent to a

change in coordinate systems (frames)change in coordinate systems (frames)

Page 13: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Affine TransformationsAffine Transformations

►Want transformations which preserve Want transformations which preserve geometrygeometry lines, polygons, quadricslines, polygons, quadrics

►Affine = line preservingAffine = line preserving Rotation, translation, scalingRotation, translation, scaling ProjectionProjection Concatenation (composition)Concatenation (composition)

Page 14: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Homogeneous CoordinatesHomogeneous Coordinates

each vertex is a column vector each vertex is a column vector

ww is usually 1.0 is usually 1.0 all operations are matrix multiplicationsall operations are matrix multiplications directions (directed line segments) can be directions (directed line segments) can be

represented with represented with ww = 0.0 = 0.0

w

z

y

x

v

Page 15: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

151173

141062

13951

12840

mmmm

mmmm

mmmm

mmmm

M

3D Transformations3D Transformations

► A vertex is transformed by 4 x 4 matricesA vertex is transformed by 4 x 4 matrices all affine operations are matrix all affine operations are matrix

multiplicationsmultiplications all matrices are stored column-major in all matrices are stored column-major in

OpenGLOpenGL matrices are always post-multipliedmatrices are always post-multiplied product of matrix and vector is product of matrix and vector is

vM

Page 16: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Specifying TransformationsSpecifying Transformations

►Programmer has two styles of Programmer has two styles of specifying transformationsspecifying transformations specify matrices (specify matrices (glLoadMatrix, glLoadMatrix, glMultMatrixglMultMatrix))

specify operation (specify operation (glRotate, glOrthoglRotate, glOrtho))

►Programmer does not have to Programmer does not have to remember the exact matricesremember the exact matrices

Page 17: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Programming Programming TransformationsTransformations

►Prior to rendering, view, locate, and Prior to rendering, view, locate, and orient:orient: eye/camera positioneye/camera position 3D geometry3D geometry

►Manage the matricesManage the matrices including matrix stackincluding matrix stack

►Combine (composite) transformationsCombine (composite) transformations

Page 18: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

vertex

ModelviewMatrix

ProjectionMatrix

PerspectiveDivision

ViewportTransform

Modelview

Modelview

Projection

object eye

clip normalizeddevice

window

► other calculations hereother calculations here material material color color shade model (flat)shade model (flat) polygon rendering modepolygon rendering mode polygon cullingpolygon culling clippingclipping

TransformationTransformationPipelinePipeline

Page 19: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Matrix OperationsMatrix Operations•Specify Current Matrix Stack

glMatrixMode( glMatrixMode( GL_MODELVIEWGL_MODELVIEW or or GL_PROJECTIONGL_PROJECTION ) )

•Other Matrix or Stack OperationsglLoadIdentity() glLoadIdentity() glPushMatrix()glPushMatrix()glPopMatrix()glPopMatrix()

•Viewport•usually same as window size•viewport aspect ratio should be same as projection transformation or resulting image may be distorted

glViewport( glViewport( x, y, width, heightx, y, width, height ) )

Page 20: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Projection TransformationProjection Transformation

► Shape of viewing frustumShape of viewing frustum► Perspective projectionPerspective projection

gluPerspective( gluPerspective( fovy, aspect, zNear, zFarfovy, aspect, zNear, zFar ) )

glFrustumglFrustum(( left,left, right,right, bottom,bottom, top,top, zNear,zNear, zFarzFar ))

► Orthographic parallel projectionOrthographic parallel projectionglOrtho(glOrtho( left,left, right,right, bottom,bottom, top,top, zNear,zNear, zFarzFar ))

gluOrtho2D( gluOrtho2D( left, right, bottom, topleft, right, bottom, top ) ) ► calls calls glOrthoglOrtho with z values near zero with z values near zero

Page 21: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Applying Projection Applying Projection TransformationsTransformations

►Typical use (orthographic Typical use (orthographic projection)projection)glMatrixMode( GL_PROJECTION );glMatrixMode( GL_PROJECTION );

glLoadIdentity();glLoadIdentity();

glOrtho( left, right, bottom, top, glOrtho( left, right, bottom, top, zNear, zFar );zNear, zFar );

Page 22: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Viewing TransformationsViewing Transformations

► Position the camera/eye in the scenePosition the camera/eye in the scene place the tripod down; aim cameraplace the tripod down; aim camera

► To “fly through” a sceneTo “fly through” a scene change viewing transformation andchange viewing transformation and

redraw sceneredraw scene► gluLookAt( eyegluLookAt( eyexx, eye, eyeyy, eye, eyezz,,

aim aimxx, aim, aimyy, aim, aimzz,, up upxx, up, upyy, up, upzz ) ) up vector determines unique orientationup vector determines unique orientation

tripod

Page 23: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Modeling TransformationsModeling Transformations

► Move objectMove objectglTranslate{fd}( glTranslate{fd}( x, y, zx, y, z ) )

► Rotate object around arbitrary axisRotate object around arbitrary axisglRotate{fd}( glRotate{fd}( angle, x, y, zangle, x, y, z ) ) angle is in degreesangle is in degrees

► Dilate (stretch or shrink) or mirror objectDilate (stretch or shrink) or mirror objectglScale{fd}( glScale{fd}( x, y, zx, y, z ) )

zyx

Page 24: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Connection: Viewing and Connection: Viewing and ModelingModeling

►Moving camera is equivalent to Moving camera is equivalent to moving every object in the world moving every object in the world towards a stationary cameratowards a stationary camera

►Viewing transformations are Viewing transformations are equivalent to several modeling equivalent to several modeling transformationstransformationsgluLookAt()gluLookAt() has its own command has its own command

can make your own can make your own polar viewpolar view or or pilot viewpilot view

Page 25: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Projection is left handedProjection is left handed

►Projection transformations Projection transformations ((gluPerspective, glOrthogluPerspective, glOrtho) are left ) are left handedhanded think of think of zNearzNear and and zFarzFar as distance from as distance from

view pointview point

►Everything else is right handed, Everything else is right handed, including the vertexes to be renderedincluding the vertexes to be rendered

xx

yy

z+

z+

left handed right handed

Page 26: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Hierarchy of ModelsHierarchy of Models

Geometry

Physics

Bio-Mechanics

Behaviour

Page 27: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Basic Physics ModellingBasic Physics Modelling

►Fundamental LawsFundamental Laws►GravityGravity►FrictionFriction►Collision ResponseCollision Response►Forward KinematicsForward Kinematics►Particle SystemsParticle Systems

Page 28: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

The Fundamental LawsThe Fundamental Laws

►Mass (m)Mass (m) Mass = number of atomic units (not Mass = number of atomic units (not

weight)weight) Measured in KilogramsMeasured in Kilograms Forces act on a mass – Newtons -> weightForces act on a mass – Newtons -> weight

►Time (t)Time (t) In a virtual environment is related to In a virtual environment is related to

frame rate not real timeframe rate not real time If system slows time slows If system slows time slows

Page 29: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Centres of MassCentres of Mass

► Position (s)Position (s) X,y,z co-ords in 3D spaceX,y,z co-ords in 3D space An object is positioned by its An object is positioned by its

centre of masscentre of mass

For complex masses centre less obvious

Page 30: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►To calculate centre of mass of object can To calculate centre of mass of object can use a mass for each vertex (n vertices)use a mass for each vertex (n vertices) X value = sum of x pos * mass (from 1 to n)X value = sum of x pos * mass (from 1 to n)

divided by sum of massesdivided by sum of masses Y value = sum of y pos * mass (from 1 to n)Y value = sum of y pos * mass (from 1 to n)

divided by sum of massesdivided by sum of masses

Bounding shapes make easier computation

Page 31: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►Velocity (v)Velocity (v) Velocity = ds/dtVelocity = ds/dt X pos = x pos + x velocity (pixels per frame)X pos = x pos + x velocity (pixels per frame) Virtual velocity = pixels/second(for a set Virtual velocity = pixels/second(for a set

fps) since we are redrawing using a frame fps) since we are redrawing using a frame raterate

New position = old position + velocity * timeNew position = old position + velocity * time

x0

Time = t0

x1 = x0=v0(t2-t1)Time = t1

Page 32: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►Acceleration (a)Acceleration (a) Rate of change of velocity with timeRate of change of velocity with time

vel

Time ->

vel

Time ->

vel

Time ->

Constant velocity(a =0) Acceleration a = constant Non-constant accel a = f(t)

Page 33: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►After t secsAfter t secs XXtt = x = x0 0 + v+ v00*t + ½*a*t*t + ½*a*t22

E.g. Object starts at pos 50 , start velocity E.g. Object starts at pos 50 , start velocity is 4 units per frame and acceleration is 2 is 4 units per frame and acceleration is 2 units per frameunits per frame22

New position xNew position xtt = 50 + 4*t + 0.5*2*t*t = 50 + 4*t + 0.5*2*t*t assuming start at frame 0 and t is no. of assuming start at frame 0 and t is no. of

framesframes

Page 34: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

► Force (f)Force (f) Force = mass * acceleration (F= m*a)Force = mass * acceleration (F= m*a) Measure in Newtons (Kg*m/sMeasure in Newtons (Kg*m/s22)) Acceleration = Force / massAcceleration = Force / mass Used in simulations to Used in simulations to

► Work out acceleration of objects when hit with a forceWork out acceleration of objects when hit with a force► Forces on colliding objectsForces on colliding objects► Acceleration given to different mass objects when hit Acceleration given to different mass objects when hit

with same forcewith same force Forces act in all three dimensions and are Forces act in all three dimensions and are

represented as vectors. represented as vectors. Usually decompose all forces into 3 vectors and Usually decompose all forces into 3 vectors and

add all forces acting on an object in each axisadd all forces acting on an object in each axis

Page 35: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►Momentum (P)Momentum (P) P = m * vP = m * v Force is the rate of change of momentumForce is the rate of change of momentum So if a small object travelling fast comes So if a small object travelling fast comes

to a halt it will impart the same force as a to a halt it will impart the same force as a large object travelling slow (principle of large object travelling slow (principle of jets and rockets)jets and rockets)

Page 36: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►Conservation of momentumConservation of momentum If a ball bounces of a wall and returns at If a ball bounces of a wall and returns at

same velocity – inelastic collision – same velocity – inelastic collision – momentum conservedmomentum conserved

►Momentum transferMomentum transfer Usually some energy is absorbed in the Usually some energy is absorbed in the

form of heat and vibration – momentum form of heat and vibration – momentum is lost – ball returns at lower velocity. is lost – ball returns at lower velocity.

Ignored in VR or game simulationsIgnored in VR or game simulations

Page 37: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Simple Bounce PhysicsSimple Bounce Physics

►Given an object with initial velocity Given an object with initial velocity ((vx,vyvx,vy), if this object collides with ), if this object collides with another object of greater mass, then another object of greater mass, then the collision is simplified, we only need the collision is simplified, we only need to predict the behaviour of the to predict the behaviour of the colliding object. colliding object.

►Consider the balls on a pool table…Consider the balls on a pool table…

Page 38: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Simple Bounce PhysicsSimple Bounce Physics

►When a ball hits a cushion, then it When a ball hits a cushion, then it reflects of the side at an angle that is reflects of the side at an angle that is equal and opposite to the incident equal and opposite to the incident angle.angle.

Normal

Page 39: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Simple Bounce PhysicsSimple Bounce Physics

(+vy,-vx)(-vy,-vx)

(-vy,+vx) (+vy,+vx)

Page 40: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Further Collision PhysicsFurther Collision Physics

► Two objects each with their own mass, when Two objects each with their own mass, when they collide we need to calculate the final they collide we need to calculate the final trajectory and velocity.trajectory and velocity.

► Using the law of the conservation of Using the law of the conservation of momentum we obtainmomentum we obtain

► For this problem we used the conservation For this problem we used the conservation of kinetic energyof kinetic energy

2222

2

1

2

1

2

1

2

1bfbafabibaia vmvmvmvm

bfbafabibaia vmvmvmvm

Page 41: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Further Collision PhysicsFurther Collision Physics

►Manipulating this equation we obtainManipulating this equation we obtain

ba

babiaiabf

ba

baaibibaf

mm

mmvvmv

mm

mmvvmv

2

2

Page 42: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Newton’s First LawNewton’s First Law

►An object at rest remains at restAn object at rest remains at rest►An object in motion remains in motion An object in motion remains in motion

(i.e. at constant velocity) until an (i.e. at constant velocity) until an exterior force acts upon the objectexterior force acts upon the object

Page 43: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Object Pair Collision Object Pair Collision DetectionDetection

►Vital component of interactionVital component of interaction►Describe Exhaustive Test for when two Describe Exhaustive Test for when two

object intersect (process hungry)object intersect (process hungry)►Try to avoid doing exhaustive test if Try to avoid doing exhaustive test if

possiblepossible

Page 44: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Exhaustive TestExhaustive Test

►Assume all objects as collection of Assume all objects as collection of triangles (polygons)triangles (polygons)

►Object 1 consists of Object 1 consists of mm triangles triangles►Object 2 consists of Object 2 consists of nn triangles triangles►Use triangle intersection test to test all Use triangle intersection test to test all

possible pairs of of intersectionspossible pairs of of intersections►This requires This requires n.mn.m triangle-triangle triangle-triangle

teststests

Page 45: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Triangle Intersection TestTriangle Intersection Test

Moller 1997 comparison Moller 1997 comparison of triangles A and Bof triangles A and B

1.1. They do not intersect if all They do not intersect if all vertices in A lie to one vertices in A lie to one side of plane of B and V.Vside of plane of B and V.V

2.2. Otherwise plane of A Otherwise plane of A intersects plane of B on Lintersects plane of B on L

3.3. Find line intersection of L Find line intersection of L with A (with A (LLAA) and L with B ) and L with B ((LLBB) )

4.4. A and B intersect only if A and B intersect only if LLAA and and LLB B overlapoverlap

AB

LB

L LA

Page 46: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Basic Rejection TestsBasic Rejection Tests► Simplest tests based on distanceSimplest tests based on distance► Each scene object has a bounding sphere. Each scene object has a bounding sphere.

Two objects cannot overlap if distance Two objects cannot overlap if distance between two centres is > than sum of the between two centres is > than sum of the radiiradii

► Better test id the Better test id the separating plane test. separating plane test. If a If a plane can be drawn such that all points of plane can be drawn such that all points of one object lie on one side and all points of one object lie on one side and all points of the other on the reverse, cannot collide. the other on the reverse, cannot collide. Key ids to find a good separating planeKey ids to find a good separating plane

► Bounding Box range testBounding Box range test

Page 47: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

General Collision DetectionGeneral Collision Detection

►Detecting collision between a set of n Detecting collision between a set of n objects generates nobjects generates n22 possible pairs of possible pairs of objects requiring testing for overlapobjects requiring testing for overlap

►Use spatial partitioning to discard as Use spatial partitioning to discard as may pairs as possible and use object may pairs as possible and use object pair collision tests on remaining pairspair collision tests on remaining pairs

►Uniform Space SubdivisionUniform Space Subdivision

Page 48: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Space SubdivisionSpace Subdivision

Page 49: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Modelling Gravity effectsModelling Gravity effects

► Gravity is a result of a distortion of space by Gravity is a result of a distortion of space by a large body , but is experienced as a a large body , but is experienced as a special force unique to earth.special force unique to earth.

► Two cases to considerTwo cases to consider Two or more objects with same relative massTwo or more objects with same relative mass One object has much greater mass than otherOne object has much greater mass than other

► F = G*m1*m2/r2F = G*m1*m2/r2 Where G is 6.67*10Where G is 6.67*10-11-11 Nm/kg Nm/kg22

And m1, m2 are masses, r is the distance And m1, m2 are masses, r is the distance between centresbetween centres

Page 50: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Modelling Projectile Modelling Projectile TrajectoriesTrajectories

T = Viy* sing

g = 9.8 m/s2

Vix = V* cos

Viy = V* sin

Xhit = Vix * Viy /g

Vi

Page 51: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

FrictionFriction

►Friction causes decelerationFriction causes deceleration►Assumed to be a constant decelerationAssumed to be a constant deceleration►Friction on a flat surface is modelled Friction on a flat surface is modelled

by applying a virtual frictionby applying a virtual friction►Each frame the velocity is reduced by Each frame the velocity is reduced by

a constant factor to match to the a constant factor to match to the desired friction (Vnew = Vold – friction)desired friction (Vnew = Vold – friction)

Page 52: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

FrictionFriction

►Usual modelled as frictional force.Usual modelled as frictional force.► If you try to push a mass in a direction If you try to push a mass in a direction

parallel to the plane, you will parallel to the plane, you will encounter frictional force.encounter frictional force.

PushFriction

Page 53: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

FrictionFriction

► Definition of static Frictional force.Definition of static Frictional force.

► Where Where mm=mass,=mass,gg=gravity and =gravity and ss is the is the static frictional coefficient.static frictional coefficient.

► If force is applied that is greater than the If force is applied that is greater than the frictional force, the object will move.frictional force, the object will move.

► When the object is in motion, the frictional When the object is in motion, the frictional coefficient decreases to the coefficient of coefficient decreases to the coefficient of kinetic frictionkinetic friction

sfstatic mgF

Page 54: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Modelling FrictionModelling Friction

►Modelling Friction on a flat surface Modelling Friction on a flat surface requires a constant negative velocity requires a constant negative velocity be applied to all objects that is be applied to all objects that is proportional to the required friction. proportional to the required friction.

►VVnewnew=V=Voldold-Friction-Friction..

► In which case it is necessary to ensure In which case it is necessary to ensure that velocity stays positive.that velocity stays positive.

Page 55: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Friction on an Inclined PlaneFriction on an Inclined Plane

►Friction and Gravity work in similar Friction and Gravity work in similar ways.ways.

+x

-x +y

-y

Page 56: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Friction on an Inclined PlaneFriction on an Inclined Plane

►The plane has coefficients The plane has coefficients ss and and kk for for static and kinetic cases.static and kinetic cases.

►The equilibrium case is when the sum The equilibrium case is when the sum of the forces acting on the body is of the forces acting on the body is zero.zero.

Page 57: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Friction on an inclined planeFriction on an inclined plane

►Normal force (Normal force () – the force that ) – the force that pushes the object back.pushes the object back.

►=mg=mg►The gravitational force must be The gravitational force must be

opposite to the normal forceopposite to the normal force

-mg=0-mg=0

Page 58: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Friction on an Inclined PlaneFriction on an Inclined Plane

At what angle does gravity overcome At what angle does gravity overcome friction?friction?

+x

-x +y

-y

Page 59: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Friction on an Inclined Plane: Friction on an Inclined Plane: Finding the Critical AngleFinding the Critical Angle

► Firstly we define an Firstly we define an xyxy coordinate system on coordinate system on the inclined plane, with the inclined plane, with xx parallel to the parallel to the plane, and the positive part of plane, and the positive part of xx in the in the downward sliding direction.downward sliding direction.

► For the x-axis we know the force of gravity For the x-axis we know the force of gravity pushing the block is pushing the block is mg(mg(sin sin ..

► The force due to friction isThe force due to friction is – –ss..

► The negative sign is because the force acts The negative sign is because the force acts in the opposite direction. in the opposite direction.

Page 60: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

►Friction on an inclined planeFriction on an inclined plane Different coefficient of friction for moving and staticDifferent coefficient of friction for moving and static

s Static

k Kinetic(moving)

Page 61: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Inclined FrictionInclined Friction► (Normal force) (Normal force) = m*g = m*g► - m*g = 0 (gravity opposes normal force)- m*g = 0 (gravity opposes normal force)► on an inclined plane force due to gravity = on an inclined plane force due to gravity =

m*g*sinm*g*sin► Force due to friction holding block = - Force due to friction holding block = - * * s s

► Since at the point of sliding these forces are Since at the point of sliding these forces are equal , equal ,

► On the x - axis (m*g*sinOn the x - axis (m*g*sin- - * * s s = 0)= 0)

► On the y axis (On the y axis ( - m*g*cos - m*g*cos = 0)= 0)► By substitution the angle at which the block By substitution the angle at which the block

starts to slide starts to slide criticalcritical = tan = tan-1-1 s s

Page 62: Further Programming for 3D applications CE00849-2 Motion, Fundamental Physics and Collision Detection Bob Hobbs Faculty of Computing, Engineering and Technology.

Other Physics to considerOther Physics to consider

►Object-to-object collision (of irregular Object-to-object collision (of irregular shaped objects)shaped objects)

►KinematicsKinematics►ParticulatesParticulates