Jump to content

Billboard arrow is flipping direction


Kesshi
 Share

Recommended Posts

Please look at this playground: http://www.babylonjs-playground.com/#1ET2K6#2
I want that the three arraws always pointing outwards of the box but depending on the camera angle the
Billboard_x and billboard_y arrow will point inwards. A Bug?

Another problem i noticed. When you look perfectly from below at the box, the arrows are pointing sidewards.

Link to comment
Share on other sites

Actually, I don't think it's a bug... it's just that the BILLBOARD modes rotate the mesh by the axis you choose and sometimes it doesn't look like you expected.

If you want to master accurately the arrow directions, you should maybe consider RotationFromAxis() : http://doc.babylonjs.com/overviews/How_Rotations_and_Translations_Work#generating-a-rotation-from-a-target-system

 

PG : http://www.babylonjs-playground.com/#VYM1E#1

Link to comment
Share on other sites

  • 1 month later...
On 23.2.2016 at 11:14 AM, jerome said:

Actually, I don't think it's a bug... it's just that the BILLBOARD modes rotate the mesh by the axis you choose and sometimes it doesn't look like you expected.

If you want to master accurately the arrow directions, you should maybe consider RotationFromAxis() : http://doc.babylonjs.com/tutorials/How_Rotations_and_Translations_Work#generating-a-rotation-from-a-target-system

 

PG : http://www.babylonjs-playground.com/#VYM1E#1

The RotationFromAxis() function is very usefull but it looks very complicated and long.
Here a much simpler version:
 

// RotationFromAxis function returns a quaternion
  var RotationFromAxis = function(a1, a2, a3) {
    var x = BABYLON.Vector3.Normalize(a1);
    var y = BABYLON.Vector3.Normalize(a2);
    var z = BABYLON.Vector3.Normalize(a3);

	var rotM = new BABYLON.Matrix();
	rotM.m[0] = x.x;
	rotM.m[1] = x.y;
	rotM.m[2] = x.z;
	rotM.m[3] = 0.0;
	
	rotM.m[4] = y.x;
	rotM.m[5] = y.y;
	rotM.m[6] = y.z;
	rotM.m[7] = 0.0;
	
	rotM.m[8] = z.x;
	rotM.m[9] = z.y;
	rotM.m[10] = z.z;
	rotM.m[11] = 0.0;
	
	rotM.m[12] = 0.0;
	rotM.m[13] = 0.0;
	rotM.m[14] = 0.0;
	rotM.m[15] = 1.0;
	
	return BABYLON.Quaternion.FromRotationMatrix(rotM);
  };

 
The difference to the original Version is that this one returns a quaterion (toEulerAngles() can be used if necessary) and the result is only correct if
the 3 given axis are orthogonal to each other (in the playground i added an additional cross product to ensure that)
Here the modified playground: http://www.babylonjs-playground.com/#VYM1E#7
 

Link to comment
Share on other sites

I like your implementation although it doesn't return the same result (didn't take the time to understand if it really does the same thing), because it's really elegant.

Yep, the current RotationFromAxis() code is quite long and complicated because it is a math process (un-rotate by projecting the axis vectors and select each step a solution), but it's really fast (only 3 effective computations for the CPU) and allocates the mimimum required memory, it is to say some scalar values only. It was heavily tested to be sure to work in every orientation and return right results, example : http://jerome.bousquie.fr/BJS/demos/rollercoaster.html

well, after reading the method FromRotationMatrix() here : https://github.com/BabylonJS/Babylon.js/blob/master/src/Math/babylon.math.ts#L1755 called in your code , it seems we are quite in the same configuration 

I need to think about how to merge your elegant code in replacement of the current one, after checking that it is as fast (regarding GC), or faster, in the render loop than the existing and achieving the same final results : euler angles, not only the quaternion ... this function is done for users wanting simplicity and wanting to use easy euler angles because they don't know how to rotate a mesh to get a known final result result.

Link to comment
Share on other sites

The main reason that i didn't use the existing Vector3.RotationFromAxis() for my project was that i prefer to work with quaternions instead of euler angles.
I didn't want to add an additional euler to quaternion conversion. Thats why i was looking for an alternative.
Then i remembered that a rotation matrix can be constructed directly from the 3 axis of a coordinate system ^_^
But i can understand that for people which are new to this topic its easier to work with euler angles.

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