Exemple #1
0
        /// <summary>
        /// Método que transforma una matrix Vector3[][] representando las normales de un Heightmap en una textura.
        /// </summary>
        /// <param name="Normalmap">Matrix de Vector3[][] de normales.</param>
        /// <returns></returns>
        public static Texture GetTextureFromNormal(Vector3[][] Normalmap)
        {
            int width  = Normalmap.GetLength(0);
            int height = Normalmap[0].GetLength(0);

            var Normals = new Color[width][];

            for (int i = 0; i < width; ++i)
            {
                Normals[i] = new Color[height];

                for (int j = 0; j < height; ++j)
                {
                    ColorValue color = new ColorValue(Normalmap[i][j].X, Normalmap[i][j].Y, Normalmap[i][j].Z);
                    Normals[i][j] = Color.FromArgb(color.ToArgb());
                }
            }

            Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    bitmap.SetPixel(i, j, Normals[i][j]);
                }
            }

            return(Texture.FromBitmap(GuiController.Instance.D3dDevice, bitmap, Usage.None, Pool.Managed));
        }
Exemple #2
0
        private void generateLines()
        {
            Random     random = new Random();
            ColorValue color;

            for (int index = 0; index < vertexCount;)
            {
                color = new ColorValue(
                    random.Next() % 256,
                    random.Next() % 256,
                    random.Next() % 256);

                // line() increments the index for us
                line(random.Next() % this.ClientSize.Width,
                     random.Next() % this.ClientSize.Height,
                     random.Next() % this.ClientSize.Width,
                     random.Next() % this.ClientSize.Height,
                     color.ToArgb(),
                     ref index);
            }
        }
        public SphereCollider()
        {
            var device = RenderManager.Instance.device;

            Mesh smesh = Mesh.Sphere(device, radius, 16, 16);

            if ((smesh.VertexFormat & VertexFormats.Diffuse) == 0)
            {
                mesh = smesh.Clone(smesh.Options.Value, smesh.VertexFormat | VertexFormats.Diffuse, device);
            }
            else
            {
                mesh = smesh.Clone(smesh.Options.Value, smesh.VertexFormat, device);
            }

            // 컬러 오프셋 찾기
            VertexElement[] decl   = mesh.Declaration;
            short           offset = 0;

            foreach (VertexElement elem in decl)
            {
                if (elem.DeclarationUsage == DeclarationUsage.Color)
                {
                    offset = elem.Offset;
                    break;
                }
            }

            // 컬러값 접근

            ColorValue color = ColorValue.FromColor(Color.FromArgb(255, 0, 255, 0));

            CustomVertex.PositionNormalColored[] data = (CustomVertex.PositionNormalColored[])mesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionNormalColored), LockFlags.None, mesh.NumberVertices);
            for (int i = 0; i < mesh.NumberVertices; i++)
            {
                data[i].Color = color.ToArgb();
            }
            mesh.VertexBuffer.Unlock();
        }
Exemple #4
0
        public Obj_Polygon2D(Vector3[] points, Color fill)
        {
            Centroid = new Vector2();

            diffuse         = new Material();
            diffuse.Diffuse = fill;
            ColorValue c = ColorValue.FromArgb(fill.ToArgb());

            c.Alpha = 255 / 2;

            CalculateProperties(points);
            Console.WriteLine("Area = {0}", Area);
            Console.WriteLine("Centroid = {0}, {1}", Centroid.X, Centroid.Y);

            polygon    = new CustomVertex.PositionColored[points.Length + 1];
            polygon[0] = new CustomVertex.PositionColored(new Vector3(Centroid.X, Centroid.Y, 0), c.ToArgb());
            for (int i = 0; i < points.Length; i++)
            {
                Console.WriteLine("{0} = {1}", i, points[i].ToString());
                polygon[i + 1] =
                    new CustomVertex.PositionColored(points[i], c.ToArgb());
            }
        }
Exemple #5
0
        /// <summary>Draw a rectangle</summary>
        public void DrawRectangle(System.Drawing.Rectangle rect, ColorValue color)
        {
            // Offset the rectangle
            rect.Offset(dialogX, dialogY);

            // If caption is enabled, offset the Y position by its height
            if (hasCaption)
                rect.Offset(0, captionHeight);

            // Get the integer value of the color
            int realColor = color.ToArgb();
            // Create some vertices
            CustomVertex.TransformedColoredTextured[] verts = {
                new CustomVertex.TransformedColoredTextured((float)rect.Left - 0.5f, (float)rect.Top -0.5f, 0.5f, 1.0f, realColor, 0, 0),
                new CustomVertex.TransformedColoredTextured((float)rect.Right - 0.5f, (float)rect.Top -0.5f, 0.5f, 1.0f, realColor, 0, 0),
                new CustomVertex.TransformedColoredTextured((float)rect.Right - 0.5f, (float)rect.Bottom -0.5f, 0.5f, 1.0f, realColor, 0, 0),
                new CustomVertex.TransformedColoredTextured((float)rect.Left - 0.5f, (float)rect.Bottom -0.5f, 0.5f, 1.0f, realColor, 0, 0),
            };

            // Get the device
            Device device = SampleFramework.Device;

            // Since we're doing our own drawing here, we need to flush the sprites
            DialogResourceManager.GetGlobalInstance().Sprite.Flush();
            // Preserve the devices current vertex declaration
            using (VertexDeclaration decl = device.VertexDeclaration)
            {
                // Set the vertex format
                device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;

                // Set some texture states
                device.TextureState[0].ColorOperation = TextureOperation.SelectArg2;
                device.TextureState[0].AlphaOperation = TextureOperation.SelectArg2;

                // Draw the rectangle
                device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, verts);

                // Reset some texture states
                device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

                // Restore the vertex declaration
                device.VertexDeclaration = decl;
            }
        }