Example #1
0
        private void DrawSingleBar(Vector2 position, int player, bool allPlayers)
        {
            _rightSprite.ColorShading.A          =
                _leftSpriteMap.ColorShading.A    =
                    _middleSprite.ColorShading.A = (byte)Opacity;
            _rightSprite.Size     = new Vector2(RIGHT_SIDE_WIDTH, this.Height);
            _rightSprite.Position = position.Clone();
            _rightSprite.X       += this.Width - RIGHT_SIDE_WIDTH;
            var barWidth       = this.Width - RIGHT_SIDE_WIDTH - LEFT_SIDE_WIDTH;
            var totalBeatlines = (from e in Players[player].Judgements select e).Take(6).Sum();

            var idx = (Players[player].IsCPUPlayer) ? 4 : player;

            if (allPlayers)
            {
                idx = 5;
            }
            _leftSpriteMap.Draw(idx, LEFT_SIDE_WIDTH, this.Height, position);
            position.X            += LEFT_SIDE_WIDTH;
            _middleSprite.Width    = barWidth;
            _middleSprite.Height   = this.Height;
            _middleSprite.Position = position.Clone();

            var maxWidth       = barWidth;
            var percentageText = " -----";

            if (totalBeatlines >= 5)
            {
                _partsSpriteMap.ColorShading.A = (byte)(_barOpacity * Opacity / 255);
                for (int y = 0; y < (int)BeatlineNoteJudgement.Count; y++)
                {
                    var width = (float)Math.Ceiling((barWidth) * Players[player].Judgements[y] / totalBeatlines);
                    width     = Math.Min(width, maxWidth);
                    maxWidth -= width;
                    _partsSpriteMap.Draw(y, width, this.Height, position);
                    position.X += width;
                }
                _barOpacity    = Math.Min(255, _barOpacity + (TextureManager.LastGameTime.ElapsedRealTime.TotalSeconds * BAR_SHOW_SPEED));
                percentageText = String.Format("{0:F1}%", Players[player].CalculatePercentage());
            }
            else
            {
                _barOpacity = 0;
            }
            _middleSprite.Draw();

            _rightSprite.Draw();
            _rightSprite.X += 35;
            _rightSprite.Y += (this.Height / 2) - 10;
            var textColour = Color.Black;

            textColour.A = (byte)Opacity;
            FontManager.DrawString(percentageText, "DefaultFont", _rightSprite.Position, textColour,
                                   FontAlign.Center);

            position.X = this.Position.X;
        }
Example #2
0
        public bool RotateHeadingToFacePosition(Vector2 target)
        {
            var clone = target.Clone();

            var toTarget = clone - Position;

            toTarget.Normalize();

            var dot   = MathHelper.Clamp(Vector2.Dot(Heading, toTarget), -1.0f, 1.0f);
            var angle = Math.Acos(dot);

            if (angle < 0.00001)
            {
                return(true);
            }
            if (angle > MaxTurnRate)
            {
                angle = MaxTurnRate;
            }
            Matrix matrix = Matrix.CreateRotationZ((float)angle * Vector2D.Sign(Heading, toTarget));

            Vector2.Transform(Heading, matrix);
            Vector2.Transform(Velocity, matrix);
            Side = Vector2D.Perp(Heading);

            return(false);
        }
Example #3
0
        private void DrawBPMText()
        {
            var bpmLabelText = _bpmTextPosition.Clone();

            bpmLabelText.X -= 120;
            bpmLabelText.Y += 4;
            if (_actualMinBpm == _actualMaxBpm)
            {
                FontManager.DrawString(String.Format("{0:000.0}", Math.Min(999.9, _displayedMinBpm)),
                                       "TwoTechLarge",
                                       _bpmTextPosition, Color.Black, FontAlign.Right);
            }
            else
            {
                _bpmTextPosition.Y += 2;
                FontManager.DrawString(String.Format("{0:000.0}", Math.Min(999.9, _displayedMinBpm)),
                                       "TwoTech24",
                                       _bpmTextPosition, Color.Black, FontAlign.Right);
                _bpmTextPosition.Y += 19;
                FontManager.DrawString(String.Format("{0:000.0}", Math.Min(999.9, _displayedMaxBpm)),
                                       "TwoTech24",
                                       _bpmTextPosition, Color.Black, FontAlign.Right);
                _bpmTextPosition.Y -= 21;

                FontManager.DrawString("Min:",
                                       "DefaultFont",
                                       bpmLabelText, Color.Black, FontAlign.Left);
                bpmLabelText.Y += 20;
                FontManager.DrawString("Max:",
                                       "DefaultFont",
                                       bpmLabelText, Color.Black, FontAlign.Left);
            }
        }
Example #4
0
        public static void Draw()
        {
            if (!IsOpen)
            {
                return;
            }

            b = MDraw.SpriteBatch;
            b.Begin();

            p = TopLeft.Clone();

            Write("Inputs Panel", p, Color.White);

            p.Y += 50f;
            p.X  = Column1;
            Write("Player 1", p, Color.White);

            p.X = Column2;
            Write("Player 2", p, Color.White);

            p.Y += 70f;

            WriteInput(InputManager.Player1.Enter, InputManager.Player2.Enter);
            WriteInput(InputManager.Player1.Back, InputManager.Player2.Back);
            WriteInput(InputManager.Player1.Clear, InputManager.Player2.Clear);
            WriteInput(InputManager.Player1.Jump, InputManager.Player2.Jump);
            WriteInput(InputManager.Player1.Attack, InputManager.Player2.Attack);
            WriteInput(InputManager.Player1.Unleash, InputManager.Player2.Unleash);
            WriteInput(InputManager.Player1.Retry, InputManager.Player2.Retry);

            b.End();
        }
Example #5
0
        private Vector2[] getCorners(Rectangle inRec, float rotation)
        {
            Vector2[] corners = new Vector2[4];

            //Get the Corners of the object's Rectangle
            int halfWidth, halfHeight;

            halfWidth  = inRec.Width / 2;
            halfHeight = inRec.Height / 2;
            corners[0] = new Vector2(inRec.X - halfWidth, inRec.Y - halfHeight);
            corners[1] = new Vector2(inRec.X + halfWidth, inRec.Y - halfHeight);
            corners[2] = new Vector2(inRec.X + halfWidth, inRec.Y + halfHeight);
            corners[3] = new Vector2(inRec.X - halfWidth, inRec.Y + halfHeight);

            //Rotates the corners to their accurate position
            Vector2[] rotatedCorners   = (Vector2[])corners.Clone();
            Matrix    myRotationMatrix = Matrix.CreateRotationZ(rotation);

            for (int i = 0; i < rotatedCorners.Length; i++)
            {
                Vector2 rotatedVector = Vector2.Transform(rotatedCorners[i] - new Vector2(inRec.X, inRec.Y), myRotationMatrix);
                rotatedCorners[i] = rotatedVector + new Vector2(inRec.X, inRec.Y);
            }

            return(rotatedCorners);
        }
