How do i convert this formula to hify javascript


This formula i use in opensim, works perfect, i think someone gave it to me. This same one could possible fix lots of problem i now have in hify. but there are differencers, and i dont get it converted. This formulae makes sure the rotation and angle is always correct at ever position calculated from the center. i post here only the formula for the center position. Maby someonme knows how todo this in hify. My math is not so perfect to solve this conv
ersion :wink:

LSL version

centerposition = currentposition+offset-<0.0 ,0.0 , 0.0>*rotation;

Centerposition , currentposition and offset are vectors.
rotation is in quaternion.

But whats the javascript version from this ?


In your script, what does the zero vector represent?

Assuming that “centerposition” is a location where you wish to position something (like a voxel or entity), you could follow the example given by @Adrian in the butterfly.js script:

var flockPosition = Vec3.sum(
			Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME), 
			Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)

…and multiply your offset by the rotation; THEN add that to av position.

So, it might look something like this:

var centerposition = Vec3.sum(
			Vec3.multiply( Quat.getFront( MyAvatar.orientation ), offset)

I have not tested this, but it seems like a step in the right…



The zero vector can be the following to as example what i have used.

startposition = currentposition+offset-<size/2 ,0.0 , 0.0>*rotation;

In this case its not for the avatar, but for entity objects, going to study your example.
if there are some improvements ill read it here.

Let me explain it beter. i need to know the start and end from entity. in what angle its placed. Thats the above formula doing for me with a small change i know the otehr side to. Also it helps me to let a entity always move in the correct direction. at least in opensim. Hify im still testing.

Beter example how i use it now, and expended this code to get it how i need it

startposition = currentposition+offset-<10/2 ,0.0 , 0.0>*rotation;
centerposition = currentposition+offset-<0.0 ,0.0 , 0.0>*rotation;
endposition =currentposition+offset+<10/2 ,0.0 , 0.0>*rotation;


Let me explain it different. if you have 2 positions x1,y1,z1 and x2,y2,z2 + rotation, movement on the X axis. I need to know all steps between both coordinates and the rotation need to follow the same angle. Also in SL you can rotate the prim, and if you enter the coordinates the movement still is on the X axis. that way you can move a entitiy on defined path (for now)

Other words i need to move entity like its a verhicle or plane.


Its a bit early in the morning for me to try to navigate this kind of math so I will look at the explanations later, for now let me offer some methods that you could use.

  1. convert quats to vector3 using Quat.safeEulerAngles(orientation) and work with Vec3 using Vec3.sum and Vec3.multiply() etc.
  2. convert Vec3 to quaternions using Quat.fromVec3Degrees or Quat.fromVec3Radians and work with quat with the likes of Quat.multiply() etc.
  3. use a crossover method to deal with different types, eg Vec3.multiplyQbyV which will multiply a quat by a vec3 and return the result as a Vec3 (very useful)

let me know if that answers your question, @azwaldo may have something in his reply, of course we are using entities and not avatars so I am not sure how Quat.getFront will work with entities given the confusion over which is the official “front” of the object, but if you can work that out please post here so we can all use it, that would save a heap of problems.


Still lost, one thing i dont understand, if i want to print as example the rotation. You would say do this.


But thats not working at all, you get [object] back. you always need todo this,


To get the numbers back, not sure why it only works that way. lucky when i use this for testing it works, but you always need to put x,y,z as seperate command. woudl be nice if you can just print it as one.

var sumrot=Vec3.sum(properties.rotation,properties.rotation);

Still need to figure out everything :open_mouth:


@Richardus yes there is an easier way, use JSON.stringify(),



AHa. ! thanks. wanted to make a short video of what i want. but foudn a problem in my lsl script. :grinning: need to fix that first. still the idea keeps the same. need a prim that moves from x1,y1,z1 to x2,y2,z2 and we nee dto move it by script all the steps between it. Then its maby not so important if you have a front backl or what direction, that you solve by rotationg it.

SHame there’s not a default command for that already.


This is what i need in HiFy, or something simmilair. Them i can work on more things.
Made also suggestion onm worklist for command.


Where hoping this worked, but im wrong.

properties = Entities.getEntityProperties(EntityObjectID);
var result=properties.position*properties.rotation;

Back to the think table, at that point LSL is a bit more flexible. Posisble do soemthing wrong with comversion and calculating it. This where just test. Failed when i converted . Tried this. but still cannot calculate both togheter, result is NULL. angles gfive result back. but the line below is fail.

var angles = Quat.safeEulerAngles(properties.rotation);
var result=properties.position*angles;

Last hope. Offcorse right before you want to sleep :expressionless: But no luck, i get incompatiblilty error if am trying this.

var angles = Quat.safeEulerAngles(properties.rotation);
var result=Vec3.multiply(properties.position,angles);


"TypeError: ambiguous call of overloaded function multiply(); candidates were

So, dont think multiply works in this case. Or im doing it still wrong.


To multiply a Quat and a Vec the function to use is Vec3.multiplyQbyV(,)
Vec3.multiply(…) takes a float and a Vec3 as indicated by the error message.


Thanks @ctrlaltdavid, thats working. Only the results are far from what you expect when i do the following at this position position = { x: 123, y: 168, z: 180 };

properties = Entities.getEntityProperties(EntityObjectID);
var result=Vec3.multiplyQbyV(properties.position,properties.rotation);
print('result = '+JSON.stringify(result))

I get back as result:

result = {“x”:0.5438162684440613,“y”:-0.10301365703344345,“z”:-0.27550163865089417

When i do the same in opensim.

vector result = position*trackrotation; 
llOwnerSay("Result ="+(string)result);

I get back,

Result =<123.000032,179.999978,168.000000>

Still doing lots wrong. :mag: needd to look closer at it.


@Richardus Try swapping properties.position and properties.rotation in the multiplyQbyV() expression, i.e., var result=Vec3.multiplyQbyV(properties.rotation, properties.position);


@ctrlaltdavid thatb did the trick, only weird thing. i have tried this before and nothing changed. so or the script where nots saved correctly or wrong old version wehre still caching around.




This formula is not working at all in Javascript. it need a different way. Only how… also seen that LSL gives a different output if you convert quart to degrees, compared to HiFi. Trying few other combinations. But technical… Stuck. :sos: Other way of calculating it brings me close to the numbers, need to be carefull that you dont mix Z and Y still happens many times. Calculated X,Y,Z seperate now, and just see a wrong result. The  :sos: stay , :wink:


If you could post more of the script in question that might give us more clues.
Also from the small bit of LSL posted is not obvious if they are working in degrees or radians.
LSL script is never going to be easy to covert, possible but not easy, not only do we have Y up causing issues but we also have -Z forward instead of +X, this means your result is likely to be -90 degrees out compared to what you might expect.


I can give the LSL script, for HiFy i dont have much workable.
But now you telling something i did not know ort forgot. Z is the wrong way ?! Always worked with only Y is wrong. but this possible explains the strange results maby to. the lsl script can look a bit messy, because its testing version.

LSL script:

vector      offset         = <0.0, 0.0, 0.0>;
float       divide         = 2;
float       partsize       = 10;
float       speed          = 0.1;

list        targetpositions = [];

vector      startposition;
vector      centerposition;
vector      endposition;
vector      currentposition;
vector      position;
rotation    rot;

integer     target_id;
integer     t=0;
float       m;
        currentposition=<123., 180., 168.>;
        llSetPos( currentposition);
    touch_start( integer total_number ) 
        llSetPos( currentposition);
        startposition =  currentposition+offset-<partsize/divide ,0.0 , 0.0>* rot;
        centerposition =  currentposition+offset-<0.0 ,0.0 , 0.0>* rot;
        endposition =  currentposition+offset+<partsize/divide ,0.0 , 0.0>* rot;         
        target_id = llTarget(<0,0,0>, 0.5);                                     

        if (m<partsize)
                llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_POSITION, startposition+offset+<m ,0.0 , 0.0>* rot ]); 

