Re: Re: Untitled

From Paltry Bushbaby, 9 Years ago, written in Lua, viewed 767 times. This paste will cross the great divide in 1 Second. This paste is a reply to Re: Untitled from Commodious Peccary - view diff
URL https://paste.godclan.hu/view/I0-PmSL5 Embed
Download Paste or View Raw
  1. function baseRotate(x, y, rz)
  2.     local x2 = x * cos(rz) - y * sin(rz)
  3.     local y2 = x * sin(rz) + y * cos(rz)
  4.     return x2, y2
  5. end
  6.  
  7. -- ZYX rotation
  8. function rotate(x, y, z, rx, ry, rz)
  9.     y, z = baseRotate(y, z, rx)
  10.     x, z = baseRotate(-x, z, ry)
  11.     x = -x
  12.     x, y = baseRotate(x, y, rz)
  13.     return x, y, z
  14. end
  15.  
  16. function setTurnVelocityAlong(vehElement, x, y, z, v)
  17.     -- Normalize vector
  18.     local r = sqrt(x * x + y * y + z * z)
  19.     local x2, y2, z2 = x * v / r, y * v / r, z * v / r
  20.  
  21.     -- Rotate vector
  22.     local rx, ry, rz = getElementRotation(vehElement, "ZYX")
  23.     x, y, z = rotate(x2, y2, z2, math.rad(rx), math.rad(ry), math.rad(rz))
  24.  
  25.     -- Set turn velocity
  26.     return setVehicleTurnVelocity(vehElement, x, y, z)
  27. end

Reply to "Re: Re: Untitled"

Here you can reply to the paste above