Monday 15 March 2010

javascript - Getting a node in a node hierarchy to face the camera (billboard) -


I have to face a node in the node hierarchy, or in other words, a billboard should be placed on each node. For, I store my world matrix, and world rotation as a quadrangle. What do I know of quadrangles, I want to find the difference between the quaternion and the rotation quaternion of the node of the operation camera, and to transfer the node only to the difference.

My camera Euler Egez, so before I make the X-X rotation, I create the Camera Quaterno, then Z-axis rotation (I do not have a Wi-axis rotation), and multiply by multiplying it.

From there, it is just to get some math differences and finally create a rotation matrix from it, and multiply the node's world matrix with it.

It ends, resulting in rotating nodes like crazy goons, and no other way is facing the camera.

Here is the relevant javascript code:

  // If there are parents, then multiply both the matrix and the rotation / local matrix here is present in the node's local Matrix // Rotation is the local rotation quaternion here (nodeparate) {math.Mat4.multMat (node.parent.worldMatrix, localMatrix, node.worldMatrix); Mathematics.Connecting.Cockets (NodeParent.Verularation, Rotation, Node Verlaration); } Else {node.worldMatrix = localMatrix; Node Verlaration = Rotation. Copy (); } // and the mess starts here (node.billboard) {var cameraX = []; Var Camarazzo = []; Var camera = []; // transform.rotation The rotation of my camera is stored as 3 Euler Angels, but I am not using the Y-axis for mathematics anymore. Quaternion .Setframxisangle ([1, 0, 0], transform. [Rotation [0], camerax); the mathematics. Quaternion. Sat Fraumaxis Angel ([0, 0, 1], Transformation. Rotation [2], Cameraszed); Math.Quaternion.concat (cameraX, camera, camera); // node var at the current rotation = initial node. Verilotation.copy (); // It should be reversed, because the difference is the camera * - initial math. Quarteran Conjugate (initial, initial); Var difference = []; Math.Quaternion.concat (camera, initial, difference); Var rotation matrix = []; the mathematics. Quaternion Throttle matrix 4 (difference, rotation matrix); Var final matrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; // is the position of the axis node, it needs to keep the rotation in the local space math. Mate 4 Translestate (final matrix, smoke [0], smoke [1], smoke [2]); Mathematics. 4. Multmat (ultimate metrics, rotation matrix, final matrix); Mathematics. 4 Transselate (final matrix, -Pivot [0], -Pivot [1], -witch [2]); // and finally the node will rotate the math. MAT4.multMat (node ​​word metrics, final metrics, node word metrics); }   

Is there any clear mistake I am doing?

Your assumption is incorrect:

I want the operation camera Rotation of the quaternion and node of the quadrant is to get the difference between, and transfer the node only to the difference.

If you did this correctly, then the result should be to face you in the same direction as the camera face. It really is different from facing the camera

What you need, change which is the camera's position to the world space Shows you can benefit from some quick research

No comments:

Post a Comment