Example #6
0
        public static Vector2 GetNormalized(this Vector2 vec)
        {
            var v = vec.Clone();

            v.Normalize();
            return(v);
        }
Example #7
0
        public Area Clone()
        {
            Area clone = new Area((Shape2)_shape.Clone(), _behavior);

            clone.Name               = _name;
            clone.Text               = _text;
            clone.TextFont           = _textFont;
            clone.TextPosition       = (Vector2)_textPosition.Clone();
            clone.TextColor          = _textColor;
            clone.RealType           = _type;
            clone.AreaColor          = _areaColor;
            clone.Behavior           = _behavior;
            clone.Description        = _description;
            clone.MetaData           = _metaData;
            clone.ImgPath            = _imgPath;
            clone.ImgScaling         = (Vector2)_imgScaling.Clone();
            clone.ImgPosition        = (Vector2)_imgPosition.Clone();
            clone.ImgIsBackground    = _imgIsBackground;
            clone.IsActive           = _isActive;
            clone.IsVisible          = _isVisible;
            clone.MinX               = _minX;
            clone.ValueSuggestedMaxX = _maxSuggestedX;
            clone.ValueSuggestedMaxY = _maxSuggestedY;
            clone.MaxX               = _maxX;
            clone.MinY               = _minY;
            clone.MaxY               = _maxY;
            clone.XParam             = _xParam;
            clone.YParam             = _yParam;
            clone.XMultiply          = _xMultiply;
            clone.YMultiply          = _yMultiply;
            clone.XYSymmetryMode     = _xYSymmetryMode;

            return(clone);
        }
Example #8
0
    public static Vector2 Unit(this Vector2 self)
    {
        Vector2 unit = self.Clone();

        unit.Normalize();
        return(unit);
    }
Example #9
0
        public static Vector2 Normalized(this Vector2 vector, float length = 1.0f)
        {
            Vector2 clone = vector.Clone();

            clone.Scale(new Vector2(length, length));
            return(clone);
        }
Example #10
0
        public void TestCloning()
        {
            Vector2 v  = new Vector2(17, 22);
            Vector2 v1 = v.Clone();

            Assert.AreEqual(v.x, v1.x);
            Assert.AreEqual(v.y, v1.y);
        }
Example #11
0
        private void ExtendForehead(Mesh mesh)
        {
            if (mesh.vertices.Length != 68)
            {
                throw new ArgumentException("Invalid face mask mesh", "mesh");
            }

            List <Vector2> verticesList = new List <Vector2> (mesh.vertices.Length);

            foreach (Vector3 v in mesh.vertices)
            {
                verticesList.Add(new Vector2(v.x, v.y));
            }

            AddForeheadPoints(verticesList);

            Vector3[] vertices = new Vector3[verticesList.Count];
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vector3(verticesList[i].x, verticesList[i].y);
            }
            mesh.vertices = vertices;

            int[] foreheadTriangles = new int[13 * 3]
            {
                68, 16, 26,
                68, 26, 25,
                69, 68, 25,
                69, 25, 24,
                69, 24, 23,
                70, 69, 23,

                70, 23, 20,

                71, 70, 20,
                71, 20, 19,
                71, 19, 18,
                72, 71, 18,
                72, 18, 17,
                72, 17, 0
            };
            int[] triangles = new int[mesh.triangles.Length + foreheadTriangles.Length];
            mesh.triangles.CopyTo(triangles, 0);
            foreheadTriangles.CopyTo(triangles, mesh.triangles.Length);
            mesh.triangles = triangles;

            Vector2[] uv = new Vector2[mesh.uv.Length];
            for (int j = 0; j < uv.Length; j++)
            {
                uv [j].x = vertices[j].x + 0.5f;
                uv [j].y = vertices[j].y + 0.5f;
            }
            mesh.uv  = uv;
            mesh.uv2 = (Vector2[])uv.Clone();

            mesh.RecalculateNormals();
        }
Example #12
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            var mousePos = new Vector2(e.Location);

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            NodeBase newNode = null;

            switch (myPointerState)
            {
            case PointerState.PlaceBlank:
                newNode = PlaceNewNode(NodeType.Blank, mousePos);
                break;

            case PointerState.PlaceLock:
                newNode = PlaceNewNode(NodeType.Lock, mousePos);
                break;

            case PointerState.PlaceRandom:
                newNode = PlaceNewNode(NodeType.RandomKey, mousePos);
                break;

            case PointerState.PlaceEvent:
                newNode = PlaceNewNode(NodeType.EventKey, mousePos);
                break;
            }

            if (newNode != null)
            {
                UncheckStateBoxes();

                PickUpNode(newNode, new Vector2(0, 0));
            }
            else
            {
                newNode = FindClickedNode(mousePos);

                UpdateConnections(mousePos, newNode);
            }

            // No node was hit, activate map dragging
            if (newNode == null)
            {
                carriedMap = true;

                mapPickedUpPos = imageBasePos.Clone();
                selectedOffset = (mousePos / ZoomScale) - imageBasePos;
            }

            panel1.Invalidate();

            mouseDownTimeStamp = DateTime.UtcNow;
        }
