Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --custom angles (just like v3 but for math with radian orientation)
- --StaliniumDev
- --who ever reads it ur free to use it lol
- --10 Jun 2021
- local allowed = {'x', 'y', 'z', 'tocf'}
- local pi, tpi = math.pi, math.pi*2
- local sin, cos = math.sin, math.cos
- local och = function(ang)
- return ang%tpi
- end
- local gcl = function(tar, orig)
- local a = tar - orig
- a = (a+pi)%tpi-pi
- return a
- end
- local lerp = function(self:angles, target:angles, step:number)
- return self+(target-self)*step
- end
- local tocf = function(self)
- return CFrame.fromOrientation(self.x, self.y, self.z)
- end
- angles = {
- new = function(x,y,z, raw)
- x = x or 0
- y = y or 0
- z = z or 0
- if not raw and false then
- return setmetatable ( { -- this never runs lol
- x = och(x);
- y = och(y);
- z = och(z);
- tocf = tocf;
- }, metafun )
- else
- return setmetatable ( {
- x = x;
- y = y;
- z = z;
- tocf = tocf;
- lerp = lerp;
- Lerp = lerp;
- }, metafun )
- end
- end,
- fromcf = function(cf)
- return angles.new(cf:ToOrientation())
- end;
- }
- local tdeg = function(a)
- return math.floor(math.deg(a)*100)/100
- end
- metafun = {
- __tostring = function(self)
- return tdeg(self.x)..', '..tdeg (self.y)..', '.. tdeg(self.z)
- end,
- __index = function(self, index)
- local low = string.lower(index)
- if low == 'unit' then
- return self/self.magnitude
- elseif low == 'magnitude' then
- return (self.x^2+self.y^2+self.z^2)^0.5
- end
- if table.find(allowed, low) then
- return rawget(self, low)
- else
- error(tostring(index)..' is not a valid member of angles')
- end
- end,
- __newindex = function(self, index)
- error('unable to set a new index in angles')
- end,
- __add = function(self, a2)
- return angles.new(self.x+a2.x, self.y+a2.y, self.z+a2.z )
- end,
- __sub = function(self, a2)
- return angles.new(
- gcl( self.x, a2.x ),
- gcl( self.y, a2.y ),
- gcl( self.z, a2.z )
- , true)
- end,
- __unm = function(self)
- return angles.new(-self.x, -self.y, -self.z)
- end,
- __mul = function(self, a2)
- if typeof(a2) == 'number' then
- return angles.new(self.x*a2, self.y*a2, self.z*a2)
- else
- return angles.new(self.x*a2.x, self.y*a2.y, self.z*a2.z )
- end
- end,
- __div = function(self, a2)
- if typeof(a2) == 'number' then
- return angles.new(self.x/a2, self.y/a2, self.z/a2)
- else
- return angles.new(self.x/a2.x, self.y/a2.y, self.z/a2.z )
- end
- end,
- }
- return angles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement