public static void GetShapeMeshData(EntityCollidable collidable, List <VertexPositionNormalTexture> vertices, List <ushort> indices)
        {
            var convexHullShape = collidable.Shape as ConvexHullShape;

            if (convexHullShape == null)
            {
                throw new ArgumentException("Wrong shape type.");
            }

            var hullTriangleVertices = new List <Vector3>();
            var hullTriangleIndices  = new List <int>();

            ConvexHullHelper.GetConvexHull(convexHullShape.Vertices, hullTriangleIndices, hullTriangleVertices);
            //The hull triangle vertices are used as a dummy to get the unnecessary hull vertices, which are cleared afterwards.
            hullTriangleVertices.Clear();
            foreach (int i in hullTriangleIndices)
            {
                hullTriangleVertices.Add(convexHullShape.Vertices[i]);
            }

            var     toReturn = new VertexPositionNormalTexture[hullTriangleVertices.Count];
            Vector3 normal;

            for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
            {
                normal = (Vector3.Normalize(Vector3.Cross(hullTriangleVertices[i + 2] - hullTriangleVertices[i], hullTriangleVertices[i + 1] - hullTriangleVertices[i])));
                vertices.Add(new VertexPositionNormalTexture((hullTriangleVertices[i]), normal, new Vector2(0, 0)));
                vertices.Add(new VertexPositionNormalTexture((hullTriangleVertices[i + 1]), normal, new Vector2(1, 0)));
                vertices.Add(new VertexPositionNormalTexture((hullTriangleVertices[i + 2]), normal, new Vector2(0, 1)));
                indices.Add(i);
                indices.Add((ushort)(i + 1));
                indices.Add((ushort)(i + 2));
            }
        }
Пример #2
0
        public double getAngle(Skeleton skeleton, JointType type0, JointType type1, JointType type2)
        {
            Microsoft.Xna.Framework.Vector3 crossProduct;
            Microsoft.Xna.Framework.Vector3 joint0Tojoint1;
            Microsoft.Xna.Framework.Vector3 joint1Tojoint2;

            Joint joint0 = skeleton.Joints[type0];
            Joint joint1 = skeleton.Joints[type1];
            Joint joint2 = skeleton.Joints[type2];

            joint0Tojoint1 = new Microsoft.Xna.Framework.Vector3(joint0.Position.X - joint1.Position.X, joint0.Position.Y - joint1.Position.Y,
                                                                 joint0.Position.Z - joint1.Position.Z);
            joint1Tojoint2 = new Microsoft.Xna.Framework.Vector3(joint2.Position.X - joint1.Position.X, joint2.Position.Y - joint1.Position.Y,
                                                                 joint2.Position.Z - joint1.Position.Z);

            joint0Tojoint1.Normalize();
            joint1Tojoint2.Normalize();

            double dotProduct = Microsoft.Xna.Framework.Vector3.Dot(joint0Tojoint1, joint1Tojoint2);

            crossProduct = Microsoft.Xna.Framework.Vector3.Cross(joint0Tojoint1, joint1Tojoint2);
            double crossProdLength = crossProduct.Length();

            double angleFormed   = Math.Atan2(crossProdLength, dotProduct);
            double angleInDegree = angleFormed * (180 / Math.PI);

            roundedAngle = Math.Round(angleInDegree, 2);

            return(roundedAngle);
        }
Пример #3
0
        XNAVector3 Unproject(XNAVector3 v, XNAMatrix projection, XNAMatrix view, XNAMatrix world, XNAVector3 camPos)
        {
            XNAVector3 p0 = GraphicsDevice.Viewport.Unproject(new XNAVector3(v.X, v.Y, 0), projection, view, world);
            XNAVector3 p1 = GraphicsDevice.Viewport.Unproject(new XNAVector3(v.X, v.Y, 1), projection, view, world);

            if (Math.Abs(p1.Z - p0.Z) <= 1e-4)
            {
                return(v);
            }
            XNAVector3 dir = XNAVector3.Normalize(p1 - p0);
            XNAVector3 p   = camPos + dir * (v.Z - camPos.Z) / dir.Z;

            return(p);
        }
