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

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Lecture 3: Transformations and Viewing. General Idea Object in model coordinates Transform into world coordinates Represent points on object as vectors.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Computer Graphics Lecture 4 Geometry & Transformations.
Three Dimensional Viewing
Rotational Equilibrium and Rotational Dynamics
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
Viewing and Transformation
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
Interactive 3D Graphics and Virtual Reality Introduction to OpenGL concepts Session 2.
Circular Motion and Other Applications of Newton’s Laws
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Introduction to 3D viewing 3D is just like taking a photograph!
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
Vectors 1D kinematics 2D kinematics Newton’s laws of motion
Classical Mechanics Describes the relationship between the motion of objects in our everyday world and the forces acting on them Conditions when Classical.
Physics. Session Opener A recent space shuttle accident occurred because of failure of heat protecting devices. How was this heat generated ?
Viewing and Projections
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Computer Graphics (fall 2009)
Advanced Computer Graphics Three Dimensional Viewing
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Collision handling: detection and response
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Computer Graphics Bing-Yu Chen National Taiwan University.
Programming 3D Applications CE Displaying Computer Graphics Week 3 Lecture 5 Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Chapter 5 Two Dimensional Forces Equilibrium An object either at rest or moving with a constant velocity is said to be in equilibrium The net force acting.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
Push and Pull Newton’s Laws. Newton’s First Law An object at rest remains at rest, and an object in motion continues in motion with constant velocity.
Forces and the Laws of Motion Chapter 4. Forces and the Laws of Motion 4.1 Changes in Motion –Forces are pushes or pullss can cause acceleration. are.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
OpenGL LAB III.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Free-Body Diagrams ForceSymbol/FormulaDescription WeightF w = mgAlways directed downward Tension ForceTPulling forces directed away from the body Normal.
Chapter 5 Force and Motion I. Classical Mechanics Describes the relationship between the motion of objects in our everyday world and the forces acting.
CSE 167 [Win 17], Lecture 5: Viewing Ravi Ramamoorthi
Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.
CSCE 441 Computer Graphics 3-D Viewing
7.3 Forces in Two Dimensions
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Computer Graphics (Spring 2003)
Computer Animation Algorithms and Techniques
The Laws of Motion (not including Atwood)
Presentation transcript:

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

Hierarchy of Models Geometry Physics Bio-Mechanics Behaviour

Transformations in OpenGL ► Modeling  Translate  Rotate  Scale  Shear ► Viewing  orient camera  projection ► Animation ► Map to screen

Camera paradigm for 3D viewing 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 taking picture with camera:  2D view of 3D scene

Model description ► Models are used to represent the 3D things we are simulating ► A standard way of defining models is needed ► Model made up of points and lines joining the lines to form faces ► A co-ordinate system is used to represent the points

Coordinate Systems ► World coordinate system: reference frame for specification of (relative) position / orientation of viewer and scene objects (size?) xwxw zwzw ywyw Scene (head looking at bird) xmxm zmzm ymym Head model xmxm zmzm ymym Bird model

Coordinate Systems ► Viewing coordinate system: reference frame for specification of scene from viewpoint of camera / viewer xwxw zwzw ywyw xmxm zmzm ymym xmxm zmzm ymym Taking a view of scene (head looking at bird) Camera yvyv zvzv xvxv

3D to 2D ► The next part of the process has to take the image from viewpoint and calculate the way the 3D shapes that can be seen can be drawn on a 2D surface. ► Any surfaces not seen are eliminated. ► Involves a mathematical process of manipulating and generating resultant 2D vertices

xwxw zwzw ywyw World coordinates Viewing Pipeline Coordinate transformations:  generation of 3D view involves sequence (pipeline) of coordinate transformations Camera Modelling coordinates 3D object 2D picture Device coordinates xmxm zmzm ymym xmxm zmzm ymym xmxm zmzm ymym xvxv zvzv yvyv Viewing coordinates

Camera Analogy ► 3D is just like taking a photograph (lots of photographs!) camera tripod model viewing volume

Camera Analogy and Transformations ► Projection transformations  adjust the lens of the camera ► Viewing transformations  tripod–define position and orientation of the viewing volume in the world ► Modeling transformations  moving the model ► Viewport transformations  enlarge or reduce the physical photograph

Coordinate Systems and Transformations ► Steps in Forming an Image  specify geometry (world coordinates)  specify camera (camera coordinates)  project (window coordinates)  map to viewport (screen coordinates) ► Each step uses transformations ► Every transformation is equivalent to a change in coordinate systems (frames)

Affine Transformations ► Want transformations which preserve geometry  lines, polygons, quadrics ► Affine = line preserving  Rotation, translation, scaling  Projection  Concatenation (composition)

Homogeneous Coordinates  each vertex is a column vector  w is usually 1.0  all operations are matrix multiplications  directions (directed line segments) can be represented with w = 0.0

3D Transformations ► A vertex is transformed by 4 x 4 matrices  all affine operations are matrix multiplications  all matrices are stored column-major in OpenGL  matrices are always post-multiplied  product of matrix and vector is

