# rotating (.. once more)

## Recommended Posts

Hi,

To describe my questions I would like to offer this pics

What I try to do (simplified): steering a cube indirect with html sliders (as per touch), whereby I have to interpolate the linear scale for left <-> right and  up <-> down into a babylon 3D rotation solution.

- The sliders are "fixed" .. If I reaches the 360 the box has turn around 360 (1 complete rotation)

- If both sliders are moved in same time I want the box to spin in z as well .. if right und up the box proceed in z

my questions are:

1) How to use Babylon.Tools.ToRadians correct?

I not are able to compute from degree to rad

If doing just

or

this has no effect on my stage.

2) What is best data stucture to solve? Should the normal quaternions structure do this job for this behavior?

3) How to got a fast smooth rotation?

The can use the slider per touch and as per click

Doing so the cube should rotate in place according to the sliders speed but needs to be able to "move" to the final rotation position if the user clicked on its own .. there should be no "the cube jumps from 0 to 170 degree"  (I was thinking about the actionmanager .. ?)

As tried with this  mesh.rotate(new BABYLON.Vector3(0, 1, 0), angle_inDegree); I only got the new added rotation angle not the interpolated delta between old and new rotation position.

I would be thankful for some solutions and answers.

With best regards,

Stefan

##### Share on other sites

Hi Virgo ;

Welcome Babylon Forum

im rotating meshes and converting degrees like this

Math.PI = 180 degree

(Math.PI / 180) * rot         you can define a variable for x          for example    if        rot = 1              equation = 1 degree

if        rot = 25              equation = 25 degree.....

you can rotate box what axis u want

box1.rotation.x = rot ;

or

box1.rotation.y = roty ; ( define a new variable for y axis maybe from your slider )

box1.rotation.z = rotz ;  ( define a new variable for z axis maybe from your slider )

hv nice time

##### Share on other sites

It would really help if you could provide a playground even one that does just a little of what you want. For example without sliders you could have a currentLeftRight and wantedLeftRight variable and do something like

``````for (angle = currentLeftRight; angle<wantedLeftRight; angle +=0.02) {
mesh.rotate(BABYLON.Axis.Y; 0.02; BABYLON.Space.WORLD)
}``````

Having a PG will attract more help.

This may help.

It does rotate as well and shows a possible way of animating a rotate in a PG.

The other things you need to consider are  do you want the z rotation to be in World or Local space and that rotation is non commutive so with two sliders in what order do you want the rotations to take place?

Note if you use mesh.rotation then this is always done in the order ZXY whereas mesh.rotate does the rotation in the order you set.

Also mesh.rotation rotates from 0 to the given angle whereas mesh.rotate rotates from current angle by the angle given.

Have a good play with a PG and give a link to it if you need more help.

##### Share on other sites

Yes!

I first returned to the basics with   "Math.PI = 180 degree"

and finally will give my focus to ZXY order if reaching that point.

Thanks!

Edited by [email protected]
spelling

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×