Example #13
0
 public PathItem(Vector2[] points)
     : base()
 {
     Position = points[0];
     WorldPoints = points;
     LocalPoints = (Vector2[])points.Clone();
     for (int i = 0; i < LocalPoints.Length; i++) LocalPoints[i] -= Position;
     LineWidth = Constants.Instance.DefaultPathItemLineWidth;
     LineColor = Constants.Instance.ColorPrimitives;
 }
        private Vector3[] mNormalAtVertices = null; // may not be there (only present for triangles created from a mesh)

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs from given positions, normal, and uv then intialize for intersection computation.
        /// </summary>
        /// <param name="parser"></param>
        protected RTTriangle(Vector3[] vertices, Vector3[] normalAtVertex, Vector2[] uvAtVertex, int material)
        {
            mType = RTGeometryType.Triangle;
            mMaterialIndex = material;
            mVertices = (Vector3[])vertices.Clone();
            if (null != normalAtVertex)
                mNormalAtVertices = (Vector3[])normalAtVertex.Clone();
            mVertexUV = (Vector2[])uvAtVertex.Clone();

            InitializeTriangle();
        }
        public override void Draw(GameTime t)
        {
            if (!Visible)
            {
                return;
            }

            MDraw.Begin();

            var   pos        = new Vector2(20f, 20f);
            float firstSpace = 150;
            float inputSpace = 200;

            MDraw.Write("Rebind Panel: Keyboard", pos, Color.White);
            pos.X  = Screen.Width * 0.2f;
            pos.Y += 40f;
            MDraw.Write("User", new Vector2(pos.X + firstSpace, pos.Y), Color.White);
            MDraw.Write("Default", new Vector2(pos.X + firstSpace + inputSpace, pos.Y), Color.White);

            pos.Y += 60f;

            for (int i = 0; i < MaxButtons; i++)
            {
                bool  active = SelectionIndex == i;
                Color color  = active ? (IsEditingKeyboard ? Color.Lime : Color.Yellow) : (IsEditingKeyboard ? Color.Gray : Color.White);

                Vector2 rowPos = pos.Clone();

                if (active)
                {
                    rowPos.X += 5f;
                }

                MDraw.Write(InputManager.SourceKeyboard.AllButtons[i].Name, rowPos, color);

                rowPos.X += firstSpace;
                var kb = InputManager.SourceKeyboard.AllButtons[i];
                if (kb.UserKey != null)
                {
                    MDraw.Write(kb.UserKey.ToString(), rowPos, color);
                }

                rowPos.X += inputSpace;
                if (kb.HardcodedKey != null)
                {
                    MDraw.Write(kb.HardcodedKey.ToString(), rowPos, color);
                }

                pos.Y += 40f;
            }

            MDraw.SpriteBatch.End();
        }
Example #16
0
        public void Vector2Clone()
        {
            tlog.Debug(tag, $"Vector2Clone START");

            using (Vector2 vec = new Vector2(20, 20))
            {
                var testingTarget = vec.Clone();
                Assert.IsNotNull(testingTarget, "should be not null");
                Assert.IsInstanceOf <Vector2>(testingTarget, "should be an instance of testing target class!");
            }

            tlog.Debug(tag, $"Vector2Clone END (OK)");
        }
Example #17
0
        private void DrawText(int player, Vector2 position)
        {
            var textPosition = position.Clone();

            textPosition.X += 25;

            FontManager.DrawString(String.Format("{0:D3}", (int)_displayedLife[player]),
                                   "DefaultFont", textPosition, Color.Black, FontAlign.Center);

            textPosition.X += 60;
            FontManager.DrawString(String.Format("{0:P0}", _displayedLife[player] / TrueCapacity),
                                   "DefaultFont", textPosition, Color.Black, FontAlign.Center);
        }
Example #18
0
        private void DrawSingleBar(Vector2 position, int player, long challengeScore, long recordScore)
        {
            position = position.Clone();
            _rightSprite.ColorShading.A          =
                _leftSpriteMap.ColorShading.A    =
                    _middleSprite.ColorShading.A = (byte)Opacity;
            _rightSprite.Position = position.Clone();
            _rightSprite.Size     = new Vector2(RIGHT_SIDE_WIDTH, this.Height);
            _rightSprite.X       += this.Width - RIGHT_SIDE_WIDTH;
            var barWidth = this.Width - LEFT_SIDE_WIDTH - RIGHT_SIDE_WIDTH;

            var idx = (player < 5 && GameCore.Instance.Players[player].IsCPUPlayer) ? 4 : player;

            _leftSpriteMap.Draw(idx, LEFT_SIDE_WIDTH, this.Height, position);
            position.X            += LEFT_SIDE_WIDTH;
            _middleSprite.Width    = barWidth;
            _middleSprite.Height   = this.Height;
            _middleSprite.Position = position.Clone();

            _partsSpriteMap.ColorShading.A = (byte)Opacity;

            var ratio = 1.0 * challengeScore / recordScore;

            ratio = Math.Max(Math.Min(1.2, ratio), 0.8);
            var width = barWidth * (ratio - 0.8) / 0.4;

            _partsSpriteMap.Draw(GetBarColour(ratio), (float)width, this.Height, position);

            _middleSprite.Draw();
            _rightSprite.Draw();
            _rightSprite.X += RIGHT_SIDE_WIDTH / 2;
            _rightSprite.Y += (this.Height / 2) - 10;
            var textColour = Color.Black;

            textColour.A = (byte)Opacity;
            FontManager.DrawString("" + challengeScore, "DefaultFont", _rightSprite.Position, textColour,
                                   FontAlign.Center);
        }
        private void DrawSweeps(Vector2 p1, Vector2 p2, Vector2 extents, Color lineColor, Color endColor)
        {
            var cur = extents.Clone();

            MDraw.DrawLine(p1 + cur, p2 + cur, lineColor);
            cur.X *= -1;
            MDraw.DrawLine(p1 + cur, p2 + cur, lineColor);
            cur.Y *= -1;
            MDraw.DrawLine(p1 + cur, p2 + cur, lineColor);
            cur.X *= -1;
            MDraw.DrawLine(p1 + cur, p2 + cur, lineColor);

            MDraw.DrawBox(p2, extents, endColor);
        }
Example #20
0
        public SwipeLine(string startConfiguration)
        {
            _startConfiguration        = startConfiguration;
            HandlePositionsRelative    = new Vector2[Length];
            _selectIntepolationHandles = new float[Length];

            for (int h = 0; h < Length; ++h)
            {
                char letter = char.ToLower(_startConfiguration[h]);
                HandlePositionsRelative[h]    = SwipeKeyboard.LETTER_POSITIONS[letter - 'a'];
                _selectIntepolationHandles[h] = 0;
            }
            OriginalHandlePositionsRelative = (Vector2[])HandlePositionsRelative.Clone();
        }
Example #21
0
        public override void Draw(GameTime t)
        {
            if (!Visible)
            {
                return;
            }

            MDraw.Begin();

            var   pos        = new Vector2(20f, 20f);
            float firstSpace = 150;

            var title = string.Format("Rebind Panel: Gamepad {0}", Index == PlayerIndex.One ? "1" : "2");

            MDraw.Write(title, pos, Color.White);
            pos.X  = Screen.Width * 0.2f;
            pos.Y += 40f;
            MDraw.Write("User", new Vector2(pos.X + firstSpace, pos.Y), Color.White);

            pos.Y += 60f;

            for (int i = 0; i < MaxButtons; i++)
            {
                bool  active    = SelectionIndex == i;
                var   rowTarget = Source.AllButtons[i];
                Color color     = rowTarget.IsRebindable ? (active ? Color.Yellow : Color.White) : (active ? new Color(150, 150, 80) : Color.Gray);

                Vector2 rowPos = pos.Clone();

                if (active)
                {
                    rowPos.X += 5f;
                }

                MDraw.Write(rowTarget.Name, rowPos, color);

                rowPos.X += firstSpace;
                if (rowTarget.ButtonList.Count > 0)
                {
                    MDraw.Write(rowTarget.ButtonList.ToPrettyString(), rowPos, color);
                }

                pos.Y += 40f;
            }

            MDraw.Write(string.Format("Rumble: {0} (press F7)", Source.RumbleEnabled ? "ON" : "OFF"), new Vector2(20f, Screen.Height - 40f), Color.DimGray);

            MDraw.SpriteBatch.End();
        }
