- 118 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' Quaternions' - asher-maynard

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

Presentation Transcript

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

- 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

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.

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

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.

Quaternion Division

- Don’t divide by Zero!

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:

Smooth rotation interpolation

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

Collision Detection

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

What collides?

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

Cheating the system

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

Bounding Spheres

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

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

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

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

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

Stationary Objects

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

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

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

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

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

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?

GPU Based Collision Detection

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

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

A Solid BSP Tree Tutorial

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

Advanced Collision Detection

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

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

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

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

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.

The new variables

- View (eye) Position

We generate a vector from the surface point to the eye:

toEye = view – vertex.position;

toEye = Normalize(toEye);

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;

Starcraft 2

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

Download Presentation

Connecting to Server..