Quaternions Paul Taylor 2010. Swizzle What is a swizzle?
-
Upload
cori-small -
Category
Documents
-
view
216 -
download
0
Transcript of Quaternions Paul Taylor 2010. Swizzle What is a swizzle?
![Page 1: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/1.jpg)
Quaternions
Paul Taylor 2010
![Page 2: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/2.jpg)
Swizzle
• What is a swizzle?
![Page 3: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/3.jpg)
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
![Page 4: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/4.jpg)
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
![Page 5: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/5.jpg)
Euler Angles (Yaw Pitch Roll)
Pros: Easy to visualiseCons: Gimbal LockIf 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.
![Page 6: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/6.jpg)
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
![Page 7: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/7.jpg)
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 vectorThe vector xyz should satisfy X2 + Y2 + Z2 = XYZ = -1 Where s2 + X2 + Y2 + Z2 = 1 the quaternion can be
considered a rotation.
![Page 8: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/8.jpg)
Quaternion Addition
![Page 9: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/9.jpg)
Quaternion Subtraction
![Page 10: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/10.jpg)
Quaternion Multiplication
![Page 11: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/11.jpg)
Quaternion Division
• Don’t divide by Zero!
![Page 12: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/12.jpg)
Quaternion Advantages
StorageMatrix must be at minimum 3x3 typically stored
as a 4x4.A quaternion may be stored as 4 values.Chaining (preparing) an xyz rotation:
Method # multiplies # add/subtracts
total operations
Rotation matrices
27 18 45Quaternions 16 12 28
![Page 13: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/13.jpg)
• Performing an xyz Rotation
Method # multiplies
# add/subtracts
# sin/cos total operations
Rotation matrix
9 6 0 15Quaternions
21 18 0 39Angle/axis 23 16 2 41
![Page 14: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/14.jpg)
Smooth rotation interpolation
• Ideal for animation• LERPING between one rotation and a second
will take the shortest path using a quaternion
![Page 15: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/15.jpg)
Collision Detection
• What is it?
• What does it need to be?– Precise– Efficient– Fast
![Page 16: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/16.jpg)
What collides?
• Almost everything• This would result in roughly n2 different
collisions to detect each frame.
![Page 17: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/17.jpg)
Cheating the system
• We CAN mathematically check every single polygon against every other.
• Just not in this lifetime!
![Page 18: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/18.jpg)
Bounding Spheres
• Collision if r1 + r2 < distance from P1 to P2
http://www.gamasutra.com/view/feature/3190/advanced_collision_detection_.php?page=2
![Page 19: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/19.jpg)
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
![Page 20: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/20.jpg)
A strange object
![Page 21: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/21.jpg)
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
![Page 22: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/22.jpg)
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 aseparating plane
Convex Only!!!
![Page 23: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/23.jpg)
Stationary Objects
• Do not move, so we do not have to detect collisions by the object, only on the object!
![Page 24: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/24.jpg)
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
![Page 25: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/25.jpg)
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
![Page 26: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/26.jpg)
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
![Page 27: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/27.jpg)
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
![Page 28: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/28.jpg)
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?
![Page 29: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/29.jpg)
GPU Based Collision Detection
• There is a bit of research in this area– GPU only solutions– CPU-GPU hybrids
![Page 30: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/30.jpg)
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
![Page 31: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/31.jpg)
A Solid BSP Tree Tutorial
• http://www.gamedev.net/reference/articles/article657.asp
![Page 32: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/32.jpg)
Advanced Collision Detection
• http://www.realtimerendering.com/intersections.html
• This is a great table for finding algorithms
![Page 33: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/33.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
http://prosjekt.ffi.no/unik-4660/lectures04/chapters/jpgfiles/specular.jpg
![Page 34: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/34.jpg)
http://www.baylee-online.net/Projects/Raytracing/Algorithms/Glossy-Reflection-Transmission
![Page 35: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/35.jpg)
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
![Page 36: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/36.jpg)
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.
![Page 37: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/37.jpg)
Creating a conehttp://fooplot.com/
![Page 38: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/38.jpg)
The new variables
• View (eye) PositionWe generate a vector from the surface point to
the eye:toEye = view – vertex.position;toEye = Normalize(toEye);
![Page 39: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/39.jpg)
The new jobs:specularPower = vertex.specular.a // a = power// Minimum of 1.0fspecularPower = max(specularPower, 1.0f);Float3 reflection = reflect(light.vector, vertex.normal);specularFactor = dot(reflection, toEye);// No specular if light is behindspecularFactor = max(specularFactor, 0.0f);// Now we add the exponentspecularFactor = pow(specularFactor, specularPower);light += specularFactor * vertex.specular * light.specular;Return light;
![Page 40: Quaternions Paul Taylor 2010. Swizzle What is a swizzle?](https://reader035.fdocuments.in/reader035/viewer/2022062719/56649ee55503460f94bf426d/html5/thumbnails/40.jpg)
Starcraft 2
http://www.gamasutra.com/view/news/28433/Blizzard_Reveals_StarCraft_II_Subscription_Option_For_Emerging_Markets.php