示例#1
0
        public void UpdateGraphLine()
        {
            SetGraphVisible(true);

            PVector2 dGraph01Size = DGraph01Size;
            PRect    dGraphRect   = DGraphRect;

            //Update Inside lines
            for (int graphLineI = 0; graphLineI < graphLines.Length; ++graphLineI)
            {
                float motionValue     = GetLineMotionValue(graphLineI);
                float nextMotionValue = GetLineMotionValue(graphLineI + 1);

                Line line = graphLines[graphLineI];
                line.X1 = dGraphRect.xMin + graphLineI * dGraph01Size.x / GraphResolution;
                line.X2 = dGraphRect.xMin + (graphLineI + 1) * dGraph01Size.x / GraphResolution;
                line.Y1 = dGraphRect.yMax - motionValue * dGraph01Size.y;
                line.Y2 = dGraphRect.yMax - nextMotionValue * dGraph01Size.y;

                float GetLineMotionValue(int index)
                {
                    float linearValue = (float)index / graphLines.Length;

                    return(EditingMotionData.GetMotionValue(linearValue));
                }
            }

            //Update Outside lines
            float outsideLeftY  = NormalToDisplayY(EditingMotionData.GetMotionValue(0f));
            float outsideRightY = NormalToDisplayY(EditingMotionData.GetMotionValue(1f));

            outsideLines[0].SetLinePosition(new Vector2(Mathf.Min(dGraphRect.xMin, 0f), outsideLeftY), new Vector2(dGraphRect.xMin, outsideLeftY));
            outsideLines[1].SetLinePosition(new Vector2(dGraphRect.xMax, outsideRightY), new Vector2(Mathf.Max(dGraphRect.xMax, (float)GraphContext.ActualWidth), outsideRightY));
        }
示例#2
0
 public MotionPoint(PVector2 mainPoint, PVector2 subPointLeft, PVector2 subPointRight)
 {
     this.MainPoint = mainPoint;
     this.SubPoints = new PVector2[] {
         subPointLeft,
         subPointRight,
     };
 }
    void Start()
    {
        PVector2 a    = new PVector2(P5JSExtension.width / 2, P5JSExtension.height);
        PVector2 b    = new PVector2(P5JSExtension.width / 2, P5JSExtension.height - 100);
        var      root = new Branch(a, b);

        tree.Add(root);
    }
示例#4
0
 void Start()
 {
     rb              = GetComponent <Rigidbody2D>();
     playerCollider  = GetComponent <BoxCollider2D>();
     appliedVelocity = PVector2.zero;
     up              = PVector2.up;
     right           = PVector2.right;
 }
示例#5
0
        public PVector2 GetMotionValue(string motionId, PVector2 linearValue, int maxSample = MotionItem.DefaultMaxSample, float tolerance = MotionItem.DefaultMaxTolerance)
        {
            MotionItem motion = GetMotion(motionId);

            return(new PVector2(
                       motion.GetMotionValue(linearValue.x, maxSample, tolerance),
                       motion.GetMotionValue(linearValue.y, maxSample, tolerance)
                       ));
        }
示例#6
0
    public float ScaleOfProjectionOn(PVector2 pv)
    {
        if (pv == PVector2.zero)
        {
            return(0f);
        }

        return((v.x * pv.v.x + v.y * pv.v.y) / pv.v.sqrMagnitude);
    }
示例#7
0
        private void BackPanel_MouseDrag_ForPanning()
        {
            const float MaxOffset = 320f;

            Vector2 cursorDelta = MouseInput.AbsolutePosition - cursorPosMemory;

            cursorPosMemory = MouseInput.AbsolutePosition;

            displayOffset += cursorDelta.ToPVector2() / displayZoom * 0.5f;
            displayOffset  = GMath.Clamp(displayOffset.ToVector2(), -MaxOffset, MaxOffset).ToPVector2();

            UpdateUiAll();
        }
示例#8
0
    public PVector2 ProjectOn(PVector2 pv)
    {
        if (pv == PVector2.zero)
        {
            return(PVector2.zero);
        }

        // Esta é a fórmula que encontrei, funciona mas (acho que) é computacionalmente caro
        //return b * Mathf.Cos(Mathf.Atan2(a.y, a.x) - Mathf.Atan2(b.y, b.x));

        // Esta é a fórmula matemática de projeção de vetores
        Vector2 projection = pv.v * ((v.x * pv.v.x + v.y * pv.v.y) / pv.v.sqrMagnitude);

        return(new PVector2(projection));
    }
示例#9
0
    void Update()
    {
        // Gira o vetor da gravidade normalizado 90º sentido anti-horário retornando o que é "direita" na orientação atual
        right = new PVector2(-Physics2D.gravity.normalized.y, Physics2D.gravity.normalized.x);
        up    = new PVector2(-right.v.y, right.v.x);
        PVector2 inputDirection = new PVector2(joystick.Direction);

        // Cálculo do quanto mover o player apenas na direção do vetor "right"
        if (inputDirection != PVector2.zero)
        {
            appliedVelocity = inputDirection.ProjectOn(right) * acceleration;
        }
        else
        {
            appliedVelocity = PVector2.zero;
        }

        if (jumpReqRemainingTime > 0f)
        {
            jumpReqRemainingTime -= Time.deltaTime;
        }
        else
        {
            jumpRequest = false;
        }
        if (jumpReqRemainingCooldown > 0f)
        {
            jumpReqRemainingCooldown -= Time.deltaTime;
        }

        // Checa se o joystick está para "cima" o suficiente para pular, baseando-se na orientação atual
        if (!jumpRequest && jumpReqRemainingCooldown <= 0f && inputDirection.ScaleOfProjectionOn(up) > .7f)
        {
            jumpRequest          = true;
            jumpReqRemainingTime = jumpRequestDuration;
        }
    }