What im trying todo.

I have the coordinate of the prim or entity and the rotation. bot are always center of the prim.entity. Im also knowing the size of the prim/entity. Now i need to know the coordinates of the prim/entity at the begin and end. Including the angle or rotation of the prim. I dont know the end coordinates, thats just what i need to calculate !


Think am changeing my idea a bit to make it more simple / different. Back to drawing board.
Still would be nice how todo the same in hifi as i do in opensim.


Yes this is going to be difficult to translate into js, some of the methods arent supported.
Not sure how this is working out of the box because <0.0 ,0.0 , 0.0>* rot; seems to be multiplying a vector by a quaternian, and as ctrlaltdavid said we use multiplyQbyV() so somehow LSL is allowing the multiplication to take place, perhaps LSL has the conversion built in?

I know we all want to be able to use our lsl scripts here, but for now its not happening, I suggest forget about the lsl script and start again writing the script from scratch in js, then it will be easier to mod in future.
I think compatibility with LSL is a step backwards, like inventing a color TV and tuning it to work best with black and white transmissions. JS is going to be way more flexible and powerful.
Sorry I cant help in this instance.


Thats what im doing all the time @Adrian , starting from scratch. and thats why im compleet stuck. because i dont know how to move entity from X,Y,Z + rotation to a new coordinate thats 10 metres forward in the x direction. If you rotate the entity the X sstill need to be the forward direction.

That lsl command is my only way i know how to move a prim. But that forumale is not convertable.

Somewhere afraid i cannot do much for a while in hifi, i dont know how to make the right formula or something is missing. Or both. and still im sure its laready possible in hifi.