Jump to content

Quaternion Rotation


Abdullah
 Share

Recommended Posts

Hey everyone... hope you all are fine... :)
i have a small query regarding rotation. Can someone explain me the purpose of QuaternionRotation and how it differs from simple rotation.??
Actually, i want to rotate my mesh using gyroscope readings of mobile sensor at real time. So what will be best for me to get maximum accuracy.
till now i am using simple rotation but it is producing some drift. so how quaternion will be good for me.. 

Thanx for your support in advance.. ;)

Link to comment
Share on other sites

Hello

for quaternion theory I suggest starting with this:

Then read this: http://doc.babylonjs.com/overviews/how_rotations_and_translations_work

and that: http://doc.babylonjs.com/tutorials/position,_rotate,_translate_and_spaces

I have to admit it is not as simple as I would have loved but in your case if you have data giving you some quaternions you just have to plug them into mesh.rotationQuaternion :)

Link to comment
Share on other sites

44 minutes ago, Abdullah said:

Hey everyone... hope you all are fine... :)
i have a small query regarding rotation. Can someone explain me the purpose of QuaternionRotation and how it differs from simple rotation.??
Actually, i want to rotate my mesh using gyroscope readings of mobile sensor at real time. So what will be best for me to get maximum accuracy.
till now i am using simple rotation but it is producing some drift. so how quaternion will be good for me.. 

Thanx for your support in advance.. ;)

I can only say that rotation matrix seems to be more friendly to me, in this case I have x,y,z axises of each object saved as 3 vectors, for example when I want to get any point of a body, for example the one on the top, I just have to add the y axis multiplied by some factor (f.e. 3) to object position. I don't know how to do the same with quaternions though, but is it really needed? Here is part of my code which actually works:

var getMatrix = function(quaternion) {
       var targetMatrix = new BABYLON.Matrix();
       BABYLON.Matrix.FromQuaternionToRef(quaternion,targetMatrix);
       return targetMatrix.asArray();
} <- repeat every time before rendering for each matrix

to access data from it just type: 

yourRotationMatrix[1] - which is y axis of x axis of the object, you can try values from 0 to 10 skipping 3 and 6 (xx,xy,xz,yx,yy,yz,zx,zy,zz).

Is it what you want?

Link to comment
Share on other sites

  • 2 weeks later...

Hello Everyone..!!!! first of all thanks for your replies.... :)
but i am still a little confused. i was trying to check the rotation quaternion function by giving some dummy values but the results was surprising. 

mesh.rotationQuaternion = new BABYLON.Quaternion(0.5, 0, 0, 0);

i was giving values in the format shown above. but the mesh was rotating in same direction when i give y or z = 0.5 and keeping all other 0. Means if i give 0.5 on any axis and keeping all other values on 0. then it is showing same behaviour.....
what is this..???? :(

i am confused so kindly help me out... :P

thanx....!!!! :)

Link to comment
Share on other sites

1 hour ago, Abdullah said:

Hello Everyone..!!!! first of all thanks for your replies.... :)
but i am still a little confused. i was trying to check the rotation quaternion function by giving some dummy values but the results was surprising. 

mesh.rotationQuaternion = new BABYLON.Quaternion(0.5, 0, 0, 0);

i was giving values in the format shown above. but the mesh was rotating in same direction when i give y or z = 0.5 and keeping all other 0. Means if i give 0.5 on any axis and keeping all other values on 0. then it is showing same behaviour.....
what is this..???? :(

i am confused so kindly help me out... :P

thanx....!!!! :)

Just tell me how should the mesh behave, you can choose between rotation matrix (free rotation, may be used for a rolling object) and euler angles (many axes jointed together, just like ArcRotateCamera, may be used for player looking around). If you really want to stay with quaternions then maybe you have to put more than 1 value different than 0 to see different kind of movement, but these are imaginary axes, so how do you know where they are? :P

Link to comment
Share on other sites

To get a quaternion from axis and angle us this

mesh.rotationQuaternion = new BABYLON.Quaternion.RotationAxis (axis , angle)

where axis = new  BABYLON.Vector3(x, y, z)

Whereas this sets a particular rotation you can apply sequences of rotations that accumulate using

mesh.rotate (axis, angle, local/world)

For more info on this read

http://babylonjsguide.github.io/intermediate/Translate#rotate

The other thing you could do is post some of the data you are getting with an explanation of what the readings are and how you want to apply them in BabylonJS and then you may get explanations of which methods are best to achieve this.

Link to comment
Share on other sites

5 hours ago, Abdullah said:

at i am getting raw data from mobile sensor

Yes I understood this and I am asking if you could capture some of this raw data and post it as raw data with an explanation of how the raw data should be read. Or even easier post a made up data stream that mirrors the actual data stream with an explanation of how to interpret the data.

Link to comment
Share on other sites

  • 2 weeks later...

Hello Everyone... hope you all are fine... :)

i need a little help. i want to rotate my mesh with rotation quaternion so when i am trying to rotate my mesh by giving some dummy values. it behaves surprising to me. 

i am continuously pressing 'L' and adding x += 0.1 each time i press 'L'. But the mesh is not moving 360 degree. it rotate at almost 180 degree. and after that it does;nt rotate even if i press L and add 0.1 to its x value. 

here is the demo.. 

http://playground.babylonjs.com/#2H9MHN#11

L code is at line 255. kindly check it. r2 is racket which is straight and still.

why is that so..... :( kindly reply me as soon as possible... :P

Link to comment
Share on other sites

@Abdullah -

First you need to access what the world coordinate system is that you are working within. If you are working in real world coordinates, your Z axis wil be pointing outward from the earth's surface, and X and Y are topographical. However, wha you're asking about is the interpretation of Quaterion math VS. Euler - which I highly recommend Euler for your prediscribed requirements. Quaternion is simple to understand, but simply a mathematical solution which allows anyone to understand orintation and direction. But everything is driven by pitch, roll, and yaw - and then interpolated to quaternion - so it is best to work with the basics - Euler.

I hope this helps.

DB

Link to comment
Share on other sites

8 hours ago, Abdullah said:

but @adam i want to use rotation quaternion instead of simple rotation function. why that is not rotating at 360 degree..???? 

You need to understand how quaternions work then: 

https://en.wikipedia.org/wiki/Quaternion

Those rotation functions make it easy to use quaternions.  I'm not sure why you want to make things more difficult for yourself.

@dbawel he is using physics

 

 

Link to comment
Share on other sites

For a start line 256 resets the value of the quaternion every time you press L and so the bat keeps the same rotation. However just dealing with that will not make the bat do what you want. You have been given a lot of good advice already so I will ask you a question. What do you think should be happening when you increment x by 0.5?

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