<div dir="auto">Furthermore, in my JavaScript code, I used the translations in the right column for multiplication, AFAIK, but I don’t recall matrix order in multiplication.  Plus, I rarely use SFMatrix4f.</div><div dir="auto"><br></div><div dir="auto">Can both ways work if SFMatrix4f isn’t used?</div><div dir="auto"><br></div><div dir="auto">Note that I haven’t see matrix multiplication in X3DJSAIL or X3DPSAIL.</div><div dir="auto"><br></div><div dir="auto">John </div><div dir="auto"><br></div><div dir="auto"><br></div><div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Nov 23, 2025 at 7:54 PM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Not to ruffle anyone’s feathers, but doesn’t this all depend on which side you are multiplying on?  If you multiply with a vector on the left side, if I put </div><div dir="auto"><br></div><div dir="auto"><div><span style="color:rgb(0,0,0);font-family:'arial',sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">1 0 0 0</span><div style="color:rgb(0,0,0);font-family:'arial',sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">0 1 0 0</div><div style="color:rgb(0,0,0);font-family:'arial',sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">0 0 1 0</div><span style="color:rgb(0,0,0);font-family:'arial',sans-serif;font-size:14px;font-style:normal;font-weight:400;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">1 2 3 1</span></div><br></div><div dir="auto">On the right side of a multiplication, and multiply by</div><div dir="auto"><br></div><div dir="auto">1 1 1 1</div><div dir="auto"><br></div><div dir="auto">I get </div><div dir="auto"><br></div><div dir="auto">2 3 4 1</div><div dir="auto"><br></div><div dir="auto">Which is correct </div><div dir="auto"><br></div><div dir="auto">If I put this vector to the right of the matrix:</div><div dir="auto"><br></div><div dir="auto">1</div><div dir="auto">1</div><div dir="auto">1</div><div dir="auto">1</div><div dir="auto"><br></div><div dir="auto">I get</div><div dir="auto"><br></div><div dir="auto">1</div><div dir="auto">1</div><div dir="auto">1</div><div dir="auto">7</div><div dir="auto"><br></div><div dir="auto">When I multiply the matrix and the vector, which is wrong.</div><div dir="auto"><br></div><div dir="auto">But I could make similar arguments for translations in the last column, and indeed, that’s how we did it in school.</div><div dir="auto"><br></div><div dir="auto">So the moral is, not only get your matrix cell position right, but also get your matrix multiplication right.</div><div dir="auto"><br></div><div dir="auto">I am referring to row times column multiplication of matrices.  If you do column times row, god help us.  Do we do left to right or right to left?</div><div dir="auto"><br></div><div dir="auto">Am I wrong?</div><div dir="auto"><br></div><div dir="auto">Isn’t there a common understanding by mathematicians that we should be following?</div><div dir="auto"><br></div><div dir="auto">John </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Nov 23, 2025 at 4:54 AM Michalis Kamburelis via x3d-public <<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:Arial,sans-serif;font-size:14px">An update about this: It seems I was confused. Disregard parts / all of my last email! And what X3DOM is doing is correct.</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">Thanks to <span>Elmar</span>, the reporter of <span><a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/castle-model-viewer/issues/122" target="_blank">https://github.com/castle-engine/castle-model-viewer/issues/122</a></span> , he pointed me to a statement in X3D spec:</div><div style="font-family:Arial,sans-serif;font-size:14px"><span><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px"><span><i>    "Since these data types are commonly used for 3D transformation matrices, translation values are stored in the fourth row"</i></span></div><div style="font-family:Arial,sans-serif;font-size:14px"><span><i><br></i></span></div><div style="font-family:Arial,sans-serif;font-size:14px"><span>So this contradicts some of my statements in the last mail, sorry for the noise!</span></div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">
    <div>
        
            </div>
    
            <div>
        
            </div></div><div style="font-family:Arial,sans-serif;font-size:14px">This means that the right way to specify translation by (1,2,3) in a matrix in X3D is </div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px"><span>1 0 0 0</span><div><span>0 1 0 0</span></div><div><span>0 0 1 0</span></div><span>1 2 3 1</span></div><div style="font-family:Arial,sans-serif;font-size:14px"><span><br></span></div><div style="font-family:Arial,sans-serif;font-size:14px">This means that</div><div style="font-family:Arial,sans-serif;font-size:14px"><ul style="margin-top:0px;margin-bottom:0px"><li style="list-style-type:"- ""><span>VRML 1.0 and X3D way of storing matrix in a file is the same.</span></li><li style="list-style-type:"- ""><span>X3DOM approach is correct.</span></li><li style="list-style-type:"- ""><span>Castle Game Engine / Castle Model Viewer past approach was correct, and my "fix" last week actually made it invalid... argh, I made a bubu :) I have now reverted my change. </span></li><li style="list-style-type:"- ""><span>_Now_ <span>Castle Game Engine / Castle Model Viewer</span> approach is again correct, and matching X3DOM.</span></li></ul><div><br></div><div>Sorry everyone for the noise :) I'm smarter now, and happy to have people testing <span>Castle Game Engine / Castle Model Viewer</span> and quickly pointing out my mistake! :)</div><div><br></div><div>I have updated the docs and testcases to be all correct, so maybe at least this helps someone to validate their browsers:</div><div><br></div><div><span>- <a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/castle-engine/tree/master/tests/data/matrix_vrml_x3d_format" target="_blank">https://github.com/castle-engine/castle-engine/tree/master/tests/data/matrix_vrml_x3d_format</a></span><div><span>- testcases:</span></div><div><span>    - <a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform.x3d" target="_blank">https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform.x3d</a></span></div><div><span>    - <a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform.x3dv" target="_blank">https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform.x3dv</a></span></div><span>    - <a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform_x3dom.html" target="_blank">https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform_x3dom.html</a></span></div><div><span><br></span></div><div><span>Regards,</span></div><div><span>Michalis</span></div></div><div>
        On Sunday, November 23rd, 2025 at 01:38, Michalis Kamburelis <<a href="mailto:michalis@castle-engine.io" target="_blank">michalis@castle-engine.io</a>> wrote:<br>
        <blockquote type="cite">
            <div style="font-family:Arial,sans-serif;font-size:14px">Short version: Let's make sure our X3D browsers honor the order of values when reading SFMatrix*, MFMatrix* fields :)</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px"><ul style="margin-top:0px;margin-bottom:0px"><li style="list-style-type:"- ""><span><span>Classic encoding link: </span><span><a rel="noreferrer nofollow noopener" href="https://www.web3d.org/documents/specifications/19776-2/V3.3/Part02/EncodingOfFields.html#SFMatrix4f" target="_blank">https://www.web3d.org/documents/specifications/19776-2/V3.3/Part02/EncodingOfFields.html#SFMatrix4f</a></span><br></span></li></ul></div><div style="font-family:Arial,sans-serif;font-size:14px"><div><br></div><div><ul style="margin-top:0px;margin-bottom:0px"><li style="list-style-type:"- ""><span><span>XML encoding link, saying the same:</span><span><a rel="noreferrer nofollow noopener" href="https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/EncodingOfFields.html#SFMatrix4f" target="_blank">https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/EncodingOfFields.html#SFMatrix4f</a></span><br></span></li></ul></div></div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">Longer version:</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">I recently found a mistake in Castle Game Engine's SFMatrix*, MFMatrix* reading/writing code. We were following VRML 1.0 order, while the X3D order (according to both classic and XML encodings specs) is different. So I fixed it, and now <span>Castle Game Engine</span> and Castle Model Viewer follow the proper X3D spec order (when reading/writing X3D).</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px">Namely, X3D classic encoding spec <span>unambiguous</span>ly says:</div><div style="font-family:Arial,sans-serif;font-size:14px"><br></div><div style="font-family:Arial,sans-serif;font-size:14px"><span>    """</span><div><span>    The first four single-precision floating point numbers represent the top row of the matrix.</span></div><div><span>    The second four single-precision floating point numbers represent the second row of the matrix.</span></div><div><span>    """</span></div><div><span><br></span></div><div><span>    Classic encoding link: </span><span><a rel="noreferrer nofollow noopener" href="https://www.web3d.org/documents/specifications/19776-2/V3.3/Part02/EncodingOfFields.html#SFMatrix4f" target="_blank">https://www.web3d.org/documents/specifications/19776-2/V3.3/Part02/EncodingOfFields.html#SFMatrix4f</a></span><div><br></div><div><span>    XML encoding link, saying the same:</span><span><a rel="noreferrer nofollow noopener" href="https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/EncodingOfFields.html#SFMatrix4f" target="_blank">https://www.web3d.org/documents/specifications/19776-1/V3.3/Part01/EncodingOfFields.html#SFMatrix4f</a></span></div><div><span><br></span></div><div>So this means that e.g. translation by 1 2 3 is encoded in X3D in a way that looks similar to how you would write it in math expressions:</div><div><br></div><div>1 0 0 1</div><div>0 1 0 2</div><div>0 0 1 3</div><div>0 0 0 1</div><div><br></div><div>For example, using MatrixTransform node (extension supported by at least Castle Game Engine, X3DOM, Instant Reality), to move object by 1 2 3 you would write this:</div><div><br></div><div><span>MatrixTransform {</span><div><span>  matrix</span></div><div><span>    1 0 0 1</span></div><div><span>    0 1 0 2</span></div><div><span>    0 0 1 3</span></div><div><span>    0 0 0 1</span></div><div><span>  children Shape {</span></div><div><span>    appearance Appearance {</span></div><div><span>      material Material { diffuseColor 0 1 0 }</span></div><div><span>    }</span></div><div><span>    geometry Sphere { }</span></div><div><span>  }</span></div><div><span>}</span></div><span></span></div><div><br></div><div>To complicate testing a bit, </div><div><br></div><div><ul style="margin-top:0px;margin-bottom:0px"><li style="list-style-type:"- ""><span>VRML 1.0 and X3D specifications here say the opposite things. And VRML 2.0 specification doesn't have a matrix field type. So it's probably easy to make the same mistake I did :) See my docs about it on <span><a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/castle-engine/tree/master/tests/data/matrix_vrml_x3d_format" target="_blank">https://github.com/castle-engine/castle-engine/tree/master/tests/data/matrix_vrml_x3d_format</a> .</span><br></span></li></ul></div><div><span><br></span></div><div><ul style="margin-top:0px;margin-bottom:0px"><li style="list-style-type:"- ""><span><span>Moreover, not many nodes in spec actually use the matrix field types. Again, see <span><a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/castle-engine/tree/master/tests/data/matrix_vrml_x3d_format" target="_blank">https://github.com/castle-engine/castle-engine/tree/master/tests/data/matrix_vrml_x3d_format</a></span> where I listed the ones that do. The <span>MatrixTransform</span>, shown above, is only an extension (and I do _not_ propose to make it part of spec; we should encourage authors to use cleaner Transform).</span></span></li></ul></div><div><span><br></span></div><div><span>I have been testing MatrixTransform in X3DOM, and I think X3DOM has a bug (just like CGE did, a month ago!) and it expects matrix in transposed order. See testcase on <span><a rel="noreferrer nofollow noopener" href="https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform_x3dom.html" target="_blank">https://github.com/castle-engine/demo-models/blob/master/x3d/matrix_transform_x3dom.html</a></span> -- only by transposing a matrix I was able to get the correct result.</span></div><div><span><br></span></div><div>Regards,</div><div>Michalis</div></div></div><div style="font-family:Arial,sans-serif;font-size:14px">
    <div></div>

            <div>

            </div>
</div>

        </blockquote><br>
    </div>_______________________________________________<br>
x3d-public mailing list<br>
<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a><br>
<a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" rel="noreferrer" target="_blank">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br>
</blockquote></div></div>
</blockquote></div></div>