public static Vector3 ExtractComponents(this Vector3 source, VectorComponent component)
 {
     return(new Vector3(
                component.HasFlag(VectorComponent.X) ? source[0] : 0,
                component.HasFlag(VectorComponent.Y) ? source[1] : 0,
                component.HasFlag(VectorComponent.Z) ? source[2] : 0));
 }
예제 #2
0
        public NodeVariable GetVector3Result()
        {
            if (resultV3Variable == null)
            {
                resultV3Variable = new NodeVariable <Vector3>();
            }

            VectorComponent targetComponent = GetInputValue(targetComponentInput);

            Vector3 originVector3 = GetInputValue(originV3Input);
            float   targetValue   = GetInputValue(valueInput);

            switch (targetComponent)
            {
            case VectorComponent.X:
                originVector3.x = targetValue;
                break;

            case VectorComponent.Y:
                originVector3.y = targetValue;
                break;

            case VectorComponent.Z:
                originVector3.z = targetValue;
                break;
            }

            resultV3Variable.value = originVector3;
            return(resultV3Variable);
        }
예제 #3
0
        /// <summary>
        /// Flatten along a particulat axis
        /// </summary>
        public static Vector3 Flatten(this Vector3 vector, VectorComponent component = VectorComponent.Y)
        {
            Vector3 flatten;
            float   magnitude = vector.magnitude;
            Vector3 direction = vector.normalized;

            switch (component)
            {
            case VectorComponent.X:
                direction.x = 0;
                break;

            case VectorComponent.Y:
                direction.y = 0;
                break;

            case VectorComponent.Z:
                direction.z = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("component", component, null);
            }
            flatten = direction * magnitude;
            return(flatten);
        }
예제 #4
0
        partial void Callback_OnClicked(VectorComponent component)
        {
            FloatDistribution distribution = Value;

            if (DistributionType == PropertyDistributionType.Curve)
            {
                CurveEditorWindow.Show(distribution.GetMinCurve(), (success, curve) =>
                {
                    if (!success)
                    {
                        return;
                    }

                    Value = new FloatDistribution(curve);
                    OnCurveChanged?.Invoke();
                });
            }
            else if (DistributionType == PropertyDistributionType.RandomCurveRange)
            {
                CurveEditorWindow.Show(distribution.GetMinCurve(), distribution.GetMaxCurve(),
                                       (success, minCurve, maxCurve) =>
                {
                    if (!success)
                    {
                        return;
                    }

                    Value = new FloatDistribution(minCurve, maxCurve);
                    OnCurveChanged?.Invoke();
                });
            }
        }
 private float ComputeMecanumDriveMotorSpeed(DenseVector desiredMovement, VectorComponent wheelForceVectorInput)
 {
     var wheelForceVector = new DenseVector(new[] { wheelForceVectorInput.X, wheelForceVectorInput.Y });
      var wheelForceVectorUnit = wheelForceVector.Normalize(2);
      var scale = wheelForceVectorUnit.DotProduct(desiredMovement);
     //         Console.WriteLine(wheelForceVector + " " + wheelForceVectorUnit + " " + desiredMovement + " " + scale);
      return scale;
 }
예제 #6
0
        private float ComputeMecanumDriveMotorSpeed(DenseVector desiredMovement, VectorComponent wheelForceVectorInput)
        {
            var wheelForceVector     = new DenseVector(new[] { wheelForceVectorInput.X, wheelForceVectorInput.Y });
            var wheelForceVectorUnit = wheelForceVector.Normalize(2);
            var scale = wheelForceVectorUnit.DotProduct(desiredMovement);

//         Console.WriteLine(wheelForceVector + " " + wheelForceVectorUnit + " " + desiredMovement + " " + scale);
            return(scale);
        }
예제 #7
0
    public static Vector3 ToVector3(this Vector2 v, string conversion)
    {
        Vector3 output = Vector3.zero;

        VectorComponent[] comps = VectorComponent.Parse(conversion, 3);
        for (int i = 0; i < 3; i++)
        {
            output[i] = comps[i].GetValue(v);
        }
        return(output);
    }