Пример #4
0
        public bool Raycast(NavPoint startPoint, Vector3 endPos, ref float t, ref Vector3 hitNormal, PolyId[] path, ref int pathCount, int maxPath)
        {
            t = 0;
            pathCount = 0;

            //validate input
            if (startPoint.Polygon == PolyId.Null || !nav.IsValidPolyRef(startPoint.Polygon))
                return false;

            PolyId curRef = startPoint.Polygon;
            Vector3[] verts = new Vector3[PathfindingCommon.VERTS_PER_POLYGON];
            int n = 0;

            hitNormal = new Vector3(0, 0, 0);

            while (curRef != PolyId.Null)
            {
                //cast ray against current polygon
                MeshTile tile;
                Poly poly;
                nav.TryGetTileAndPolyByRefUnsafe(curRef, out tile, out poly);

                //collect vertices
                int nv = 0;
                for (int i = 0; i < poly.VertCount; i++)
                {
                    verts[nv] = tile.Verts[poly.Verts[i]];
                    nv++;
                }

                float tmin, tmax;
                int segMin, segMax;
                if (!Intersection.SegmentPoly2D(startPoint.Position, endPos, verts, nv, out tmin, out tmax, out segMin, out segMax))
                {
                    //could not hit the polygon, keep the old t and report hit
                    pathCount = n;
                    return true;
                }

                //keep track of furthest t so far
                if (tmax > t)
                    t = tmax;

                //store visited polygons
                if (n < maxPath)
                    path[n++] = curRef;

                //ray end is completely inside the polygon
                if (segMax == -1)
                {
                    t = float.MaxValue;
                    pathCount = n;
                    return true;
                }

                //follow neighbours
                PolyId nextRef = PolyId.Null;

                for (int i = poly.FirstLink; i != Link.Null; i = tile.Links[i].Next)
                {
                    Link link = tile.Links[i];

                    //find link which contains the edge
                    if (link.Edge != segMax)
                        continue;

                    //get pointer to the next polygon
                    MeshTile nextTile;
                    Poly nextPoly;
                    nav.TryGetTileAndPolyByRefUnsafe(link.Reference, out nextTile, out nextPoly);

                    //skip off-mesh connection
                    if (nextPoly.PolyType == PolygonType.OffMeshConnection)
                        continue;

                    //if the link is internal, just return the ref
                    if (link.Side == BoundarySide.Internal)
                    {
                        nextRef = link.Reference;
                        break;
                    }

                    //if the link is at the tile boundary

                    //check if the link spans the whole edge and accept
                    if (link.BMin == 0 && link.BMax == 255)
                    {
                        nextRef = link.Reference;
                        break;
                    }

                    //check for partial edge links
                    int v0 = poly.Verts[link.Edge];
                    int v1 = poly.Verts[(link.Edge + 1) % poly.VertCount];
                    Vector3 left = tile.Verts[v0];
                    Vector3 right = tile.Verts[v1];

                    //check that the intersection lies inside the link portal
                    if (link.Side == BoundarySide.PlusX || link.Side == BoundarySide.MinusX)
                    {
                        //calculate link size
                        float s = 1.0f / 255.0f;
                        float lmin = left.Z + (right.Z - left.Z) * (link.BMin * s);
                        float lmax = left.Z + (right.Z - left.Z) * (link.BMax * s);
                        if (lmin > lmax)
                        {
                            //swap
                            float temp = lmin;
                            lmin = lmax;
                            lmax = temp;
                        }

                        //find z intersection
                        float z = startPoint.Position.Z + (endPos.Z - startPoint.Position.Z) * tmax;
                        if (z >= lmin && z <= lmax)
                        {
                            nextRef = link.Reference;
                            break;
                        }
                    }
                    else if (link.Side == BoundarySide.PlusZ || link.Side == BoundarySide.MinusZ)
                    {
                        //calculate link size
                        float s = 1.0f / 255.0f;
                        float lmin = left.X + (right.X - left.X) * (link.BMin * s);
                        float lmax = left.X + (right.X - left.X) * (link.BMax * s);
                        if (lmin > lmax)
                        {
                            //swap
                            float temp = lmin;
                            lmin = lmax;
                            lmax = temp;
                        }

                        //find x intersection
                        float x = startPoint.Position.X + (endPos.X - startPoint.Position.X) * tmax;
                        if (x >= lmin && x <= lmax)
                        {
                            nextRef = link.Reference;
                            break;
                        }
                    }
                }

                if (nextRef == PolyId.Null)
                {
                    //no neighbour, we hit a wall

                    //calculate hit normal
                    int a = segMax;
                    int b = (segMax + 1) < nv ? segMax + 1 : 0;
                    Vector3 va = verts[a];
                    Vector3 vb = verts[b];
                    float dx = vb.X - va.X;
                    float dz = vb.Z - va.Z;
                    hitNormal.X = dz;
                    hitNormal.Y = 0;
                    hitNormal.Z = -dx;
                    hitNormal.Normalize();

                    pathCount = n;
                    return true;
                }

                //no hit, advance to neighbour polygon
                curRef = nextRef;
            }

            pathCount = n;

            return true;
        }
