darcome Posted April 18, 2015 Share Posted April 18, 2015 Hello everyone, I've put online the following playground: http://www.babylonjs-playground.com/#1PM4XG to ask the following question: I hope to be clear If you press 4 times the X key, you'll notice the torus is rotating on the x axis. Then if you press 4 times the Z key, you'll notice the torus is spinning Then if you press 4 times the X key again, you'll notice the torus is rotating on an axis different than the x axis How can I obtain to make the torus rotate on the x axis?Something like resetting the axis but maintaining the rotation done till that moment If you don't understand what I mean, don't worry... It's me unable to exlpain in english... Thanks in advance for your help and patience Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 18, 2015 Share Posted April 18, 2015 Is using world coordinates solves the problem? http://www.babylonjs-playground.com/#1PM4XG#1 Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 19, 2015 Share Posted April 19, 2015 Is using world coordinates solves the problem? http://www.babylonjs-playground.com/#1PM4XG#1 I think they might be looking for this: http://www.babylonjs-playground.com/#1PM4XG#2That is, spinning in local coords but rotating in world coords.. RaananW and Jaskar 2 Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 Ok, probably the example i made wasn't enough complicate... here is another: http://www.babylonjs-playground.com/#1PM4XG#3 Try the following: press Left and Right arrows and see the front wheels to steer correctly. Then restart the playground and press the Up and Down arrows and see the "car" goind back and forward and the wheels spinning Then restart the palyground, press Up and Down arrows, then Left or Right, and you'll see the wheels steer incorrectly How can I solve it? If you need more explanations, just tell me. But I hope it is clear Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted April 19, 2015 Share Posted April 19, 2015 http://www.babylonjs-playground.com/#1PM4XG#4 http://www.babylonjs-playground.com/#1PM4XG#6 http://www.babylonjs-playground.com/#1PM4XG#7 : just for all axis.z use the World mode if (evt.keyCode == 90) //z { window.torus.rotate (BABYLON.Axis.Y, 0.14, BABYLON.Space.WORLD);}else if (evt.keyCode == 88) //x{ window.torus.rotate (BABYLON.Axis.X, 0.14, BABYLON.Space.WORLD);} Quote Link to comment Share on other sites More sharing options...
jerome Posted April 19, 2015 Share Posted April 19, 2015 When your car drives ahead or back, you give rotation to every torus... so their local system are rotated in the same timeIf you "turn" right or left, your torus rotate according to the current system position, it is to say as you expect if you don't move the car before, and according to their new rotated position if the car has moved... not clear ? check this : http://www.babylonjs-playground.com/#1PM4XG#5 Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted April 19, 2015 Share Posted April 19, 2015 http://www.babylonjs...d.com/#1PM4XG#7 this is need to limitation move control i think this is your answer Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 NasimiAsi, with your links finishing with 6 and 7 if i press left or right. the wheels are not rotating on the right axis jerome, with your playground, if i press back and then left or right, the wheels do not rotate on the right axis Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 NasimiAsi, even in your last playground, if i press left or riht, the wheels rotate on the same axis... they don't steer left or right Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted April 19, 2015 Share Posted April 19, 2015 this is not for rotation problem maybe you need change algorithm or fix this bug with more conditions you need more condition like a:start moveb:end move c:start rotation d:end rotation maybe this fix itif(a || b ){ reset local rotation do move set local rotation again} Quote Link to comment Share on other sites More sharing options...
jerome Posted April 19, 2015 Share Posted April 19, 2015 @darcome : I know... I didn't fix anything, but just showed you axis so it is easier to understand how the Y axis is rotated when the car moves forward/backward, so why the wheel rotations aren't good then. As NasimiAsl explains, maybe, you need to swap local/world and reset some system NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 Yeah, I think that too jerome and NasimiAsl, but I don't know how to reset the axis maintaining the rotations done till that moment I hope someone will be able to help me! However thank you for the axis thing! Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 19, 2015 Share Posted April 19, 2015 I find it easiest to do stuff like this with parenting.Demo: http://www.babylonjs-playground.com/#1PM4XG#8 All I did is add an extra mesh ("axle") between the car and the wheel. So the parentage goes: "car -> axle -> wheel". That way, the wheels can rotate locally (relative to the axle) and the axle can rotate relative to the car. If you don't want to use parenting like this, you should probably use quaternions. If you wanted to reset/reapply rotations, then unless I'm missing something you'd need to track and calculate the Euler angles, and it would be a lot of math. PS: The drawback to using empty "container" meshes is that you tend to find BJS bugs where their transforms don't get inherited. I found one while making the demo above; there's a line at the end to work around it. I don't know if support for quaternions is more robust or not... jerome 1 Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 fenomas, but in your example, the box doesn't rotate it only goes back and forward Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 19, 2015 Share Posted April 19, 2015 fenomas, but in your example, the box doesn't rotate it only goes back and forward Sure, because it's a demo to show how to make the wheels rotate and turn on the correct axes, which is what I understood this thread to be about. Of course, if you want to rotate the box you can simply do that - the wheels are parented to it, so they'll move with it. Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 Thanks to your idea of containers, this is the best thing I've been able to obtain... http://www.babylonjs-playground.com/#IRNRP#1 I use WASD, because the arrows make the page move... as you can see, the "car" can move around... but as soon as you steer, the wheels stay in place instead of following the car... I think because of the bug you mentioned earlier... but how can I get rid of it? Thanks in advance for your help Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 19, 2015 Share Posted April 19, 2015 I think because of the bug you mentioned earlier... but how can I get rid of it? Giving the empty container a (small) change in position or rotation every frame should work - see the line at the end of my demo. Or you can just wait for a new build, as DK already pushed a fix. I think they're daily? Quote Link to comment Share on other sites More sharing options...
darcome Posted April 19, 2015 Author Share Posted April 19, 2015 I used it (it's in my last demo), but it didn't solve the problem... or better, it solves the problem if i only go forward or back... but as soon as I steer, the wheels don't follow the car... Quote Link to comment Share on other sites More sharing options...
fenomas Posted April 20, 2015 Share Posted April 20, 2015 DK's fix is now in the playground, so that issue should be fixed (and the workaround is no longer necessary). Quote Link to comment Share on other sites More sharing options...
jerome Posted April 20, 2015 Share Posted April 20, 2015 let us know if it solved the problem pleaserotations aren't commutative (rotation x, y, z is not the same as rotation x, z, y) and it's not that easy to do NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
darcome Posted April 20, 2015 Author Share Posted April 20, 2015 I am afraid it didn't solve the problem... http://www.babylonjs-playground.com/#IRNRP#2 I deleted the workaround and if you use WASD you see the front wheels don't move with the car Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted April 20, 2015 Share Posted April 20, 2015 @fenomas main question is this 1. rotate x axis ( world or local)2. rotate y or z axis ( world or local) how can back to rotation state befor step 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted April 20, 2015 Share Posted April 20, 2015 https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations In your place, I wouldn't use mesh.rotate() around local/world axis but maybe mesh.rotation() or mesh.rotationQuaternion() in order to turn wheels and vehicle.These functions use Euler angles or quaternion. I guess you can express then the rotation easily in the world.The wheels rotate around their own axis : local ?The wheels and the vehicle turn around a vertical axis (not the Y world axis) centered on them. For the vehicle, this may be the Y local axis. Not for the wheels because you've done many local rotations before. Quote Link to comment Share on other sites More sharing options...
darcome Posted April 20, 2015 Author Share Posted April 20, 2015 as stated in the link you posted: Please note that mesh.rotate generates a quaternion and then uses mesh.rotationQuaternion. So even if I didn't know, I am just using quaternions I think what i really need is a way to reset rotation angles but maintaining the rotations made till that moment. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted April 20, 2015 Share Posted April 20, 2015 http://schteppe.github.io/cannon.js/demos/rigidVehicle.html 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.