예제 #8
0
        /// <summary>
        /// Triggered when the scale value in the currently active <see cref="SceneObject"/> changes. Updates the
        /// necessary GUI elements.
        /// </summary>
        /// <param name="value">New value of the component that changed.</param>
        /// <param name="component">Identifier of the component that changed.</param>
        private void OnScaleChanged(float value, VectorComponent component)
        {
            if (activeSO == null)
            {
                return;
            }

            activeSO.LocalScale = soScale.Value;

            modifyState = InspectableState.ModifyInProgress;
            EditorApplication.SetSceneDirty();
        }
        partial void OnClicked(VectorComponent component)
        {
            int componentIdx = (int)component;
            Vector3Distribution distribution = Value;

            if (DistributionType == PropertyDistributionType.Curve)
            {
                AnimationCurve[] curves = AnimationUtility.SplitCurve3D(distribution.GetMinCurve());
                if (componentIdx < curves.Length)
                {
                    CurveEditorWindow.Show(curves[componentIdx], (success, curve) =>
                    {
                        if (!success)
                        {
                            return;
                        }

                        curves[componentIdx] = curve;

                        Vector3Curve compoundCurve = AnimationUtility.CombineCurve3D(curves);
                        Value = new Vector3Distribution(compoundCurve);
                        OnCurveChanged?.Invoke();
                    });
                }
            }
            else if (DistributionType == PropertyDistributionType.RandomCurveRange)
            {
                AnimationCurve[] minCurves = AnimationUtility.SplitCurve3D(distribution.GetMinCurve());
                AnimationCurve[] maxCurves = AnimationUtility.SplitCurve3D(distribution.GetMaxCurve());

                if (componentIdx < minCurves.Length && componentIdx < maxCurves.Length)
                {
                    CurveEditorWindow.Show(minCurves[componentIdx], maxCurves[componentIdx],
                                           (success, minCurve, maxCurve) =>
                    {
                        if (!success)
                        {
                            return;
                        }

                        minCurves[componentIdx] = minCurve;
                        maxCurves[componentIdx] = maxCurve;

                        Vector3Curve minCompoundCurves = AnimationUtility.CombineCurve3D(minCurves);
                        Vector3Curve maxCompoundCurves = AnimationUtility.CombineCurve3D(maxCurves);

                        Value = new Vector3Distribution(minCompoundCurves, maxCompoundCurves);
                        OnCurveChanged?.Invoke();
                    });
                }
            }
        }
예제 #10
0
        public static float GetVectorComponent(this Vector3 vector, VectorComponent component)
        {
            switch (component)
            {
            case VectorComponent.x:
                return(vector.x);

            case VectorComponent.y:
                return(vector.y);

            case VectorComponent.z:
                return(vector.z);

            default:
                return(0);
            }
        }
예제 #11
0
 public static VectorComponent[] Parse(string s, int expectedLength)
 {
     VectorComponent[] output = new VectorComponent[expectedLength];
     (VectorComponent c, string s)? part = ParseOne(s);
     for (int i = 0; i < expectedLength; i++)
     {
         if (part == null)
         {
             output[i] = new VectorComponent(false, '0');
         }
         else
         {
             output[i] = part.Value.c;
             part      = ParseOne(part.Value.s);
         }
     }
     return(output);
 }
예제 #12
0
        public static Vector3 InvertComponent(this Vector3 vector, VectorComponent component)
        {
            switch (component)
            {
            case VectorComponent.x:
                vector.x *= -1;
                break;

            case VectorComponent.y:
                vector.y *= -1;
                break;

            case VectorComponent.z:
                vector.z *= -1;
                break;
            }
            return(vector);
        }
예제 #13
0
        public static Vector3 SetComponent(this Vector3 vector, VectorComponent component, float f)
        {
            switch (component)
            {
            case VectorComponent.x:
                vector.x = f;
                break;

            case VectorComponent.y:
                vector.y = f;
                break;

            case VectorComponent.z:
                vector.z = f;
                break;
            }
            return(vector);
        }
예제 #14
0
        /// <summary>
        /// Triggered when the position value in the currently active <see cref="SceneObject"/> changes. Updates the
        /// necessary GUI elements.
        /// </summary>
        /// <param name="value">New value of the component that changed.</param>
        /// <param name="component">Identifier of the component that changed.</param>
        private void OnPositionChanged(float value, VectorComponent component)
        {
            if (activeSO == null)
            {
                return;
            }

            if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
            {
                activeSO.Position = soPos.Value;
            }
            else
            {
                activeSO.LocalPosition = soPos.Value;
            }

            modifyState = InspectableState.ModifyInProgress;
            EditorApplication.SetSceneDirty();
        }
예제 #15
0
        /// <summary>
        /// Triggered when the rotation value in the currently active <see cref="SceneObject"/> changes. Updates the
        /// necessary GUI elements.
        /// </summary>
        /// <param name="value">New value of the component that changed.</param>
        /// <param name="component">Identifier of the component that changed.</param>
        private void OnRotationChanged(float value, VectorComponent component)
        {
            if (activeSO == null)
            {
                return;
            }

            Quaternion rotation = Quaternion.FromEuler(soRot.Value);

            if (EditorApplication.ActiveCoordinateMode == HandleCoordinateMode.World)
            {
                activeSO.Rotation = rotation;
            }
            else
            {
                activeSO.LocalRotation = rotation;
            }

            lastRotation = rotation;
            modifyState  = InspectableState.ModifyInProgress;
            EditorApplication.SetSceneDirty();
        }
