Example #1
0
 /// <summary>
 /// Creates a new bullet visualisation.
 /// </summary>
 /// <param name="quarter">Town quarter where the bullet is located</param>
 /// <param name="start">Starting position</param>
 /// <param name="azimuth">The flight direction</param>
 /// <param name="range">The flight range</param>
 /// <param name="startHeight">Starting height</param>
 /// <param name="endHeight">Ending height</param>
 public BulletVisualisation(TownQuarter quarter, Vector2 start, float azimuth, float range, float startHeight, float endHeight)
 {
     Vector2 end = start.Go(range, azimuth);
     Vector2 startL = start.Go(Width, azimuth - MathHelper.PiOver2);
     Vector2 startR = start.Go(Width, azimuth + MathHelper.PiOver2);
     Vector2 endL = end.Go(Width, azimuth - MathHelper.PiOver2);
     Vector2 endR = end.Go(Width, azimuth + MathHelper.PiOver2);
     horizontalPlate = new Plate(quarter, startL.ToVector3(startHeight), startR.ToVector3(startHeight), endL.ToVector3(endHeight), endR.ToVector3(endHeight), Texture, Texture, false);
     verticalPlate = new Plate(quarter, start.ToVector3(startHeight + Width), start.ToVector3(startHeight - Width), end.ToVector3(endHeight + Width), end.ToVector3(endHeight - Width), Texture, Texture, false);
 }
Example #2
0
 public static Matrix CreateLocalTransformation(Vector2 position, float rotation, Vector2 scale)
 {
     return
         Matrix.CreateScale(new Vector3(scale, 1.0f)) *
         Matrix.CreateRotationZ(MathHelper.ToRadians(rotation)) *
         Matrix.CreateTranslation(position.ToVector3());
 }
Example #3
0
        public Incinerator(Vector2 position)
        {
            this.Position = position;
            cube = new Cube(new Vector3(position.X, 0, position.Y), RM.GetTexture("incinerator"));

            cube.ScaleVector = new Vector3(24, 64, 24);
            cube.SetPosition(position.ToVector3() + new Vector3(0, -56, 0));
        }
Example #4
0
File: Door.cs Project: Frib/LD25
        public Door(Vector2 position)
        {
            Position = position;
            cube = new Cube(Position.ToVector3(), RM.GetTexture("door"));
            cube.SetPosition(new Vector3(Position.X, Y, Position.Y));

            HudIcons.Add(new HudIcon() { text = "Open door", texture = RM.GetTexture("opendooricon"), Action = (() => state = DoorState.Opening) });
            HudIcons.Add(new HudIcon() { text = "Close door", texture = RM.GetTexture("closedooricon"), Action = (() => state = DoorState.Closing) });

            HudIcons.Add(new HudIcon() { text = "Lock/unlock", texture = RM.GetTexture("lockicon"), Action = (() => Locked = !Locked) });
            HudIcons.Add(new HudIcon() { text = "Toggle AI", texture = RM.GetTexture("dooraiicon"), Action = (() => ai = !ai) });
        }
Example #5
0
        public void ToVector3Test()
        {
            const float TestValueA = 5.722222f;
            const float TestValueB = -72.333e-7f;

            Vector2 vectorA = new Vector2(TestValueA, TestValueB);

            Vector3 resultA = vectorA.ToVector3();

            Assert.AreEqual(resultA.X, TestValueA);
            Assert.AreEqual(resultA.Y, TestValueB);
            Assert.AreEqual(resultA.Z, 0);
        }
Example #6
0
        public static Vector2 PointToWorldSpace(Vector2 point,
                                       Vector2 heading,
                                       Vector2 position)
        {
            Vector2 TransPoint = point;
            float desiredAngle = WrapAngle((float)Math.Atan2(heading.Y, heading.X));

            TransPoint = Vector2.Transform(point,
                                 Matrix.CreateRotationZ(desiredAngle) *
                                 Matrix.CreateTranslation(position.ToVector3())
                                 );

            return TransPoint;

        }
Example #7
0
 public static List<Obj_AI_Base> VCollision(this Spell spell, Vector2 fromVector2, List<Vector2> to)
 {
     return spell.VCollision(fromVector2.ToVector3(), to.ToVector3());
 }
