question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixed order of elements in matrix

See original GitHub issue

When initializing a matrix with all elements, the order of these elements corresponds to row-wise iteration, whereas actual indexing of the matrix elements is done column-wise. That is confusing, and may easily cause errors.

Example code:

var matrix1 = new THREE.Matrix4(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
for (var i = 0; i < matrix1.elements.length; i++) {
  console.log("matrix1[" + i + "] = " + matrix1.elements[i]);
}

Example output:

matrix1[0] = 0
matrix1[1] = 4
matrix1[2] = 8
matrix1[3] = 12
matrix1[4] = 1
matrix1[5] = 5
matrix1[6] = 9
matrix1[7] = 13
matrix1[8] = 2
matrix1[9] = 6
matrix1[10] = 10
matrix1[11] = 14
matrix1[12] = 3
matrix1[13] = 7
matrix1[14] = 11
matrix1[15] = 15 

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Sep 10, 2013

I would leave it the way it is, personally. The API is human-readable.

shadowMatrix.set( 0.5, 0.0, 0.0, 0.5,
                  0.0, 0.5, 0.0, 0.5,
                  0.0, 0.0, 0.5, 0.5,
                  0.0, 0.0, 0.0, 1.0 );
1reaction
gero3commented, Aug 27, 2013

That’s historically grown.

In r1 the math library was row major completely but the graphics renderer was column major which meant we had to transpose the matrices every frame.

In r49 the math library got update to make use of Float32Array and column major to have no problems with the graphics renderer. To make sure the transition would be easy we kept every methods arguments the same because a lot of code was already working with it and not a lot of code needed to know the elements exact value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mix order of rows in a matrix? - MATLAB Answers
Assuming that your matrix has the same number of rows as your vector has elements, then you just need to use the same...
Read more >
Rearrange all elements of array which are multiples of x in ...
Given an array of integers 'arr' and a number x, the task is to sort all the elements which are multiples of x...
Read more >
Finding the order of an element in GL(2,R)
My difficulty lies with problem 1b where I am given a matrix A= (0−110) and asked to find its order. Now I am...
Read more >
Mixed array - APL Wiki
In nested array theory, a mixed array is one that mixes simple scalar characters and numbers, or simple scalars with arrays which are...
Read more >
Mixed finite element method - Wikipedia
In numerical analysis, the mixed finite element method, is a type of finite element method in which extra fields to be solved are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found