示例#10
0
        private void UpdateGrid()
        {
            PRect    graphRect   = DGraphRect;
            PVector2 graph01Size = DGraph01Size;

            for (int i = 0; i < gridVerticals.Length; ++i)
            {
                Line  line = gridVerticals[i];
                float x    = graphRect.xMin + ((i - (GridHorizontalCount / 3)) * graph01Size.x / (GridVerticalCount / 4 - 1));
                line.X1     =
                    line.X2 = x;
                line.Y1     = 0d;
                line.Y2     = ActualHeight;
            }
            for (int i = 0; i < gridHorizontals.Length; ++i)
            {
                Line  line = gridHorizontals[i];
                float y    = graphRect.yMax - ((i - (GridHorizontalCount / 3)) * graph01Size.y / (GridHorizontalCount / 4 - 1));
                line.Y1     =
                    line.Y2 = y;
                line.X1     = 0d;
                line.X2     = ActualWidth;
            }
        }
 public static PVector2 rotate(this PVector2 v, float radians)
 {
     return(new PVector2(Mathf.Cos(radians) * v.x - Mathf.Sin(radians) * v.y, Mathf.Sin(radians) * v.x + Mathf.Cos(radians) * v.y));
 }
示例#12
0
        public static PVector2 GetMotionValue(string fileId, string motionId, PVector2 linearValue, int maxSample = MotionItem.DefaultMaxSample, float tolerance = MotionItem.DefaultMaxTolerance)
        {
            MotionFile file = MotionStorage.GetFile(fileId);

            return(file.GetMotionValue(motionId, PMath.Clamp01(linearValue), maxSample, tolerance));
        }
示例#13
0
 public Particle(PVector2 position, PVector2 velocityPerTick)
 {
     this.Position = position;
     this.VelocityPerTick = velocityPerTick;
     this.Age = 0;
 }
示例#14
0
 public static Vector2 ToVector2(this PVector2 value)
 {
     return(new Vector2(value.x, value.y));
 }
示例#15
0
 private void ResetEnv()
 {
     displayZoom   = 0.6f;
     displayOffset = new PVector2();
 }
 public Branch(PVector2 begin, PVector2 end)
 {
     this.begin    = begin;
     this.end      = end;
     this.finished = false;
 }
示例#17
0
 //Events
 //PointChanged
 internal void Data_MainPointChanged(PVector2 position)
 {
     UpdateWithOtherUI();
 }
示例#18
0
 internal void Data_SubPointChanged(int index, PVector2 position)
 {
     UpdateWithOtherUI();
 }
示例#19
0
        public void LoadFromJson(JObject jRoot)
        {
            //MotionTree
            JObject jRootFolder = jRoot[RootFolderName] as JObject;

            LoadItemRecursive(jRootFolder, null);


            void LoadItemRecursive(JToken jItem, MotionFolderItem parent)
            {
                JToken jType    = jItem["Type"];
                string typeText = jType != null?jType.ToString() : null;

                string name = (jItem.Parent as JProperty).Name;

                if (typeText == "Motion")
                {
                    LoadMotion(parent, jItem, name);
                }
                else
                {
                    LoadFolder(parent, jItem, name);
                }
            }

            void LoadMotion(MotionFolderItem parent, JToken jItem, string name)
            {
                JObject jData   = jItem["Data"] as JObject;
                JArray  jPoints = jData["Point"] as JArray;

                MotionItem motion = CreateMotionEmpty(parent);

                motion.SetName(name);

                foreach (JToken jPointToken in jPoints)
                {
                    JArray jPoint = jPointToken as JArray;

                    MotionPoint point = new MotionPoint(
                        PVector2.Parse(jPoint[0].ToObject <string>()),
                        PVector2.Parse(jPoint[1].ToObject <string>()),
                        PVector2.Parse(jPoint[2].ToObject <string>()));
                    motion.AddPoint(point);
                }
            }

            void LoadFolder(MotionFolderItem parent, JToken jItem, string name)
            {
                MotionFolderItem folder = CreateFolder(parent);

                if (parent == null)
                {
                    rootFolder = folder;
                }
                else
                {
                    folder.SetName(name);
                }

                JObject jItems = jItem["Items"] as JObject;

                foreach (JToken jChild in jItems.Children())
                {
                    JProperty jChildProp = jChild as JProperty;
                    LoadItemRecursive(jChildProp.Value, folder);
                }
            }
        }
示例#20
0
 public MotionPoint(PVector2 mainPoint) : this(
         mainPoint,
         new PVector2(-DefaultSubPointOffset, 0f),
         new PVector2(DefaultSubPointOffset, 0f))
 {
 }
示例#21
0
 public static PVector2 GetMotionValue(string motionId, PVector2 linearValue, int maxSample = MotionItem.DefaultMaxSample, float tolerance = MotionItem.DefaultMaxTolerance)
 {
     return(GetMotionValue(null, motionId, linearValue, maxSample, tolerance));
 }
示例#22
0
        public void SetMainPoint(PVector2 position)
        {
            MainPoint = position;

            MainPointChanged?.Invoke(position);
        }
示例#23
0
        public void SetSubPoint(int index, PVector2 position)
        {
            SubPoints[index] = position;

            SubPointChanged?.Invoke(index, position);
        }