예제 #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            ms = Mouse.GetState();

            Ray   pickRay   = Editor.heightmap.GetPickRay();
            float rayLength = 0f;

            if (Editor.camera.state == Camera.State.Fixed && layerID != -1 && currentTool != Tool.Select)
            {
                heightmap.bShowCursor = true;

                for (int i = 0; i < heightmap.triangle.Length; i++)
                {
                    Heightmap.Tri thisTri = heightmap.triangle[i];
                    if (MathExtra.Intersects(pickRay, thisTri.p1, thisTri.p3, thisTri.p2, thisTri.normal, false, true, out rayLength))
                    {
                        heightmap.testTriangle[2].SetNewCoordinates(thisTri.p1, thisTri.p2, thisTri.p3, Microsoft.Xna.Framework.Graphics.Color.White);

                        Vector3 rayTarget = pickRay.Position + pickRay.Direction * rayLength;
                        heightmap.groundCursorPosition.X = rayTarget.X / (heightmap.size.X * heightmap.cellSize.X);
                        heightmap.groundCursorPosition.Y = rayTarget.Y;
                        heightmap.groundCursorPosition.Z = rayTarget.Z / (heightmap.size.Y * heightmap.cellSize.Y);

                        Point pixel = new Point((int)(rayTarget.X / heightmap.cellSize.X), (int)(rayTarget.Z / heightmap.cellSize.Y));

                        if (rayLength > 0f)
                        {
                            if (ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                            {
                                switch (currentTool)
                                {
                                case Tool.Fill:
                                    heightmap.Paint(pixel.X, pixel.Y, heightmap.groundCursorStrength / 100f, layerID - 1);
                                    break;

                                case Tool.Unfill:
                                    heightmap.Paint(pixel.X, pixel.Y, -heightmap.groundCursorStrength / 100f, layerID - 1);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else if (heightmap.bShowCursor)
            {
                heightmap.bShowCursor = false;
            }
        }
예제 #2
0
        //Brute force method
        private void CheckTerrainRay()
        {
            Ray sunSay = new Ray(Editor.camera.position, direction);

            bHasBlockedRay = false;

            if (Editor.heightmap != null && Editor.heightmap.triangle != null && Editor.heightmap.triangle.Length > 0)
            {
                for (int i = 0; i < Editor.heightmap.triangle.Length; i++)
                {
                    Heightmap.Tri triangle  = Editor.heightmap.triangle[i];
                    float         rayLength = 0f;
                    if (MathExtra.Intersects(sunSay, triangle.p1, triangle.p2, triangle.p3, triangle.normal, true, true, out rayLength))
                    {
                        bHasBlockedRay = true;
                        break;
                    }
                }
            }
        }
예제 #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            ms = Mouse.GetState();
            //List<int> TriangleList = new List<int>();

            int o = 0;

            Ray   pickRay   = Editor.heightmap.GetPickRay();
            float rayLength = 0f;
            float?rayLengthParent;

            //TODO: Use a QuadTree
            if (ms.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                o += 1;
            }

            //if (heightmap.quadTree != null)
            heightmap.quadTree.boundingBox.Intersects(ref pickRay, out rayLengthParent);

            if (rayLengthParent == null)
            {
                o += 1;
            }
            else
            //if (MathExtra.Intersects(pickRay, heightmap.quadTree.BoundingCoordinates.LowerRight, heightmap.quadTree.BoundingCoordinates.UpperRight, heightmap.quadTree.BoundingCoordinates.UpperLeft, Vector3.Up, true, false, out rayLengthParent) || MathExtra.Intersects(pickRay, heightmap.quadTree.BoundingCoordinates.LowerRight, heightmap.quadTree.BoundingCoordinates.UpperLeft, heightmap.quadTree.BoundingCoordinates.LowerLeft, Vector3.Up, true, false, out rayLengthParent))
            {
                Vector3 rayTargetParent = pickRay.Position + pickRay.Direction * (float)rayLengthParent;
                if (rayLengthParent >= 0f)
                {
                    //Parse Quadtree based on rayTarget.Position
//                    List<int> TriangleList = heightmap.quadTree.GetTriangleIndexes(heightmap.quadTree.NodeList[0], rayTargetParent.X, rayTargetParent.Z);
                    List <int> TriangleList = new List <int>();
                    heightmap.quadTree.GetTriangleIndexes(heightmap.quadTree.NodeList[0], ref TriangleList, ref pickRay);

                    if (Editor.camera.state == Camera.State.Fixed)
                    {
                        //for (int i = 0; i < heightmap.triangle.Length; i++)
                        foreach (int i in TriangleList)
                        {
                            Heightmap.Tri thisTri = heightmap.triangle[i];
                            //heightmap.testTriangle[6].SetNewCoordinates(thisTri.p1, thisTri.p2, thisTri.p3, Microsoft.Xna.Framework.Graphics.Color.Pink);
                            if (MathExtra.Intersects(pickRay, thisTri.p1, thisTri.p2, thisTri.p3, thisTri.normal, false, true, out rayLength))
                            {
                                //heightmap.testTriangle[6].SetNewCoordinates(thisTri.p1, thisTri.p2, thisTri.p3, Microsoft.Xna.Framework.Graphics.Color.Red);

                                Vector3 rayTarget = pickRay.Position + pickRay.Direction * rayLength;
                                heightmap.groundCursorPosition.X = rayTarget.X / (heightmap.size.X * heightmap.cellSize.X);
                                heightmap.groundCursorPosition.Y = rayTarget.Y;
                                heightmap.groundCursorPosition.Z = rayTarget.Z / (heightmap.size.Y * heightmap.cellSize.Y);

                                if (rayLength > 0f)
                                {
                                    if (ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                                    {
                                        bEditing = true;

                                        switch (currentTool)
                                        {
                                        case Tool.Raise:
                                            heightmap.RiseHeight(thisTri.id);
                                            break;

                                        case Tool.Lower:
                                            heightmap.LowerHeight(thisTri.id);
                                            break;

                                        case Tool.Smooth:
                                            heightmap.Smooth(thisTri.id);
                                            break;

                                        case Tool.Flatten:
                                            if (!bHeightSet)
                                            {
                                                heightmap.flattenHeight = heightmap.groundCursorPosition.Y;
                                                bHeightSet = true;
                                            }
                                            heightmap.FlattenVertices(thisTri.id);
                                            break;
                                        }
                                    }
                                    else if (bHeightSet)
                                    {
                                        bHeightSet = false;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }



            if (bEditing && ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
            {
                bEditing = false;
                Editor.heightmap.CalculateNormals();
                //Game1.heightmap.CalculateLightmapNormals();

                //Game1.heightmap.GenerateNormals();
            }
        }