Пример #5
0
        public void NextRound()
        {
            RoundTimer.Reset();
            int countBefore = Participants.Count;

            Participants.RemoveAll(creature => creature == null || creature.IsDead || creature.Status.Money < 10.0m || creature.Physics.IsInLiquid);
            int countAfter = Participants.Count;

            if (countAfter > 0 && countAfter < countBefore)
            {
                Participants[0].World.LogEvent(String.Format("Dice: {0} player(s) left the game.", countBefore - countAfter));
            }

            if (Participants.Count < 2)
            {
                EndGame();
                return;
            }


            foreach (var participant in Participants)
            {
                var money = participant.Status.Money;

                var bet = (decimal)(int)(MathFunctions.Rand(0.1f, 0.25f) * money);
                Pot += (DwarfBux)bet;
                participant.Status.Money -= (DwarfBux)bet;

                IndicatorManager.DrawIndicator((-(DwarfBux)bet).ToString(),
                                               participant.AI.Position + Microsoft.Xna.Framework.Vector3.Up, 4.0f,
                                               GameSettings.Default.Colors.GetColor("Negative", Microsoft.Xna.Framework.Color.Red));
            }
            Participants[0].World.LogEvent(String.Format("Dice: Entering round {0}/{1}. The Pot is {2}.", CurrentRound, MaxRounds, Pot.ToString()));

            List <Creature> winners = new List <Creature>();
            List <int>      rolls   = new List <int>();
            int             maxRoll = 0;

            foreach (var participant in Participants)
            {
                Microsoft.Xna.Framework.Vector3 vel = (participant.AI.Position - Location) + MathFunctions.RandVector3Cube() * 0.5f;
                vel.Normalize();
                vel *= 5;
                vel += Microsoft.Xna.Framework.Vector3.Up * 1.5f;
                participant.World.ParticleManager.Create("dice", participant.AI.Position, -vel, Microsoft.Xna.Framework.Color.White);
                int roll = MathFunctions.RandInt(1, 7);
                rolls.Add(roll);
                if (roll >= maxRoll)
                {
                    maxRoll = roll;
                }
            }

            for (int k = 0; k < rolls.Count; k++)
            {
                if (rolls[k] >= maxRoll)
                {
                    winners.Add(Participants[k]);
                }
            }

            if (winners.Count == 1)
            {
                var maxParticipant = winners[0];
                maxParticipant.Status.Money += Pot;
                winners[0].World.LogEvent(String.Format("{0} won {1} at dice.", maxParticipant.Stats.FullName, Pot));
                maxParticipant.NoiseMaker.MakeNoise("Pleased", maxParticipant.AI.Position, true, 0.5f);
                IndicatorManager.DrawIndicator((Pot).ToString(),
                                               maxParticipant.AI.Position + Microsoft.Xna.Framework.Vector3.Up + Microsoft.Xna.Framework.Vector3.Forward * 0.1f, 10.0f,
                                               GameSettings.Default.Colors.GetColor("Positive", Microsoft.Xna.Framework.Color.Green));
                Pot = 0.0m;
                maxParticipant.AddThought(Thought.ThoughtType.WonGambling);
            }
            else
            {
                Participants[0].World.LogEvent(String.Format("Nobody won this round of dice. The Pot is {0}.", Pot.ToString()));
            }

            if (PotFixture != null)
            {
                PotFixture.SetFullness((float)(decimal)(Pot / 500.0m));
            }

            CurrentRound++;
            if (CurrentRound > MaxRounds)
            {
                CurrentRound = 1;
                EndGame();
            }
        }
