Exemplo n.º 1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _chunkManager.ChunkSystem.Renderer.RenderAll();

            lock (_physicsMutex)
            {
                if (drawPhysics)
                {
                    modelDrawer.Draw(MathConverter.Convert(cam.View), MathConverter.Convert(cam.Projection));
                }
            }

            if (pickedPos != Vector3I.One * -1)
            {
                BoundingBox picked = new BoundingBox(pickedPos.ToVector3() - 0.55f * Vector3.One, pickedPos.ToVector3() + 0.55f * Vector3.One);
                BoundingBoxRenderer.Render(GraphicsDevice, picked, camManager.MainCamera);

                BoundingBox sidePicked = new BoundingBox(sidePickedPos.ToVector3() - 0.55f * Vector3.One, sidePickedPos.ToVector3() + 0.55f * Vector3.One);
                BoundingBoxRenderer.Render(GraphicsDevice, sidePicked, Color.Blue, camManager.MainCamera);

                BoundingBox b1 = new BoundingBox(pickedPos.ToVector3(), pickedPos.ToVector3() + Vector3.One);
                BoundingBox b2 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left, pickedPos.ToVector3() + Vector3.Up + Vector3.Backward);
                BoundingBox b3 = new BoundingBox(pickedPos.ToVector3() + Vector3.Forward, pickedPos.ToVector3() + Vector3.Up + Vector3.Right);
                BoundingBox b4 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Forward, pickedPos.ToVector3() + Vector3.Up);

                BoundingBox b5 = new BoundingBox(pickedPos.ToVector3() + Vector3.Down, pickedPos.ToVector3() + Vector3.Right + Vector3.Backward);
                BoundingBox b6 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Down, pickedPos.ToVector3() + Vector3.Backward);
                BoundingBox b7 = new BoundingBox(pickedPos.ToVector3() + Vector3.Forward + Vector3.Down, pickedPos.ToVector3() + Vector3.Right);
                BoundingBox b8 = new BoundingBox(pickedPos.ToVector3() + Vector3.Left + Vector3.Forward + Vector3.Down, pickedPos.ToVector3());
            }

            spriteBatch.Begin();

            spriteBatch.DrawString(font, "Target: " + cam.Target, Vector2.One * 2f, Color.White);
            spriteBatch.DrawString(font, "Position: " + cam.Position, new Vector2(2, 2 + font.LineSpacing + 2), Color.White);
            spriteBatch.DrawString(font, "Selected: " + ((pickedPos == Vector3I.One * -1) ? "None" : pickedPos.ToString()), new Vector2(2, 2 + 2 * font.LineSpacing + 2), Color.White);

            if (_paused)
            {
                Vector2 dim = font.MeasureString("Paused");

                spriteBatch.DrawString(font, "Paused", new Vector2(GraphicsDevice.Viewport.Width - dim.X - 2, 2), Color.White);
            }

            spriteBatch.Draw(contentLibrary.DummyPixel, new Rectangle(GraphicsDevice.Viewport.Width / 2 - 1, GraphicsDevice.Viewport.Height / 2 - 1, 2, 2), Color.White);

            spriteBatch.End();

            _fpsCounter.Draw();

            base.Draw(gameTime);
        }