Example #22
0
        private void DrawMenuItems(int startItem, int lastItem)
        {
            int xOptionOffset = CalculateXOptionOffset();
            var position      = new Vector2 {
                X = this.X + 10, Y = this.Y + 30
            };

            for (int i = startItem; i <= lastItem; i++)
            {
                MenuItem menuItem = _menuItems[i];
                Color    drawColor;

                if (IsSelected(menuItem))
                {
                    SelectedItemBackgroundColor.A = Opacity;
                    drawColor = HighlightColor;
                    _selectedItemSprite.ColorShading = SelectedItemBackgroundColor;
                    _selectedItemSprite.Position     = position.Clone();
                    _selectedItemSprite.Y           += 1;
                    _selectedItemSprite.X           -= 5;
                    _selectedItemSprite.Width        = this.Width - 10;
                    _selectedItemSprite.Height       = ItemSpacing + 3;
                    _selectedItemSprite.Draw();
                }
                else
                {
                    drawColor = TextColor;
                }

                drawColor.A = menuItem.Enabled ? Opacity : (byte)(Opacity / 2);
                FontManager.DrawString(menuItem.ItemText, FontName, position, drawColor, FontAlign.Left);
                position.X += xOptionOffset;

                var menuOptionText = menuItem.SelectedText();
                var scale          = FontManager.ScaleTextToFit(menuOptionText, FontName, (int)this.Width - 20 - xOptionOffset,
                                                                1000);

                FontManager.DrawString(menuOptionText, FontName, position, scale, drawColor, FontAlign.Left);


                position.X -= xOptionOffset;
                position.Y += ItemSpacing;
            }
        }
Example #23
0
        public CollisionPolygon(Vector2[] v)
        {
            vertices = (Vector2[])v.Clone();
            Trans = true;
            temp = new Vector2[v.Length];

            float or = 0, ir = float.MaxValue;
            float t;
            foreach (var item in vertices)
            {
                t = item.LengthSquared();
                or = MathHelper.Max(or, t);
                ir = MathHelper.Min(ir, t);
            }
            or = (float)System.Math.Sqrt(or);
            ir = (float)System.Math.Sqrt(ir);
            outCircle = new CollisionCircle(or, Position);
            inCircle = new CollisionCircle(ir, Position);
        }
Example #24
0
        }                                             //Maps we can display

        /// <summary>
        /// Converts from Ark position to normalized, between (-0.5, 0.5).
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Vector2 ConvertFromGamePositionToNormalized(Vector2 input)
        {
            Vector2 o = input.Clone();

            //Translate by the map image offset
            if (mapImageOffset != null)
            {
                o.x += mapImageOffset.x;
                o.y += mapImageOffset.y;
            }

            //Scale by the size of our image
            o.Divide(captureSize);

            //Move
            o.Add(0.5f);

            return(o);
        }
Example #25
0
        public static Vector2 ClampBetween(this Vector2 self, Vector2 min, Vector2 max)
        {
            Vector2 vec = self.Clone();             // ヴェクターをクローンする

            if (self.X < min.X)
            {
                vec.X = min.X;
            }
            else if (self.X > max.X)
            {
                vec.X = max.X;
            }

            if (self.Y < min.Y)
            {
                vec.Y = min.Y;
            }
            else if (self.Y > max.Y)
            {
                vec.Y = max.Y;
            }

            return(vec);
        }
Example #26
0
 public static Vector2 GetNormal(this Vector2 vector)
 {
     return(vector.Clone().Rotate(90));
 }
Example #27
0
 public void Reset()
 {
     Position  = _startingPosition.Clone();
     Direction = Vector2Extension.RandomStartingVector();
 }