Пример #6
0
        public static Vector3 Normalize(Vector3 vectorToNormalize)
        {
            var normalizedVector = MonoGameVector3.Normalize(vectorToNormalize.MonoGameVector);

            return(new Vector3(normalizedVector));
        }
Пример #7
0
        /// <summary>
        /// check for new updates
        /// </summary>
        public void Update()
        {
            // get the mousestate
            Microsoft.Xna.Framework.Input.MouseState ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            this.lastKeyboardState    = this.currentKeyboardState;
            this.currentKeyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            // get the movement and position

            this.mouseMovement         = new Microsoft.Xna.Framework.Vector2((FenrirGame.Instance.Properties.ScreenWidth / 2 - ms.X), (FenrirGame.Instance.Properties.ScreenHeight / 2 - ms.Y));
            this.currentMousePosition -= mouseMovement * 1.05f;
            Microsoft.Xna.Framework.Input.Mouse.SetPosition(FenrirGame.Instance.Properties.ScreenWidth / 2, FenrirGame.Instance.Properties.ScreenHeight / 2);

            if (this.currentMousePosition.X < 0)
            {
                this.currentMousePosition.X = 0;
            }
            else if (this.currentMousePosition.X > FenrirGame.Instance.Properties.ScreenWidth)
            {
                this.currentMousePosition.X = FenrirGame.Instance.Properties.ScreenWidth;
            }

            if (this.currentMousePosition.Y < 0)
            {
                this.currentMousePosition.Y = 0;
            }
            else if (this.currentMousePosition.Y > FenrirGame.Instance.Properties.ScreenHeight)
            {
                this.currentMousePosition.Y = FenrirGame.Instance.Properties.ScreenHeight;
            }

            // get the scrollwheel
            this.scrollValue    = scrollValueOld - ms.ScrollWheelValue;
            this.scrollValueOld = ms.ScrollWheelValue;

            // calculate boundingbox
            this.boundingBox.X = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.X;
            this.boundingBox.Y = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.Y;

            // buttonstates
            Boolean leftPressed  = ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            Boolean rightPressed = ms.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;

            // reset click events
            this.releaseLeft  = false;
            this.releaseRight = false;
            this.leftClick    = false;
            this.rightClick   = false;

            // check if dragging or clicked
            if (leftPressed)
            {
                if (!this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = this.currentMousePosition;
                }
                else if (!this.leftDrag && (Math.Abs(this.currentMousePosition.X - this.dragLeftStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragLeftStart.Value.Y) > 5))
                {
                    this.leftDrag = true;
                }
            }
            else
            {
                if (this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = null;
                    this.leftDrag      = false;
                    this.releaseLeft   = true;

                    if (!this.leftDrag)
                    {
                        this.leftClick = true;
                    }
                }
            }

            if (rightPressed)
            {
                if (!this.dragRightStart.HasValue)
                {
                    this.dragRightStart = this.currentMousePosition;
                }
                else if (!this.rightDrag && (Math.Abs(this.currentMousePosition.X - this.dragRightStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragRightStart.Value.Y) > 5))
                {
                    this.rightDrag = true;
                }
            }
            else
            {
                if (this.dragRightStart.HasValue)
                {
                    this.dragRightStart = null;
                    this.rightDrag      = false;
                    this.releaseRight   = true;

                    if (!this.rightDrag)
                    {
                        this.rightClick = true;
                    }
                }
            }

            // keaboard stuff
            this.moveCamLeft  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A);
            this.moveCamRight = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D);
            this.moveCamUp    = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W);
            this.moveCamDown  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S);
            this.resetCamRot  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0);

            if (currentKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape) && !lastKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                this.endCurrentAction = true;
            }
            else
            {
                this.endCurrentAction = false;
            }

            if (FenrirGame.Instance.Properties.CurrentGameState == GameState.InGame)
            {
                Microsoft.Xna.Framework.Vector3 nearsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 0f);
                Microsoft.Xna.Framework.Vector3 farsource  = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 1f);

                Microsoft.Xna.Framework.Vector3 nearPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);
                Microsoft.Xna.Framework.Vector3 farPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    farsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);

                Microsoft.Xna.Framework.Vector3 direction = farPoint - nearPoint;
                direction.Normalize();
                this.mouseRay = new Microsoft.Xna.Framework.Ray(nearPoint, direction);

                this.currentMousePositionInWorld = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    Microsoft.Xna.Framework.Matrix.Identity
                    );
            }
        }
