Jump to content

update matrix with a clickevent inside shader


Nabroski
 Share

Recommended Posts

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

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
)
 
Dont worry i will investigate :)
 
 
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...