static void InitShape()
        {
            Coefficients DefaultCoefficients = TimeWarp.Coefficients;

            Vector2D[] engineconevertecies = new Vector2D[]
            {
                new Vector2D(30, 10),
                new Vector2D(-30, 40),
                new Vector2D(-30, -40),
                new Vector2D(30, -10)
            };
            Vector2D offset = Polygon2D.CalcCentroid(engineconevertecies);

            OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(
                engineconevertecies,
                ref offset,
                engineconevertecies,
                Vector2D.Subtract);

            //engineconevertecies = Vector2D.Translate(-offset, engineconevertecies);

            IGeometry2D mainhull   = new Polygon2D(ALVector2D.Zero, Polygon2D.FromRectangle(80, 10));
            IGeometry2D engine     = new Polygon2D(new ALVector2D(0, new Vector2D(-30, 0)), Polygon2D.FromNumberofSidesAndRadius(10, 40));
            IGeometry2D enginecone = new Polygon2D(new ALVector2D(0, offset), engineconevertecies);

            DefaultShape = new RigidBodyTemplate(12, 1231.9384791047398f, new IGeometry2D[] { engine, mainhull, enginecone }, new Coefficients[] { DefaultCoefficients, DefaultCoefficients, DefaultCoefficients });
            DefaultShape.BalanceBody();
            //////DefaultShape.CalcInertiaMultiplier(.1f);
        }
Exemplo n.º 2
0
        static void InitShape()
        {
            Coefficients        DefaultCoefficients = TimeWarp.Coefficients;
            List <IGeometry2D>  goes = new List <IGeometry2D>();
            List <Coefficients> coes = new List <Coefficients>();

            Vector2D[] engineconevertecies = new Vector2D[]
            {
                new Vector2D(-50, 10),
                new Vector2D(-100, 20),
                new Vector2D(-100, -20),
                new Vector2D(-50, -10)
            };
            Vector2D offset = Polygon2D.CalcCentroid(engineconevertecies);

            //engineconevertecies = Vector2D.Translate( -offset,engineconevertecies);

            OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(
                engineconevertecies,
                ref offset,
                engineconevertecies,
                Vector2D.Subtract);

            goes.Add(new Polygon2D(ALVector2D.Zero, Polygon2D.FromRectangle(20, 150)));
            coes.Add(DefaultCoefficients);

            goes.Add(new Polygon2D(new ALVector2D(0, new Vector2D(-100, 0)), Polygon2D.FromNumberofSidesAndRadius(10, 20)));
            coes.Add(DefaultCoefficients);

            goes.Add(new Polygon2D(new ALVector2D(0, offset), engineconevertecies));
            coes.Add(DefaultCoefficients);
            DefaultShape = new RigidBodyTemplate(18, 3383.9114375372737f, goes.ToArray(), coes.ToArray());
            DefaultShape.BalanceBody();
            ////DefaultShape.CalcInertiaMultiplier(.1f);
        }
