Files
gm_construct_port/code/PreviewEntity.cs
2021-08-05 17:54:51 +03:00

40 lines
886 B
C#

namespace Sandbox.Tools
{
public class PreviewEntity : ModelEntity
{
public bool RelativeToNormal { get; set; } = true;
public bool OffsetBounds { get; set; } = false;
public Rotation RotationOffset { get; set; } = Rotation.Identity;
public Vector3 PositionOffset { get; set; } = Vector3.Zero;
internal bool UpdateFromTrace( TraceResult tr )
{
if ( !IsTraceValid( tr ) )
{
return false;
}
if ( RelativeToNormal )
{
Rotation = Rotation.LookAt( tr.Normal, tr.Direction ) * RotationOffset;
Position = tr.EndPos + Rotation * PositionOffset;
}
else
{
Rotation = Rotation.Identity * RotationOffset;
Position = tr.EndPos + PositionOffset;
}
if ( OffsetBounds )
{
Position += tr.Normal * CollisionBounds.Size * 0.5f;
}
return true;
}
protected virtual bool IsTraceValid( TraceResult tr ) => tr.Hit;
}
}