Exemplo n.º 1
0
        /// <summary>
        /// <para>Produces vertices for a UVSphere mesh.</para>
        /// Increasing the segments horizontally or vertically will increase the resolution of the mesh.
        /// </summary>
        /// <param name="radius">Radius of sphere to base mesh on</param>
        /// <param name="horizontalSegments">Number of times to divide sphere horizontally.</param>
        /// <param name="verticalSegments">Number of times to divide sphere vertically.</param>
        /// <returns></returns>
        public List <Vector3> GetSphereVectors(float radius, float horizontalSegments, float verticalSegments)
        {
            List <Vector3> coords = new List <Vector3>();

            for (var i = 1; i <= horizontalSegments; i++)
            {
                // Move down by (Math.PI / 2) to orient the semi-circle correctly
                var parallel = (Math.PI * i / (horizontalSegments + 1)) - Math.PI / 2;

                for (var j = 0; j < verticalSegments; j++)
                {
                    var meridian = 2.0 * Math.PI * (j + 1) / verticalSegments;

                    coords.Add(ShapeHelpers.SphereCoordsToWorldCoords(radius, meridian, parallel));
                }
            }

            var things = "";

            foreach (var co in coords)
            {
                things += $" = ({co.X}, {co.Y}, {co.Z})\n";
            }

            return(coords);
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>Rotates all vertices in the mesh, from the origin, by the given rotation vector in degrees.</para>
        /// <para>This is useful for rotating an object before placing it in a ShapeGroup.</para>
        /// For camera rotation, use RotateCamera(rotationVector).
        /// </summary>
        public void RotateVerticesAboutOrigin(Vector3 rotationVectorDegrees)
        {
            foreach (var face in Faces)
            {
                for (var i = 0; i < face.VerticeCount; i++)
                {
                    face.Composition[i].Position =
                        Vector3.Transform(
                            face.Composition[i].Position,
                            Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (float)rotationVectorDegrees.X.ToRadians()));

                    face.Composition[i].Position =
                        Vector3.Transform(
                            face.Composition[i].Position,
                            Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)rotationVectorDegrees.Y.ToRadians()));

                    face.Composition[i].Position =
                        Vector3.Transform(
                            face.Composition[i].Position,
                            Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (float)rotationVectorDegrees.Z.ToRadians()));
                    if ((i + 1) % 3 == 0 && i != face.VerticeCount - 1)
                    {
                        var newNormal = ShapeHelpers.GetNormal(
                            face.Composition[i].Position,
                            face.Composition[i + 1].Position,
                            face.Composition[i + 2].Position);

                        face.Composition[i].Normal     = newNormal;
                        face.Composition[i + 1].Normal = newNormal;
                        face.Composition[i + 2].Normal = newNormal;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public FaceTriangle(
            Vector3 top,
            Vector3 bottomLeft,
            Vector3 bottomRight)
        {
            VerticeCount = 3;
            PolygonCount = 1;
            Composition  = new VertexPositionNormalTexture[VerticeCount];

            var normal = ShapeHelpers.GetNormal(top, bottomLeft, bottomRight);

            Composition[0] = new VertexPositionNormalTexture(top, normal, new Vector2(0.5f, 0));
            Composition[1] = new VertexPositionNormalTexture(bottomLeft, normal, new Vector2(0, 1));
            Composition[2] = new VertexPositionNormalTexture(bottomRight, normal, new Vector2(1, 1));
        }
Exemplo n.º 4
0
        private Dictionary <int, CircleShape> Buttons()
        {
            Dictionary <int, CircleShape> buttons = new Dictionary <int, CircleShape>();

            //On the screen of selection character :
            // Add the button "Back to Menu"
            buttons.Add(0, ShapeHelpers.RedCircleShape(78f, 6, new Vector2f(19f, 915f), Color.Cyan));

            // Add the button "Random Character"
            buttons.Add(1, ShapeHelpers.RedCircleShape(78f, 6, new Vector2f(312f, 915f), Color.Cyan));

            // Add the button "Next" to go to selection stage screen
            buttons.Add(2, ShapeHelpers.RedCircleShape(78f, 6, new Vector2f(1766f, 923f), Color.Cyan));

            return(buttons);
        }
Exemplo n.º 5
0
        protected override void InternalDraw(SpriteBatch spriteBatch)
        {
            var show = Selected && DateTime.Now.Millisecond % 1000 < 500;

            _nineSlice.DrawRectangle(spriteBatch, Bounds, 3f);

            if (Selected)
            {
                ShapeHelpers.DrawRectangle(spriteBatch, Bounds, Color.Green);
            }

            var tempText = show ? Value.Insert(Value.Length, "|") : Value;

            spriteBatch.DrawString(_font, tempText,
                                   new Vector2(Bounds.Left + 10, Bounds.Center.Y - _font.MeasureString(tempText).Y / 2f), Color.Black);
        }
Exemplo n.º 6
0
        public FaceSquare(
            Vector3 topLeft,
            Vector3 topRight,
            Vector3 bottomLeft,
            Vector3 bottomRight)
        {
            VerticeCount = 6;
            PolygonCount = 2;
            Composition  = new VertexPositionNormalTexture[VerticeCount];

            var normal = ShapeHelpers.GetNormal(topLeft, topRight, bottomLeft);

            // Squares are made of two triangles. This makes it easier to process
            Composition[0] = new VertexPositionNormalTexture(topLeft, normal, new Vector2(0, 0));
            Composition[1] = new VertexPositionNormalTexture(topRight, normal, new Vector2(1, 0));
            Composition[2] = new VertexPositionNormalTexture(bottomLeft, normal, new Vector2(0, 1));

            normal = ShapeHelpers.GetNormal(bottomLeft, topRight, bottomRight);

            Composition[3] = new VertexPositionNormalTexture(bottomLeft, normal, new Vector2(0, 1));
            Composition[4] = new VertexPositionNormalTexture(topRight, normal, new Vector2(1, 0));
            Composition[5] = new VertexPositionNormalTexture(bottomRight, normal, new Vector2(1, 1));
        }
Exemplo n.º 7
0
        public void FillRoundedRectangle(NoForms.Common.Rectangle rect, float radX, float radY, UBrush brush)
        {
            var rr = ShapeHelpers.RoundedRectangle(rect, radX, radY);

            realRenderer.graphics.FillPath(CreateBrush(brush), rr);
        }
Exemplo n.º 8
0
        public void DrawRoundedRectangle(NoForms.Common.Rectangle rect, float radX, float radY, UBrush brush, UStroke stroke)
        {
            var rr = ShapeHelpers.RoundedRectangle(rect, radX, radY);

            realRenderer.graphics.DrawPath(CreatePen(brush, stroke), rr);
        }
Exemplo n.º 9
0
 public override void DrawDebug(SpriteBatch spriteBatch) =>
 ShapeHelpers.DrawRectangle(spriteBatch, Bounds, Color.Red);
Exemplo n.º 10
0
 public override void DrawDebug(SpriteBatch spriteBatch)
 {
     ShapeHelpers.DrawRectangle(spriteBatch, new Rectangle((int)_position.X, (int)_position.Y, _width, 10),
                                Color.Red);
 }