Exemplo n.º 3
0
        /// <summary>
        /// repositions the polygon so the Centroid is the origin.
        /// </summary>
        /// <param name="vertices">The vertices of the polygon.</param>
        /// <returns>The vertices of the polygon with the Centroid as the Origin.</returns>
        public static Vector2D[] MakeCentroidOrigin(Vector2D[] vertices)
        {
            Vector2D centroid;

            BoundingPolygon.GetCentroid(vertices, out centroid);
            return(OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(vertices, ref centroid, Vector2D.Subtract));
        }
        public static Vector2D[][] MakeCentroidOrigin(Vector2D[][] polygons)
        {
            Vector2D centroid = GetCentroid(polygons);

            Vector2D[][] result = new Vector2D[polygons.Length][];
            for (int index = 0; index < polygons.Length; ++index)
            {
                result[index] = OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(polygons[index], ref centroid, Vector2D.Subtract);
            }
            return(result);
        }
            public PointF[] GetDots(Size ViewableAreaSize, Vector2D cameraPosition, float scale)
            {
                Vector2D      tmp       = new Vector2D(ViewableAreaSize.Width / (2 * scale), ViewableAreaSize.Height / (2 * scale));
                Vector2D      Offset    = tmp - cameraPosition;
                BoundingBox2D screenbox = new BoundingBox2D(cameraPosition + tmp, cameraPosition - tmp);
                Vector2D      startpos  = new Vector2D();
                Vector2D      endpos    = new Vector2D();

                startpos.X = size.X * (float)Math.Floor(screenbox.Lower.X * sizeInv.X);
                startpos.Y = size.Y * (float)Math.Floor(screenbox.Lower.Y * sizeInv.Y);
                endpos.X   = size.X * (float)Math.Floor(screenbox.Upper.X * sizeInv.X);
                endpos.Y   = size.Y * (float)Math.Floor(screenbox.Upper.Y * sizeInv.Y);
                startpos  += Offset;
                endpos    += Offset;

                int           length      = dots.Length;
                List <PointF> returnvalue = new List <PointF>();
                Vector2D      pos         = new Vector2D();

                for (pos.X = startpos.X; pos.X <= endpos.X; pos.X += size.X)
                {
                    for (pos.Y = startpos.Y; pos.Y <= endpos.Y; pos.Y += size.Y)
                    {
                        Vector2D[] values = OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(
                            dots,
                            ref pos,
                            Vector2D.Add);

                        OperationHelper.ArrayRefOp <Vector2D, float, Vector2D>(
                            values,
                            ref scale,
                            values,
                            Vector2D.Multiply);
                        //Vector2D[] values = Vector2D.Translate(pos,dots);
                        //values = Vector2D.Multiply(scale,values);
                        for (int vpos = 0; vpos < length; ++vpos)
                        {
                            PointF point = new PointF();
                            point.X = (float)values[vpos].X;
                            point.Y = (float)values[vpos].Y;
                            returnvalue.Add(point);
                        }
                        if (returnvalue.Count > maxdots)
                        {
                            return(returnvalue.ToArray());
                        }
                    }
                }
                return(returnvalue.ToArray());
            }
Exemplo n.º 6
0
        public static Vector2D[][] CenterVertexesRange(Vector2D[][] polygons)
        {
            if (polygons == null)
            {
                throw new ArgumentNullException("polygons");
            }
            Vector2D centroid = GetCentroidOfRange(polygons);

            Vector2D[][] result = new Vector2D[polygons.Length][];
            for (int index = 0; index < polygons.Length; ++index)
            {
                result[index] = OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(polygons[index], ref centroid, Vector2D.Subtract);
            }
            return(result);
        }
        public void DrawDots(WindowState state)
        {
            Vector2D      Offset    = state.Offset;
            BoundingBox2D screenbox = state.ScreenBoundingBox;
            Vector2D      startpos  = new Vector2D();
            Vector2D      endpos    = new Vector2D();

            startpos.X = size.X * (float)Math.Floor(screenbox.Lower.X * sizeInv.X);
            startpos.Y = size.Y * (float)Math.Floor(screenbox.Lower.Y * sizeInv.Y);
            endpos.X   = size.X * (float)Math.Floor(screenbox.Upper.X * sizeInv.X);
            endpos.Y   = size.Y * (float)Math.Floor(screenbox.Upper.Y * sizeInv.Y);
            startpos  += Offset;
            endpos    += Offset;

            int      length = dots.Length;
            Vector2D pos    = new Vector2D();
            int      count  = 0;

            Gl.glBegin(Gl.GL_POINTS);
            for (pos.X = startpos.X; pos.X <= endpos.X; pos.X += size.X)
            {
                for (pos.Y = startpos.Y; pos.Y <= endpos.Y; pos.Y += size.Y)
                {
                    Matrix3x3 matrix = Matrix3x3.FromScale(new Vector2D(state.Scale, state.Scale)) * Matrix3x3.FromTranslate2D(pos);

                    // Vector2D[] values = Vector2D.Transform(matrix, dots);

                    Vector2D[] values = OperationHelper.ArrayRefOp <Matrix3x3, Vector2D, Vector2D>(
                        ref matrix,
                        dots,
                        Vector2D.Multiply);


                    for (int vpos = 0; vpos < length; ++vpos)
                    {
                        state.DrawPoint(values[vpos], colors[vpos]);
                        count++;
                    }
                    if (count > maxdots)
                    {
                        return;
                    }
                }
            }
            Gl.glEnd();
        }
