Jump to content

Seeking aid with multi-axis rotation problem


Psistorm Voxel
 Share

You are about to reply to a thread that has been inactive for 755 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've been trying to solve this issue for a little while now, the main issue is that the order of rotation for what I have in mind is problematic. To sum it up:

An object is supposed to rotate first around Z, THEN around the Y axis but in its new, rotated coordinate system. So imagine you take an object in SL, twist it around Z, then set transforms to local, and twist it around local Y. This should technically be easy, BUT. This object is a) meant to be attached and b) ideally work in an already twisted coordinate system, so another rotation would be multiplied into this process, which is what makes this so complex. Because at the start of the transformation, I first have to factor out the previous Y/Z tilt angles to get a base rotation which might differ from 0/0/0, and THEN multiply any changed tilt values back into it again. I have a relevant code snippet here, I tried to first rotate around Z specifically, then take the existing rotation and add an axis angle rotation around the rotated Y axis, but it's not working at all for me.

 

//rotation _rBaseRot = llGetLocalRot() / llEuler2Rot(<0, iTiltV, iTiltH> * DEG_TO_RAD);
			    	rotation _rBaseRot = llGetLocalRot() / llEuler2Rot(<0, -iTiltV, 0> * DEG_TO_RAD);
			    			 _rBaseRot = _rBaseRot       / llEuler2Rot(<0, 0, iTiltH>  * DEG_TO_RAD);
			    	
			    	if (~llSubStringIndex(message, "tilth"))
			    	{
			    		if (message == "tilth") iTiltH  = 0;
			        	else 				    iTiltH += (integer)_sTarget;
			    	}
			    	
			    	else
			    	{
				    	if (message == "tiltv") iTiltV = 0;
				    	if (message == "tilt")
				    	{
				    		iTiltV = 0;
				    		iTiltH = 0;
				    	}
				        else
				        	iTiltV += (integer)_sTarget;
			    	}
			        
			        llSetObjectDesc((string)iTiltH + ", " + (string)iTiltV);
			        
			        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, _rBaseRot * llEuler2Rot(<0, 0, iTiltH> * DEG_TO_RAD)]);
			        //llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, llGetLocalRot() * (llEuler2Rot(<0, -iTiltV, 0> * DEG_TO_RAD))]);
			        llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, llAxisAngle2Rot(<-llSin(iTiltH), llCos(iTiltH), 0> * DEG_TO_RAD, -iTiltV * DEG_TO_RAD)]);

Any sort of help on how to math this out better would be appreciated, I consider myself somewhat adept at scripting, but rotational math has always been a weak point of mine.

Link to comment
Share on other sites

I'm too lazy to try and parse your code example (fix the tabbing at least and maybe I'd be able to read it better) but rotations on the intrinsic axes of an object are as simple as left-multiplying its starting rotation.

rotation IntrinsicRotation = llGetRot();

// 15 degree rotation about an x-axis.
rotation X15 = llAxisAngle2Rot(<1,0,0>,15*DEG_TO_RAD);

// rotate the object 15 degrees about the world's X-axis:
llSetRot(IntrinsicRotation*X15);

// rotate the object 15 degrees about it's own x-axis:
llSetRot(X15*IntrinsicRotation);

 

  • Like 1
Link to comment
Share on other sites

Yeah not sure why the tabbing was so messed up, realized it too late. I did try this and it helps, now I just need to figure out the pre-existing rotation part. Aka if the user rotates the object, that should be respected and tilts should be applied on top of that. But I should be at the point where I can figure that out pretty easily, so thank you!

Edit:
And solved the issue, thank you again! The respective code is here, formatted nicely this time:

//obtain "natural" rtation of object without tilt angles
rotation _rBaseRot = llEuler2Rot(<0, iTiltV, -iTiltH> * DEG_TO_RAD) * llGetLocalRot();

  //Update tilt angles here

//rotate first around local Z, THEN around local Y
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL,  llEuler2Rot(<0, 0, iTiltH>  * DEG_TO_RAD)  * _rBaseRot]);
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, (llEuler2Rot(<0, -iTiltV, 0> * DEG_TO_RAD)) * llGetLocalRot()]);A

 

Edited by Psistorm Ikura
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 755 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...