- 104 Views
- Uploaded on
- Presentation posted in: General

Quaternions

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Quaternions

Paul Taylor 2010

- What is a swizzle?

- 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

- 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

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.

- 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

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.

- Don’t divide by Zero!

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:

- Performing an xyz Rotation

- Ideal for animation
- LERPING between one rotation and a second will take the shortest path using a quaternion

- What is it?
- What does it need to be?
- Precise
- Efficient
- Fast

- Almost everything
- This would result in roughly n2 different collisions to detect each frame.

- We CAN mathematically check every single polygon against every other.
- Just not in this lifetime!

- Collision if r1 + r2 < distance from P1 to P2

http://www.gamasutra.com/view/feature/3190/advanced_collision_detection_.php?page=2

- 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

- 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

- 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!!!

- Do not move, so we do not have to detect collisions by the object, only on the object!

- 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

- 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

- 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

- 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

- The Atari had built-in collision detection in the video chip, this made collisions extremely simple
- Can we do something similar today?

- There is a bit of research in this area
- GPU only solutions
- CPU-GPU hybrids

- 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

- http://www.gamedev.net/reference/articles/article657.asp

- http://www.realtimerendering.com/intersections.html
- This is a great table for finding algorithms

http://prosjekt.ffi.no/unik-4660/lectures04/chapters/jpgfiles/specular.jpg

- 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://www.baylee-online.net/Projects/Raytracing/Algorithms/Glossy-Reflection-Transmission

- 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

- 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.

http://fooplot.com/

- View (eye) Position
We generate a vector from the surface point to the eye:

toEye = view – vertex.position;

toEye = Normalize(toEye);

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;

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