Exemplo n.º 2
0
        private Tuple <HermiteData, Edge[]> CubeInfo(Chunk c, Vector3I min, GridPoint XYZ, GridPoint XMaxYZ, GridPoint XYMaxZ, GridPoint XYZMax, GridPoint XMaxYMaxZ, GridPoint XMaxYZMax, GridPoint XYMaxZMax, GridPoint XMaxYMaxZMax)
        {
            HermiteData hermiteData = new HermiteData(new List <Vector3>(), new List <Vector3>());

            // get edge table index
            int cubeIndex = 0;

            if (XYZ.Density < _minimumSolidDensity)
            {
                cubeIndex += 1;
            }
            if (XMaxYZ.Density < _minimumSolidDensity)
            {
                cubeIndex += 2;
            }
            if (XMaxYMaxZ.Density < _minimumSolidDensity)
            {
                cubeIndex += 4;
            }
            if (XYMaxZ.Density < _minimumSolidDensity)
            {
                cubeIndex += 8;
            }
            if (XYZMax.Density < _minimumSolidDensity)
            {
                cubeIndex += 16;
            }
            if (XMaxYZMax.Density < _minimumSolidDensity)
            {
                cubeIndex += 32;
            }
            if (XMaxYMaxZMax.Density < _minimumSolidDensity)
            {
                cubeIndex += 64;
            }
            if (XYMaxZMax.Density < _minimumSolidDensity)
            {
                cubeIndex += 128;
            }

            GridPoint[][][] lookupTable = new GridPoint[][][]
            {
                new GridPoint[][]
                {
                    new GridPoint[]
                    {
                        XYZ,
                        XYZMax,
                    },
                    new GridPoint[]
                    {
                        XYMaxZ,
                        XYMaxZMax,
                    }
                },
                new GridPoint[][]
                {
                    new GridPoint[]
                    {
                        XMaxYZ,
                        XMaxYZMax,
                    },
                    new GridPoint[]
                    {
                        XMaxYMaxZ,
                        XMaxYMaxZMax,
                    }
                },
            };

            int edge = _edgeTable[cubeIndex];

            List <Edge> xEdges = new List <Edge>();

            // loop through all the edges
            for (int i = 0; i < 12; i++)
            {
                // if this edge contains no intersection, skip it
                if ((edge & (1 << i)) == 0)
                {
                    continue;
                }

                int[] corner1Offset = _intersections[i][0];
                int[] corner2Offset = _intersections[i][1];

                Vector3I corner1 = min;
                Vector3I corner2 = min;

                corner1.X += corner1Offset[0];
                corner1.Y += corner1Offset[1];
                corner1.Z += corner1Offset[2];

                corner2.X += corner2Offset[0];
                corner2.Y += corner2Offset[1];
                corner2.Z += corner2Offset[2];

                GridPoint corner1Point = lookupTable[corner1Offset[0]][corner1Offset[1]][corner1Offset[2]];
                GridPoint corner2Point = lookupTable[corner2Offset[0]][corner2Offset[1]][corner2Offset[2]];

                Vector3I  delta = (corner2 - corner1) * (corner1Point.Density < _minimumSolidDensity ? -1 : 1); // negate if corner1 is less than the isovalue because we assume corner2 at first.
                Direction dir   = GetDirectionFromDelta(delta);

                xEdges.Add(new Edge(corner1, corner2, dir));

                Vector3 intersectionPoint = DualContouring.InterpolateIntersectionPoint(_minimumSolidDensity, corner1.ToVector3(), corner2.ToVector3(),
                                                                                        corner1Point.Density,
                                                                                        corner2Point.Density);

                Vector3I  minCorner = Vector3I.Min(corner1, corner2);
                GridPoint minPoint  = (minCorner == corner1) ? corner1Point : corner2Point;

                Vector3   naturalNormal           = _densityGradientFunction.df(intersectionPoint.X, intersectionPoint.Y, intersectionPoint.Z);
                Vector3F8 compressedNaturalNormal = new Vector3F8(naturalNormal);

                Vector3 normal = compressedNaturalNormal.ToVector3();
                //normal = naturalNormal;

                switch (dir)
                {
                case Direction.XIncreasing:
                case Direction.XDecreasing:
                    normal = minPoint.XPositiveNormal;

                    if (normal == Vector3.Zero)
                    {
                        GridPoint withNormal = new GridPoint(minPoint);

                        withNormal.XPositiveNormal = naturalNormal;

                        c.SetPoint(minCorner.X, minCorner.Y, minCorner.Z, withNormal, true);
                    }
                    break;

                case Direction.YIncreasing:
                case Direction.YDecreasing:
                    normal = minPoint.YPositiveNormal;

                    if (normal == Vector3.Zero)
                    {
                        GridPoint withNormal = new GridPoint(minPoint);

                        withNormal.YPositiveNormal = naturalNormal;

                        c.SetPoint(minCorner.X, minCorner.Y, minCorner.Z, withNormal, true);
                    }
                    break;

                case Direction.ZIncreasing:
                case Direction.ZDecreasing:
                    normal = minPoint.ZPositiveNormal;

                    if (normal == Vector3.Zero)
                    {
                        GridPoint withNormal = new GridPoint(minPoint);

                        withNormal.ZPositiveNormal = naturalNormal;

                        c.SetPoint(minCorner.X, minCorner.Y, minCorner.Z, withNormal, true);
                    }
                    break;
                }

                if (normal == Vector3.Zero)
                {
                    normal = naturalNormal;
                }

                normal.Normalize();

                hermiteData.Add(intersectionPoint, normal);
            }

            Tuple <HermiteData, Edge[]> ret = new Tuple <HermiteData, Edge[]>(hermiteData, xEdges.ToArray());

            return(ret);
        }