Example #28
0
 /// <summary>
 /// Transforms a poly with the provided matrix
 /// </summary>
 public static Vector2[] Transform(Matrix mat, Vector2[] poly)
 {
     Vector2[] ret = (Vector2[])poly.Clone();
     Vector2.Transform(ret, ref mat, ret);
     return ret;
 }
        private static void CreateFaceMaskPrefab()
        {
            float  width    = 512f;
            float  height   = 512f;
            string basePath = "Assets/FaceMaskExample/FaceMaskPrefab/";

            GameObject newObj = new GameObject("FaceMaskTrackedMesh");

            //Add MeshFilter Component.
            MeshFilter meshFilter = newObj.AddComponent <MeshFilter>();

            // Create Mesh.
            meshFilter.mesh = new Mesh();
            Mesh mesh = meshFilter.sharedMesh;

            mesh.name = "DlibFaceLandmark68Mesh";

            // Mesh_vertices
            Vector3[] vertices = new Vector3[68] {
                new Vector3(117, 250),
                new Vector3(124, 291),
                new Vector3(131, 330),
                new Vector3(136, 369),
                new Vector3(146, 404),
                new Vector3(167, 433),
                new Vector3(192, 459),
                new Vector3(222, 480),
                new Vector3(261, 485),
                new Vector3(300, 478),

                new Vector3(328, 453),
                new Vector3(353, 425),
                new Vector3(372, 394),
                new Vector3(383, 357),
                new Vector3(387, 319),
                new Vector3(392, 281),
                new Vector3(397, 241),
                new Vector3(135, 224),
                new Vector3(151, 205),
                new Vector3(175, 196),

                new Vector3(202, 192),
                //22^23
                new Vector3(228, 205),  //new Vector3(228, 197), y+10
                new Vector3(281, 205),  //new Vector3(281, 197), y+10

                new Vector3(308, 191),
                new Vector3(334, 195),
                new Vector3(358, 205),
                new Vector3(374, 222),
                new Vector3(255, 228),
                new Vector3(256, 254),
                new Vector3(257, 279),

                new Vector3(258, 306),
                new Vector3(230, 322),
                new Vector3(243, 325),
                new Vector3(259, 329),
                new Vector3(274, 324),
                new Vector3(288, 320),
                new Vector3(168, 237),
                new Vector3(182, 229),
                new Vector3(200, 229),
                new Vector3(214, 239),

                new Vector3(199, 241),
                new Vector3(182, 242),
                new Vector3(296, 238),
                new Vector3(310, 228),
                new Vector3(327, 228),
                new Vector3(341, 235),
                new Vector3(328, 240),
                new Vector3(311, 240),
                //49
                new Vector3(198, 372),  //new Vector3(198, 367), y+5

                new Vector3(219, 360),

                new Vector3(242, 357),
                new Vector3(261, 360),
                new Vector3(280, 357),
                new Vector3(301, 357),
                //55
                new Vector3(322, 367),  //new Vector3(322, 362), y+5

                new Vector3(303, 387),
                new Vector3(282, 396),
                new Vector3(261, 398),
                new Vector3(241, 396),
                new Vector3(218, 388),
                //61^65
                new Vector3(205, 373),  //new Vector3(205, 368), y+5
                new Vector3(242, 371),  //new Vector3(242, 366), y+5
                new Vector3(261, 373),  //new Vector3(261, 368), y+5
                new Vector3(280, 370),  //new Vector3(280, 365), y+5
                new Vector3(314, 368),  //new Vector3(314, 363) y+5

                new Vector3(281, 382),
                new Vector3(261, 384),
                new Vector3(242, 383)
            };

            Vector3[] vertices2 = (Vector3[])vertices.Clone();
            for (int j = 0; j < vertices2.Length; j++)
            {
                vertices2[j].x = (vertices2[j].x - width / 2f) / width;
                vertices2[j].y = (height / 2f - vertices2[j].y) / height;
            }
            mesh.vertices = vertices2;

            // Mesh_triangles
            int[] triangles = new int[327] {
                // Around the right eye 21
                0, 36, 1,
                1, 36, 41,
                1, 41, 31,
                41, 40, 31,
                40, 29, 31,
                40, 39, 29,
                39, 28, 29,
                39, 27, 28,
                39, 21, 27,
                38, 21, 39,
                20, 21, 38,
                37, 20, 38,
                37, 19, 20,
                18, 19, 37,
                18, 37, 36,
                17, 18, 36,
                0, 17, 36,

                // (inner right eye 4)
                36, 37, 41,
                37, 40, 41,
                37, 38, 40,
                38, 39, 40,

                // Around the left eye 21
                45, 16, 15,
                46, 45, 15,
                46, 15, 35,
                47, 46, 35,
                29, 47, 35,
                42, 47, 29,
                28, 42, 29,
                27, 42, 28,
                27, 22, 42,
                22, 43, 42,
                22, 23, 43,
                23, 44, 43,
                23, 24, 44,
                24, 25, 44,
                44, 25, 45,
                25, 26, 45,
                45, 26, 16,

                // (inner left eye 4)
                44, 45, 46,
                47, 44, 46,
                43, 44, 47,
                42, 43, 47,

                // Eyebrows, nose and cheeks 13
                20, 23, 21,
                21, 23, 22,
                21, 22, 27,
                29, 30, 31,
                29, 35, 30,
                30, 32, 31,
                30, 33, 32,
                30, 34, 33,
                30, 35, 34,
                1, 31, 2,
                2, 31, 3,
                35, 15, 14,
                35, 14, 13,

                // mouth 48
                33, 51, 50,
                32, 33, 50,
                31, 32, 50,
                31, 50, 49,
                31, 49, 48,
                3, 31, 48,
                3, 48, 4,
                4, 48, 5,
                48, 59, 5,
                5, 59, 6,
                59, 58, 6,
                58, 7, 6,
                58, 57, 7,
                57, 8, 7,
                57, 9, 8,
                57, 56, 9,
                56, 10, 9,
                56, 55, 10,
                55, 11, 10,
                55, 54, 11,
                54, 12, 11,
                54, 13, 12,
                35, 13, 54,
                35, 54, 53,
                35, 53, 52,
                34, 35, 52,
                33, 34, 52,
                33, 52, 51,

                48, 49, 60,
                48, 60, 59,
                49, 50, 61,
                49, 61, 60,
                60, 67, 59,
                59, 67, 58,
                50, 51, 61,
                51, 62, 61,
                67, 66, 58,
                66, 57, 58,
                51, 52, 63,
                51, 63, 62,
                66, 65, 56,
                66, 56, 57,
                52, 53, 63,
                53, 64, 63,
                65, 64, 55,
                65, 55, 56,
                53, 54, 64,
                64, 54, 55,

                // inner mouth 6
                60, 61, 67,
                61, 62, 67,
                62, 66, 67,
                62, 63, 65,
                62, 65, 66,
                63, 64, 65
            };
            mesh.triangles = triangles;

            // Mesh_uv
            Vector2[] uv = new Vector2[68];
            for (int j = 0; j < uv.Length; j++)
            {
                uv[j].x = vertices[j].x / width;
                uv[j].y = (height - vertices[j].y) / height;
            }
            mesh.uv  = uv;
            mesh.uv2 = (Vector2[])uv.Clone();

            mesh.RecalculateNormals();

            // Add Collider Component.
            MeshCollider meshCollider = newObj.AddComponent <MeshCollider>();

            meshCollider.sharedMesh = CreatePrimitiveQuadMesh();

            // Add Renderer Component.
            MeshRenderer meshRenderer = newObj.AddComponent <MeshRenderer>();
            Material     material     = new Material(Shader.Find("Hide/FaceMaskShader"));

            // Create alpha mask texture.
            Vector2[] facialContourUVPoints = new Vector2[] {
                uv [0],
                uv [1],
                uv [2],
                uv [3],
                uv [4],
                uv [5],
                uv [6],
                uv [7],
                uv [8],
                uv [9],
                uv [10],
                uv [11],
                uv [12],
                uv [13],
                uv [14],
                uv [15],
                uv [16],
                uv [26],
                uv [25],
                uv [24],
                uv [23],
                uv [20],
                uv [19],
                uv [18],
                uv [17]
            };

            /*
             * Vector2[] rightEyeContourUVPoints = new Vector2[]{
             *  uv[36],
             *  uv[37],
             *  uv[38],
             *  uv[39],
             *  uv[40],
             *  uv[41]
             * };
             *
             * Vector2[] leftEyeContourUVPoints = new Vector2[]{
             *  uv[42],
             *  uv[43],
             *  uv[44],
             *  uv[45],
             *  uv[46],
             *  uv[47]
             * };
             */

            Vector2[] mouthContourUVPoints = new Vector2[] {
                uv [60],
                uv [61],
                uv [62],
                uv [63],
                uv [64],
                uv [65],
                uv [66],
                uv [67]
            };

            Texture2D alphaMaskTexture     = AlphaMaskTextureCreater.CreateAlphaMaskTexture(width, height, facialContourUVPoints, /*rightEyeContourUVPoints, leftEyeContourUVPoints,*/ mouthContourUVPoints);
            string    alphaMaskTexturePath = basePath + "FaceMaskAlphaMask.png";

            byte[] pngData = alphaMaskTexture.EncodeToPNG();

            if (CreateWithoutFolder(basePath))
            {
                File.WriteAllBytes(alphaMaskTexturePath, pngData);
                AssetDatabase.ImportAsset(alphaMaskTexturePath, ImportAssetOptions.ForceUpdate);
                AssetDatabase.SaveAssets();

                Debug.Log("Create asset \"" + basePath + "FaceMaskAlphaMask.png\"");
            }

            TextureImporter importer = TextureImporter.GetAtPath(alphaMaskTexturePath) as TextureImporter;

            importer.textureType    = TextureImporterType.Default;
            importer.mipmapEnabled  = false;
            importer.wrapMode       = TextureWrapMode.Clamp;
            importer.maxTextureSize = 1024;
            //importer.textureFormat = TextureImporterFormat.RGBA16;
            EditorUtility.SetDirty(importer);
            AssetDatabase.ImportAsset(alphaMaskTexturePath, ImportAssetOptions.ForceUpdate);
            AssetDatabase.SaveAssets();

            GameObject.DestroyImmediate(alphaMaskTexture);
            alphaMaskTexture = AssetDatabase.LoadAssetAtPath(alphaMaskTexturePath, typeof(Texture2D)) as Texture2D;
            material.SetTexture("_MaskTex", alphaMaskTexture);
            meshRenderer.material = material;

            // Add TracedMesh Compornent.
            newObj.AddComponent <TrackedMesh>();

            // Save FaceMask Assets.
            if (CreateWithoutFolder(basePath))
            {
                AssetDatabase.CreateAsset(material, basePath + "FaceMaskMaterial.mat");
                AssetDatabase.CreateAsset(mesh, basePath + "DlibFaceLandmark68Mesh.asset");
                AssetDatabase.SaveAssets();

                string prefab_path = basePath + "FaceMaskTrackedMesh.prefab";

#if UNITY_2018_3_OR_NEWER
                PrefabUtility.SaveAsPrefabAsset(newObj, prefab_path);
#else
                UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(prefab_path, typeof(UnityEngine.Object));
                if (prefab == null)
                {
                    PrefabUtility.CreatePrefab(prefab_path, newObj);
                }
                else
                {
                    PrefabUtility.ReplacePrefab(newObj, prefab);
                }
#endif

                AssetDatabase.SaveAssets();

                Debug.Log("Create asset \"" + basePath + "FaceMaskMaterial.mat\"");
                Debug.Log("Create asset \"" + basePath + "DlibFaceLandmark68Mesh.asset\"");
                Debug.Log("Create asset \"" + basePath + "FaceMaskTrackedMesh.prefab\"");
            }

            GameObject.DestroyImmediate(newObj);
        }
