Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Problems with Rotation

Karandas Banjo
Registered User
Join date: 7 Jan 2005
Posts: 35
10-24-2005 08:02
I've got a bit of a problem with llSetRot. I'm trying to build a gun that you can rotate on both the y axis and the z axis using a series of 4 buttons (two for z+ and -, two for y + and -). It works fine rotating z on its own or y on its own, but when i try both i have a bit of a problem.

Say this is a side view of the object:

The horizontal line being X axis and the vertical one being Z axis.

When rotating on the Z axis alone it would rotate like this:


And on the Y axis alone it would be like this:


However, when trying to combine them it seels to rotate like this:

(with ed being the Y rotation value and blue being the z rotation value)

This is a bit of a problem, because it actually changes the angle of the gun to the horizontal, while i just want it to rotate without changing this angle. Is there any function that allows this, or some value to multiply by that fixes this? Thanks.
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
10-24-2005 08:47
I think you are applying the rotations in the wrong order... But then I need to see the code itself to tell you for sure. I'm a bit confused about what you are trying to achieve actually, any rotation around an axis that is not Z will make the wall horizontal anyway ?
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Karandas Banjo
Registered User
Join date: 7 Jan 2005
Posts: 35
10-24-2005 09:00
From: Jesrad Seraph
I think you are applying the rotations in the wrong order... But then I need to see the code itself to tell you for sure. I'm a bit confused about what you are trying to achieve actually, any rotation around an axis that is not Z will make the wall horizontal anyway ?


I dont have access to the code wright now because of the update, but heres what i remember of the code for control of the y axis rotation:

receivedrot is an integer of the rotation in degrees
currentrot is a vector of the current rotation, also in degrees.

The buttons send the total rotation, rather than what to increment by, so pressing the "increase rotation by 20 degrees" button once sends the value 20, but the second time sends the value 40, etc.

CODE

currentrot = (llRot2Euler(llGetRot()) * RAD_TO_DEG);
llSetRot = llEuler2Rot(<currentrot.x, receivedrot, currentrot.z> * DEG_TO_RAD);


Here's also a better example of what happens when combining the rotations, the red line making the end of the gun:
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
10-24-2005 09:16
Hmmm, I would advise strongly against coverting to Euler and back, SL has been inconsistent when using those in my experience.

What about, instead, combining the rotations directly ?
CODE

llSetRot(llEuler2Rot(DEG_TO_RAD * <0, receivedrot, 0>) * llGetRot());
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Karandas Banjo
Registered User
Join date: 7 Jan 2005
Posts: 35
10-24-2005 09:18
From: Jesrad Seraph
Hmmm, I would advise strongly against coverting to Euler and back, SL has been inconsistent when using those in my experience.

What about, instead, combining the rotations directly ?
CODE

llSetRot(llEuler2Rot(DEG_TO_RAD * <0, receivedrot, 0>) * llGetRot());


Hmm, I'll give that a try. Thanks :)
Karandas Banjo
Registered User
Join date: 7 Jan 2005
Posts: 35
10-24-2005 13:12
Well i tried that in the preview grid and it didnt fix the problem :(
Online Doesburg
absurd hero
Join date: 6 Jul 2005
Posts: 53
10-24-2005 18:35
Try reversing the order of the two rotations, but I'm not sure if that'll help. The order is important though when multiplying quaternions.

CODE

llSetRot( llGetRot() * llEuler2Rot(DEG_TO_RAD * <0, receivedrot, 0>) );
_____________________
"The evil that is in the world almost always comes of ignorance, and good intentions may do as much harm as malevolence if they lack understanding." - Albert Camus
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
10-25-2005 04:52
Karandas, if you are building a gun, I assume that what you're trying to do is control azimuth and elevation - i.e. swing it a bit left and point it up a notch.

To do this it is usually easier to keep one variable for azimuth, and one for elevation. Change those variables when the buttons are pressed, and then calculate a new angle based on the rest/base position and those 2 values rather than trying to calculate the next rotation based on this rotation (especially when working with Euler angles, which experience a phenomenon knows as gimbal lock).

When I next get in-world, I'll put together some example code.
Karandas Banjo
Registered User
Join date: 7 Jan 2005
Posts: 35
10-25-2005 17:44
I've got it sorted now, the fix was
CODE
llEuler2Rot(<0,(0 - elevation),0> * DEG_TO_RAD) * llEuler2Rot(<0,0,direction> * DEG_TO_RAD)


Thanks for all the help though :)