Presentation is loading. Please wait.

Presentation is loading. Please wait.

GAM 325/425: Applied 3D Geometry

Similar presentations


Presentation on theme: "GAM 325/425: Applied 3D Geometry"— Presentation transcript:

1 GAM 325/425: Applied 3D Geometry
Lecture 3B: Using Affine Transformations

2 Coordinate Frames There are 3 important coordinate frames:
World Space: Fixed origin & axes Reference for relative position and orientation between objects Object (Model) Space: Origin sets for the ‘center’ of the model geometry Sets the up/forward orientation of the model Camera Space: More on this in a future lecture Problem: There are no conventions or standards for any of these spaces. Which is the up axis? Which is the forward one? World space axis are often determined by the graphics library but object space is influenced by the 3D modelling software Getting artists and programmers to stick to specific conventions is crucial! If the origin for the 3D model isn’t right, turning or positioning in game will be incorrect If the ‘forward’ and ‘up’ alignment of the model is wrong, game motion will be incorrect

3 Object Space Sidebar: We’ll keep our example in the xz-plane for simplicity, but the principle applies to the full 3D space In general, objects will be composed of a collection of point appropriately centered at the origin (defining the object’s Local Space). We will always observe the following conventions: Up along the y axis Forward along the z axis The object’s placement relative to the origin depends on the needs of the application Placing an object in World Space means applying some transform W to scale/rotate/translate the object Example: If 𝐖= 𝐓 (0,0,7) then applying W to each point of the object will translate it 7 unit along the z axis x 𝐓 (0,0,7) 𝑃 1 𝑃 2 𝑃 3 𝑃 1 𝑃 2 𝑃 3 z

4 World Space: Order of Operation
In most cases (for us!), W will be a combination of scale, rotation and translation. But the order of operation is important. Example: Compare 𝐖 1 = 𝐓 (0,0,7) 𝐑 𝐲, 𝝅 𝟐 versus 𝐖 2 = 𝐑 𝐲, 𝝅 𝟐 𝐓 (0,0,7) 𝐖 1 works as expected, but 𝐖 2 induces an unexpected translation In general, some order of operations have unwanted side effects… z x 𝑃 1 𝑃 2 𝑃 3 z x 𝑃 1 𝑃 2 𝑃 3 𝑃 1 𝑃 2 𝑃 3 𝑃 1 𝑃 2 𝑃 3

5 World Space: Order of Operation
To avoid unwanted side effect, world matrices are usually constructed as follow: 𝐖=𝐓𝐑𝐒 Remember: these matrices are applied in right to left order First scale the object, then apply rotation and finally translate In terms of applications: for fixed/unmoving objects in a scene, keeping the combined W form would work fine. However, for more dynamic objects that need to have their position/rotation (and maybe scale) continually modified, the combined form gets unwieldy: Given W, how do we move forward? How do we rotate relative to the local space? Two solutions: Use Matrix Decomposition to extract T, R and S. (Section or my document) Avoid the costly decomposition by keeping all three transform type separately Warning: When using row vectors, we reverse the order as W = SRT. See LASR page

6 Avoiding Matrix Decomposition
Assume any scaling done is uniform: same amount of scaling across all three axis. This covers the vast majority of the situations we will encounter But 𝐒 𝑎,𝑎,𝑎 =𝑎𝐈 This means uniform scaling are commutative with rotations 𝐑 𝑛 𝐒 𝑛 𝐑 𝑛−1 𝐒 𝑛−1 … 𝐑 0 𝐒 0 = (𝐒 𝑛 𝐒 𝑛−1 … 𝐒 0 ) 𝐑 𝑛 𝐑 𝑛−1 … 𝐑 0 = 𝑎 𝑛 𝑎 𝑛−1 … 𝑎 0 𝐑 𝑛 𝐑 𝑛−1 … 𝐑 0 =𝑎𝐑 Therefore, for objects that need to be updated frequently, keep track of: Changes to the (uniform) scale factor s Current rotation matrix R Current translation vector t Update the above values as necessary When the world matrix W is needed, reconstruct it in TRS form using the following transforms: 𝐖= 𝐈 𝐭 𝟎 𝑇 𝟏 𝐑 𝟎 𝟎 𝑇 𝑠𝐈 𝟎 𝟎 𝑇 1 = 𝑠𝐑 𝐭 𝟎 𝑇 1

7 Avoiding Matrix Decomposition: Example
z x 𝑃 1 𝑃 2 𝑃 3 Step 0: initial placement: 𝑠 0 =1 𝐑 0 = 𝐑 𝐲, 𝝅 𝟐 𝐭 0 =(−6,0,6) Step 1: Moving fwd by 12 then rotate by 𝐑 𝐲, 𝝅 𝟐 : 𝑠 1 = 𝑠 0 , 𝐑 1 = 𝐑 𝐲, 𝝅 𝟐 𝐑 0 = 𝐑 𝐲,𝝅 What about 𝐭 𝟏 ? 𝐖 0 𝑃 1 = 𝑠 𝐑 0 𝐭 0 𝟎 𝑇 = 𝑠 𝐑 − = − = − And similarly for the other two points z x 𝑃 1 𝑃 2 𝑃 3 𝐭 1 = 𝐭 0 + 𝐑 = − = 𝐖 1 𝑃 1 = 𝑠 𝐑 1 𝐭 1 𝟎 𝑇 = 𝑠 𝐑 = − = And similarly for the other two points

8 Avoiding Matrix Decomposition: Example
8 z x 𝑃 1 𝑃 2 𝑃 3 Step 2: Again fwd by 12 then rotate by 𝐑 𝐲, 𝝅 𝟐 : 𝑠 2 = 𝑠 1 , 𝐑 2 = 𝐑 𝐲, 𝝅 𝟐 𝐑 𝟏 = 𝐑 𝐲, 𝟑𝝅 𝟐 Step 3: Again fwd by 12 then rotate by 𝐑 𝐲, 𝝅 𝟐 : 𝑠 3 = 𝑠 2 , 𝐑 3 = 𝐑 𝐲, 𝝅 𝟐 𝐑 𝟐 = 𝐑 𝐲,𝟐𝝅 𝐭 2 = 𝐭 1 + 𝐑 𝟏 = −12 = 6 0 −6 𝐖 2 𝑃 1 = 𝑠 𝐑 𝟐 𝐭 𝟐 𝟎 𝑇 = 𝑠 𝐑 𝟐 − = − − = 4 0 −6 1 And similarly for the other two points z x 𝑃 1 𝑃 2 𝑃 3 𝐭 3 = 𝐭 𝟐 + 𝐑 𝟐 = 6 0 −6 + − = −6 0 −6 𝐖 𝟑 𝑃 1 = 𝑠 𝐑 3 −6 0 −6 𝟎 𝑇 = 𝑠 𝐑 −6 0 − = −6 0 − = −6 0 −4 1 And similarly for the other two points

9


Download ppt "GAM 325/425: Applied 3D Geometry"

Similar presentations


Ads by Google