Jump to content
Lolita Erin

How can i compare 2 rotation variables?

Recommended Posts

hello i have try to compare 2 rotation variables and no luck can anyone give me avise?

both variables has this value <0.00000, 0.00000, 0.38268, 0.92388> i all ready check it using llownersay

i am using some code like this

 

 rotation myQuatRot = llEuler2Rot(<0.0,0.0,45.0> * DEG_TO_RAD);
 list temp = llGetLinkPrimitiveParams(1,[ PRIM_ROT_LOCAL ]  ); 
 rotation r = llList2Rot( temp,0); 
 if (myQuatRot == r) llOwnerSay(" MATCH");

Thanks for any help

Share this post


Link to post
Share on other sites

You say you're checking with llOwnerSay, but that code looks OK to me.  So my first thought is that probably myQuatRot and r don't match exactly, all the way down to the 6th decimal point or whatever it is.   

Have you checked by saying something like 

lllOwnerSay("myQuatRot is "+(string)myQuatRot+" and r is "+(string) r);

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

That's not a good idea.  Your chances of getting a perfect match are very close to zero.  All you need is a tiny bit of roundoff error to make it fail.  Whenever you need to compare two vectors, rotations, or floats, the best solution is to ask whether they are within a small acceptable range of each other.  There's no one-size-fits-all test, because each situation demands a different definition of "acceptable".  In your case, you might want to ask whether r.x and r.y and r.z are within, say, 0.05 of myQuatRot.x, myQuatRot.y and myQuatRot.z .  It's a good idea to do some practical tests to decide for yourself how much error is going to be reasonable.

  • Like 2

Share this post


Link to post
Share on other sites

hi Innula thanks for your reply and yes i have try that here is the result

 

myQuatRot is <0.00000, 0.00000, 0.38268, 0.92388> and r is <0.00000, 0.00000, 0.38268, 0.92388>

but cant compare it

Share this post


Link to post
Share on other sites

I usually print it out like this, llOwnerSay( "myQuatRot is "+ llList2String((list)myQuatRot, 0) +" and r is "+ llList2String((list)r, 0)); to display the 6th decimal point as well.

What takes me wonder is that you are calling it on the root prim of a linkset. So whenever the object is rotated away from 45Z, the code will fail.

  • Like 1

Share this post


Link to post
Share on other sites
      integer prims=llGetNumberOfPrims();  
      integer x;
 
      rotation myQuatRot = llEuler2Rot(<0.0,0.0,45.0> * DEG_TO_RAD);
      vector myVecZ = llRot2Euler(myQuatRot)*RAD_TO_DEG;
      
      for(x = 1; x <= prims;++x){ 
        key link_key = llGetLinkKey(x);       
        list temp = llGetLinkPrimitiveParams(x,[ PRIM_ROT_LOCAL ]  ); 
        rotation r = llList2Rot( temp,0); 
        vector rr = llRot2Euler(r)*RAD_TO_DEG;

        if (myVecZ.z == rr.z) llOwnerSay("Link # "+ (string)x + " rr.z " + (string)rr.z);

        
      }  

This works ok change it to DEG....

 

any suggestion?

Share this post


Link to post
Share on other sites
3 minutes ago, Lolita Erin said:

i manualy set the 45 for testing porpuse

That's the cause of the error then most likely.

  • Like 1

Share this post


Link to post
Share on other sites

i made it work thanks 

check_prims(){
      integer prims=llGetNumberOfPrims();  
      integer x;
 
      rotation myQuatRot = llEuler2Rot(<0.0,0.0,45.0> * DEG_TO_RAD);
      vector myVecZ = llRot2Euler(myQuatRot)*RAD_TO_DEG;
      
      for(x = 1; x <= prims;++x){ 
        key link_key = llGetLinkKey(x);       
        list temp = llGetLinkPrimitiveParams(x,[ PRIM_ROT_LOCAL ]  ); 
        rotation r = llList2Rot( temp,0); 
        vector rr = llRot2Euler(r)*RAD_TO_DEG;

        if (myVecZ.z == rr.z){
             
             llOwnerSay("CHANGE Link # "+ (string)x + " rr.z " + (string)rr.z);
             llSetLinkPrimitiveParamsFast( x, [PRIM_ROT_LOCAL, ZERO_ROTATION] );
             
            }
        
      }  
}

 