Specifying Transformations ► Programmer has two styles of specifying transformations  specify matrices ( glLoadMatrix, glMultMatrix )  specify operation ( glRotate, glOrtho ) ► Programmer does not have to remember the exact matrices

Programming Transformations ► Prior to rendering, view, locate, and orient:  eye/camera position  3D geometry ► Manage the matrices  including matrix stack ► Combine (composite) transformations

vertexvertex Modelview Matrix Projection Matrix Perspective Division Viewport Transform Modelview Projection object eye clip normalized device window ► other calculations here  material  color  shade model (flat)  polygon rendering mode  polygon culling  clipping Transformation Pipeline

Matrix Operations Specify Current Matrix Stack glMatrixMode( GL_MODELVIEW or GL_PROJECTION ) Other Matrix or Stack OperationsglLoadIdentity()glPushMatrix()glPopMatrix() Viewport usually same as window size viewport aspect ratio should be same as projection transformation or resulting image may be distorted glViewport( x, y, width, height )

Projection Transformation ► Shape of viewing frustum ► Perspective projection gluPerspective( fovy, aspect, zNear, zFar ) glFrustum ( left, right, bottom, top, zNear, zFar ) ► Orthographic parallel projection glOrtho( left, right, bottom, top, zNear, zFar ) gluOrtho2D( left, right, bottom, top ) ► calls glOrtho with z values near zero

Applying Projection Transformations ► Typical use (orthographic projection) glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( left, right, bottom, top, zNear, zFar );

Viewing Transformations ► Position the camera/eye in the scene  place the tripod down; aim camera ► To “fly through” a scene  change viewing transformation and redraw scene ► gluLookAt( eye x, eye y, eye z, aim x, aim y, aim z, up x, up y, up z )  up vector determines unique orientation tripod

Modeling Transformations ► Move object glTranslate{fd}( x, y, z ) ► Rotate object around arbitrary axis glRotate{fd}( angle, x, y, z )  angle is in degrees ► Dilate (stretch or shrink) or mirror object glScale{fd}( x, y, z )

Connection: Viewing and Modeling ► Moving camera is equivalent to moving every object in the world towards a stationary camera ► Viewing transformations are equivalent to several modeling transformations gluLookAt() has its own command can make your own polar view or pilot view

Projection is left handed ► Projection transformations ( gluPerspective, glOrtho ) are left handed  think of zNear and zFar as distance from view point ► Everything else is right handed, including the vertexes to be rendered x x y y z+ left handedright handed

Hierarchy of Models Geometry Physics Bio-Mechanics Behaviour

Basic Physics Modelling ► Fundamental Laws ► Gravity ► Friction ► Collision Response ► Forward Kinematics ► Particle Systems

The Fundamental Laws ► Mass (m)  Mass = number of atomic units (not weight)  Measured in Kilograms  Forces act on a mass – Newtons -> weight ► Time (t)  In a virtual environment is related to frame rate not real time  If system slows time slows

Centres of Mass ► Position (s)  X,y,z co-ords in 3D space  An object is positioned by its centre of mass For complex masses centre less obvious

► To calculate centre of mass of object can use a mass for each vertex (n vertices)  X value = sum of x pos * mass (from 1 to n) divided by sum of masses divided by sum of masses  Y value = sum of y pos * mass (from 1 to n) divided by sum of masses divided by sum of masses Bounding shapes make easier computation

► Velocity (v)  Velocity = ds/dt  X pos = x pos + x velocity (pixels per frame)  Virtual velocity = pixels/second(for a set fps) since we are redrawing using a frame rate  New position = old position + velocity * time x 0 Time = t 0 x 1 = x 0 =v 0 (t 2 -t 1 ) Time = t 1

► Acceleration (a)  Rate 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)

► After t secs  X t = x 0 + v 0 *t + ½*a*t 2  E.g. Object starts at pos 50, start velocity is 4 units per frame and acceleration is 2 units per frame 2  New position x t = *t + 0.5*2*t*t assuming start at frame 0 and t is no. of frames assuming start at frame 0 and t is no. of frames

► Force (f)  Force = mass * acceleration (F= m*a)  Measure in Newtons (Kg*m/s 2 )  Acceleration = Force / mass  Used in simulations to ► Work out acceleration of objects when hit with a force ► Forces on colliding objects ► Acceleration given to different mass objects when hit with same force  Forces act in all three dimensions and are represented as vectors.  Usually decompose all forces into 3 vectors and add all forces acting on an object in each axis

► Momentum (P)  P = m * v  Force is the rate of change of momentum  So if a small object travelling fast comes to a halt it will impart the same force as a large object travelling slow (principle of jets and rockets)

► Conservation of momentum  If a ball bounces of a wall and returns at same velocity – inelastic collision – momentum conserved ► Momentum transfer  Usually some energy is absorbed in the form of heat and vibration – momentum is lost – ball returns at lower velocity.  Ignored in VR or game simulations

