Lolita Erin Posted July 18, 2017 Posted July 18, 2017 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
Innula Zenovka Posted July 18, 2017 Posted July 18, 2017 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); 1
Rolig Loon Posted July 18, 2017 Posted July 18, 2017 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. 2
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 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
arton Rotaru Posted July 18, 2017 Posted July 18, 2017 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. 1
Nova Convair Posted July 18, 2017 Posted July 18, 2017 I use this to compare 2 rotations: if (llAngleBetween(rot1,rot2)<0.0005) llSay(0,"this is equal enough for me"); 5
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 Thank you Rolig Loon and arton Rotaru. arton Rotaru, i manualy set the 45 for testing porpuse and the idea is to find the linked objet that is not rotated correctly and fix it thanks
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 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?
arton Rotaru Posted July 18, 2017 Posted July 18, 2017 3 minutes ago, Lolita Erin said: i manualy set the 45 for testing porpuse That's the cause of the error then most likely. 1
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 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] ); } } }
Rolig Loon Posted July 18, 2017 Posted July 18, 2017 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. 1
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 Thanks Rolig Loon any sample code thanks
Rolig Loon Posted July 18, 2017 Posted July 18, 2017 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"); 1
arton Rotaru Posted July 18, 2017 Posted July 18, 2017 (edited) 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 July 18, 2017 by arton Rotaru
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 (edited) 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 July 18, 2017 by Lolita Erin
Innula Zenovka Posted July 18, 2017 Posted July 18, 2017 (edited) 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 July 18, 2017 by Innula Zenovka 1
arton Rotaru Posted July 18, 2017 Posted July 18, 2017 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. 3
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 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....
Rolig Loon Posted July 18, 2017 Posted July 18, 2017 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. 1
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 off course!!! i was getting crazy lol i will do that
Rolig Loon Posted July 18, 2017 Posted July 18, 2017 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. 1
Innula Zenovka Posted July 18, 2017 Posted July 18, 2017 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. 2
Lolita Erin Posted July 18, 2017 Author Posted July 18, 2017 yes i use name on prims on the ones i need to manipulate other i dont put them same name to all. 1
Innula Zenovka Posted July 18, 2017 Posted July 18, 2017 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. 1
Lucia Nightfire Posted July 19, 2017 Posted July 19, 2017 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. 1
Recommended Posts
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