Example #30
0
    public void Regenerate()
    {
        Stopwatch regenStopWatch = new Stopwatch();

        regenStopWatch.Start();

        Stopwatch deformatePolyStopWatch = new Stopwatch();

        // Create Vector2 vertices
        Vector2[] vertices2D = new Vector2[startVerticesCount];

        float angleStep = (Mathf.PI * 2) / startVerticesCount;

        for (int i = 0; i < startVerticesCount; i++)
        {
            float x = Mathf.Sin(i * angleStep) * circleRadius;
            float y = Mathf.Cos(i * angleStep) * circleRadius;

            vertices2D[i] = new Vector2(x, y);
        }

        deformatePolyStopWatch.Start();
        for (int defIdx = 0; defIdx < numDeformationsInitial; defIdx++)
        {
            vertices2D = DeformatePolygon(vertices2D, gauss_um_initial, gauss_sigma_initial);
        }
        deformatePolyStopWatch.Stop();

        for (int layerIdx = 0; layerIdx < numLayers; layerIdx++)
        {
            GameObject   layerGo;
            MeshRenderer layerMeshRend;
            MeshFilter   layerMeshFilter;
            if (layerIdx >= _layers.Count)
            {
                layerGo         = new GameObject($"layer {layerIdx}");
                layerMeshRend   = layerGo.AddComponent <MeshRenderer>();
                layerMeshFilter = layerGo.AddComponent <MeshFilter>();
                layerGo.transform.SetParent(transform);
                layerGo.transform.localPosition = Vector3.zero;
                layerMeshRend.sortingOrder      = layerIdx / interleaveLayersStep;
                _layers.Add(layerGo);
            }
            else
            {
                layerGo         = _layers[layerIdx];
                layerMeshRend   = layerGo.GetComponent <MeshRenderer>();
                layerMeshFilter = layerGo.GetComponent <MeshFilter>();
                layerGo.transform.localScale = Vector3.one;
            }

            var layerVerts = vertices2D.Clone() as Vector2[];

            deformatePolyStopWatch.Start();
            for (int addDefIdx = 0; addDefIdx < numDeformationsVariation; addDefIdx++)
            {
                layerVerts = DeformatePolygon(layerVerts, gauss_um_addition, gauss_sigma_additional);
            }
            deformatePolyStopWatch.Stop();

            // Use the triangulator to get indices for creating triangles
            Triangulator tr      = new Triangulator(layerVerts);
            int[]        indices = tr.Triangulate();

            // Create the Vector3 vertices
            Vector3[] vertices = new Vector3[layerVerts.Length];
            for (int i = 0; i < layerVerts.Length; i++)
            {
                vertices[i] = new Vector3(layerVerts[i].x, layerVerts[i].y, 0);
            }

            // Create the mesh
            Mesh msh = new Mesh();
            msh.vertices  = vertices;
            msh.triangles = indices;
            msh.RecalculateNormals();
            msh.RecalculateBounds();

            layerMeshFilter.mesh = msh;

            var mat = new Material(usedMaterial);
            mat.color = Color;

            layerMeshRend.material = mat;
        }

        regenStopWatch.Stop();
        Debug.Log($"{gameObject.name} regenerate duration: {regenStopWatch.Elapsed}");
        Debug.Log($"{gameObject.name} deformate Polygon duration: {deformatePolyStopWatch.Elapsed}");
    }
