1

I'm working on Libdx app using Decals. Decals are 2d sprites in 3d world.

I have problem that when I say:

decal.setRotationX(angle)

everything works fine, but when I say:

decal.setRotationX(angle);
decal.setRotationY(angle2);

The decal rotates over Y axis only.

How to manage that problem? I have found that Decal in source code uses Quaternion for rotation, but currently I don't know how to customize that to face my requirements.

Tnx in advance!

EDIT:

I have managed to rotate decal around multiple axis with:

decal.getRotation().setEulerAngles(yaw,pitch,roll);

Now my question is how to animate this with TweenEngine?

In get values method I have:

returnValues[0] = target.getRotation().getYaw();
returnValues[1] = target.getRotation().getPitch();
returnValues[2] = target.getRotation().getRoll();

In set values method I have:

target.getRotation().setEulerAngles(newValues[0], newValues[1],
                newValues[2]);

But decal is not moving or animating, it's stucked in one position (slightly rotated over XYZ axis).

Any idea, values in TweenEngine are correct but somehow decal is not refreshing and rotating.

Veljko
  • 1,893
  • 6
  • 28
  • 58

1 Answers1

2

If you want to do it only once, you can do it like this:

decal.rotateX(angleX);
decal.rotateY(angleY);
decal.rotateZ(angleZ);

This will "add" the given angle to the current one though.

An alternative way would be to use the rotation Quaternion of the Decal:

decal.getRotation().setEulerAngles(yaw, pitch, roll);

The following image shows what "yaw", "pitch" and "roll" means:

Roll, pitch, yaw http://i.msdn.microsoft.com/dynimg/IC79189.gif

EDIT: I've just seen the JavaDoc of Decal.getRotation() and it says that the returned quaternion should not be modified! I've also checked the code and every other method of Decal sets an internal update flag which will cause the decal to change the next time it's rendered. Decal.getRotation() does not set this flag and thus the changes to it won't get recognized.

It seems like currently there is no really clean and easy way to set the rotation on all three axes at the same time. A workaround might look like this:

decal.setRotationX(0);
decal.setRotationY(0);
decal.setRotationZ(0);
decal.rotateX(angleX);
decal.rotateY(angleY);
decal.rotateZ(angleZ);

It first resets all angles to 0 and then rotates on each axis while not overwriting any other axis.

noone
  • 19,520
  • 5
  • 61
  • 76
  • Can you provide some code for rotating decal with TweenEngine? I'm trying this...but nothing happens: In get values: returnValues[0] = target.getRotation().x; returnValues[1] = target.getRotation().y; In set values: target.getRotation().setEulerAngles(newValues[0], newValues[1],target.getRotation().z); – Veljko Jul 08 '14 at 12:58
  • Sorry, I haven't used TweenEngine myself. – noone Jul 08 '14 at 13:08
  • Ok, tnx! I will update my question. Your aproach works, but it's not animatable yet :) – Veljko Jul 08 '14 at 13:10
  • I have managed to get correct values from TweenEngine, but decal is not refreshing. Why I cant rotate decal continiously? – Veljko Jul 08 '14 at 17:18
  • Oops, I've just noticed the JavaDoc of the `getRotation()` method. I'll update my answer. – noone Jul 08 '14 at 19:02
  • Tnx for an idea. I will try that way. – Veljko Jul 08 '14 at 19:46
  • It works. It's not the cleaneast way, but for now it's good enough. If someone finds out better way, I'm happy to hear about it. Tnx again. – Veljko Jul 09 '14 at 07:23
  • @Veljko I made a PR to add a method which does this in one line. (https://github.com/libgdx/libgdx/pull/2111) – noone Jul 13 '14 at 22:31
  • Good idea! Now we just need to wait for devs to merge it. In the mean while I will use your aproach. Tnx again. – Veljko Jul 13 '14 at 22:39