Exemplo n.º 8
0
 public static Vector2D[] ApplyMatrix(ref Matrix2x3 matrix, Vector2D[] vertexes)
 {
     return(OperationHelper.ArrayRefOp <Matrix2x3, Vector2D, Vector2D>(ref matrix, vertexes, Vector2D.Transform));
 }
        //public static List<PointF[]> GetVertexes(Size ViewableAreaSize, float scale, Vector2D cameraPosition, List<ICollidableBody> Collidables)
        public static List <PointF[]> GetVertexes(WindowState wstate, List <ICollidableBody> Collidables)
        {
            List <PointF[]> returnvalue = new List <PointF[]>();

            BoundingBox2D screenbox = wstate.ScreenBoundingBox;

            float baseradiusInc = (float)(MathHelper.PI * 2) / ((float)NumberofCircleVertexes);
            float radiusInc     = baseradiusInc;
            int   numerofCV     = NumberofCircleVertexes;
            float sizedCV       = 100;

            foreach (Physics2D.ICollidableBody body in Collidables)
            {
                if (body.BoundingBox2D == null)
                {
                    body.CalcBoundingBox2D();
                }
                if (!screenbox.TestIntersection(body.BoundingBox2D))
                {
                    continue;
                }
                foreach (Physics2D.ICollidableBodyPart part in body.CollidableParts)
                {
                    if (part.UseCircleCollision)
                    {
                        if (part.BaseGeometry.BoundingRadius > sizedCV)
                        {
                            numerofCV = NumberofCircleVertexes + (int)MathHelper.Sqrt(part.BaseGeometry.BoundingRadius - sizedCV);
                            if (numerofCV > 100)
                            {
                                numerofCV = 100;
                            }
                            radiusInc = (float)(MathHelper.PI * 2) / ((float)numerofCV);
                        }
                        else
                        {
                            numerofCV = NumberofCircleVertexes;
                            radiusInc = baseradiusInc;
                        }

                        PointF[] points = new PointF[numerofCV];
                        for (int angle = 0; angle != numerofCV; ++angle)
                        {
                            Vector2D vect = Vector2D.FromLengthAndAngle(part.BaseGeometry.BoundingRadius, ((float)angle) * radiusInc + part.GoodPosition.Angular);
                            vect            = (vect + wstate.Offset + part.GoodPosition.Linear) * wstate.Scale;
                            points[angle].X = (float)vect.X;
                            points[angle].Y = (float)vect.Y;
                        }
                        returnvalue.Add(points);
                    }
                    else
                    {
                        Vector2D[] vects = OperationHelper.ArrayRefOp <Vector2D, Vector2D, Vector2D>(
                            part.DisplayVertices,
                            ref wstate.Offset,
                            Vector2D.Add);

                        //Vector2D[] vects = Vector2D.Multiply(wstate.Scale, Vector2D.Translate(wstate.Offset, part.DisplayVertices));
                        PointF[] points = new PointF[vects.Length];
                        for (int pos = 0; pos != vects.Length; ++pos)
                        {
                            //Vector2D vect = (vects[pos] + Offset) * scale;
                            points[pos].X = (float)vects[pos].X;
                            points[pos].Y = (float)vects[pos].Y;
                        }
                        returnvalue.Add(points);
                    }
                }
            }
            return(returnvalue);
        }
        void DrawVertexes(WindowState state)
        {
            List <IControlable> BODIES = new List <IControlable>(world.Collidables);
            float baseradiusInc        = (float)(MathHelper.PI * 2) / ((float)numberofCircleVertexes);
            float radiusInc            = baseradiusInc;
            int   numerofCV            = numberofCircleVertexes;
            float sizedCV = 100;

            int       color  = defaultColor1.ToArgb();
            int       color2 = defaultColor2.ToArgb();
            Matrix3x3 matrix = Matrix3x3.FromScale(new Vector2D(state.Scale, state.Scale)) * Matrix3x3.FromTranslate2D(state.Offset);

            foreach (IControlable body in BODIES)
            {
                if (body.BoundingBox2D == null || !body.IgnoreInfo.IsCollidable)
                {
                    body.CalcBoundingBox2D();
                }
                if (!state.ScreenBoundingBox.TestIntersection(body.BoundingBox2D) || body.IsExpired || body.IsInvisible)
                {
                    continue;
                }
                ControlableWave wave = body as ControlableWave;

                if (body.ControlHandler != null &&
                    body.Target != null && !body.Target.IsExpired && !body.Target.IsInvisible &&
                    body.Controlers != null && body.Controlers.Length > 0)
                {
                    Vector2D   direction = Vector2D.Normalize(body.Target.Current.Position.Linear - body.Current.Position.Linear);
                    Vector2D[] vertexes  = new Vector2D[3];
                    vertexes[0] = body.Current.Position.Linear + direction * (body.BoundingRadius + 60);
                    vertexes[1] = body.Current.Position.Linear + Vector2D.Rotate(MathHelper.PI / 24, direction) * (body.BoundingRadius + 20);
                    vertexes[2] = body.Current.Position.Linear + Vector2D.Rotate(-MathHelper.PI / 24, direction) * (body.BoundingRadius + 20);

                    //Vector2D.Transform(matrix, ref vertexes);
                    OperationHelper.ArrayRefOp <Matrix3x3, Vector2D, Vector2D>(
                        ref matrix,
                        vertexes,
                        vertexes,
                        Vector2D.Multiply);


                    Gl.glBegin(Gl.GL_POLYGON);
                    SetColor(teamcolors[body.FactionInfo.FactionNumber]);
                    Gl.glVertex3f(vertexes[0].X, vertexes[0].Y, 0);
                    SetColor(teamcolors[0]);
                    Gl.glVertex3f(vertexes[1].X, vertexes[1].Y, 0);
                    Gl.glVertex3f(vertexes[2].X, vertexes[2].Y, 0);
                    Gl.glEnd();
                }
                foreach (Physics2D.ICollidableBodyPart part in body.CollidableParts)
                {
                    //Gl.glLoadIdentity();
                    Gl.glBegin(Gl.GL_POLYGON);
                    //IColoredPart colored = part as IColoredPart;
                    if (part.UseCircleCollision)
                    {
                        if (part.BaseGeometry.BoundingRadius > sizedCV)
                        {
                            numerofCV = numberofCircleVertexes + (int)MathHelper.Sqrt(part.BaseGeometry.BoundingRadius - sizedCV);
                            if (numerofCV > 100)
                            {
                                numerofCV = 100;
                            }
                            radiusInc = (float)(MathHelper.PI * 2) / ((float)numerofCV);
                        }
                        else
                        {
                            numerofCV = numberofCircleVertexes;
                            radiusInc = baseradiusInc;
                        }

                        for (int angle = 0; angle != numerofCV; ++angle)
                        {
                            Vector2D vect = matrix * (Vector2D.FromLengthAndAngle(part.BaseGeometry.BoundingRadius, ((float)angle) * radiusInc + part.GoodPosition.Angular) + part.GoodPosition.Linear);

                            int vectColor = color2;
                            if (angle == 0)
                            {
                                vectColor = color;
                                if (body != null)
                                {
                                    vectColor = teamcolors[body.FactionInfo.FactionNumber];
                                }
                            }
                            if (wave != null)
                            {
                                if (wave.Colors.Length > angle)
                                {
                                    vectColor = (wave.Colors[angle]);
                                }
                                else
                                {
                                    if (wave.PrimaryColor != 0)
                                    {
                                        vectColor = (wave.PrimaryColor);
                                    }
                                }
                            }
                            SetColor(vectColor);

                            Gl.glVertex3f((float)vect.X, (float)vect.Y, 0);
                        }

                        //soundInfo.Add(points);
                    }
                    else
                    {
                        Vector2D[] vects = part.DisplayVertices;
                        if (vects != null)
                        {
                            vects = OperationHelper.ArrayRefOp <Matrix3x3, Vector2D, Vector2D>(
                                ref matrix,
                                part.DisplayVertices,
                                Vector2D.Multiply);

                            //vects = Vector2D.Transform(matrix, part.DisplayVertices);
                            for (int pos = 0; pos != vects.Length; ++pos)
                            {
                                int vectColor = color2;
                                if (pos == 0)
                                {
                                    vectColor = color;
                                    if (body != null)
                                    {
                                        vectColor = teamcolors[body.FactionInfo.FactionNumber];
                                    }
                                }
                                SetColor(vectColor);
                                Gl.glVertex3f((float)vects[pos].X, (float)vects[pos].Y, 0);
                            }
                        }
                    }
                    Gl.glEnd();
                }
            }
        }