예제 #16
0
        public static Vector3 SetVectorComponent(this Vector3 vector, VectorComponent component, float f, bool invert = false)
        {
            if (invert)
            {
                f *= -1;
            }
            switch (component)
            {
            case VectorComponent.x:
                vector.x = f;
                break;

            case VectorComponent.y:
                vector.y = f;
                break;

            case VectorComponent.z:
                vector.z = f;
                break;
            }
            return(vector);
        }
예제 #17
0
 public RotationComponentCurveViewModel([NotNull] CurveEditorViewModel editor, CurveViewModelBase parent, [NotNull] ComputeAnimationCurve <Quaternion> computeCurve, VectorComponent component)
     : base(editor, parent, computeCurve)
 {
     Component = component;
     Color     = Editor.GetColor(component);
 }
 private void Internal_onConstantFocusChanged(bool p0, RangeComponent p1, VectorComponent p2)
 {
     OnConstantFocusChanged?.Invoke(p0, p1, p2);
 }
 private void Internal_onConstantConfirmed(RangeComponent p0, VectorComponent p1)
 {
     OnConstantConfirmed?.Invoke(p0, p1);
 }
 private void Internal_onClicked(VectorComponent p0)
 {
     Callback_OnClicked(p0);
 }
 private static extern void Internal_setInputFocus(IntPtr thisPtr, RangeComponent rangeComponent, VectorComponent vectorComponent, bool focus);
 /// <summary>Sets input focus to a specific component&apos;s input box.</summary>
 /// <param name="rangeComponent">
 /// Whether to focus on the minimum or the maximum part of the range. Only relevant if the distribution represents a
 /// constant range.
 /// </param>
 /// <param name="vectorComponent">
 /// Vector component to focus on. Only relevant of the distribution constant is a vector type, and if the current
 /// distribution type is a non-curve (constant) type.
 /// </param>
 /// <param name="focus">True to enable focus, false to disable.</param>
 public void SetInputFocus(RangeComponent rangeComponent, VectorComponent vectorComponent, bool focus)
 {
     Internal_setInputFocus(mCachedPtr, rangeComponent, vectorComponent, focus);
 }
 public Color GetColor(VectorComponent component)
 {
     return VectorComponentColor[(int)component];
 }
예제 #24
0
 protected VectorComponentCurveViewModel([NotNull] CurveEditorViewModel editor, CurveViewModelBase parent, [NotNull] ComputeAnimationCurve <TValue> computeCurve, VectorComponent component)
     : base(editor, parent, computeCurve)
 {
     Component = component;
     Color     = Editor.GetColor(component);
 }
예제 #25
0
 public Vector4ComponentCurveViewModel([NotNull] CurveEditorViewModel editor, CurveViewModelBase parent, [NotNull] ComputeAnimationCurve <Vector4> computeCurve, VectorComponent component)
     : base(editor, parent, computeCurve, component)
 {
 }
예제 #26
0
 public Vector3ComponentCurveViewModel([NotNull] CurveEditorViewModel editor, CurveViewModelBase parent, [NotNull] ComputeAnimationCurve <Vector3> computeCurve, VectorComponent component)
     : base(editor, parent, computeCurve, component)
 {
     if (component == VectorComponent.W)
     {
         throw new ArgumentException("Vector component 'W' is invalid, only 'X', 'Y' and 'Z' are supported.", nameof(component));
     }
 }
예제 #27
0
 /// <summary>
 /// Triggered when the user clicks on the curve display. Only relevant if the distribution is a curve distribution.
 /// Provides the index of the clicked curve.
 /// </summary>
 partial void OnClicked(VectorComponent p0);
 public RotationComponentControlPointViewModel([NotNull] CurveViewModelBase curve, [NotNull] IMemberNode keyNode, [NotNull] IMemberNode valueNode, [NotNull] IMemberNode tangentTypeNode, VectorComponent component)
     : base(curve, keyNode, valueNode, tangentTypeNode)
 {
     Component = component;
     SynchronizePoint();
 }
 public void VectorComponentParsesCorrectly(string s, VectorComponent[] expected)
 {
     VectorComponent[] actual = VectorComponent.Parse(s, expected.Length);
     Assert.That(actual, Is.EquivalentTo(expected));
 }
예제 #30
0
 /// <summary>
 /// Triggered when the user changes the field value of a single component.
 /// </summary>
 /// <param name="newValue">New value of a single component in the 3D vector field.</param>
 /// <param name="component">Component that was changed.</param>
 private void OnFieldValueChanged(float newValue, VectorComponent component)
 {
     property.SetValue(guiField.Value);
     state |= InspectableState.ModifyInProgress;
 }
 /// <summary>
 /// Triggered when the user clicks on the curve display. Only relevant if the distribution is a curve distribution.
 /// Provides the index of the clicked curve.
 /// </summary>
 partial void Callback_OnClicked(VectorComponent p0);