Exemplo n.º 1
0
        private void Move(NotuiElement element, BehaviorState state, Matrix4x4 usedplane)
        {
            var disptr = element.DisplayTransformation;

            if (Draggable)
            {
                var worldvel = Vector4.Transform(new Vector4(state.DeltaPos * DraggingCoeffitient * 0.5f, 0, 0), usedplane).xyz();
                if (element.Parent != null)
                {
                    Matrix4x4.Invert(element.Parent.DisplayMatrix, out var invparenttr);
                    worldvel = Vector4.Transform(new Vector4(worldvel, 0), invparenttr).xyz();
                }

                disptr.Translate(worldvel);
                if (LimitTranslation)
                {
                    disptr.Position = Intersections.BoxPointLimit(BoundingBoxMin, BoundingBoxMax, disptr.Position);
                }
            }
            if (Scalable)
            {
                var sclvel = state.DeltaSize * ScalingCoeffitient * 0.5f;
                disptr.Scale = Vector3.Max(
                    new Vector3(ScaleMinMax.X),
                    Vector3.Min(
                        new Vector3(ScaleMinMax.Y),
                        disptr.Scale * new Vector3(1 + sclvel)
                        )
                    );
            }
            if (Pivotable)
            {
                // see if rotation is still inside boundaries
                var targetrot = state.TotalAngle + state.DeltaAngle * RotationCoeffitient * 0.5f * (1 / disptr.Scale.Length());
                if (!LimitRotation || RotationMinMax.X <= targetrot && targetrot <= RotationMinMax.Y)
                {
                    state.TotalAngle = targetrot;

                    var worldaxis = Vector3.TransformNormal(Vector3.UnitZ, usedplane);
                    if (element.Parent != null)
                    {
                        Matrix4x4.Invert(element.Parent.DisplayMatrix, out var invparenttr);
                        worldaxis = Vector3.TransformNormal(worldaxis, invparenttr);
                    }
                    var worldrot = Quaternion.CreateFromAxisAngle(worldaxis, state.DeltaAngle * RotationCoeffitient);
                    disptr.LocalRotate(worldrot);
                }
            }
            state.Mainloop(element.Context.DeltaTime);
        }