Abdullah Posted February 3, 2017 Share Posted February 3, 2017 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.. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 3, 2017 Share Posted February 3, 2017 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 Bricktheworld, Abdullah and Phuein 3 Quote Link to comment Share on other sites More sharing options...
wo997 Posted February 3, 2017 Share Posted February 3, 2017 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? Abdullah 1 Quote Link to comment Share on other sites More sharing options...
leanderr Posted February 3, 2017 Share Posted February 3, 2017 This Article got some nice Examples and Playgrounds for you http://babylonjsguide.github.io/advanced/Euler_Angles.html Abdullah 1 Quote Link to comment Share on other sites More sharing options...
Abdullah Posted February 14, 2017 Author Share Posted February 14, 2017 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... thanx....!!!! Quote Link to comment Share on other sites More sharing options...
wo997 Posted February 14, 2017 Share Posted February 14, 2017 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... 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? Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 14, 2017 Share Posted February 14, 2017 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. Abdullah 1 Quote Link to comment Share on other sites More sharing options...
Abdullah Posted February 15, 2017 Author Share Posted February 15, 2017 thanx @JohnK for your reply... i have mentioned in my post that i am getting raw data from mobile sensor and i am trying to rotate my mesh on that readings. And data is coming at high speed. so i want to try quaternion rotation. but not understanding it well... Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 15, 2017 Share Posted February 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Abdullah Posted February 26, 2017 Author Share Posted February 26, 2017 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... Quote Link to comment Share on other sites More sharing options...
adam Posted February 26, 2017 Share Posted February 26, 2017 http://playground.babylonjs.com/#2H9MHN#12 Instead of setting the x, y, z, w properties of a quaterion directly, you should use mesh.rotate or something like BABYLON.Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, mesh.rotationQuaterion). Quote Link to comment Share on other sites More sharing options...
jerome Posted February 26, 2017 Share Posted February 26, 2017 https://github.com/BabylonJS/Documentation/blob/master/content/overviews/Standard/How_Rotations_and_Translations_Work.md Quote Link to comment Share on other sites More sharing options...
Abdullah Posted February 27, 2017 Author Share Posted February 27, 2017 thanx @adam and @jerome for your replies. but @adam i want to use rotation quaternion instead of simple rotation function. why that is not rotating at 360 degree..???? i have used simple rotation and used it very well ... but not understanding how to use rotation quaternion for 360 degree rotation... ??? Quote Link to comment Share on other sites More sharing options...
dbawel Posted February 27, 2017 Share Posted February 27, 2017 @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 Quote Link to comment Share on other sites More sharing options...
adam Posted February 27, 2017 Share Posted February 27, 2017 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 Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 27, 2017 Share Posted February 27, 2017 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.