About the appendxxx and prependxxx in the Matrix3D of AS3

Source: Internet
Author: User

Recently in the 3D related to some of the foundation, because make AS3 so many years, decided to 3D base this piece or from AS3 start, 3D game development This piece from u3d start, pull away, When studying Matrix3D class, we found that some methods of matrix processing transformation are divided into appendxxx and prependxxx two kinds, the explanation in the Help document is the difference between the post and the front, so it is unclear, so I decided to take some time to get this thing.

Directly on the code, the last line of comments is the execution result of the first four lines of code:

1 varM:matrix3d =NewMatrix3D ();2M.appendrotation (45, Vector3d.x_axis);3M.appendtranslation (10, 20, 30);4 Trace (M.decompose ());5 //Vector3D, Vector3D (0.7853981852531433, 0, 0), Vector3D (1, 1, 1 )6 7 varM:matrix3d =NewMatrix3D ();8M.appendtranslation (10, 20, 30);9M.appendrotation (45, Vector3d.x_axis);Ten Trace (M.decompose ()); One //Vector3D ( -7.071067810058594, 35.35533905029297), Vector3D (0.7853981852531433, 0, 0), Vector3D (1, 1, 1) A  - varM:matrix3d =NewMatrix3D (); -M.prependrotation (45, Vector3d.x_axis); theM.prependtranslation (10, 20, 30); - Trace (M.decompose ()); - //Vector3D ( -7.071067810058594, 35.35533905029297), Vector3D (0.7853981852531433, 0, 0), Vector3D (1, 1, 1) -  + varM:matrix3d =NewMatrix3D (); -M.prependtranslation (10, 20, 30); +M.prependrotation (45, Vector3d.x_axis); A Trace (M.decompose ()); at //Vector3D, Vector3D (0.7853981852531433, 0, 0), Vector3D (1, 1, 1 )

The above example shows that the difference between the two is that the order of operations is different, and the order of prependxxx is reversed, OK, let's look at an example:

1 varM:matrix3d =NewMatrix3D ();2M.appendrotation (45, Vector3d.x_axis);3M.appendtranslation (10, 15, 20);4M.appendtranslation (10, 15, 20);5M.appendrotation (45, Vector3d.y_axis);6M.appendtranslation (10, 15, 20);7M.appendtranslation (10, 20, 30);8M.appendrotation (45, Vector3d.z_axis);9 Trace (M.decompose ());Ten //Vector3D ( -1.8198051452636719, 90.10408020019531, 64.14213562011719), Vector3D (0.7853981852531433, 0.7853982448577881, 0.7853981852531433), Vector3D (1, 1, 1) OneM.appendtranslation (10, 20, 30); A Trace (M.decompose ()); - //Vector3D (8.180194854736328, 110.10408020019531, 94.14213562011719), Vector3D (0.7853981852531433, 0.7853982448577881, 0.7853981852531433), Vector3D (1, 1, 1) -  the varM:matrix3d =NewMatrix3D (); -M.appendrotation (45, Vector3d.x_axis); -M.appendtranslation (10, 15, 20); -M.appendtranslation (10, 15, 20); +M.appendrotation (45, Vector3d.y_axis); -M.appendtranslation (10, 15, 20); +M.appendtranslation (10, 20, 30); AM.appendrotation (45, Vector3d.z_axis); at Trace (M.decompose ()); - //Vector3D ( -1.8198051452636719, 90.10408020019531, 64.14213562011719), Vector3D (0.7853981852531433, 0.7853982448577881, 0.7853981852531433), Vector3D (1, 1, 1) -M.prependtranslation (10, 20, 30); - Trace (M.decompose ()); - //Vector3D (25.857860565185547, 107.78174591064453, 82.0710678100586), Vector3D (0.7853981852531433, 0.7853982448577881, 0.7853981852531433), Vector3D (1, 1, 1)

All in all, appendxxx is more suitable for our logic, that is, to add a transformation on a previous basis, while prependxxx can be considered as a new matrix to add the current transformation, and then add all of its own transformations, that is, prependxxx the added transformation is always before all the conversion;

Or appendxxx can be treated as global coordinates, and prependxxx can be treated as local coordinates.

About the appendxxx and prependxxx in the Matrix3D of AS3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.