Share this post


Link to post
Share on other sites
8 minutes ago, Lolita Erin said:

any suggestion?

Yes, I still advise strongly against making an absolute comparison like this, whether you are doing it by Nova's method (which I like) or by testing individual elements of your two rotations.  Calculated values of ANY variable with a floating point component will always have some uncertainty, so you cannot rely on making absolute comparisons with them.  Always test to see whether the values fall within some expected, acceptable range of a target.

  • Like 1

Share this post


Link to post
Share on other sites
Just now, Lolita Erin said:

Thanks Rolig Loon any sample code thanks

Use Nova's ....

19 minutes ago, Nova Convair said:

if (llAngleBetween(rot1,rot2)<0.0005) llSay(0,"this is equal enough for me");

;)

  • Like 1

Share this post


Link to post
Share on other sites

I'm still wondering what the purpose of this is. Wouldn't it be easier to just compare each link but the root, against ZERO_ROTATION, to make all links have the same orientation as the root?

Edited by arton Rotaru

Share this post


Link to post
Share on other sites

No because some link prims orientation are diferen, i have vehicle mesh all Linked, something very strange happend when i attach a Prim (for the engine script) after i linked some mesh part not all some move little for example some are 180 Degre and others are 179.90 and you can see the vehicle is broke, so i am trying to make small script to find all that 179.90 and change it to 180 but for some reason i just cant mmmmm.....

Edited by Lolita Erin

Share this post


Link to post
Share on other sites

If I properly understand the problem, components in the build are drifting out of their correct rotation for some reason.   If that's the case, since you know the desired rotations for all the child prims, why not simply loop through the linkset every so often, setting them to the correct rotations  (whether they need resetting or not)?    If they don't need moving, they won't move. If they do need to move, they will.   No need to worry about determining whether or not they need to.

Edited by Innula Zenovka
  • Like 1

Share this post


Link to post
Share on other sites

I see. Well in that case you will have to safe all links with their name, and the desired rotations in lists. Because UUIDs will be different for each copy of the vehicle. Hardcoded, so it won't read in wrong rotations.

Then searching for the linknumber for each name, and apply the correct rotation.

  • Like 3

Share this post


Link to post
Share on other sites

Thanks again for advise, i was trying to loop for all the Links are about 90, check the rotation, if they match to the rotation change it, because i know the rotation erro after i link the empty prim to the vehicle. but i just cant compare...

i set a variable to 179.90 to search in the prims and even i know there are some links with rotation 179.90 all the result are 180...

 

here is the result my variable to search (was 179.90) and the result of the rotation 

Link # 18 myVecZ.z 179.899994 rr.z 180.000000

so like Rolig say is very complex to compare....

 

Share this post


Link to post
Share on other sites
3 minutes ago, Lolita Erin said:

so like Rolig say is very complex to compare....

So, like Innula says, don't bother.  Just assume that they are all wrong and set them deliberately to the values that you want.  If they are already correct, they won't move.  If they have drifted a bit, they will be corrected.  Easy peasy, and you don't need to compare anything.

  • Like 1

Share this post


Link to post
Share on other sites

Just pay attention to Arton's latest note so that you don't accidentally apply the wrong rotations to the wrong prims.  With a little care, your problem should be solved.  :)

  • Like 1

Share this post


Link to post
Share on other sites

Never hard-code link numbers.   Always name the prims (or put something in the description field) and use that to identify the prims and read their link numbers.  

  • Like 2

Share this post


Link to post
Share on other sites
56 minutes ago, Lolita Erin said:

yes i use name on prims on the ones  i need to manipulate other i dont put them same name to all.

People use these forums as a learning resource -- I certainly did when I was starting, and still do -- so I sometimes take the opportunity to point stuff out that most of us probably know anyway but that someone reading the thread in the future might find helpful.

  • Like 1

Share this post


Link to post
Share on other sites

Maybe soon we'll get access to an unchangeable prim parameter that would be unique enough to reference instead with link,name,desc,settext changes in mod objects, heh.

  • Like 1

Share this post


Link to post
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.

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.


×
×
  • Create New...