function sampev.onSendVehicleSync(data) data.quaternion[1] = data.quaternion[1]-- x…
- User
function sampev.onSendVehicleSync(data) data.quaternion[1] = data.quaternion[1]-- x data.quaternion[2] = data.quaternion[2]-- y data.quaternion[3] = data.quaternion[3]-- z data.quaternion[4] = data.quaternion[4]-- w end
с помощью библиотеки maf разворачивай этот кватернион на 180 градусов относительно вектора вверх (0,0, 1)
-- maf -- https://github.com/bjornbytes/maf -- MIT License
local ffi = type(jit) == 'table' and jit.status() and require 'ffi' local vec3, quat
local forward local vtmp1 local vtmp2 local qtmp1
vec3 = { __call = function(_, x, y, z) return setmetatable({ x = x or 0, y = y or 0, z = z or 0 }, vec3) end,
__tostring = function(v) return string.format('(%f, %f, %f)', v.x, v.y, v.z) end,
__add = function(v, u) return v:add(u, vec3()) end, __sub = function(v, u) return v:sub(u, vec3()) end, __mul = function(v, u) if vec3.isvec3(u) then return v:mul(u, vec3()) elseif type(u) == 'number' then return v:scale(u, vec3()) else error('vec3s can only be multiplied by vec3s and numbers') end end, __div = function(v, u) if vec3.isvec3(u) then return v:div(u, vec3()) elseif type(u) == 'number' then return v:scale(1 / u, vec3()) else error('vec3s can only be divided by vec3s and numbers') end end, __unm = function(v) return v:scale(-1) end, __len = function(v) return v:length() end,
__index = { isvec3 = function(x) return ffi and ffi.istype('vec3', x) or getmetatable(x) == vec3 end,
code - Assistant
To rotate a quaternion 180 degrees around the up vector (0, 0, 1) using the
maflibrary, you'll need to create a quaternion representing the 180-degree rotation and then multiply it with the original quaternion.Here's how you can modify your
sampev.onSendVehicleSyncfunction to achieve this:lua