yuccai Posted July 17, 2014 Share Posted July 17, 2014 Hello,I'd like to know if there is a method to calculate the position and the rotation from a transform matrix.In my case i calculate a transform matrix and i want to apply it to my mesh. I tried mesh.setPivotMatrix but i don't want to move the pivot, i want to move the mesh. So i have to move my mesh with mesh.position and mesh.rotation. It changes the worldmatrix of my mesh and i want this new worldmatrix equal to my transform matrix. That's why the function setWorldMatrix could be the theoretical solution of my issue. Thanks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 17, 2014 Share Posted July 17, 2014 you can just set the mesh._worldMatrix even if this is a bit hacky Quote Link to comment Share on other sites More sharing options...
yuccai Posted July 17, 2014 Author Share Posted July 17, 2014 Well, the worldMatrix has changed but not the mesh position. How is calculate the worldMatrix? I thought it was the matrix who described a mesh position in the world space, that it was the rotation matrix (the product of the 3 Euler angles rotation matrix), the mesh.position Vector3 as the 4th column,a BABYLON.Vector3.Zero() as the 4th row complet with 1 for m[16].If i change the mesh position, the word matrix will change but if i change the world matrix, the mesh position won't change.The behaviour of the member mesh._worldMatrix is the same as mesh._pivotMatrix because this is only the value of the matrix that changed, they are no calculation.mesh.setPivotMatrix(m) is different that mesh._pivotMatrix = m I made this for test : http://jsfiddle.net/yuccai/LStwp/ you can move/rotate your mesh, get the world/pivot matrix, set the world matrix with mesh._wordMatrix = m, set the pivotMatrix with mesh.setPivotMatrix(m) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 18, 2014 Share Posted July 18, 2014 WorldMatrix in babylon.js is built from position/rotation/scaling properties I do not get what you want to achieve. You need to extract rotation/translation from your matrix? As You mentioned there are ways to do that but babylonjs won't infer position/rotation from a matrix Quote Link to comment Share on other sites More sharing options...
yuccai Posted July 18, 2014 Author Share Posted July 18, 2014 It is better if i don't need to extract rotation/translation from my matrix, if i could use this matrix like mesh.setPivotMatrix but without moving the pivot. If i apply 1 0 0 0 to my pivot matrix, the mesh position won't changed but we'll see the mesh in (0,0,5) if its pivot is at its 0 1 0 0 the center of mass. The problem is that i don't want to change the intrinsic properties of my mesh like 0 0 1 5 its pivot and if i apply a rotation around y axis, the mesh will rotate around (0,0,0) and not around itself in (0,0,5). 0 0 0 1 So i can't move directly my mesh from a transform matrix in babylonjs? Do i have to extract rotation/translation ? I tried to convert the rotation matrix into 3 euler angles but this is not precise (gimblal lock). I also tried to convert this matrix rotation into quaternion but it isn't precise too. I've seen the bakeTransformIntoVertices method but i don't understand how it works. Could it solve my problem? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 19, 2014 Share Posted July 19, 2014 You cannot get both Either you set the matrix manually but then position and rotation won't be usable or you have to extract rotation/position ANd you are right the bakeTransformIntoVertices could be a great idea: This function takes your matrix in parameter and update directly the vertices. This will then allow you to keep using position/rotation afterwards Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted July 20, 2014 Share Posted July 20, 2014 There is something I don't understand... You said that the values for mesh.position and mesh.rotation are the same before and after applying a matrix to mesh.setPivotMatrix,but the mesh is then drawn elsewhere and the pivot point seems to have moved (if the pivot point was at start, say, in the center of the mesh, after mesh.setPivotMatrix the pivot point is elsewhere - you checked this by applying a rotation to the object, which confirm a new pivot point position -). So it seems that mesh.setPivotMatrix defines a new location and orientation for the pivot point by changing all vertices coordinates inside the mesh.But DK said that bakeTransformIntoVertices takes matrix in parameter and update directly the vertices. That sounds similar to me. DK, what mesh.setPivotMatrix does exactly ? And what's the difference with bakeTransformIntoVertices ? BTW, I'm not sure bakeTransformIntoVertices will be a usefull solution for this problem since yuccai said he do not want to change the intrinsic properties of his mesh. Is there no simple way to apply this transform matrix directly to the mesh location and orientation without changing the vertices inside the mesh ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 21, 2014 Share Posted July 21, 2014 "DK, what mesh.setPivotMatrix does exactly ? And what's the difference with bakeTransformIntoVertices ?"bakeTransformIntoVertices : This function updates the vertices it selvesmesh.setPivotMatrix : This defines an additional matrix which will be multiplied by worldMatrix. Vertices remains unchanged hereBoth functions should produce the same visual rendering Quote Link to comment Share on other sites More sharing options...
yuccai Posted July 22, 2014 Author Share Posted July 22, 2014 I tried once more time to change the world matrix and i found this : there is a visual rendering if the initial mesh position belongs to the camera frustum. My camera is in ((0,0,0) position ; (0,0,0) rotation) and by default the mesh is in (0,0,0) too. If i change the world matrix, nothing happens but if i put the mesh in (0,0,1), the world matrix changes will affect the mesh and we'll see the mesh where it is described in the world matrix. Then if i change the mesh position or rotation, the mesh moves relative to its previous position If i apply mesh.position.z += 1, the mesh will be in (0,0,2).I did the same thing but i put initially the mesh in (0,0,1000) and (0,0,1001). In the first case, the mesh belongs to the camera frustum and it moves, in the second case, nothing happens. Is that behavior normal or not? Anyway this method does not solve my problem because the world matrix changes does not effect on the mesh position. That's why i'll extract the Euler angles from the transform matrix. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 22, 2014 Share Posted July 22, 2014 Yep this is expected but as I mentioned earlier setting directly the worldMatrix is not supported Quote Link to comment Share on other sites More sharing options...
yuccai Posted July 27, 2014 Author Share Posted July 27, 2014 I find a solution to my issue.I use a handler that i move with the method setPivotMatrix but it is the parent of my mesh. Although the handler pivot is still in (0,0,0), my mesh pivot is in the same position that the handler absolute position and i've got the rendering that i wish.Thanks for your answers, you've been helpful GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.