Exemplo n.º 1
0
        public void Draw(Vector3 position, Vector3 color, EffectMatrices effectMatrices, float transparency = 1.0f)
        {
            Matrix translation = Matrix.CreateTranslation(position);
            Matrix world       = cubeScale * translation * effectMatrices.World;

            cubeEffect.View       = effectMatrices.View;
            cubeEffect.Projection = effectMatrices.Projection;
            cubeEffect.World      = world;

            cubeEffect.Color = color;
            cubeEffect.Alpha = transparency;

            Game.GraphicsDevice.SetVertexBuffer(cubeMeshPart.VertexBuffer);
            Game.GraphicsDevice.Indices = cubeMeshPart.IndexBuffer;

            foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                Game.GraphicsDevice.DrawIndexedPrimitives(
                    PrimitiveType.TriangleList,
                    0,
                    cubeMeshPart.StartIndex,
                    cubeMeshPart.PrimitiveCount);
            }
        }
Exemplo n.º 2
0
        private void DrawCube(Cube cube, float transparency = 1.0f)
        {
            Vector3 cubeScenePosition = Nocubeless.CubeWorld.GetGraphicsCubePosition(cube.Coordinates);

            EffectMatrices effectMatrices =
                new EffectMatrices(Nocubeless.Camera.GetProjection(),
                                   Nocubeless.Camera.GetView(),
                                   Matrix.Identity);

            cubeDrawer.Draw(cubeScenePosition, cube.Color.ToVector3(), effectMatrices, transparency);
        }
Exemplo n.º 3
0
        private void DrawChunk(CubeChunk chunk)
        {
            Vector3 position = Nocubeless.CubeWorld.GetGraphicsCubePosition(chunk.Coordinates);
            float   gaps     = 1 / Nocubeless.CubeWorld.GetGraphicsCubeRatio(); // DESIGN: don't do 1 / x

            EffectMatrices effectMatrices =
                new EffectMatrices(Nocubeless.Camera.GetProjection(),
                                   Nocubeless.Camera.GetView(),
                                   Matrix.Identity);

            chunkDrawer.Draw(ref chunk, position, gaps, effectMatrices);
        }
Exemplo n.º 4
0
        public PickerCube(Game game, float height) : base(game)
        {
            Height = height;

            CreateColors(out cubeColors);
            cubeDrawer = new CubeDrawer(Game, Height); // BUG: lol bug

            #region Effect Matrices Set-up
            var         fov = MathHelper.PiOver2;
            const float zNear = 0.1f, zFar = 100.0f;
            var         position = new Vector3(0.0f, 0.0f, -5.0f);
            var         target   = new Vector3(0.0f, 0.0f, 0.0f);
            var         up       = Vector3.UnitY;
            effectMatrices = new EffectMatrices(
                Matrix.CreatePerspectiveFieldOfView(fov, Game.GraphicsDevice.Viewport.AspectRatio, zNear, zFar),
                Matrix.CreateLookAt(position, target, up),
                Matrix.CreateWorld(Vector3.Zero, -Vector3.UnitZ, up));
            #endregion
        }
Exemplo n.º 5
0
        public void Draw(ref CubeChunk chunk, Vector3 position, float gap, EffectMatrices effectMatrices) // TO-OPTIMIZE
        {
            cubeEffect.View       = effectMatrices.View;
            cubeEffect.Projection = effectMatrices.Projection;

            Game.GraphicsDevice.SetVertexBuffer(cubeMeshPart.VertexBuffer);
            Game.GraphicsDevice.Indices = cubeMeshPart.IndexBuffer;

            for (int x = 0; x < CubeChunk.Size; x++)
            {
                for (int y = 0; y < CubeChunk.Size; y++)
                {
                    for (int z = 0; z < CubeChunk.Size; z++)
                    {
                        if (chunk[x + (y * CubeChunk.Size) + (z * CubeChunk.Size * CubeChunk.Size)] == null)
                        {
                            continue;
                        }

                        Vector3 cubePosition = new Vector3(position.X + (x * gap), position.Y + (y * gap), position.Z + (z * gap));

                        Matrix translation = Matrix.CreateTranslation(cubePosition);
                        Matrix world       = cubeScale * translation * effectMatrices.World;

                        cubeEffect.World = world;
                        cubeEffect.Alpha = 1; // actually, it's always full alpha.

                        cubeEffect.Color = chunk[x + (y * CubeChunk.Size) + (z * CubeChunk.Size * CubeChunk.Size)].ToVector3();

                        foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            Game.GraphicsDevice.DrawIndexedPrimitives(
                                PrimitiveType.TriangleList,
                                0,
                                cubeMeshPart.StartIndex,
                                cubeMeshPart.PrimitiveCount);
                        }
                    }
                }
            }
        }