Example #31
0
        public PrimitiveShape(Vector2[] vertices, Color color, DrawType type)
        {
            this.vertices = (Vector2[])vertices.Clone();
            this.transformedVertices = new Vector2[vertices.Length];
            this.type = type;

            List<Color> temp = new List<Color>();
            foreach (Vector2 vertice in this.vertices)
            {
                temp.Add(color);
            }
            this.lineColor = temp.ToArray();
            CalculatePointsAndBounds();
        }
Example #32
0
 public PrimitiveShape(Vector2[] vertices, Color[] lineColor, DrawType type)
 {
     this.vertices = (Vector2[])vertices.Clone();
     this.transformedVertices = new Vector2[vertices.Length];
     this.type = type;
     this.lineColor = lineColor;
     CalculatePointsAndBounds();
 }
Example #33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="widthSegments"></param>
        /// <param name="heightSegments"></param>
        public PlaneGeometry(float width, float height, int widthSegments = 1, int heightSegments = 1)
        {
            Debug.Assert(this.FaceVertexUvs.Count == 1, "Should only be 1 element at this stage");

            var widthHalf     = width / 2;
            var heightHalf    = height / 2;
            var gridX         = widthSegments;
            var gridZ         = heightSegments;
            var gridX1        = gridX + 1;
            var gridZ1        = gridZ + 1;
            var segmentWidth  = width / gridX;
            var segmentHeight = height / gridZ;

            var normal = new Vector3(0, 0, 1);

            for (var iz = 0; iz < gridZ1; iz++)
            {
                var y = iz * segmentHeight - heightHalf;
                for (var ix = 0; ix < gridX1; ix++)
                {
                    var x = ix * segmentWidth - widthHalf;
                    this.Vertices.Add(new Vector3(x, -y, 0));
                }
            }

            for (var iz = 0; iz < gridZ; iz++)
            {
                for (var ix = 0; ix < gridX; ix++)
                {
                    var a = ix + gridX1 * iz;
                    var b = ix + gridX1 * (iz + 1);
                    var c = (ix + 1) + gridX1 * (iz + 1);
                    var d = (ix + 1) + gridX1 * iz;

                    var uva = new Vector2(ix / (float)gridX1, 1 - iz / gridZ);
                    var uvb = new Vector2(ix / (float)gridX1, 1 - (iz + 1) / gridZ);
                    var uvc = new Vector2((ix + 1) / (float)gridX1, 1 - (iz + 1) / gridZ);
                    var uvd = new Vector2((ix + 1) / (float)gridX1, 1 - iz / gridZ);

                    var face = new Face3(a, b, d, new Vector3().One(), Color.White);
                    face.Normal = normal;
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    this.Faces.Add(face);

                    this.FaceVertexUvs[0].Add(new List <Vector2> {
                        uva, uvb, uvd
                    });

                    face        = new Face3(b, c, d, new Vector3().One(), Color.White);
                    face.Normal = normal;
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    this.Faces.Add(face);

                    this.FaceVertexUvs[0].Add(new List <Vector2> {
                        (Vector2)uvb.Clone(), uvc, (Vector2)uvd.Clone()
                    });
                }
            }
        }
Example #34
0
        /// <summary>
        /// </summary>
        /// <param name="u"></param>
        /// <param name="v"></param>
        /// <param name="udir"></param>
        /// <param name="vdir"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="depth"></param>
        /// <param name="materialIndex"></param>
        private void BuildPlane(
            string u,
            string v,
            int udir,
            int vdir,
            float width,
            float height,
            float depth,
            int materialIndex)
        {
            var w          = string.Empty;
            var gridX      = this.widthSegments;
            var gridY      = this.heightSegments;
            var widthHalf  = width / 2;
            var heightHalf = height / 2;
            var offset     = this.Vertices.Count;

            if ((u == "x" && v == "y") || (u == "y" && v == "x"))
            {
                w = "z";
            }
            else if ((u == "x" && v == "z") || (u == "z" && v == "x"))
            {
                w     = "y";
                gridY = this.depthSegments;
            }
            else if ((u == "z" && v == "y") || (u == "y" && v == "z"))
            {
                w     = "x";
                gridX = this.depthSegments;
            }

            var gridX1        = gridX + 1;
            var gridY1        = gridY + 1;
            var segmentWidth  = width / gridX;
            var segmentHeight = height / gridY;
            var normal        = new Vector3().SetValue(w, depth > 0 ? 1 : -1);

            for (var iy = 0; iy < gridY1; iy++)
            {
                for (var ix = 0; ix < gridX1; ix++)
                {
                    var vector = new Vector3();
                    vector.SetValue(u, (ix * segmentWidth - widthHalf) * udir);
                    vector.SetValue(v, (iy * segmentHeight - heightHalf) * vdir);
                    vector.SetValue(w, depth);

                    this.Vertices.Add(vector);
                }
            }

            //if (this.FaceVertexUvs.Count < 1)
            //    this.FaceVertexUvs.Add(new List<List<Vector2>>());
            Debug.Assert(this.FaceVertexUvs.Count == 1, "Should only be 1 element at this stage");

            for (var iy = 0; iy < gridY; iy++)
            {
                for (var ix = 0; ix < gridX; ix++)
                {
                    var a = ix + gridX1 * iy;
                    var b = ix + gridX1 * (iy + 1);
                    var c = (ix + 1) + gridX1 * (iy + 1);
                    var d = (ix + 1) + gridX1 * iy;

                    var uva = new Vector2(ix / gridX, 1 - iy / gridY);
                    var uvb = new Vector2(ix / gridX, 1 - (iy + 1) / gridY);
                    var uvc = new Vector2((ix + 1) / gridX, 1 - (iy + 1) / gridY);
                    var uvd = new Vector2((ix + 1) / gridX, 1 - iy / gridY);

                    var face = new Face3(a + offset, b + offset, d + offset, new Vector3().One(), Color.White);
                    face.Normal = normal;
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.MaterialIndex = materialIndex;

                    this.Faces.Add(face);
                    {
                        var uvs = new List <Vector2> {
                            uva, uvb, uvd
                        };
                        this.FaceVertexUvs[0].Add(uvs);
                    }

                    face        = new Face3(b + offset, c + offset, d + offset, new Vector3().One(), Color.White);
                    face.Normal = normal;
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.VertexNormals.Add((Vector3)normal.Clone());
                    face.MaterialIndex = materialIndex;

                    this.Faces.Add(face);
                    {
                        var uvs = new List <Vector2> {
                            (Vector2)uvb.Clone(), uvc, (Vector2)uvd.Clone()
                        };
                        this.FaceVertexUvs[0].Add(uvs);
                    }
                }
            }

            this.MergeVertices();
        }
