view frustum in the context of head tracking

14
View frustum in the context of head tracking How to define a correct frustum, thus the projection matrix? Naëm Baron - 2014

Upload: n-baron

Post on 13-Jul-2015

220 views

Category:

Engineering


2 download

TRANSCRIPT

Page 1: View frustum in the context of head tracking

View frustum in the context of head tracking

How to define a correct frustum, thus the projection matrix?

Naëm Baron - 2014

Page 2: View frustum in the context of head tracking

Regular frustum

Far clip distance

Near clip distance

Frustum

Camera/HeadTop View

A frustum illustrate a Projection matrix usually defined by :

near clip distance, far clip distance, FOV and aspect ratio.

Naëm Baron - 2014

Page 3: View frustum in the context of head tracking

Projection matrix PThe Projection matrix P is usually defined with the following relations :

Naëm Baron - 2014

𝑷 = 𝑓 𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝐹𝑂𝑉𝑦, 𝑟𝑎𝑡𝑖𝑜

or

𝑷 = 𝑓 𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑛𝑒𝑎𝑟𝑃𝑙𝑎𝑛𝑒𝑊𝑖𝑑𝑡ℎ, 𝑛𝑒𝑎𝑟𝑃𝑙𝑎𝑛𝑒𝐻𝑒𝑖𝑔ℎ𝑡

Page 4: View frustum in the context of head tracking

Frustum’s extent

Left extent

Right extent

Top View

Far clip distance

Near clip distance

Camera/Head

A Frustum can also be defined using the “extents” at near clip distance in place of the FOV + aspect ratio.

Naëm Baron - 2014

Page 5: View frustum in the context of head tracking

Frustum’s extent

Left extent

Front View

Right extent

Bottom extent

Top extent

Left/right/top/bottom extent is the distance from the center…

in the left/right/top/bottom direction at the near clip distance.

Far clip plane

Near clip plane

Naëm Baron - 2014

Page 6: View frustum in the context of head tracking

Projection matrix PA new relations to define P:

Naëm Baron - 2014

𝑷 = 𝑓 𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝐹𝑂𝑉𝑦, 𝑟𝑎𝑡𝑖𝑜

or

𝑷 = 𝑓 𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑛𝑒𝑎𝑟𝑃𝑙𝑎𝑛𝑒𝑊𝑖𝑑𝑡ℎ, 𝑛𝑒𝑎𝑟𝑃𝑙𝑎𝑛𝑒𝐻𝑒𝑖𝑔ℎ𝑡

or

𝑷 = 𝑓𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒,

𝑙𝑒𝑓𝑡𝐸𝑥𝑡𝑒𝑛𝑡, 𝑟𝑖𝑔ℎ𝑡𝐸𝑥𝑡𝑒𝑛𝑡, 𝑡𝑜𝑝𝐸𝑥𝑡𝑒𝑛𝑡, 𝑏𝑜𝑡𝑡𝑜𝑚𝐸𝑥𝑡𝑒𝑛𝑡

Page 7: View frustum in the context of head tracking

Adding the screen

Far clip distance

Near clip distance

Camera/Head

Screen

Top View

In immersive virtual reality system like CAVE™ or Wall, the frustum has to “fit” to the screen…

Naëm Baron - 2014

Page 8: View frustum in the context of head tracking

Adding the screen

Far clip distance

Top View

In immersive virtual reality system like CAVE™ or Wall, the frustum has to “fit” to the screen… …wherever the Camera/Head is positioned.

Naëm Baron - 2014

Extents: Left ≠ Right

Asymmetric frustum

Page 9: View frustum in the context of head tracking

Projection matrix PWhich function to choose ?

Naëm Baron - 2014

𝑷 = 𝑓 𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝐹𝑂𝑉𝑦, 𝑟𝑎𝑡𝑖𝑜

or

𝑷 = 𝑓 𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑛𝑒𝑎𝑟𝑃𝑙𝑎𝑛𝑒𝑊𝑖𝑑𝑡ℎ, 𝑛𝑒𝑎𝑟𝑃𝑙𝑎𝑛𝑒𝐻𝑒𝑖𝑔ℎ𝑡

or

𝑷 = 𝑓𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒, 𝑓𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒,

𝑙𝑒𝑓𝑡𝐸𝑥𝑡𝑒𝑛𝑡, 𝑟𝑖𝑔ℎ𝑡𝐸𝑥𝑡𝑒𝑛𝑡, 𝑡𝑜𝑝𝐸𝑥𝑡𝑒𝑛𝑡, 𝑏𝑜𝑡𝑡𝑜𝑚𝐸𝑥𝑡𝑒𝑛𝑡

Symmetric frustum only

Asymmetric frustum

How to define the extents according to the head and screen positions ?How to compute P using the extents ?

Page 10: View frustum in the context of head tracking

