Пример #1
0
 public static void DrawLine(Location from, Location to, Color4 color)
 {
     var vertices = new PositionColored[2];
     vertices[0] = new PositionColored(from.ToVector3(), color.ToArgb());
     vertices[1] = new PositionColored(to.ToVector3(), color.ToArgb());
     Device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
 public VertexPositonNormalColorTexture(Vector3 Position, Vector3 normal, Color4 Color, Vector2 texcoords)
 {
     this.Position = Position;
     this.Color = Color.ToArgb();
     this.texcoords = texcoords;
     this.Normal = normal;
 }
Пример #3
0
 public override void DrawLine(ref Vector3 from, ref Vector3 to, Color4 fromColor, Color4 toColor)
 {
     PositionColored[] vertices = new PositionColored[2];
     vertices[0] = new PositionColored(from, fromColor.ToArgb());
     vertices[1] = new PositionColored(to, toColor.ToArgb());
     device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
Пример #4
0
        public override void DrawBox(ref Vector3 bbMin, ref Vector3 bbMax, Color4 color)
        {
            var p1 = bbMin;
            var p2 = new Vector3(bbMax.X, bbMin.Y, bbMin.Z);
            var p3 = new Vector3(bbMax.X, bbMax.Y, bbMin.Z);
            var p4 = new Vector3(bbMin.X, bbMax.Y, bbMin.Z);
            var p5 = new Vector3(bbMin.X, bbMin.Y, bbMax.Z);
            var p6 = new Vector3(bbMax.X, bbMin.Y, bbMax.Z);
            var p7 = bbMax;
            var p8 = new Vector3(bbMin.X, bbMax.Y, bbMax.Z);

            int intColor = color.ToArgb();
            PositionColored[] vertices = new PositionColored[] {
                new PositionColored(p1, intColor), new PositionColored(p2, intColor),
                new PositionColored(p2, intColor), new PositionColored(p3, intColor),
                new PositionColored(p3, intColor), new PositionColored(p4, intColor),
                new PositionColored(p4, intColor), new PositionColored(p1, intColor),
                
                new PositionColored(p1, intColor), new PositionColored(p5, intColor),
                new PositionColored(p2, intColor), new PositionColored(p6, intColor),
                new PositionColored(p3, intColor), new PositionColored(p7, intColor),
                new PositionColored(p4, intColor), new PositionColored(p8, intColor),
                
                new PositionColored(p5, intColor), new PositionColored(p6, intColor),
                new PositionColored(p6, intColor), new PositionColored(p7, intColor),
                new PositionColored(p7, intColor), new PositionColored(p8, intColor),
                new PositionColored(p8, intColor), new PositionColored(p5, intColor),
            };

            device.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
        }
Пример #5
0
 public override void DrawContactPoint(ref Vector3 pointOnB, ref Vector3 normalOnB, float distance, int lifeTime, Color4 color)
 {
     int intColor = color.ToArgb();
     PositionColored[] vertices = new PositionColored[2];
     vertices[0] = new PositionColored(pointOnB, intColor);
     vertices[1] = new PositionColored(pointOnB + normalOnB, intColor);
     device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
Пример #6
0
 public override void DrawLine(ref Vector3 from, ref Vector3 to, Color4 color)
 {
     int intColor = color.ToArgb();
     PositionColored[] vertices = new PositionColored[2];
     vertices[0].Position = from;
     vertices[0].Color = intColor;
     vertices[1].Position = to;
     vertices[1].Color = intColor;
     device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
Пример #7
0
 /// <summary>
 /// Convert an Assimp aiColour4D into an integer.
 /// </summary>
 /// <param name="vValue">The assimp value.</param>
 /// <returns>The equivilant DX value.</returns>
 public static int toDX9(aiColor4D vValue)
 {
     Color4 pColour = new Color4(vValue.a, vValue.r, vValue.g, vValue.b);
     return pColour.ToArgb();
 }
Пример #8
0
        private void FillVertexBuffer(Mesh animationMesh, List<odfVertex> vertexList, float[][] vertexWeights, int selectedBoneIdx)
        {
            using (DataStream vertexStream = animationMesh.LockVertexBuffer(LockFlags.None))
            {
                Color4 col = new Color4(1f, 1f, 1f);
                for (int j = 0; j < vertexList.Count; j++)
                {
                    odfVertex vertex = vertexList[j];
            #if !DONT_MIRROR
                    Vector3 position = new Vector3(vertex.Position.X, vertex.Position.Y, -vertex.Position.Z);
                    Vector3 normal = new Vector3(vertex.Normal.X, vertex.Normal.Y, -vertex.Normal.Z);
            #else
                    Vector3 position = vertex.Position;
                    Vector3 normal = vertex.Normal;
            #endif
                    float[] boneWeights = vertexWeights[j];
                    vertexStream.Write(position.X);
                    vertexStream.Write(position.Y);
                    vertexStream.Write(position.Z);
                    vertexStream.Write(boneWeights[0]);
                    vertexStream.Write(boneWeights[1]);
                    vertexStream.Write(boneWeights[2]);
                    vertexStream.Write(vertex.BoneIndices[0]);
                    vertexStream.Write(vertex.BoneIndices[1]);
                    vertexStream.Write(vertex.BoneIndices[2]);
                    vertexStream.Write(vertex.BoneIndices[3]);
                    vertexStream.Write(normal.X);
                    vertexStream.Write(normal.Y);
                    vertexStream.Write(normal.Z);
                    if (selectedBoneIdx >= 0)
                    {
                        col.Red = 0f; col.Green = 0f; col.Blue = 0f;
                        byte[] boneIndices = vertex.BoneIndices;
                        for (int k = 0; k < boneIndices.Length; k++)
                        {
                            if (boneIndices[k] == 0xFF)
                            {
                                continue;
                            }

                            byte boneIdx = boneIndices[k];
                            if (boneIdx == selectedBoneIdx)
                            {
            /*								switch (cols)
                                {
                                case WeightsColourPreset.Greyscale:
                                    col.r = col.g = col.b = boneWeights[k];
                                    break;
                                case WeightsColourPreset.Metal:
                                    col.r = boneWeights[k] > 0.666f ? 1f : boneWeights[k] * 1.5f;
                                    col.g = boneWeights[k] * boneWeights[k] * boneWeights[k];
                                    break;
                                case WeightsColourPreset.Rainbow:*/
                                    if (boneWeights[k] > 0.75f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[k]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[k] > 0.5f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[k]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[k] > 0.25f)
                                    {
                                        col.Red = (boneWeights[k] - 0.25f) * 4f;
                                        col.Green = 1f;
                                        col.Blue = 0f;
                                    }
                                    else
                                    {
                                        col.Green = boneWeights[k] * 4f;
                                        col.Blue = 1f - boneWeights[k] * 4f;
                                    }
            /*									break;
                                }*/
                                break;
                            }
                        }
                    }
                    vertexStream.Write(col.ToArgb());
                    vertexStream.Write(vertex.UV[0]);
                    vertexStream.Write(vertex.UV[1]);
                }
                animationMesh.UnlockVertexBuffer();
            }
        }
Пример #9
0
        /// <summary>
        /// Renders a line.
        /// </summary>
        /// <param name="x0">The X coordinate of the first point.</param>
        /// <param name="y0">The Y coordinate of the first point.</param>
        /// <param name="color0">The color of the first point.</param>
        /// <param name="x1">The X coordinate of the second point.</param>
        /// <param name="y1">The Y coordinate of the second point.</param>
        /// <param name="color1">The color of the second point.</param>
        internal override void RenderLine(int x0, int y0, Color4 color0, int x1, int y1, Color4 color1) {
            lineBuffer.Add(new ColoredVertex(
                new Vector3(x0, y0, 0.0f),
                color0.ToArgb()
            ));

            lineBuffer.Add(new ColoredVertex(
                new Vector3(x1, y1, 0.0f),
                color1.ToArgb()
            ));
        }
Пример #10
0
 private void SetRenderState(RenderState state, Color4 val)
 {
     var oldVal = ActiveD3D9Device.GetRenderState<Color4>(state);
     if (oldVal != val)
         ActiveD3D9Device.SetRenderState(state, val.ToArgb());
 }
Пример #11
0
 public VertexPositionColor(Vector3 Position, Color4 Color)
 {
     this.Position = Position;
     this.Color = Color.ToArgb();
 }
Пример #12
0
        private void FillVertexBuffer(SlimDX.Direct3D9.Mesh animationMesh, List<Operations.vVertex> vertexList, int selectedBoneIdx)
        {
            using (DataStream vertexStream = animationMesh.LockVertexBuffer(LockFlags.None))
            {
                Color4 col = new Color4(1f, 1f, 1f);
                for (int i = 0; i < vertexList.Count; i++)
                {
                    Operations.vVertex vertex = vertexList[i];
                    vertexStream.Write(vertex.position.X);
                    vertexStream.Write(vertex.position.Y);
                    vertexStream.Write(vertex.position.Z);
                    if (vertex.boneIndices != null)
                    {
                        vertexStream.Write(vertex.weights[0]);
                        vertexStream.Write(vertex.weights[1]);
                        vertexStream.Write(vertex.weights[2]);
                        vertexStream.Write((byte)vertex.boneIndices[0]);
                        vertexStream.Write((byte)vertex.boneIndices[1]);
                        vertexStream.Write((byte)vertex.boneIndices[2]);
                        vertexStream.Write((byte)vertex.boneIndices[3]);
                    }
                    else
                    {
                        vertexStream.Write((float)0);
                        vertexStream.Write((float)0);
                        vertexStream.Write((float)0);
                        vertexStream.Write((byte)0);
                        vertexStream.Write((byte)0);
                        vertexStream.Write((byte)0);
                        vertexStream.Write((byte)0);
                    }
                    vertexStream.Write(vertex.normal.X);
                    vertexStream.Write(vertex.normal.Y);
                    vertexStream.Write(vertex.normal.Z);
                    if (selectedBoneIdx >= 0)
                    {
                        col.Red = 0f; col.Green = 0f; col.Blue = 0f;
                        int[] boneIndices = vertex.boneIndices;
                        float[] boneWeights = vertex.weights;
                        for (int j = 0; j < boneIndices.Length; j++)
                        {
                            if (boneIndices[j] == 0 && boneWeights[j] == 0)
                            {
                                continue;
                            }

                            int boneIdx = boneIndices[j];
                            if (boneIdx == selectedBoneIdx)
                            {
            /*								switch (cols)
                                {
                                case WeightsColourPreset.Greyscale:
                                    col.r = col.g = col.b = boneWeights[j];
                                    break;
                                case WeightsColourPreset.Metal:
                                    col.r = boneWeights[j] > 0.666f ? 1f : boneWeights[j] * 1.5f;
                                    col.g = boneWeights[j] * boneWeights[j] * boneWeights[j];
                                    break;
                                WeightsColourPreset.Rainbow:*/
                                    if (boneWeights[j] > 0.75f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[j]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[j] > 0.5f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[j]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[j] > 0.25f)
                                    {
                                        col.Red = (boneWeights[j] - 0.25f) * 4f;
                                        col.Green = 1f;
                                        col.Blue = 0f;
                                    }
                                    else
                                    {
                                        col.Green = boneWeights[j] * 4f;
                                        col.Blue = 1f - boneWeights[j] * 4f;
                                    }
            /*									break;
                                }*/
                                break;
                            }
                        }
                    }
                    vertexStream.Write(col.ToArgb());
                    vertexStream.Write(vertex.uv[0]);
                    vertexStream.Write(vertex.uv[1]);
                }
                animationMesh.UnlockVertexBuffer();
            }
        }
Пример #13
0
 public override void DrawLine(ref Vector3 from, ref Vector3 to, Color4 color)
 {
     int intColor = color.ToArgb();
     lineBuffer.Add(new PositionColored(from, intColor));
     lineBuffer.Add(new PositionColored(to, intColor));
 }
Пример #14
0
        public override void DrawTriangle(ref Vector3 v0, ref Vector3 v1, ref Vector3 v2, Color4 color, float __unnamed004)
        {
            int intColor = color.ToArgb();
            PositionColored[] vertices = new PositionColored[4];
            vertices[0].Position = v0;
            vertices[0].Color = intColor;
            vertices[1].Position = v1;
            vertices[1].Color = intColor;
            vertices[2].Position = v2;
            vertices[2].Color = intColor;
            vertices[3].Position = v0;
            vertices[3].Color = intColor;

            device.DrawUserPrimitives(PrimitiveType.LineStrip, 3, vertices);
        }
Пример #15
0
        public override void DrawBox(ref Vector3 bbMin, ref Vector3 bbMax, ref Matrix trans, Color4 color)
        {
            var p1 = Vector3.TransformCoordinate(bbMin, trans);
            var p2 = Vector3.TransformCoordinate(new Vector3(bbMax.X, bbMin.Y, bbMin.Z), trans);
            var p3 = Vector3.TransformCoordinate(new Vector3(bbMax.X, bbMax.Y, bbMin.Z), trans);
            var p4 = Vector3.TransformCoordinate(new Vector3(bbMin.X, bbMax.Y, bbMin.Z), trans);
            var p5 = Vector3.TransformCoordinate(new Vector3(bbMin.X, bbMin.Y, bbMax.Z), trans);
            var p6 = Vector3.TransformCoordinate(new Vector3(bbMax.X, bbMin.Y, bbMax.Z), trans);
            var p7 = Vector3.TransformCoordinate(bbMax, trans);
            var p8 = Vector3.TransformCoordinate(new Vector3(bbMin.X, bbMax.Y, bbMax.Z), trans);

            int intColor = color.ToArgb();
            PositionColored[] vertices = new PositionColored[] {
                new PositionColored(p1, intColor), new PositionColored(p2, intColor),
                new PositionColored(p2, intColor), new PositionColored(p3, intColor),
                new PositionColored(p3, intColor), new PositionColored(p4, intColor),
                new PositionColored(p4, intColor), new PositionColored(p1, intColor),
                
                new PositionColored(p1, intColor), new PositionColored(p5, intColor),
                new PositionColored(p2, intColor), new PositionColored(p6, intColor),
                new PositionColored(p3, intColor), new PositionColored(p7, intColor),
                new PositionColored(p4, intColor), new PositionColored(p8, intColor),
                
                new PositionColored(p5, intColor), new PositionColored(p6, intColor),
                new PositionColored(p6, intColor), new PositionColored(p7, intColor),
                new PositionColored(p7, intColor), new PositionColored(p8, intColor),
                new PositionColored(p8, intColor), new PositionColored(p5, intColor),
            };

            device.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
        }
Пример #16
0
 public override void DrawTriangle(ref Vector3 v0, ref Vector3 v1, ref Vector3 v2, Color4 color, float __unnamed004)
 {
     int intColor = color.ToArgb();
     lineBuffer.Add(new PositionColored(v0, intColor));
     lineBuffer.Add(new PositionColored(v1, intColor));
     lineBuffer.Add(new PositionColored(v2, intColor));
     lineBuffer.Add(new PositionColored(v0, intColor));
 }
Пример #17
0
        private void FillVertexBuffer(Mesh animationMesh, List<xxVertex> vertexList, int selectedBoneIdx)
        {
            using (DataStream vertexStream = animationMesh.LockVertexBuffer(LockFlags.None))
            {
                Color4 col = new Color4(1f, 1f, 1f);
                for (int i = 0; i < vertexList.Count; i++)
                {
                    xxVertex vertex = vertexList[i];
                    vertexStream.Write(vertex.Position.X);
                    vertexStream.Write(vertex.Position.Y);
                    vertexStream.Write(vertex.Position.Z);
                    vertexStream.Write(vertex.Weights3[0]);
                    vertexStream.Write(vertex.Weights3[1]);
                    vertexStream.Write(vertex.Weights3[2]);
                    vertexStream.Write(vertex.BoneIndices[0]);
                    vertexStream.Write(vertex.BoneIndices[1]);
                    vertexStream.Write(vertex.BoneIndices[2]);
                    vertexStream.Write(vertex.BoneIndices[3]);
                    vertexStream.Write(vertex.Normal.X);
                    vertexStream.Write(vertex.Normal.Y);
                    vertexStream.Write(vertex.Normal.Z);
                    if (selectedBoneIdx >= 0)
                    {
                        col.Red = 0f; col.Green = 0f; col.Blue = 0f;
                        byte[] boneIndices = vertex.BoneIndices;
                        float[] boneWeights = vertex.Weights4(true);
                        for (int j = 0; j < boneIndices.Length; j++)
                        {
                            if (boneIndices[j] == 0xFF)
                            {
                                continue;
                            }

                            byte boneIdx = boneIndices[j];
                            if (boneIdx == selectedBoneIdx)
                            {
            /*								switch (cols)
                                {
                                case WeightsColourPreset.Greyscale:
                                    col.r = col.g = col.b = boneWeights[j];
                                    break;
                                case WeightsColourPreset.Metal:
                                    col.r = boneWeights[j] > 0.666f ? 1f : boneWeights[j] * 1.5f;
                                    col.g = boneWeights[j] * boneWeights[j] * boneWeights[j];
                                    break;
                                WeightsColourPreset.Rainbow:*/
                                    if (boneWeights[j] > 0.75f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[j]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[j] > 0.5f)
                                    {
                                        col.Red = 1f;
                                        col.Green = (1f - boneWeights[j]) * 2f;
                                        col.Blue = 0f;
                                    }
                                    else if (boneWeights[j] > 0.25f)
                                    {
                                        col.Red = (boneWeights[j] - 0.25f) * 4f;
                                        col.Green = 1f;
                                        col.Blue = 0f;
                                    }
                                    else
                                    {
                                        col.Green = boneWeights[j] * 4f;
                                        col.Blue = 1f - boneWeights[j] * 4f;
                                    }
            /*									break;
                                }*/
                                break;
                            }
                        }
                    }
                    vertexStream.Write(col.ToArgb());
                    vertexStream.Write(vertex.UV[0]);
                    vertexStream.Write(vertex.UV[1]);
                }
                animationMesh.UnlockVertexBuffer();
            }
        }
Пример #18
0
 public VertexPositionColorTex(Vector3 Position, Color4 Color, Vector2 texcoords)
 {
     this.Position = Position;
     this.Color = Color.ToArgb();
     this.texcoords = texcoords;
 }
Пример #19
0
        // Create a systemmem texture, fill with the given color and copy it to a more hardware-friendly memory pool
        public static Texture CreateTexture(int w, int h, Format format, Color4 color)
        {
            Texture texture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.SystemMemory);
            DataRectangle drect = texture.LockRectangle(0, LockFlags.None);
            DataStream ds = drect.Data;

            // pixelsize in bytes
            int fieldsize = 8;
            switch (format)
            {
                case Format.A8R8G8B8:
                    fieldsize = 4;
                    break;
                case Format.A16B16G16R16F:
                    fieldsize = 8;
                    break;
            }

            // Fill texture with color
            for (int j = 0; j < (w * h); j++)
            {
                int x = ((j) % (w));
                int y = ((j) / (w));

                ds.Seek((long)(y * fieldsize) + (long)(x * fieldsize), System.IO.SeekOrigin.Begin);

                switch (format)
                {
                    case Format.A8R8G8B8:
                        ds.Write<int>(color.ToArgb());
                        break;
                    case Format.A16B16G16R16F:
                        Half[] half = Half.ConvertToHalf(new float[] { color.Red, color.Green, color.Blue, color.Alpha });
                        ds.Write<Half4>(new Half4(half[0], half[1], half[2], half[3]));
                        break;
                }

            }
            texture.UnlockRectangle(0);
            Texture realtexture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.Default);
            Renderer.Instance.device.UpdateTexture(texture, realtexture);
            texture.Dispose();
            return realtexture;
        }
Пример #20
0
        public override void DrawArc(ref Vector3 center, ref Vector3 normal, ref Vector3 axis, float radiusA, float radiusB, float minAngle, float maxAngle, Color4 color, bool drawSect, float stepDegrees)
        {
            Vector3 vx = axis;
            Vector3 vy = Vector3.Cross(normal, axis);
            float step = stepDegrees * ((float)Math.PI / 180.0f);
            int nSteps = (int)((maxAngle - minAngle) / step);
            if (nSteps == 0)
                nSteps = 1;

            Vector3 next = center + radiusA * vx * (float)Math.Cos(minAngle) + radiusB * vy * (float)Math.Sin(minAngle);

            if (drawSect)
                DrawLine(ref center, ref next, color);

            int intColor = color.ToArgb();
            PositionColored[] vertices = new PositionColored[nSteps + 1];
            vertices[0].Position = next;
            vertices[0].Color = intColor;
            for (int i = 1; i <= nSteps; i++)
            {
                float angle = minAngle + (maxAngle - minAngle) * (float)i / (float)nSteps;
                next = center + radiusA * vx * (float)Math.Cos(angle) + radiusB * vy * (float)Math.Sin(angle);
                vertices[i].Position = next;
                vertices[i].Color = intColor;
            }
            device.DrawUserPrimitives(PrimitiveType.LineStrip, nSteps, vertices);

            if (drawSect)
                DrawLine(ref center, ref next, color);
        }