Example #8
0
            /// <summary>
            ///     Returns an Area-of-Effect cone prediction from a prediction input source.
            /// </summary>
            /// <param name="input">
            ///     <see cref="PredictionInput" /> input
            /// </param>
            /// <returns>
            ///     <see cref="PredictionOutput" /> output
            /// </returns>
            public static PredictionOutput GetConePrediction(PredictionInput input)
            {
                var mainTargetPrediction = Movement.GetPrediction(input, false, true);
                var posibleTargets = new List<PossibleTarget>
                                         {
                                             new PossibleTarget
                                                 {
                                                     Position = mainTargetPrediction.UnitPosition.ToVector2(), 
                                                     Unit = input.Unit
                                                 }
                                         };

                if (mainTargetPrediction.Hitchance >= HitChance.Medium)
                {
                    // Add the posible targets  in range:
                    posibleTargets.AddRange(GetPossibleTargets(input));
                }

                if (posibleTargets.Count > 1)
                {
                    var candidates = new List<Vector2>();

                    foreach (var target in posibleTargets)
                    {
                        target.Position = target.Position - input.From.ToVector2();
                    }

                    for (var i = 0; i < posibleTargets.Count; i++)
                    {
                        for (var j = 0; j < posibleTargets.Count; j++)
                        {
                            if (i != j)
                            {
                                var p = (posibleTargets[i].Position + posibleTargets[j].Position) * 0.5f;
                                if (!candidates.Contains(p))
                                {
                                    candidates.Add(p);
                                }
                            }
                        }
                    }

                    var bestCandidateHits = -1;
                    var bestCandidate = new Vector2();
                    var positionsList = posibleTargets.Select(t => t.Position).ToList();

                    foreach (var candidate in candidates)
                    {
                        var hits = GetHits(candidate, input.Range, input.Radius, positionsList);
                        if (hits > bestCandidateHits)
                        {
                            bestCandidate = candidate;
                            bestCandidateHits = hits;
                        }
                    }

                    if (bestCandidateHits > 1 && input.From.ToVector2().DistanceSquared(bestCandidate) > 50 * 50)
                    {
                        return new PredictionOutput
                                   {
                                       Hitchance = mainTargetPrediction.Hitchance, AoeHitCount = bestCandidateHits, 
                                       UnitPosition = mainTargetPrediction.UnitPosition, 
                                       CastPosition = bestCandidate.ToVector3(), Input = input
                                   };
                    }
                }

                return mainTargetPrediction;
            }
 /// <summary>
 /// finds the velocity of a point rotating about another point
 /// </summary>
 /// <param name="relPos">the relative position of the point (from its center of rotation)</param>
 /// <param name="angVel">the angular velocity of the point</param>
 /// <returns></returns>
 public static Vector2 VelOfPoint(Vector2 relPos, float angVel)
 {
     return Vector3.Cross(angVel * Vector3.UnitZ, relPos.ToVector3()).ToVector2();
 }
        public void ApplyImpulse(Vector2 impulse, Vector2 contact)
        {
            this.vel += impulse * this.InvMass;

            var impulsiveTorque = Vector3.Cross((contact - this.Position).ToVector3(), impulse.ToVector3());
            this.ang_v += impulsiveTorque.Z * this.GetInverseInertiaMoment();
        }
Example #11
0
 public void RpcResetCampInfo(int playerID, int camp, Vector2 position)
 {
     Debug.LogFormat("Unit{2}.RpcResetCampInfo({0},{1})", camp, position, playerID);
     name = "Player Unit " + playerID;
     if (isLocalPlayer)
     {
         transform.position = position.ToVector3(1.1f);
         _rebirthPosition = Position;
     }
 }
