Jump to content

# solved update matrix with a clickevent inside shader

## 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

##### 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)
``````

##### 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

``````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:

##### Share on other sites

What do you mean by "reset itself" ?

##### 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 :)

##### Share on other sites

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

##### Share on other sites

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)

##### Share on other sites

Quote

BabylonJS Unsolved Mysteries (to be continued)

lol

## 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.

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...
×
• ### Recently Browsing   0 members

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