mirror of
https://github.com/Mista-Tea/improved-stacker.git
synced 2025-03-04 03:12:57 -05:00
Fixing a longstanding issue with rotations that didn't treat the new rotations relative to the user's selected direction.
For example, with the new behavior a positive pitch will ALWAYS mean an UPWARD angle RELATIVE to the new direction. Basically, instead of rotation based on the prop's fixed directions, we rotate on the new angle depending on the user's selection. E.g., selecting "Behind" means we want to stack as if the prop's true "Behind" (i.e. -ent:Forward()) is actually it's "Front". Stacking "Up" means the prop's "Up" angle becomes it's new "Front" angle, etc.
This commit is contained in:
parent
c05b40fe24
commit
c559d85c50
@ -411,6 +411,15 @@ OffsetFunctions = {
|
||||
[DIRECTION_DOWN] = function( angle, offset ) return (-angle:Up() * offset.x) + ( angle:Forward() * offset.z) + ( angle:Right() * offset.y) end,
|
||||
}
|
||||
|
||||
RotationFunctions = {
|
||||
[DIRECTION_FRONT] = function( angle ) return angle:Right(), angle:Up(), angle:Forward() end,
|
||||
[DIRECTION_BACK] = function( angle ) return -angle:Right(), angle:Up(), -angle:Forward() end,
|
||||
[DIRECTION_RIGHT] = function( angle ) return -angle:Forward(), angle:Up(), angle:Right() end,
|
||||
[DIRECTION_LEFT] = function( angle ) return angle:Forward(), angle:Up(), -angle:Right() end,
|
||||
[DIRECTION_UP] = function( angle ) return -angle:Right(), angle:Forward(), angle:Up() end,
|
||||
[DIRECTION_DOWN] = function( angle ) return angle:Right(), angle:Forward(), -angle:Up() end,
|
||||
}
|
||||
|
||||
--[[--------------------------------------------------------------------------
|
||||
-- GetDirection( number, number, angle )
|
||||
--
|
||||
@ -465,8 +474,10 @@ end
|
||||
-- two angles together. The first angle is modified directly by refence, so this does not
|
||||
-- return anything.
|
||||
--]]--
|
||||
function RotateAngle( angle, rotation )
|
||||
angle:RotateAroundAxis( angle:Right(), rotation.x )
|
||||
angle:RotateAroundAxis( angle:Up(), -rotation.y )
|
||||
angle:RotateAroundAxis( angle:Forward(), rotation.z )
|
||||
function RotateAngle( stackMode, stackDir, angle, rotation )
|
||||
local axisPitch, axisYaw, axisRoll = RotationFunctions[ stackDir ]( angle )
|
||||
|
||||
angle:RotateAroundAxis( axisPitch, rotation.p )
|
||||
angle:RotateAroundAxis( axisYaw, -rotation.y )
|
||||
angle:RotateAroundAxis( axisRoll, rotation.r )
|
||||
end
|
@ -669,7 +669,8 @@ function TOOL:LeftClick( tr, isRightClick )
|
||||
-- calculate the next stacked entity's position
|
||||
entPos = entPos + (direction * distance) + offset
|
||||
-- rotate the next stacked entity's angle by the client's rotation values
|
||||
improvedstacker.RotateAngle( entAng, stackRotation )
|
||||
improvedstacker.RotateAngle( stackMode, stackDirection, entAng, stackRotation )
|
||||
|
||||
|
||||
-- check if the stacked props would be spawned outside of the world
|
||||
if ( stayInWorld and not util.IsInWorld( entPos ) ) then self:SendError( L(prefix.."error_not_in_world", localify.GetLocale( self:GetOwner() )) ) break end
|
||||
@ -1135,7 +1136,7 @@ if ( CLIENT ) then
|
||||
-- calculate the next stacked entity's position
|
||||
entPos = entPos + (direction * distance) + offset
|
||||
-- rotate the next stacked entity's angle by the client's rotation values
|
||||
improvedstacker.RotateAngle( entAng, stackRotation )
|
||||
improvedstacker.RotateAngle( stackMode, stackDirection, entAng, stackRotation )
|
||||
|
||||
local ghost = ghosts[ i ]
|
||||
ghost:SetPos( entPos )
|
||||
|
Loading…
Reference in New Issue
Block a user