Пример #1
0
        private static M2 Transform(M2Model model, IEnumerable <int> indicies, MapDoodadDefinition mddf)
        {
            var currentM2 = new M2();

            currentM2.Vertices.Clear();
            currentM2.Indices.Clear();

            var posX   = (mddf.Position.X - TerrainConstants.CenterPoint) * -1;
            var posY   = (mddf.Position.Y - TerrainConstants.CenterPoint) * -1;
            var origin = new Vector3(posX, posY, mddf.Position.Z);

            // Create the scale matrix used in the following loop.
            Matrix scaleMatrix;

            Matrix.CreateScale(mddf.Scale, out scaleMatrix);

            // Creation the rotations
            var rotateZ = Matrix.CreateRotationZ(MathHelper.ToRadians(mddf.OrientationB + 180));
            var rotateY = Matrix.CreateRotationY(MathHelper.ToRadians(mddf.OrientationA));
            var rotateX = Matrix.CreateRotationX(MathHelper.ToRadians(mddf.OrientationC));

            var worldMatrix = Matrix.Multiply(scaleMatrix, rotateZ);

            worldMatrix = Matrix.Multiply(worldMatrix, rotateX);
            worldMatrix = Matrix.Multiply(worldMatrix, rotateY);

            for (var i = 0; i < model.BoundingVertices.Length; i++)
            {
                var position = model.BoundingVertices[i];
                var normal   = model.BoundingNormals[i];

                // Scale and Rotate
                Vector3 rotatedPosition;
                Vector3.Transform(ref position, ref worldMatrix, out rotatedPosition);

                Vector3 rotatedNormal;
                Vector3.Transform(ref normal, ref worldMatrix, out rotatedNormal);
                rotatedNormal.Normalize();

                // Translate
                Vector3 finalVector;
                Vector3.Add(ref rotatedPosition, ref origin, out finalVector);

                currentM2.Vertices.Add(finalVector);
            }

            currentM2.Indices.AddRange(indicies);
            return(currentM2);
        }
Пример #2
0
        public void SelectLine(WCell.Util.Graphics.Vector3 p1, WCell.Util.Graphics.Vector3 p2, Color color, bool doNotReplace = true)
        {
            const float halfLineWidth = 0.5f;

            var s1 = p1 - halfLineWidth;
            var s2 = p1 + halfLineWidth;

            var t1 = p2 - halfLineWidth;
            var t2 = p2 + halfLineWidth;

            s1.Z = s2.Z = Math.Max(s1.Z, s2.Z);
            t1.Z = t2.Z = Math.Max(t1.Z, t2.Z);
            var tri1 = new Triangle(s1, s2, t2);
            var tri2 = new Triangle(t2, t1, s1);

            Select(ref tri1, doNotReplace, color);
            Select(ref tri2, true, color);
        }
Пример #3
0
        public void SelectPoint(WCell.Util.Graphics.Vector3 p, Color color, bool doNotReplace = true)
        {
            const float sideDist = 0.5f;

            var p1 = p;
            var p2 = p;
            var p3 = p;

            p1.X += sideDist;

            p2.X -= sideDist;
            p2.Y -= sideDist;

            p3.X -= sideDist;
            p3.Y += sideDist;

            var tri1 = new Triangle(p1, p2, p3);

            Select(ref tri1, doNotReplace, color);
        }
Пример #4
0
        private void SelectOnPath()
        {
            Ray ray;
            if (!GetRayToCursor(out ray))
            {
                // Outside of current map
                return;
            }

            WVector3 v = new WVector3(float.MinValue, float.MinValue, float.MinValue);
            IShape found = null;
            foreach (var shape in Shapes)
            {
                if (shape.IntersectFirstTriangle(ray, out v) == -1) continue;

                found = shape;
                break;
            }

            if (found == null)
                return;

            selectedPoints.Add(new RegionalPoint
            {
                Shape = found,
                Point = v
            });

            if (selectedPoints.Count <= 1) return;

            // highlight corridor and visited fringe
            var start = selectedPoints[0];
            if (!(start.Shape is NavMesh)) return;

            var dest = selectedPoints[1];
            if (!(dest.Shape is NavMesh)) return;

            var visited = new HashSet<int>();
            var path = new Path();

            var corridor = (start.Shape as NavMesh).Tile.Pathfinder.FindCorridor(start.Point, dest.Point, out visited);

            if (corridor.IsNull) return;

            // highlight fringe
            /*foreach (var tri in visited)
                {
                    SelectTriangle(tri, true, new Color(120, 10, 10, 128));
                }*/

            // highlight corridor
            var current = corridor;
            while (!current.IsNull)
            {
                // TODO: manage paths that cross tile boundaries.
                SelectTriangle(start.Shape, current.Triangle, true);
                current = current.Previous;
            }

            // draw line to along the path
            (start.Shape as NavMesh).Tile.Pathfinder.FindPathStringPull(start.Point, dest.Point, corridor, path);

            var p = start.Point;
            LineSelectionRenderer.SelectPoint(start.Point, Color.Black);
            while (path.HasNext())
            {
                var q = path.Next();
                LineSelectionRenderer.SelectLine(p, q, Color.Green);
                LineSelectionRenderer.SelectPoint(q, Color.Black);
                p = q;
            }

            // highlight corners
            /*current = corridor;
                while (!current.IsNull)
                {
                    //var tri = Tile.NavMesh.FindFirstTriangleUnderneath(curren);
                    SelectTriangle(current.Triangle, true);

                    if (current.Edge != -1 && current.Previous != null)
                    {
                        WVector3 left, right, apex;
                        Tile.NavMesh.GetOutsideOrderedEdgePointsPlusApex(current.Previous.Triangle, current.Edge, out left, out right, out apex);
                        LineSelectionRenderer.SelectPoint(left, Color.LimeGreen);
                        LineSelectionRenderer.SelectPoint(right, Color.Red);
                        LineSelectionRenderer.SelectPoint(apex, Color.Azure);
                    }
                    current = current.Previous;
                }*/
        }
