Nabroski Posted July 6, 2018 Share Posted July 6, 2018 Hello i'm exploring the matrix func. inside Babylonjs, a matrix lib can be easy see here : http://glmatrix.net/docs/module-mat4.html or very hard see here : https://doc.babylonjs.com/api/classes/babylon.matrix I kind of understand where the problem occurs, after unsucessfull 3h, i think i might be better to ask the community. Thanks https://www.babylonjs-playground.com/#Y7Q181 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 6, 2018 Share Posted July 6, 2018 Can you tell us more about what you want to do? Seems unclear to me Just assuming the problem is in the matrix, let's see what we have here: let nR = BABYLON.Matrix.Identity(); nR= BABYLON.Matrix.RotationY(newPosY); rM= BABYLON.Matrix.RotationX(newPosX); rM.multiplyToRef(nR,rM) This cannot work all xxxToRef functions are used to avoid creating new objects and instead reuse existing one. So for instance the matrix.multiply function will return a NEW matrix where the multiplyToRef will use the last parameter to store the result and thus avoid creating a new matrix So the correct code should be in your case: let final = BABYLON.Matrix.Identity(); nR = BABYLON.Matrix.RotationY(newPosY); rM = BABYLON.Matrix.RotationX(newPosX); // Multiply rM by nR and store the result in final rM.multiplyToRef(nR,final) If you don't want xxtoRef functions, you can use this code (probably easier to read but less efficient as it will put pressure on the GC): nR = BABYLON.Matrix.RotationY(newPosY); rM = BABYLON.Matrix.RotationX(newPosX); // Multiply rM by nR and store the result in final let final = rM.multiply(nR) Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 6, 2018 Author Share Posted July 6, 2018 Hello thank you i try simple to multiply to matrieces ( how hard can it be ) https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations http://glmatrix.net/docs/mat4.js.html#line584 multiply by http://glmatrix.net/docs/mat4.js.html#line541 let rMat = mat4.create(); mat4.identity(rMat); canvas.addEventListener const nRot = mat4.create(); mat4.rotateY(nRot, nRot, (deltaX *0.5)*0.01 ); mat4.rotateX(rMat, rMat, (deltaY *0.5)*0.01 ); mat4.multiply(rMat, nRot,rMat); canvas.addEventListener end requestAnimationFrame gl.uniformMatrix4fv(uLocRot, false, rMat); requestAnimationFrame end // and it's working Yes, but the Matrix resets its self, see here: https://www.babylonjs-playground.com/#Y7Q181#2 @DeltakoshRaw WebGL http://bl.ocks.org/tolkanabroski/3fcaab9467652a797851c7e080976f09 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 6, 2018 Share Posted July 6, 2018 What do you mean by "reset itself" ? Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 6, 2018 Author Share Posted July 6, 2018 i guess becourse of scene.onBeforeRenderObservable.add or any other renderloop inside the createScene the Matrix isent stored properly. ( i leave this here, for later for debuging reasons # just an other debug playground https://www.babylonjs-playground.com/#Y7Q181#4 # minimal copy paste from the docs https://www.babylonjs-playground.com/#Y7Q181#3 ) Dont worry i will investigate :) Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 6, 2018 Author Share Posted July 6, 2018 on other hand i spend already like 6h hours with a simple matrix multiplication, i code this like in 10min. if anyone has suggestions. ur welcome https://www.babylonjs-playground.com/#Y7Q181#5 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 7, 2018 Author Share Posted July 7, 2018 24h later ended up implementing my own matrix operations (its working now, (no wonder)) have to figure out how to stack different pointer events ... i leave it here, maybe some1 find it useful. https://www.babylonjs-playground.com/#Y7Q181#6 BabylonJS Unsolved Mysteries (to be continued) Arte 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted July 9, 2018 Share Posted July 9, 2018 Quote BabylonJS Unsolved Mysteries (to be continued) lol Nabroski 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.