Understanding Papervision3D: Matrix3D

Monday, November 24th, 2008 | how it works

This post will cover how you use a Matrix3D to scale, pitch, yaw, roll, and translate 3d objects:

Every 3d object within Papervision3D has a Matrix3D that defines its scale, pitch, yaw, roll, x, y, and z (changing x, y, and z is referred to as “translation” because they move a group of points equally). You will find the Matrix3D in the “transform” property of your 3d object.

The default 4 column by 4 row Matrix 3d with no scale, yaw, pitch, roll, or translation is set up as follows:

1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
0, 0, 0, 1

These values are stored in the “transform” property of your 3d object using a “n”, a integer defining the row, and an integer for the column:

n11, n12, n13, n14
n21, n22, n23, n24
n31, n32, n33, n34
n41, n42, n43, n44

For example: cube.transform.n11

Scale, pitch, yaw, and roll are handled in the first 3 columns and rows of the matrix (play with the explorer above to figure out how it works):

1, 0, 0
0, 1, 0
0, 0, 1

x, y, and z are all handled first 3 numbers in the last column:

0
0
0

The last row hangs around to make Matrix multiplication possible. Have fun playing with the explorer to get a hang of how 3d objects are moved around. I hope to cover some of the Matrix3D math functions in the future.

Tags:

  • To achieve that :

    create a basicRenderView
    add a cube to the root displayObject3D

    the displayObject3D as a public transform matrix as member

    displayObject3D.transform

    if you modify the matrix, the object will be transformed moved or scaled, rotate etc.

    A matrix3D is a composition of 1 matrix and 2 vector.

    a matrix 3D for scale and rotation :

    transform.n11 transform.n21 transform.n31
    transform.n12 transform.n22 transform.n32
    transform.n13 transform.n23 transform.n33

    for n12 mean nXY coordinate of row and columns

    look at that matrix whe can whrite that

    X 0 0
    0 Y 0
    0 0 Z

    changing X Y or Z will scale your transform matrix. When papervision will render one frame
    the obejct will be scale (transform by scale)

    if you want rotate arround X (roll) you will change your matrix like that :

    1 0 0
    0 cosA sin-A
    0 sinA cosA

    because to roll arround X the X vector must remain unchanged
    and the X and Y must be moved (origin unchanged but and position moved)



    rotate arround Y
    cosA 0 sinA
    0 1 0
    sin-A 0 cosA


    rotate arround Z
    cosA sin-A 0
    sinA cosA 0
    0 0 1



    the matrix3D use 2 vector in addition :

    X 0 0 tX
    0 Y 0 tY
    0 0 Z tZ
    X Y Z ?


    tX, tY, tZ are used for translation
    X Y Z are the coordinates
    ? is replaced by 1, but in fact isn't used (I think)
    in papervision the complete transform matrix3D is ordered like that

    transform.n11 transform.n21 transform.n31 transform.n41
    transform.n12 transform.n22 transform.n32 transform.n42
    transform.n13 transform.n23 transform.n33 transform.n43
    transform.n14 transform.n24 transform.n34 transform.n44


    You have to map cursors on the transform matrix and you can map tweener.
    BUT I think this demo use quaternion to avoid Euler gimbal lock
    http://en.wikipedia.org/wiki/Gimbal_lock
    Quaternion is another problem but if you don't use thems X, Y and Z can lock.

    Thx John for your demo. It has help me to understand Matrix and transformation matrix
    and the render pipe of papervision. The response may contain errors or imprecisions,
    in such case feel free to correct it.


    gamedev
    http://www.gamedev.net/reference/articles/artic...
    http://www.gamedev.net/reference/list.asp?categ...
    Mathematic matrix :
    http://en.wikipedia.org/wiki/Matrix_(mathematics)
  • kimpai
    hello, I'm trying to learn a little more about the matrix3D. Anybody know a way to know which side of the cube is facing the camera, through the matrix3D (like front, top, left....). I've seen this solution: http://forum.papervision3d.org/viewtopic.php?f=... but only works when the face is aligned with the axis and does not work when the faces have a different rotation despite being facing the camera. help?? Someone??
  • Dan
    Would you happen to know how to construct a z-up matrix using a papervision y-up one?
  • why no source? can you post the source for this?
    I love digging arround in the code - it's how I learn best, and I would like to see how you integrated a BasicView into a Flex "Application"
  • sliz
    so good!
  • Marcus Booster
    This is great, thanks!
  • zhaohongri
    thanks a lot,:)

    your son is very loveliness
  • John Lindquist
    I saw your request in the requests section. Be patient.
  • zhaohongri
    can you give some example and docs about Quaternion?
blog comments powered by Disqus

Search

Recommended Books

Speaking at FITC Toronto

Recent Comments

 

November 2008
M T W T F S S
    Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...