Пример #5
0
        private void InitializeEffect()
        {
            UpdateProjection();
            effect.World = Matrix.Identity;
            effect.View = _view;
            effect.Projection = _proj;

            effect.AmbientLightColor = new XVector3(0.3f, 0.3f, 0.3f);
            effect.DiffuseColor = new XVector3(1.0f, 1.0f, 1.0f);
            effect.SpecularColor = new XVector3(0.25f, 0.25f, 0.25f);
            effect.SpecularPower = 5.0f;
            effect.Alpha = 1.0f;

            effect.VertexColorEnabled = true;

            var lightDirection = new WVector3(0.0f, 0.0f, -1.0f).ToXna();
            lightDirection.Normalize();
            effect.LightingEnabled = true;

            effect.DirectionalLight0.Enabled = true;
            effect.DirectionalLight0.DiffuseColor = XVector3.One;
            effect.DirectionalLight0.Direction = lightDirection;
            effect.DirectionalLight0.SpecularColor = new XVector3(0.25f, 0.25f, 0.25f);

            effect.DirectionalLight1.Enabled = false;
            effect.DirectionalLight1.DiffuseColor = new XVector3(0.1f, 0.1f, 0.1f);
            effect.DirectionalLight1.Direction = XVector3.Normalize(new XVector3(-1.0f, -1.0f, 1.0f));

            GlobalIlluminationLevel = 1.75f;
            //_vertexDeclaration = new VertexDeclaration(VertexPositionNormalColored.VertexElements);
        }
Пример #6
0
        private static M2 Transform(M2Model model, IEnumerable<int> indicies, MapDoodadDefinition mddf)
        {
            var currentM2 = new M2();
            currentM2.Vertices.Clear();
            currentM2.Indices.Clear();

            var posX = (mddf.Position.X - TerrainConstants.CenterPoint)*-1;
            var posY = (mddf.Position.Y - TerrainConstants.CenterPoint)*-1;
            var origin = new Vector3(posX, posY, mddf.Position.Z);

            // Create the scale matrix used in the following loop.
            Matrix scaleMatrix;
            Matrix.CreateScale(mddf.Scale, out scaleMatrix);

            // Creation the rotations
            var rotateZ = Matrix.CreateRotationZ(MathHelper.ToRadians(mddf.OrientationB + 180));
            var rotateY = Matrix.CreateRotationY(MathHelper.ToRadians(mddf.OrientationA));
            var rotateX = Matrix.CreateRotationX(MathHelper.ToRadians(mddf.OrientationC));

            var worldMatrix = Matrix.Multiply(scaleMatrix, rotateZ);
            worldMatrix = Matrix.Multiply(worldMatrix, rotateX);
            worldMatrix = Matrix.Multiply(worldMatrix, rotateY);

            for (var i = 0; i < model.BoundingVertices.Length; i++)
            {
                var position = model.BoundingVertices[i];
                var normal = model.BoundingNormals[i];

                // Scale and Rotate
                Vector3 rotatedPosition;
                Vector3.Transform(ref position, ref worldMatrix, out rotatedPosition);

                Vector3 rotatedNormal;
                Vector3.Transform(ref normal, ref worldMatrix, out rotatedNormal);
                rotatedNormal.Normalize();

                // Translate
                Vector3 finalVector;
                Vector3.Add(ref rotatedPosition, ref origin, out finalVector);

                currentM2.Vertices.Add(finalVector);
            }

            currentM2.Indices.AddRange(indicies);
            return currentM2;
        }