Example #12
0
    public void SetPoint(int index, Vector2 point)
    {
		if (index > -1 && index < _points.Count)
        {
			Vector3 p = transform.InverseTransformPoint(point.ToVector3(_yPosition));
            Vector2 pos = new Vector2(p.x, p.z);
            
			_points[index] = pos;
        }
    }
        public static Matrix CreateOrthonormalBasis(Vector2 x, Vector2 ySugg)
        {
            Vector3 z = Vector3.Cross(x.ToVector3(), ySugg.ToVector3());
            if (z.LengthSquared() == 0.0) new Exception("arguments cannot be parrallel.");

            Vector3 y = Vector3.Cross(z, x.ToVector3());
            y.Normalize();
            z.Normalize();

            Matrix m = new Matrix();
            m.Right = x.ToVector3();
            m.Up = y;
            m.Forward = z;
            m.Translation = Vector3.Zero;

            return m;
        }
        public static RenderInstruction Rectangle(Vector2 topLeft2d, Vector2 dims, Color c) 
        {
            Vector3 topLeft     = topLeft2d.ToVector3();
            Vector3 topRight    = new Vector3(topLeft.X + dims.X, topLeft.Y, 0);
            Vector3 bottomRight = new Vector3(topLeft.X, topLeft.Y - dims.Y, 0);
            Vector3 bottomLeft  = new Vector3(topLeft.X + dims.X, topLeft.Y - dims.Y, 0);

            VertexPositionColor[] vertexRectangle = new VertexPositionColor[4];

            vertexRectangle[0].Position = topLeft;
            vertexRectangle[1].Position = topRight;
            vertexRectangle[2].Position = bottomRight;
            vertexRectangle[3].Position = bottomLeft;

            // Do __not__ touch the order of these.
            int[] ind = new int[6];
            ind[0] = 0;
            ind[1] = 1;
            ind[2] = 2;
            ind[3] = 3;
            ind[4] = 2;
            ind[5] = 1;

            vertexRectangle[0].Color = vertexRectangle[1].Color =
                vertexRectangle[2].Color = vertexRectangle[3].Color = c;

            return new RenderInstruction(vertexRectangle, ind, PrimitiveType.TriangleList);
        }
        /// <summary>
        /// Creates a RenderInstruction representing a line.
        /// </summary>
        /// <param name="start2d">The starting point of the line</param>
        /// <param name="end2d">The ending point of the line</param>
        /// <param name="color">The color of the line</param>
        public static RenderInstruction Line(Vector2 start2d, Vector2 end2d, Color color)
        {
            VertexPositionColor[] line = new VertexPositionColor[2];
            line[0].Position = start2d.ToVector3();
            line[1].Position = end2d.ToVector3();
            line[0].Color = line[1].Color = color;

            int[] ind = { 0, 1 };

            return new RenderInstruction(line, ind, PrimitiveType.LineList);
        }
        public static RenderInstruction Triangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
        {
            VertexPositionColor[] vertexTriangle = new VertexPositionColor[3];
            vertexTriangle[0].Position = v1.ToVector3();
            vertexTriangle[1].Position = v2.ToVector3();
            vertexTriangle[2].Position = v3.ToVector3();
            vertexTriangle[0].Color = vertexTriangle[1].Color = vertexTriangle[2].Color = color;

            int[] ind = { 0, 1, 2 };

            return new RenderInstruction(vertexTriangle, ind, PrimitiveType.TriangleList);
        }
        /// <summary>
        /// Creates a Rendernstruction representing a circle. Uses triangle fan method.
        /// </summary>
        /// <param name="center2d">The center of the circle</param>
        /// <param name="rad">The radian of the circle</param>
        /// <param name="rads">Number of radians to draw (if drawing a half circle for example)</param>
        /// <param name="closeCircle">
        /// If set to <c>true</c>, connect the circle.
        /// Unless not drawing a full circle, set to true.
        /// </param>
        /// <param name="c">The color of the circle</param>
        public static RenderInstruction Circle(Vector2 center2d, float rad, double rads,
            bool closeCircle, Color c)
        {
            Vector3 center = center2d.ToVector3();
            // number of vertices used
            const int quality = 43;
            // number of triangles used, -1 because the center vertex 
            const int nTriangles = quality - 1;

            VertexPositionColor[] vertexCircle = new VertexPositionColor[quality];
            vertexCircle[0].Position = center;
            vertexCircle[0].Color = c;

            // Find quality - 1 points on the circle pereferi.
            for (int n = 1; n < quality; n++)
            {
                double frac = n / (float) (quality - 1);
                double r    = frac * rads;

                Vector3 offset = new Vector3(rad * (float)Math.Cos(r), rad * (float)Math.Sin(r), 0);
                vertexCircle[n].Position = center + offset;
                vertexCircle[n].Color = c;
            }

            // Every group of three indexes points to indexes that points to coordinates in vertexCircle.
            // Together, these coordinates form a triangle.
            int[] ind = new int[nTriangles * 3];
            short ii = 0;

            for (; ii < ind.Length - 3; ii += 3)
            {
                // + 1 because ii start at zero, but vertexIndex start at 1 since center has index 0
                int vertexIndex = (ii/ 3) + 1;

                // All triangles points to the center,
                // and two coordinates on the pereferi.
                // Note that the order of the two coordinates are important.
                ind[ii] = 0;
                ind[ii + 2] = vertexIndex;
                ind[ii + 1] = vertexIndex + 1;
            }

            // Last one that glues it together.
            if (closeCircle)
            {
                ind[ii] = 0;
                ind[ii + 2] = (short)(ii / 3 + 1);
                ind[ii + 1] = 1;
            }

            return new RenderInstruction(vertexCircle, ind, PrimitiveType.TriangleList);
        }
Example #18
0
    public int AddPoint(Vector2 point, int insertPoint)
    {
		if (insertPoint < 0 || insertPoint > _points.Count - 1)
        {
            Vector3 p = transform.InverseTransformPoint(point.ToVector3(_yPosition));
            Vector2 pos = new Vector2(p.x, p.z);

            KeyValuePair<Vector2, Vector2> values = new KeyValuePair<Vector2,Vector2>(pos, pos);
			_startEndPoints.Add(values);

			_points.Add(pos);
        }
        else
        {
            Vector3 p = transform.InverseTransformPoint(point.ToVector3(_yPosition));
            Vector2 pos = new Vector2(p.x, p.z);

            KeyValuePair<Vector2, Vector2> values = new KeyValuePair<Vector2, Vector2>(pos, pos);
			_startEndPoints.Insert(insertPoint, values);

			_points.Insert(insertPoint, pos);
        }

		return (insertPoint < 0 || insertPoint > _points.Count - 1) ? _points.Count - 1 : insertPoint;
    }
Example #19
0
 private void RecalculateCameraPosition(Vector2 cameraPosition)
 {
     cameraPositionComponent = position + cameraPosition * componentBoardRatio;
     cameraViewRectangle = new Rectangle(
         cameraPositionComponent.ToVector3(),
         (cameraPositionComponent + camera.ViewSize * componentBoardRatio).ToVector3(),
         cameraColor);
 }