Jump to content

Rotation question


darcome
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);}
Link to comment
Share on other sites

When your car drives ahead or back, you give rotation to every torus... so their local system are rotated in the same time

If 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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 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 move

b:end move

 

c:start  rotation 

d:end rotation

 

maybe this fix it

if(a || b ){

   reset local rotation

   do move

    set local rotation again

}

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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