Example #35
0
 protected void init(Vector2[] poly)
 {
     if (poly.Length < 3) throw new ArgumentException("Must have 3 or more points!");
     this.poly = (Vector2[])poly.Clone();
     int left = int.MaxValue; foreach (Vector2 v in poly) left = Math.Min((int)v.X, left);
     int top = int.MaxValue; foreach (Vector2 v in poly) top = Math.Min((int)v.Y, top);
     int right = int.MinValue; foreach (Vector2 v in poly) right = Math.Max((int)v.X, right);
     int bottom = int.MinValue; foreach (Vector2 v in poly) bottom = Math.Max((int)v.Y, bottom);
     bounds = new Rectangle(left, top, right - left + 1, bottom - top + 1);
 }
Example #36
0
 public new void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color)
 {
     position = position.Clone(_translation[_translationIndex], _translation[_translationIndex + 1]);
     base.DrawString(spriteFont, text, position, color);
 }
Example #37
0
        /// <summary>
        /// Triangulates a 2D polygon produced the indexes required to render the points as a triangle list.
        /// </summary>
        /// <param name="inputVertices">The polygon vertices in counter-clockwise winding order.</param>
        /// <param name="desiredWindingOrder">The desired output winding order.</param>
        /// <param name="outputVertices">The resulting vertices that include any reversals of winding order and holes.</param>
        /// <param name="indices">The resulting indices for rendering the shape as a triangle list.</param>
        public static void Triangulate(
			Vector2[] inputVertices,
			WindingOrder desiredWindingOrder,
			out Vector2[] outputVertices,
			out int[] indices)
        {
            Log("\nBeginning triangulation...");

            List<Triangle> triangles = new List<Triangle>();

            //make sure we have our vertices wound properly
            if (DetermineWindingOrder(inputVertices) == WindingOrder.Clockwise)
            {
                outputVertices = ReverseWindingOrder(inputVertices);

                System.Console.WriteLine(WindingOrder.Clockwise.ToString());
            }
            else
            {
                outputVertices = (Vector2[])inputVertices.Clone();
                System.Console.WriteLine(WindingOrder.CounterClockwise.ToString());
            }
            //clear all of the lists
            polygonVertices.Clear();
            earVertices.Clear();
            convexVertices.Clear();
            reflexVertices.Clear();

            //generate the cyclical list of vertices in the polygon
            for (int i = 0; i < outputVertices.Length; i++)
                polygonVertices.AddLast(new Vertex(outputVertices[i], i));

            //categorize all of the vertices as convex, reflex, and ear
            FindConvexAndReflexVertices();
            FindEarVertices();

            //clip all the ear vertices
            while (polygonVertices.Count > 3 && earVertices.Count > 0)
                ClipNextEar(triangles);

            //if there are still three points, use that for the last triangle
            if (polygonVertices.Count == 3)
                triangles.Add(new Triangle(
                    polygonVertices[0].Value,
                    polygonVertices[1].Value,
                    polygonVertices[2].Value));

            //add all of the triangle indices to the output array
            indices = new int[triangles.Count * 3];

            //move the if statement out of the loop to prevent all the
            //redundant comparisons
            if (desiredWindingOrder == WindingOrder.CounterClockwise)
            {
                for (int i = 0; i < triangles.Count; i++)
                {
                    indices[(i * 3)] = triangles[i].A.Index;
                    indices[(i * 3) + 1] = triangles[i].B.Index;
                    indices[(i * 3) + 2] = triangles[i].C.Index;
                }
            }
            else
            {
                for (int i = 0; i < triangles.Count; i++)
                {
                    indices[(i * 3)] = triangles[i].C.Index;
                    indices[(i * 3) + 1] = triangles[i].B.Index;
                    indices[(i * 3) + 2] = triangles[i].A.Index;
                }
            }
        }
Example #38
0
        // This one just calls another DrawString, so avoid changing
        //public new void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color, float rotation,
        //	Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
        //{
        //	base.DrawString(spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth);
        //}

        public new void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color, float rotation,
                                   Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            position = position.Clone(_translation[_translationIndex], _translation[_translationIndex + 1]);
            base.DrawString(spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth);
        }
Example #39
0
        void GameState.Update(Main game, GameTime gameTime)
        {
            if (!failure)
            {
                if (backgrounds.Count <= 3)
                {
                    PlaySound(voiceSuccess, 1.0f, true);
                    Util.GotoRandomMinigame(game);
                }

                currentSprite = runAnimTexture;
                playerPosition.Y = GROUND_HEIGHT;
                screenAdjustment = RUN_SPEED - ((CENTER - playerPosition.X) * SPEED_INFLUENCE);

                if (knockbackTimer < 0)
                {
                    HandleMovement(game.keyboard);
                    HandleSlide(game.keyboard);
                    HandlePunch(game.keyboard, game.prevKeyboard);
                    HandleJump(game.keyboard, game.prevKeyboard);
                    HandleObstacles();

                    if (knockbackTimer <= KNOCKBACK_BUFFER || knockbackTimer == KNOCKBACK_DURATION)
                    {
                        MoveScreen(screenAdjustment);
                        PlaySound(voiceRandom, VOICE_RANDOM_CHANCE, false);
                    }
                    else
                    {
                        currentSprite = hitTexture;
                        knockbackTimer--;
                        if (knockbackTimer == KNOCKBACK_BUFFER + 1) PlaySound(voiceRecover, VOICE_RECOVER_CHANCE, true);
                    }
                }
                else
                {
                    currentSprite = hitTexture;
                    knockbackTimer--;
                    MoveScreen(-KNOCKBACK_DISTANCE / KNOCKBACK_DURATION);
                }

                heart.Update(gameTime);
                if (heart.heartMeter == 0) failure = true;

                if (heart.beat)
                {
                    Vector2[] tempArray = new Vector2[blipPositions.Length+1];
                    for (int j = 0; j < blipPositions.Length; j++)
                    {
                        tempArray[j] = blipPositions[j];
                    }
                    tempArray[tempArray.Length - 1] = new Vector2(-monitorBlipTexture.Width, 14);
                    blipPositions = (Vector2[])tempArray.Clone();
                }
            }
            else
            {
                currentSprite = hitTexture;
                if (quitTimer == QUIT_DURATION) PlaySound(voiceFailure, VOICE_FAILURE_CHANCE, true);
                quitTimer--;
                if (quitTimer == 0)
                {
                    Main.SubmitResult("Defeat", 0);
                    game.currentState = new MenuState();
                }
            }
        }