To get the projection matrix according to the head position :

1. Define the head position relative to the screen center. ℎ𝑒𝑎𝑑𝑃𝑜𝑠𝑆𝑐𝑟𝑒𝑒𝑛 = 𝑠𝑐𝑟𝑒𝑒𝑛. 𝐼𝑛𝑣𝑒𝑟𝑠𝑒𝑇𝑟𝑎𝑛𝑠𝑓𝑜𝑟𝑚 ℎ𝑒𝑎𝑑𝑃𝑜𝑠𝑊𝑜𝑟𝑙𝑑 *

2. Using the screen size (width, height) you can define the frustum’s extent at the screen distance.

𝑠𝑐𝑟𝑒𝑒𝑛𝐸𝑥𝑡𝑒𝑛𝑡. 𝐿𝑒𝑓𝑡 = −𝑤𝑖𝑑𝑡ℎ

2+ ℎ𝑒𝑎𝑑𝑃𝑜𝑠𝑆𝑐𝑟𝑒𝑒𝑛. 𝑋 **

3. Convert the frustum’s extent at screen distance in frustum’s extent at near clip distance. Using Intercept theorem:

𝑒𝑥𝑡𝑒𝑛𝑡. 𝐿𝑒𝑓𝑡 =𝑛𝑒𝑎𝑟𝐶𝑙𝑖𝑝𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒

𝑠𝑐𝑟𝑒𝑒𝑛𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒∗ 𝑠𝑐𝑟𝑒𝑒𝑛𝐸𝑥𝑡𝑒𝑛𝑡. 𝐿𝑒𝑓𝑡

4. Compute the Projection matrix using the near clip extents.____________________________________________________________________________________________________________

projMtx.m00 = (2.0f * nearClipDistance) / (extent.Right - extent.Left);

projMtx.m02 = (extent.Right + extent.Left) / (extent.Right - extent.Left);

projMtx.m11 = (2.0f * nearClipDistance) / (extent.Top - extent.Bottom);

projMtx.m12 = (extent.Top + extent.Bottom) / (extent.Top - extent.Bottom);

projMtx.m22 = -(farClipDistance + nearClipDistance) / (farClipDistance - nearClipDistance);

projMtx.m23 = (-2.0f * farClipDistance * nearClipDistance) / (farClipDistance - nearClipDistance);

projMtx.m32 = -1.0f;

____________________________________________________________________________________________________________

P from head and screen positions

* InverseTransform convert position from world space to screen local space** X, Y or Z depending on the coordinate system

Naëm Baron - 2014

Page 11: View frustum in the context of head tracking

Intercept Theorem ?

A

B

C

D

E

𝐷𝐸 ‖ 𝐵𝐶

𝐴𝐷

𝐷𝐵=

𝐴𝐸

𝐸𝐶

and

𝑫𝑬

𝑩𝑪=[𝑨𝑫]

[𝑨𝑩]

Math proof: http://math.stackexchange.com/questions/92929/similar-triangle-theorem-in-the-incommensurable-case/92933#92933

Simple explanation:∠BAC and ∠DAE are “proportionally” the same.Thus, the sides are also “proportionally” the same.In fine, the respective quotients of the sides are equals.

Naëm Baron - 2014

Page 12: View frustum in the context of head tracking

Back to frustum

Top View

We can use the “Intercept Theorem” to convert the screen extents to near clip extents.

A

BC

DE

𝐴𝐷 = 𝑁𝑒𝑎𝑟 𝑐𝑙𝑖𝑝 𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒𝐴𝐵 = 𝑆𝑐𝑟𝑒𝑒𝑛 𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒𝐵𝐶 = 𝐿𝑒𝑓𝑡 𝑠𝑐𝑟𝑒𝑒𝑛′𝑠 𝑒𝑥𝑡𝑒𝑛𝑡𝑫𝑬 = ?

𝐷𝐸 =𝐴𝐷

𝐴𝐵∗ 𝐵𝐶

𝐷𝐸 is the left extent at near clip distance.

Naëm Baron - 2014

Page 13: View frustum in the context of head tracking

Final note

At each tracking frame (not rendering frame):

Naëm Baron - 2014

1

• Define the head position relative to the screen center.

2

• Define the frustum’s extent at the screen distance.

3

• Extent at screen distance Extent at near clip distance.

4• Compute Projection matrix

Left, Right, Top, Bottom

Left, Right, Top, Bottom

Page 14: View frustum in the context of head tracking

return;

Naëm Baron

Naem.Baron—gmail•com

Additional resources:http://paulbourke.net/stereographics/stereorender/http://schabby.de/projection-matrix/http://simply3d.wordpress.com/2009/05/30/perspective-projection-part-3/http://msdn.microsoft.com/en-us/library/windows/desktop/bb205353(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/dd373537(v=vs.85).aspx