Пример #8
0
 public void Normalize()
 {
     _vector.Normalize();
 }
Пример #9
0
        private void UpdateLink(int num)
        {


            if (((num >= 0) && (num <= (mSpriteList.Count - 1))) && (this.mPoints.Count >= 2))
            {
                Vector3 absoluteTopLeft = new Vector3();
                Vector3 absoluteTopRight = new Vector3();
                Vector3 absoluteBottomLeft = new Vector3();
                Vector3 absoluteBottomRight = new Vector3();

                Sprite sprite = mSpriteList[num];

                Segment horizontalConnectingSegment = GetHorizontalSegmentAt(num);

                float oldZ = sprite.Z;

                sprite.Position = (horizontalConnectingSegment.Point1.ToVector3() + horizontalConnectingSegment.Point2.ToVector3()) / 2.0f;

                sprite.Z = oldZ;

                horizontalConnectingSegment.ScaleBy(2);

                Vector3 normalVector = horizontalConnectingSegment.Point2.ToVector3() - horizontalConnectingSegment.Point1.ToVector3();
                normalVector = new Vector3(-normalVector.Y, normalVector.X, 0);
                normalVector.Normalize();
                normalVector *= Width / 2.0f;

                #region Get the left side

                if (num == 0)
                {

                    absoluteTopLeft = mPoints[num] + normalVector;
                    absoluteBottomLeft = mPoints[num] - normalVector;

                }
                else
                {
                    Segment thisAboveSegment = horizontalConnectingSegment;
                    thisAboveSegment.MoveBy(normalVector.X, normalVector.Y);
                    thisAboveSegment.ScaleBy(10);

                    Segment thisBelowSegment = horizontalConnectingSegment;
                    thisBelowSegment.MoveBy(-normalVector.X, -normalVector.Y);
                    thisBelowSegment.ScaleBy(10);

                    Segment leftAboveSegment;
                    Segment leftBelowSegment;

                    GetSegmentsAboveAndBelow(num - 1, out leftAboveSegment, out leftBelowSegment);
                    leftAboveSegment.ScaleBy(10);
                    leftBelowSegment.ScaleBy(10);

                    Point point;

                    thisAboveSegment.IntersectionPoint(ref leftAboveSegment, out point);
                    if (double.IsNaN(point.X) || double.IsNaN(point.Y))
                    {
                        absoluteTopLeft = mPoints[num] + normalVector;
                    }
                    else
                    {
                        absoluteTopLeft.X = (float)point.X;
                        absoluteTopLeft.Y = (float)point.Y;
                    }

                    thisBelowSegment.IntersectionPoint(ref leftBelowSegment, out point);


                    if (double.IsNaN(point.X) || double.IsNaN(point.Y))
                    {
                        absoluteBottomLeft = mPoints[num] - normalVector;
                    }
                    else
                    {
                        absoluteBottomLeft.X = (float)point.X;
                        absoluteBottomLeft.Y = (float)point.Y;
                    }
                }
                #endregion

                if (num + 1 == mPoints.Count - 1)
                {
                    absoluteTopRight = mPoints[num + 1] + normalVector;
                    absoluteBottomRight = mPoints[num + 1] - normalVector;
                }
                else
                {
                    Segment thisAboveSegment = horizontalConnectingSegment;
                    thisAboveSegment.MoveBy(normalVector.X, normalVector.Y);
                    thisAboveSegment.ScaleBy(10);

                    Segment thisBelowSegment = horizontalConnectingSegment;
                    thisBelowSegment.MoveBy(-normalVector.X, -normalVector.Y);
                    thisBelowSegment.ScaleBy(10);

                    Segment rightAboveSegment;
                    Segment rightBelowSegment;

                    GetSegmentsAboveAndBelow(num + 1, out rightAboveSegment, out rightBelowSegment);

                    rightAboveSegment.ScaleBy(10);
                    rightBelowSegment.ScaleBy(10);

                    Point point;
                    thisAboveSegment.IntersectionPoint(ref rightAboveSegment, out point);

                    if (double.IsNaN(point.X) || double.IsNaN(point.Y))
                    {
                        // this likely occurs because the slope for the endpoints of this Sprite and the slope
                        // for the endpoints of the next Sprite are equal, so parallel segments never intersect
                        absoluteTopRight = mPoints[num + 1] + normalVector;
                    }
                    else
                    {

                        absoluteTopRight.X = (float)point.X;
                        absoluteTopRight.Y = (float)point.Y;
                    }

                    thisBelowSegment.IntersectionPoint(ref rightBelowSegment, out point);


                    if (double.IsNaN(point.X) || double.IsNaN(point.Y))
                    {
                        // this likely occurs because the slope for the endpoints of this Sprite and the slope
                        // for the endpoints of the next Sprite are equal, so parallel segments never intersect
                        absoluteBottomRight = mPoints[num + 1] - normalVector;
                    }
                    else
                    {
                        absoluteBottomRight.X = (float)point.X;
                        absoluteBottomRight.Y = (float)point.Y;
                    }

                }

                Vector3 tempVector = absoluteTopLeft - sprite.Position;
                sprite.Vertices[0].Scale = new Microsoft.Xna.Framework.Vector2(tempVector.X, tempVector.Y);

                tempVector = absoluteTopRight - sprite.Position;
                sprite.Vertices[1].Scale = new Microsoft.Xna.Framework.Vector2(tempVector.X, tempVector.Y);

                tempVector = absoluteBottomRight - sprite.Position;
                sprite.Vertices[2].Scale = new Microsoft.Xna.Framework.Vector2(tempVector.X, tempVector.Y);

                tempVector = absoluteBottomLeft - sprite.Position;
                sprite.Vertices[3].Scale = new Microsoft.Xna.Framework.Vector2(tempVector.X, tempVector.Y);


                SpriteManager.ManualUpdate(sprite);
                /*
                Vector3 vector;
                Vector3 vector2;
                Sprite sprite;
                if (num < 2)
                {
                    vector = (Vector3) this.points[0];
                    vector2 = (Vector3) this.points[1];
                    sprite = mSpriteList[0];
                    Vector3 vector3 = new Vector3(vector2.X - vector.X, vector2.Y - vector.Y, 0f);
                    Matrix sourceMatrix = Matrix.CreateRotationZ(-1.570796f);

                    vector3 = Vector3.Transform(vector3, sourceMatrix);

                    vector3.Normalize();
                    vector3 = (Vector3) (vector3 * this.Width);
                    if (vector3.Length() != 0f)
                    {
                        sprite.Vertices[0].Position = vector2 - vector3;
                        sprite.Vertices[1].Position = vector2 + vector3;
                        sprite.Vertices[2].Position = vector + vector3;
                        sprite.Vertices[3].Position = vector - vector3;
                    }
                    else
                    {
                        sprite.Vertices[0].Position = vector;
                        sprite.Vertices[1].Position = vector;
                        sprite.Vertices[2].Position = vector;
                        sprite.Vertices[3].Position = vector;
                    }
                }
                else if (num == (this.points.Count - 1))
                {
                    Point point;
                    Point point2;
                    vector = (Vector3) this.points[num - 2];
                    vector2 = (Vector3) this.points[num - 1];
                    Vector3 vector4 = (Vector3) this.points[num];
                    sprite = mSpriteList[num - 1];
                    Sprite sprite2 = mSpriteList[num - 2];
                    Vector3 vector5 = vector - vector2;
                    Vector3 vector6 = vector4 - vector2;
                    double num2 = System.Math.Atan2((double) vector6.Y, (double) vector6.X);
                    double num3 = System.Math.Atan2((double) vector5.Y, (double) vector5.X);
                    double d = (num2 + num3) / 2.0;
                    Vector3 vector7 = new Vector3((float) System.Math.Cos(d), (float) System.Math.Sin(d), 0f);

                    vector5 = FlatRedBall.Math.MathFunctions.TransformVector(vector5,  Matrix.CreateRotationZ(1.570796f));

                    vector6 = FlatRedBall.Math.MathFunctions.TransformVector(vector6,  Matrix.CreateRotationZ(-1.570796f));

                    vector5.Normalize();
                    vector5 = (Vector3) (vector5 * this.Width);
                    vector6.Normalize();
                    vector6 = (Vector3) (vector6 * this.Width);
                    vector7.Normalize();
                    if (num3 > num2)
                    {
                        vector7 = (Vector3) (vector7 * -1f);
                    }
                    vector7 = (Vector3) (vector7 * this.Width);
                    Segment line = new Segment(
                        new Point((double) (vector.X + vector5.X), (double) (vector.Y + vector5.Y)), new Point((double) (vector2.X + vector5.X), (double) (vector2.Y + vector5.Y)));
                    Segment line2 = new Segment(
                        new Point((double) (vector.X - vector5.X), (double) (vector.Y - vector5.Y)), new Point((double) (vector2.X - vector5.X), (double) (vector2.Y - vector5.Y)));
                    Segment line3 = new Segment(
                        new Point((double) (vector2.X + vector6.X), (double) (vector2.Y + vector6.Y)), new Point((double) (vector4.X + vector6.X), (double) (vector4.Y + vector6.Y)));
                    Segment line4 = new Segment(
                        new Point((double) (vector2.X - vector6.X), (double) (vector2.Y - vector6.Y)), new Point((double) (vector4.X - vector6.X), (double) (vector4.Y - vector6.Y)));


                    if (System.Math.Abs((double)(System.Math.Abs((double)(num2 - num3)) - 3.1415926535897931)) < 0.0010000000474974513)
                    {
                        point = new Point((double) (vector2.X + vector7.X), (double) (vector2.Y + vector7.Y));
                        point2 = new Point((double) (vector2.X - vector7.X), (double) (vector2.Y - vector7.Y));
                    }
                    else
                    {
                        line.IntersectionPoint(ref line3, out point);
                        line2.IntersectionPoint(ref line4, out point2);
                    }
                    Vector3 vector8 = new Vector3(vector4.X - vector6.X, vector4.Y - vector6.Y, 0f);
                    Vector3 vector9 = new Vector3(vector4.X + vector6.X, vector4.Y + vector6.Y, 0f);
                    sprite.Vertices[0].Position = vector8;
                    sprite.Vertices[1].Position = vector9;
                    sprite.Vertices[2].Position.X = (float)point.X;
                    sprite.Vertices[2].Position.Y = (float)point.Y;
                    sprite.Vertices[3].Position.X = (float)point2.X;
                    sprite.Vertices[3].Position.Y = (float)point2.Y;
                    sprite2.Vertices[0].Position = sprite.Vertices[3].Position;
                    sprite2.Vertices[1].Position = sprite.Vertices[2].Position;
                }
                 * 
                 */
            }
        }
Пример #10
0
        void GetSegmentsAboveAndBelow(int index, out Segment aboveSegment, out Segment belowSegment)
        {
            Segment segment = GetHorizontalSegmentAt(index);

            segment.ScaleBy(2); // so they intersect

            Vector3 normalVector = segment.Point2.ToVector3() - segment.Point1.ToVector3();
            normalVector = new Vector3(-normalVector.Y, normalVector.X, 0);
            normalVector.Normalize();
            normalVector = normalVector * Width / 2.0f;

            aboveSegment = segment;
            aboveSegment.MoveBy(normalVector.X, normalVector.Y);

            belowSegment = segment;
            belowSegment.MoveBy(-normalVector.X, -normalVector.Y);
        }