Simple Bounce Physics ► Given an object with initial velocity (vx,vy), if this object collides with another object of greater mass, then the collision is simplified, we only need to predict the behaviour of the colliding object. ► Consider the balls on a pool table…

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

Simple Bounce Physics (+vy,-vx) (-vy,-vx) (-vy,+vx) (+vy,+vx)

Further Collision Physics ► Two objects each with their own mass, when they collide we need to calculate the final trajectory and velocity. ► Using the law of the conservation of momentum we obtain ► For this problem we used the conservation of kinetic energy

Further Collision Physics ► Manipulating this equation we obtain

Newton’s First Law ► An object at rest remains at rest ► An object in motion remains in motion (i.e. at constant velocity) until an exterior force acts upon the object

Object Pair Collision Detection ► Vital component of interaction ► Describe Exhaustive Test for when two object intersect (process hungry) ► Try to avoid doing exhaustive test if possible

Exhaustive Test ► Assume all objects as collection of triangles (polygons) ► Object 1 consists of m triangles ► Object 2 consists of n triangles ► Use triangle intersection test to test all possible pairs of of intersections ► This requires n.m triangle-triangle tests

Triangle Intersection Test Moller 1997 comparison of triangles A and B 1. They do not intersect if all vertices in A lie to one side of plane of B and V.V 2. Otherwise plane of A intersects plane of B on L 3. Find line intersection of L with A ( L A ) and L with B ( L B ) 4. A and B intersect only if L A and L B overlap A B LBLB L LALA

Basic Rejection Tests ► Simplest tests based on distance ► Each scene object has a bounding sphere. Two objects cannot overlap if distance between two centres is > than sum of the radii ► Better test id the separating plane test. If a plane can be drawn such that all points of one object lie on one side and all points of the other on the reverse, cannot collide. Key ids to find a good separating plane ► Bounding Box range test

General Collision Detection ► Detecting collision between a set of n objects generates n 2 possible pairs of objects requiring testing for overlap ► Use spatial partitioning to discard as may pairs as possible and use object pair collision tests on remaining pairs ► Uniform Space Subdivision

Space Subdivision

Modelling Gravity effects ► Gravity is a result of a distortion of space by a large body, but is experienced as a special force unique to earth. ► Two cases to consider  Two or more objects with same relative mass  One object has much greater mass than other ► F = G*m1*m2/r2  Where G is 6.67* Nm/kg 2  And m1, m2 are masses, r is the distance between centres

Modelling Projectile Trajectories  T = Viy* sin  g g = 9.8 m/s 2 Vix = V* cos  Viy = V* sin  Xhit = Vix * Viy /g Vi

Friction ► Friction causes deceleration ► Assumed to be a constant deceleration ► Friction on a flat surface is modelled by applying a virtual friction ► Each frame the velocity is reduced by a constant factor to match to the desired friction (Vnew = Vold – friction)

Friction ► Usual modelled as frictional force. ► If you try to push a mass in a direction parallel to the plane, you will encounter frictional force. Push Friction

Friction ► Definition of static Frictional force. ► Where m=mass,g=gravity and  s is the static frictional coefficient. ► If force is applied that is greater than the frictional force, the object will move. ► When the object is in motion, the frictional coefficient decreases to the coefficient of kinetic friction

Modelling Friction ► Modelling Friction on a flat surface requires a constant negative velocity be applied to all objects that is proportional to the required friction. ► V new =V old -Friction. ► In which case it is necessary to ensure that velocity stays positive.

Friction on an Inclined Plane ► Friction and Gravity work in similar ways.  +x+x -x-x +y+y -y-y

Friction on an Inclined Plane ► The plane has coefficients  s and  k for static and kinetic cases. ► The equilibrium case is when the sum of the forces acting on the body is zero.

Friction on an inclined plane ► Normal force (  ) – the force that pushes the object back. ►  =mg ► The gravitational force must be opposite to the normal force  -mg=0

Friction on an Inclined Plane At what angle does gravity overcome friction?  +x+x -x-x +y+y -y-y

Friction on an Inclined Plane: Finding the Critical Angle ► Firstly we define an xy coordinate system on the inclined plane, with x parallel to the plane, and the positive part of x in the downward sliding direction. ► For the x-axis we know the force of gravity pushing the block is mg(sin . ► The force due to friction is –  s. ► The negative sign is because the force acts in the opposite direction.

► Friction on an inclined plane  Different coefficient of friction for moving and static    s Static  k Kinetic(moving)

Inclined Friction ► (Normal force)  = m*g ►  - m*g = 0 (gravity opposes normal force) ► on an inclined plane force due to gravity = m*g*sin  ► Force due to friction holding block = -  *  s ► Since at the point of sliding these forces are equal, ► On the x - axis (m*g*sin  -  *  s = 0) ► On the y axis (  - m*g*cos  = 0) ► By substitution the angle at which the block starts to slide  critical = tan -1  s

Other Physics to consider ► Object-to-object collision (of irregular shaped objects) ► Kinematics ► Particulates