Advertisement
BloodknightStudios

Untitled

Nov 29th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. function setVectorLength(%vec, %desiredLength)
  2. {
  3.    error("setVectorLength vec:" SPC %vec SPC "desiredLength" SPC %desiredLength);
  4.    //this only works if we start with a unit vector so we have the relative valuse for x y and z
  5.    %vecNorm = vectorLen(%vec) > 1 ? vectorNormalize(%vec) : %vec;
  6.  
  7.    // x + y + z = the number to devide the length by in order to get the proper scale by which to
  8.    //multiply the vector elements
  9.    %nl = mAbs(getWord(%vecNorm, 0)) + mAbs(getWord(%vecNorm, 1)) + mAbs(getWord(%vecNorm, 2));
  10.    %scale = %desiredLength / %nl;
  11.    //now vector scale it and send it back
  12.    %newVec = vectorScale(%vecNorm, %scale);
  13.    error("finalVec:" SPC %newVec);
  14.    return %newVec;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement