Advertisement
Guest User

bone_pos_rot

a guest
Aug 2nd, 2015
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. sx,sy,sz = 0,0,3
  2. tx,ty,tz = 0,0,4
  3. fx,fy,fz = 0,1,3
  4.  
  5. function getMatrixFromPoints(x,y,z,x3,y3,z3,x2,y2,z2)
  6.     x3 = x3-x
  7.     y3 = y3-y
  8.     z3 = z3-z
  9.     x2 = x2-x
  10.     y2 = y2-y
  11.     z2 = z2-z
  12.     local x1 = y2*z3-z2*y3
  13.     local y1 = z2*x3-x2*z3
  14.     local z1 = x2*y3-y2*x3
  15.     x2 = y3*z1-z3*y1
  16.     y2 = z3*x1-x3*z1
  17.     z2 = x3*y1-y3*x1
  18.     local len1 = 1/math.sqrt(x1*x1+y1*y1+z1*z1)
  19.     local len2 = 1/math.sqrt(x2*x2+y2*y2+z2*z2)
  20.     local len3 = 1/math.sqrt(x3*x3+y3*y3+z3*z3)
  21.     x1 = x1*len1 y1 = y1*len1 z1 = z1*len1
  22.     x2 = x2*len2 y2 = y2*len2 z2 = z2*len2
  23.     x3 = x3*len3 y3 = y3*len3 z3 = z3*len3
  24.     return x1,y1,z1,x2,y2,z2,x3,y3,z3
  25. end
  26.  
  27. function getEulerAnglesFromMatrix(x1,y1,z1,x2,y2,z2,x3,y3,z3)
  28.     local nz1,nz2,nz3
  29.     nz3 = math.sqrt(x2*x2+y2*y2)
  30.     nz1 = -x2*z2/nz3
  31.     nz2 = -y2*z2/nz3
  32.     local vx = nz1*x1+nz2*y1+nz3*z1
  33.     local vz = nz1*x3+nz2*y3+nz3*z3
  34.     return math.deg(math.asin(z2)),-math.deg(math.atan2(vx,vz)),-math.deg(math.atan2(x2,y2))
  35. end
  36.  
  37. function getMatrixFromEulerAngles(x,y,z)
  38.     x,y,z = math.rad(x),math.rad(y),math.rad(z)
  39.     local sinx,cosx,siny,cosy,sinz,cosz = math.sin(x),math.cos(x),math.sin(y),math.cos(y),math.sin(z),math.cos(z)
  40.     return
  41.         cosy*cosz-siny*sinx*sinz,cosy*sinz+siny*sinx*cosz,-siny*cosx,
  42.         -cosx*sinz,cosx*cosz,sinx,
  43.         siny*cosz+cosy*sinx*sinz,siny*sinz-cosy*sinx*cosz,cosy*cosx
  44. end
  45.  
  46. if not script_serverside then
  47.     function getBoneMatrix(ped,bone)
  48.         local x,y,z,tx,ty,tz,fx,fy,fz
  49.         x,y,z = getPedBonePosition(ped,bone_0[bone])
  50.         if bone == 1 then
  51.             local x6,y6,z6 = getPedBonePosition(ped,6)
  52.             local x7,y7,z7 = getPedBonePosition(ped,7)
  53.             tx,ty,tz = (x6+x7)*0.5,(y6+y7)*0.5,(z6+z7)*0.5
  54.         elseif bone == 3 then
  55.           if not (getPedSkin(ped) == 0) then
  56.             local x21,y21,z21 = getPedBonePosition(ped,21)
  57.             local x31,y31,z31 = getPedBonePosition(ped,31)
  58.             tx,ty,tz = (x21+x31)*0.5,(y21+y31)*0.5,(z21+z31)*0.5
  59.           else
  60.             local x21,y21,z21 = getPedBonePosition(ped,22)
  61.             local x31,y31,z31 = getPedBonePosition(ped,32)
  62.             tx,ty,tz = (x21+x31)*0.5,(y21+y31)*0.5,(z21+z31)*0.5
  63.             --tx,ty,tz = getPedBonePosition(ped,bone_t[bone])
  64.           end
  65.         else
  66.             tx,ty,tz = getPedBonePosition(ped,bone_t[bone])
  67.         end
  68.         fx,fy,fz = getPedBonePosition(ped,bone_f[bone])
  69.         local xx,xy,xz,yx,yy,yz,zx,zy,zz = getMatrixFromPoints(x,y,z,tx,ty,tz,fx,fy,fz)
  70.         if bone == 1 or bone == 3 then xx,xy,xz,yx,yy,yz = -yx,-yy,-yz,xx,xy,xz end
  71.         return xx,xy,xz,yx,yy,yz,zx,zy,zz
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement