Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local quat = {
- tostring = function(self)
- return "[x:"..self.v.x..", y:"..self.v.y..", z:"..self.v.z..", w:"..self.a.."]"
- end,
- lengthSq = function(self)
- return self.v.x*self.v.x + self.v.y*self.v.y + self.v.z*self.v.z + self.a*self.a
- end,
- length = function(self)
- return math.sqrt(self:lengthSq())
- end,
- conjugate = function(self)
- return new(-self.v,self.a)
- end,
- normalize = function(self)
- local l = self:length()
- return new(self.v:div(l), self.a/l)
- end,
- inverse = function(self)
- if self:lengthSq() < 1e-5 then
- return self
- end
- local tmp = self:conjugate()
- return tmp:normalize()
- end,
- mulQuat = function(self, q)
- return new(q.v:mul(self.a) + self.v:mul(q.a) + self.v:cross(q.v), self.a*q.a-self.v:dot(q.v))
- end,
- mul = function(self,v)
- local tmp = self:mulQuat(new(v,0))
- tmp = tmp:mulQuat(self:inverse())
- return tmp.v
- end,
- }
- local vmetatable = {
- __index = quat,
- --__add = vector.add,
- --__sub = vector.sub,
- --__mul = vector.mul,
- --__div = vector.div,
- --__unm = vector.unm,
- __tostring = quat.tostring,
- --__eq = vector.equals,
- }
- function new(vec, w)
- return setmetatable({
- v = vec or vector.new(),
- a = tonumber(w) or 1,
- }, vmetatable)
- end
- function new2(quat)
- return setmetatable({
- v = vector.new(quat.x, quat.y, quat.z),
- a = quat.w,
- }, vmetatable)
- end
- local last = new2(ship.getQuaternion())
- local total = 0
- local cachedTotal = 0
- local counter = 0
- while true do
- local cur = new2(ship.getQuaternion())
- local inv = cur:inverse()
- inv = inv:mulQuat(last)
- last = cur
- local angle = 2*math.atan(inv.v:length(), inv.a)
- -- convert to RPM
- local rpm = angle / (2 * math.pi) * 20 * 60
- --print(rmp)
- total = total + rpm
- counter = counter + 1
- if counter == 20 then
- cachedTotal = total / 20
- counter = 0
- total = 0
- end
- commands.exec(string.format("title @a actionbar {\"text\":\"RMP: %5.1f / %5.1f\"}", rpm, cachedTotal))
- --sleep(0.01)
- end
Advertisement
Add Comment
Please, Sign In to add comment