Jump to content

Rotation division by an integer


BetaGem
 Share

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

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

Recommended Posts

hi everyone

rotations are always a problem ... is there a way to make a simple division of a rotation by an integer rot / 2,   rot / 3    ?

for example I know 2 vectors and so I can calculate llRotBetween to know the rotation from one to another, but I'm looking for a way to do only 1/3 or 1/4 of this rotation

Link to comment
Share on other sites

Unless you want to drive yourself crazy with quaternion math, the easy way is to do all your math with vectors and then use llEuler2Rot and llRot2Euler for going between the rotation and vector versions.

vector Original = llRot2Vector(my_Original_rotation);

vector Smaller = Original * RAD_TO_DEG / 4;

rotation New = llEuler2Rot(Smaller);

Edited by Rolig Loon
Typos, as usual
  • Like 1
Link to comment
Share on other sites

I agree that it would be an interesting mathematical exercise to try the quaternion math.  There are many times, though, when you have to ask yourself whether it's worth your time (and the probable complexity of your code) to go to all the trouble of getting the nice mathematical answer.  I think this is one of those times.  Except for the rather low probability of running into gimbal lock, you get just as good a result by framing a problem like this as a vector issue rather than a rotation issue. You'll get fewer gray hairs too.  ?

Link to comment
Share on other sites

the issue with writing our own LSL functions for quaternion math is that whatever we write is typically slower and more script memory consumptive than the API functions

agree with Rolig that is faster and easier to use euler in pretty much most cases

where thinking in quaternions can be effective is when we just kinda know what the values needed are. Example of just kinda knowing:

/* simple door
  prim parameters
  size: x = 1.0, y = 0.1, z = 1.0
  slice: B = 0.0, E = 0.5
  rotation: x= 90.0, y = 0.0, z = 90.0 
*/

rotation q = <0.70711, 0.00000, 0.00000, 0.70711>;
rotation r;

pivot()
{
    llSetLocalRot((r = (ZERO_ROTATION / r)) * llGetLocalRot());    
    llSetTimerEvent((r != q) * 5.);
}

default
{
    state_entry()
    {
        r = q;    
    }
    
    touch_start(integer n)
    {
        pivot();
    }
    
    collision_start(integer n)
    {
        pivot();
    }
    
    timer()
    {
        pivot();    
    }
}

 

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2015 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...