1 / 40

Quaternions

Quaternions. Paul Taylor 2010. Swizzle. What is a swizzle?. Matrix Rotations. A simple 2D ( xy ) Rotation Matrix: Rotates in the xy plane counterclockwise by Ɵ Degrees ( In a RH Space) The Determinant is always 1. http://en.wikipedia.org/wiki/Rotation_matrix. 3D Rotations.

venus
Download Presentation

Quaternions

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. Quaternions Paul Taylor 2010

  2. Swizzle • What is a swizzle?

  3. Matrix Rotations • A simple 2D (xy) Rotation Matrix: • Rotates in the xy plane counterclockwise by Ɵ Degrees ( In a RH Space) • The Determinant is always 1 http://en.wikipedia.org/wiki/Rotation_matrix

  4. 3D Rotations • Rx rotates Y towards Z • Ry rotates Z towards X • Rz rotates X towards Y http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_two_and_three_dimensions

  5. Euler Angles (Yaw Pitch Roll) Pros: Easy to visualise Cons: Gimbal Lock If any one axis is exactly 0 or PI or –PI (Where Cos Ɵ = 1 and Sin Ɵ = 0) The freedom of rotation is limited to a plane.

  6. Rotation about an Axis • U is a unit vector specifying the rotation plane • C = Cos Ɵ • S = Sin Ɵ http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_two_and_three_dimensions

  7. The quaternion solution Q Quaternion is a 4-tuple of numbers, typically called (s, x, y, z) S acts as a scalar, and xyz act as a 3D vector The vector xyz should satisfy X2 + Y2 + Z2 = XYZ = -1 Where s2 + X2 + Y2 + Z2 = 1 the quaternion can be considered a rotation.

  8. Quaternion Addition

  9. Quaternion Subtraction

  10. Quaternion Multiplication

  11. Quaternion Division • Don’t divide by Zero!

  12. Quaternion Advantages Storage Matrix must be at minimum 3x3 typically stored as a 4x4. A quaternion may be stored as 4 values. Chaining (preparing) an xyz rotation:

  13. Performing an xyz Rotation

  14. Smooth rotation interpolation • Ideal for animation • LERPING between one rotation and a second will take the shortest path using a quaternion

  15. Collision Detection • What is it? • What does it need to be? • Precise • Efficient • Fast

  16. What collides? • Almost everything • This would result in roughly n2 different collisions to detect each frame.

  17. Cheating the system • We CAN mathematically check every single polygon against every other. • Just not in this lifetime!

  18. Bounding Spheres • Collision if r1 + r2 < distance from P1 to P2 http://www.gamasutra.com/view/feature/3190/advanced_collision_detection_.php?page=2

  19. Bounding Boxes • Axis Aligned (AABB) • This allows for compatibility with oct trees, and extreme simplification of intersections • Oriented (OBB) • These will fit strange objects better • Only need to be created once • Much more complex to intersect

  20. A strange object

  21. Bounding Trees • We can create a small tree to bound a stupid object. • These must be built offline • Each vertex must be matrix multiplied into the world, so things will start to get expensive

  22. The Separating Axis Theorem • This theorem allows for collision detection utilising separating axis’ is 2D • It dumbs down to the ability to put a line between the two objects. • This extends to 3D using a separating plane Convex Only!!!

  23. Stationary Objects • Do not move, so we do not have to detect collisions by the object, only on the object!

  24. BSP Trees and Collisions • Using Cartesian plane equations and the vertices of our object BSP intersections are extremely quick. • ax + by + cz + d = 0 • ax + by + cz + d > 0 positive side of the BSP polygon • ax + by + cz + d < 0 negative side of the BSP polygon

  25. Size == Time step • A small object will need a smaller change in time to detect collisions. • How can you make this work? • The two special cases: • Small vs Small object (both high resolution) • Small vs large object (large is at a low resolution) http://www.gamasutra.com/view/feature/3190/advanced_collision_detection_.php?page=2

  26. Bezier Curve Collisions • We can use the Convex Hull Property for coarse collision detection • This extends to 3D easily. • For more accurate collisions you will need to do something like Cartesian plane equations, by calculating the plane at points on the curve • Tessellation into polygons remains the most common approach

  27. For only low detail Bezier collisions... • We can use a vastly simplified polygon surface • This is useless as a basis for a high accuracy collision detection algorithm, as it will reject some collisions http://www.gamasutra.com/view/feature/3190/advanced_collision_detection_.php?page=3

  28. Per-Pixel Collision Detection • The Atari had built-in collision detection in the video chip, this made collisions extremely simple • Can we do something similar today?

  29. GPU Based Collision Detection • There is a bit of research in this area • GPU only solutions • CPU-GPU hybrids

  30. Direction Based Collision Trees • What if we only consider colliding with objects in the direction that the focus object is travelling? • Calculating the Normal Plane for the rear-most point would give us an instant cull of many objects

  31. A Solid BSP Tree Tutorial • http://www.gamedev.net/reference/articles/article657.asp

  32. Advanced Collision Detection • http://www.realtimerendering.com/intersections.html • This is a great table for finding algorithms

  33. http://prosjekt.ffi.no/unik-4660/lectures04/chapters/jpgfiles/specular.jpghttp://prosjekt.ffi.no/unik-4660/lectures04/chapters/jpgfiles/specular.jpg Specular Lighting • This is the light that an object reflects into the viewers eye • For this we will need to add a few more variables to our light system

  34. http://www.baylee-online.net/Projects/Raytracing/Algorithms/Glossy-Reflection-Transmissionhttp://www.baylee-online.net/Projects/Raytracing/Algorithms/Glossy-Reflection-Transmission

  35. Creating a cone • A modified version of Lambert’s Cosine law is implemented, giving an easily controlled and calculated light cone. “the radiant intensity observed from a "Lambertian" surface is directly proportional to the cosine of the angle θ between the observer's line of sight and the surface normal.” - Wikipedia

  36. So the intensity of the light drops off as the angle increases. • Light intensity = cos()n • n is an exponent which changes the speed of the falloff for a specular highlight. • A high n will create a very sharp reflection through a small cone • A low n (n is always >=1) will create a much broader cone of reflection.

  37. http://fooplot.com/ Creating a cone

  38. The new variables • View (eye) Position We generate a vector from the surface point to the eye: toEye = view – vertex.position; toEye = Normalize(toEye);

  39. The new jobs: specularPower = vertex.specular.a // a = power // Minimum of 1.0f specularPower = max(specularPower, 1.0f); Float3 reflection = reflect(light.vector, vertex.normal); specularFactor = dot(reflection, toEye); // No specular if light is behind specularFactor = max(specularFactor, 0.0f); // Now we add the exponent specularFactor = pow(specularFactor, specularPower); light += specularFactor * vertex.specular* light.specular; Return light;

  40. Starcraft 2 http://www.gamasutra.com/view/news/28433/Blizzard_Reveals_StarCraft_II_Subscription_Option_For_Emerging_Markets.php

More Related