Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RyuK · Jun 09, 2015 at 05:12 AM · vectormatrixmatrix4x4

Why Matrix4x4.MultiplyPoint does row-major access while Matrix4x4 is column-major?

Hello, http://docs.unity3d.com/ScriptReference/Matrix4x4.html says "Matrices in unity are column major." but the implementation of Matrix4x4.MultiplyPoint seems to do row-major access by multiplying row vectors of the matrix with the column vector. What's the reason behind this implementation?

 public Vector3 MultiplyPoint(Vector3 v)
 {
     Vector3 result;
     result.x = this.m00 * v.x + this.m01 * v.y + this.m02 * v.z + this.m03;
     result.y = this.m10 * v.x + this.m11 * v.y + this.m12 * v.z + this.m13;
     result.z = this.m20 * v.x + this.m21 * v.y + this.m22 * v.z + this.m23;
     float num = this.m30 * v.x + this.m31 * v.y + this.m32 * v.z + this.m33;
     num = 1f / num;
     result.x *= num;
     result.y *= num;
     result.z *= num;
     return result;
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 09, 2015 at 05:45 AM

I have to admit that the internal layout is really strange but all methods / operators work on the same basis.

First of all the float values are ordered like this:

 m00
 m01
 m02
 m03
 m10
 ...

However the declaration order has no meaning at all. They have defined an indexer which accesses them in this order:

 0 -> m00
 1 -> m10
 2 -> m20
 3 -> m30
 4 -> m01
 5 -> m02
 ...

The row / column indexer just use this logic:

 this[row + column*4].

From this information we can say that the first number in the variable names referes to the row index and the second to the column index: "m(r)(c)"

 m00
  ||
  |\__ column index
  \___ row index

So the first column is made up of those values: m00 m10 m20 m30

According to the indexer layout it's column major and that's also how it's used. The only thing that's actually row major is the actual memory layout of the float values in the struct. That might be necessary for the native code. However since in C# you can't access the fields in declaration order the order of the index

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pld · Apr 25, 2016 at 10:31 PM 0
Share

The floats are not stored in row-major order (m00, m01, m02, m03...), they are stored in column-major order (m00, m10, m20, m30, ...). You can verify this with ilspy/dnspy or by casting a $$anonymous$$atrix4x4* to a float* and exa$$anonymous$$ing it in detail.

Thus, it does make sense: indexing and underlying storage are both column-major.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How is a gameobject rotated when you set it's forward? 0 Answers

InverseTransformPoint via Matrices? 2 Answers

Creating a Matrix4x4 from an Object's Transform 1 Answer

Matrix rotation of a Vector3 around three planes of rotation 1 Answer

WorldToViewportPoint problem 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges