Beispiel #1
0
        public void Draw(object sender, Draw3DEventArgs e)
        {
            // Transparency
            AlphaTestEffect effect = new AlphaTestEffect(e.GraphicsDevice);

            effect.Texture = Client.TerrainTexture;
            //effect.ReferenceAlpha = 1;
            if (DebugSettings.RenderWireframe)
            {
                effect.Texture = Client.EmptyTexture;
            }

            effect.World      = Matrix.Identity;
            effect.Projection = Client.MainPlayer.Camera.ProjectionMatrix;
            effect.View       = Client.MainPlayer.Camera.ViewMatrix;
            for (int x = 0; x < Chunks.GetLength(0); x++)
            {
                for (int y = 0; y < Chunks.GetLength(1); y++)
                {
                    for (int z = 0; z < Chunks.GetLength(2); z++)
                    {
                        if (!Chunks[x, y, z].Visible)
                        {
                            continue;
                        }
                        BoundingBoxRenderer.Render(Chunks[x, y, z].Box,
                                                   Client.Device,
                                                   Client.MainPlayer.Camera.ViewMatrix,
                                                   Client.MainPlayer.Camera.ProjectionMatrix,
                                                   Color.White);
                        effect.CurrentTechnique.Passes[0].Apply();
                        Chunks[x, y, z].Draw(e.GraphicsDevice);
                    }
                }
            }
        }
Beispiel #2
0
        public void Draw2D(object sender, Draw2DEventArgs e)
        {
            frameCounter++;

            e.SpriteBatch.Begin();

            if (!Client.Paused)
            {
                // Crosshair
                e.SpriteBatch.Draw(Client.CrosshairTexture,
                                   Client.WindowCenter,                                                            // Center of screen
                                   null,                                                                           // Source rectangle
                                   Color.White,                                                                    // Color
                                   0f,                                                                             // Rotation
                                   new Vector2(Client.CrosshairTexture.Width, Client.CrosshairTexture.Height) / 2, // Image center
                                   1f,                                                                             // Scale
                                   SpriteEffects.None,
                                   0f                                                                              // Depth
                                   );
                e.SpriteBatch.Draw(Client.EmptyTexture, Client.WindowCenter, Color.Red);
                string fps = string.Format("FPS: {0}", frameRate);
                e.SpriteBatch.DrawString(Client.Font, fps, Vector2.Zero, Color.White);

                MouseState m          = Mouse.GetState();
                int        mouseX     = m.X;
                int        mouseY     = m.Y;
                Vector3    nearsource = new Vector3((float)mouseX, (float)mouseY, 0f);
                Vector3    farsource  = new Vector3((float)mouseX, (float)mouseY, 1f);

                Vector3 nearPoint = Client.Viewport.Unproject(nearsource,
                                                              Client.MainPlayer.Camera.ProjectionMatrix,
                                                              Client.MainPlayer.Camera.ViewMatrix,
                                                              Matrix.Identity);

                Vector3 farPoint = Client.Viewport.Unproject(farsource,
                                                             Client.MainPlayer.Camera.ProjectionMatrix,
                                                             Client.MainPlayer.Camera.ViewMatrix,
                                                             Matrix.Identity);

                Vector3 direction = farPoint - nearPoint;
                direction.Normalize();

                //Matrix rotationMatrix = Matrix.CreateRotationX(Client.MainPlayer.Camera.Rotation.X) *
                //                        Matrix.CreateRotationY(Client.MainPlayer.Camera.Rotation.Y);
                //distance = Vector3.Transform(distance, rotationMatrix);

                Ray r = new Ray(nearPoint.Center(), direction);
                foreach (Vector3I coord in GetCellsOnRay(r, 15))
                {
                    BlockID id        = Client.MainWorld[coord];
                    Vector3 renderPos = coord.ToRenderCoords();
                    Vector3 min       = new Vector3(renderPos.X - 1f, renderPos.Y - 1f, renderPos.Z - 1f);
                    Vector3 max       = new Vector3(renderPos.X + 1f, renderPos.Y + 1f, renderPos.Z + 1f);

                    float i = Vector3.Distance(Client.MainPlayer.Camera.Position, renderPos);
                    if (i < 2)
                    {
                        continue;
                    }
                    if (id != BlockID.None && id != BlockID.Air)
                    {
                        e.SpriteBatch.DrawString(Client.Font, "Looking: " + id + " - " + i, new Vector2(0, 80), Color.White);
                        BoundingBoxRenderer.Render(new BoundingBox(min, max),
                                                   Client.Device,
                                                   Client.MainPlayer.Camera.ViewMatrix,
                                                   Client.MainPlayer.Camera.ProjectionMatrix,
                                                   Color.Red);
                        Selected = coord;
                        break;
                    }
                    else
                    {
                        BoundingBoxRenderer.Render(new BoundingBox(min, max),
                                                   Client.Device,
                                                   Client.MainPlayer.Camera.ViewMatrix,
                                                   Client.MainPlayer.Camera.ProjectionMatrix,
                                                   Color.White);
                    }
                }

                if (Mouse.GetState().LeftButton == ButtonState.Pressed &&
                    Client.MainWorld[Selected] != BlockID.None &&
                    Client.MainWorld[Selected] != BlockID.Air)
                {
                    Client.MainWorld[Selected] = BlockID.Air;
                }
            }
            else
            {
                AnchoredText t = new AnchoredText(Client.Font, "PAUSED: " + Client.Version, Client.WindowCenter, TextAnchor.MiddleCenter);
                t.Draw(e.SpriteBatch);
            }
            e.SpriteBatch.End();
        }