Xiija Posted September 20, 2017 Share Posted September 20, 2017 hoping someone has done something like this before.. setup: it's for an OCD build, you touch a picture until it hangs straight. When you touch the picture, it rotates -45 degrees on the X axis, next touch, it rotates to +30 degrees on the X axis, then -15 degrees, and finally goes to Zero Rotation and gives a msg in local that the pic is finally straight. this works ok when the Z axis is zero, but as soon as the Z axis is changed, the pic is tilted and no longer straight when facing the toucher. ( there needs to be some rotation on the Y axis to correct this? ) **the actual code uses a random number and a variable ...tog = 1 ... llSetRot( llGetRot() * llEuler2Rot( <(llFrand(18.0) + 1.0) * (tog = -tog), 0, 0> * DEG_TO_RAD )); Thanx for any help or advice Link to comment Share on other sites More sharing options...
Innula Zenovka Posted September 20, 2017 Share Posted September 20, 2017 (edited) if you want to use the object's frame of reference, not the region's then you need to translate the rotation by llGetRot(). You're doing it the other way round. Try float tog = 1.0; default { state_entry() { //llSay(0, "Hello, Avatar!"); } touch_start(integer total_number) { float fRandom = tog * (llFrand(18.0)+1.0); rotation r = llEuler2Rot(<fRandom, 0, 0> * DEG_TO_RAD ); llSetRot(r *llGetRot()); tog *= -1.0; } } I broke it down so I could see what was going on. Generally, beware of the * sign in rotation formulae. It may look as if you're multiplying the rotation by something and, in multiplication, it doesn't matter which order you use -- 6 * 3 == 3 * 6. But in rotation calculations, * means "translate by" and the order really does matter. Edited September 20, 2017 by Innula Zenovka Link to comment Share on other sites More sharing options...
Xiija Posted September 20, 2017 Author Share Posted September 20, 2017 sweet, works great tysm i'm trying to zero out the rot after 10 clicks , but can't figure out the syntax? using this isn't working, i know i'm forgetting something, and have tried a few things but they don't work. llSetRot( ZERO_ROTATION * llGetRot() ); Thanx for any help Link to comment Share on other sites More sharing options...
Innula Zenovka Posted September 20, 2017 Share Posted September 20, 2017 For the final movement, why not edit the quaternion direct? This seems to work The object seems to drift a bit on its Y axis, for some reason I don't understand, which is why I correct the Y axis, too. float tog = 1.0; integer counter; rotation r; default { state_entry() { } touch_start(integer total_number) { if(++counter % 11){ float fRandom = tog * (llFrand(18.0)+1.0); r = llEuler2Rot(<fRandom, 0, 0> * DEG_TO_RAD ); llSetRot(r *llGetRot()); tog *= -1.0; } else{ llOwnerSay("finished"); r = llGetRot(); r.x = 0.0; r.y =0.0; llSetRot(r); } } } Link to comment Share on other sites More sharing options...
Xiija Posted September 20, 2017 Author Share Posted September 20, 2017 works! tysm ::hugs:: Link to comment Share on other sites More sharing options...
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