Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        protected override void OnRender()
        {
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightGray, 1.0f, 0);
            Device.BeginScene();

            Device.SetTransform(TransformState.View, Freelook.View);

            foreach (RigidBody body in PhysicsContext.World.CollisionObjectArray)
            {
                Device.SetTransform(TransformState.World, body.WorldTransform);
                RenderWithMaterial(body);

                if (Physics.HasDistanceResult)
                {
                    Device.Material = ActiveMaterial;
                    Device.SetTransform(TransformState.World, Matrix.Identity);
                    PositionColored[] vertices = new PositionColored[2];
                    vertices[0] = new PositionColored(Physics.distanceFrom, -1);
                    vertices[1] = new PositionColored(Physics.distanceTo, -1);
                    Device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
                }
            }

            DebugDrawWorld();

            Fps.Text = string.Format(
                "Move using mouse and WASD+shift\n" +
                "F3 - Toggle debug\n" +
                "F11 - Toggle fullscreen\n" +
                "Distance: {0}", Physics.distance.ToString("0.00"));
            Fps.OnRender(FramesPerSecond);

            Device.EndScene();
            Device.Present();
        }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public static PositionColored[] BillboardColored(float size)
        {
            PositionColored[] b = new PositionColored[4];

            b[0].Position.X = -size;
            b[0].Position.Y = size;
            b[1].Position.X = size;
            b[1].Position.Y = size;
            b[2].Position.X = size;
            b[2].Position.Y = -size;
            b[3].Position.X = -size;
            b[3].Position.Y = -size;
            b[0].Position.Z = b[1].Position.Z = b[2].Position.Z = b[3].Position.Z = 0.0f;
            b[0].Color      = b[1].Color = b[2].Color = b[3].Color = Color.Black.ToArgb();

            return(b);
        }
Ejemplo n.º 13
0
        public override void DrawTransform(ref Matrix transform, float orthoLen)
        {
            Vector3 start = new Vector3(transform.M41, transform.M42, transform.M43);

            PositionColored[] vertices = new PositionColored[6];
            vertices[0].Position = start;
            vertices[0].Color    = 0xff0000;
            vertices[1].Position = new Vector3(start.X + orthoLen, start.Y, start.Z);
            vertices[1].Color    = 0xff0000;
            vertices[2].Position = start;
            vertices[2].Color    = 0x00ff00;
            vertices[3].Position = new Vector3(start.X, start.Y + orthoLen, start.Z);
            vertices[3].Color    = 0x00ff00;
            vertices[4].Position = start;
            vertices[4].Color    = 0x0000ff;
            vertices[5].Position = new Vector3(start.X, start.Y, start.Z + orthoLen);
            vertices[5].Color    = 0x0000ff;

            device.DrawUserPrimitives(PrimitiveType.LineList, 3, vertices);
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        public override void DrawArc(ref Vector3 center, ref Vector3 normal, ref Vector3 axis, float radiusA, float radiusB, float minAngle, float maxAngle, Color 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 = ColorToInt(ref color);
            PositionColored last     = new PositionColored(ref next, intColor);

            for (int i = 1; i <= nSteps; i++)
            {
                lines.Add(last);
                float angle = minAngle + (maxAngle - minAngle) * i / nSteps;
                next = center + radiusA * vx * (float)Math.Cos(angle) + radiusB * vy * (float)Math.Sin(angle);
                last = new PositionColored(ref next, intColor);
                lines.Add(last);
            }

            if (drawSect)
            {
                DrawLine(ref center, ref next, color);
            }
        }
Ejemplo n.º 16
0
        public void RenderSoftBody(SoftBody softBody)
        {
            AlignedFaceArray faces = softBody.Faces;
            int faceCount          = faces.Count;

            if (faceCount > 0)
            {
                PositionedNormal[] vectors = new PositionedNormal[faceCount * 6];
                int v = 0;

                int i;
                for (i = 0; i < faces.Count; i++)
                {
                    NodePtrArray nodes = faces[i].N;
                    Node         n0    = nodes[0];
                    Node         n1    = nodes[1];
                    Node         n2    = nodes[2];
                    n0.GetX(out vectors[v].Position);
                    n0.GetNormal(out vectors[v].Normal);
                    n1.GetX(out vectors[v + 1].Position);
                    n1.GetNormal(out vectors[v + 1].Normal);
                    n2.GetX(out vectors[v + 2].Position);
                    n2.GetNormal(out vectors[v + 2].Normal);
                    v += 3;
                }

                device.VertexFormat = PositionedNormal.FVF;
                device.DrawUserPrimitives(PrimitiveType.TriangleList, faces.Count, vectors);
            }
            else
            {
                AlignedTetraArray tetras = softBody.Tetras;
                int tetraCount           = tetras.Count;

                if (tetraCount > 0)
                {
                    PositionedNormal[] vectors = new PositionedNormal[tetraCount * 12];
                    int v = 0;

                    for (int i = 0; i < tetraCount; i++)
                    {
                        NodePtrArray nodes = tetras[i].Nodes;
                        Vector3      v0    = nodes[0].X;
                        Vector3      v1    = nodes[1].X;
                        Vector3      v2    = nodes[2].X;
                        Vector3      v3    = nodes[3].X;
                        Vector3      v10   = v1 - v0;
                        Vector3      v02   = v0 - v2;

                        Vector3 normal = Vector3.Cross(v10, v02);
                        normal.Normalize();
                        vectors[v].Position     = v0;
                        vectors[v].Normal       = normal;
                        vectors[v + 1].Position = v1;
                        vectors[v + 1].Normal   = normal;
                        vectors[v + 2].Position = v2;
                        vectors[v + 2].Normal   = normal;

                        normal = Vector3.Cross(v10, v3 - v0);
                        normal.Normalize();
                        vectors[v + 3].Position = v0;
                        vectors[v + 3].Normal   = normal;
                        vectors[v + 4].Position = v1;
                        vectors[v + 4].Normal   = normal;
                        vectors[v + 5].Position = v3;
                        vectors[v + 5].Normal   = normal;

                        normal = Vector3.Cross(v2 - v1, v3 - v1);
                        normal.Normalize();
                        vectors[v + 6].Position = v1;
                        vectors[v + 6].Normal   = normal;
                        vectors[v + 7].Position = v2;
                        vectors[v + 7].Normal   = normal;
                        vectors[v + 8].Position = v3;
                        vectors[v + 8].Normal   = normal;

                        normal = Vector3.Cross(v02, v3 - v2);
                        normal.Normalize();
                        vectors[v + 9].Position  = v2;
                        vectors[v + 9].Normal    = normal;
                        vectors[v + 10].Position = v0;
                        vectors[v + 10].Normal   = normal;
                        vectors[v + 11].Position = v3;
                        vectors[v + 11].Normal   = normal;
                        v += 12;
                    }
                    device.VertexFormat = PositionedNormal.FVF;
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, tetraCount * 4, vectors);
                }
                else if (softBody.Links.Count > 0)
                {
                    AlignedLinkArray links = softBody.Links;
                    int linkCount          = links.Count;
                    int linkColor          = System.Drawing.Color.Black.ToArgb();

                    device.VertexFormat = PositionColored.FVF;

                    PositionColored[] linkArray = new PositionColored[linkCount * 2];

                    for (int i = 0; i < linkCount; i++)
                    {
                        Link link = links[i];
                        linkArray[i * 2].Position     = link.Nodes[0].X;
                        linkArray[i * 2].Color        = linkColor;
                        linkArray[i * 2 + 1].Position = link.Nodes[1].X;
                        linkArray[i * 2 + 1].Color    = linkColor;
                    }
                    device.DrawUserPrimitives(PrimitiveType.LineList, links.Count, linkArray);
                }
            }
        }
Ejemplo n.º 17
0
        public override void DrawArc(ref Vector3 center, ref Vector3 normal, ref Vector3 axis, float radiusA, float radiusB, float minAngle, float maxAngle, Color 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 = ColorToInt(ref color);
            PositionColored last = new PositionColored(ref next, intColor);
            for (int i = 1; i <= nSteps; i++)
            {
                lines.Add(last);
                float angle = minAngle + (maxAngle - minAngle) * i / nSteps;
                next = center + radiusA * vx * (float)Math.Cos(angle) + radiusB * vy * (float)Math.Sin(angle);
                last = new PositionColored(ref next, intColor);
                lines.Add(last);
            }

            if (drawSect)
                DrawLine(ref center, ref next, color);
        }
Ejemplo n.º 18
0
        public static PositionColored[] BillboardColored(float size)
        {
            PositionColored[] b = new PositionColored[4];

            b[0].Position.X = -size;
            b[0].Position.Y = size;
            b[1].Position.X = size;
            b[1].Position.Y = size;
            b[2].Position.X = size;
            b[2].Position.Y = -size;
            b[3].Position.X = -size;
            b[3].Position.Y = -size;
            b[0].Position.Z = b[1].Position.Z = b[2].Position.Z = b[3].Position.Z = 0.0f;
            b[0].Color = b[1].Color = b[2].Color = b[3].Color = Color.Black.ToArgb();

            return b;
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public override void DrawTransform(ref Matrix transform, float orthoLen)
        {
            Vector3 start = new Vector3(transform.M41, transform.M42, transform.M43);

            PositionColored[] vertices = new PositionColored[6];
            vertices[0].Position = start;
            vertices[0].Color = 0xff0000;
            vertices[1].Position = new Vector3(start.X + orthoLen, start.Y, start.Z);
            vertices[1].Color = 0xff0000;
            vertices[2].Position = start;
            vertices[2].Color = 0x00ff00;
            vertices[3].Position = new Vector3(start.X, start.Y + orthoLen, start.Z);
            vertices[3].Color = 0x00ff00;
            vertices[4].Position = start;
            vertices[4].Color = 0x0000ff;
            vertices[5].Position = new Vector3(start.X, start.Y, start.Z + orthoLen);
            vertices[5].Color = 0x0000ff;

            device.DrawUserPrimitives(PrimitiveType.LineList, 3, vertices);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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);
        }
        public void RenderSoftBody(SoftBody softBody)
        {
            AlignedFaceArray faces = softBody.Faces;
            int faceCount = faces.Count;

            if (faceCount > 0)
            {
                PositionedNormal[] vectors = new PositionedNormal[faceCount * 6];
                int v = 0;

                int i;
                for (i = 0; i < faces.Count; i++)
                {
                    NodePtrArray nodes = faces[i].N;
                    Node n0 = nodes[0];
                    Node n1 = nodes[1];
                    Node n2 = nodes[2];
                    n0.GetX(out vectors[v].Position);
                    n0.GetNormal(out vectors[v].Normal);
                    n1.GetX(out vectors[v + 1].Position);
                    n1.GetNormal(out vectors[v + 1].Normal);
                    n2.GetX(out vectors[v + 2].Position);
                    n2.GetNormal(out vectors[v + 2].Normal);
                    v += 3;
                }

                device.VertexFormat = PositionedNormal.FVF;
                device.DrawUserPrimitives(PrimitiveType.TriangleList, faces.Count, vectors);
            }
            else
            {
                AlignedTetraArray tetras = softBody.Tetras;
                int tetraCount = tetras.Count;

                if (tetraCount > 0)
                {
                    PositionedNormal[] vectors = new PositionedNormal[tetraCount * 12];
                    int v = 0;

                    for (int i = 0; i < tetraCount; i++)
                    {
                        NodePtrArray nodes = tetras[i].Nodes;
                        Vector3 v0 = nodes[0].X;
                        Vector3 v1 = nodes[1].X;
                        Vector3 v2 = nodes[2].X;
                        Vector3 v3 = nodes[3].X;
                        Vector3 v10 = v1 - v0;
                        Vector3 v02 = v0 - v2;

                        Vector3 normal = Vector3.Cross(v10, v02);
                        normal.Normalize();
                        vectors[v].Position = v0;
                        vectors[v].Normal = normal;
                        vectors[v + 1].Position = v1;
                        vectors[v + 1].Normal = normal;
                        vectors[v + 2].Position = v2;
                        vectors[v + 2].Normal = normal;

                        normal = Vector3.Cross(v10, v3 - v0);
                        normal.Normalize();
                        vectors[v + 3].Position = v0;
                        vectors[v + 3].Normal = normal;
                        vectors[v + 4].Position = v1;
                        vectors[v + 4].Normal = normal;
                        vectors[v + 5].Position = v3;
                        vectors[v + 5].Normal = normal;

                        normal = Vector3.Cross(v2 - v1, v3 - v1);
                        normal.Normalize();
                        vectors[v + 6].Position = v1;
                        vectors[v + 6].Normal = normal;
                        vectors[v + 7].Position = v2;
                        vectors[v + 7].Normal = normal;
                        vectors[v + 8].Position = v3;
                        vectors[v + 8].Normal = normal;

                        normal = Vector3.Cross(v02, v3 - v2);
                        normal.Normalize();
                        vectors[v + 9].Position = v2;
                        vectors[v + 9].Normal = normal;
                        vectors[v + 10].Position = v0;
                        vectors[v + 10].Normal = normal;
                        vectors[v + 11].Position = v3;
                        vectors[v + 11].Normal = normal;
                        v += 12;
                    }
                    device.VertexFormat = PositionedNormal.FVF;
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, tetraCount * 4, vectors);
                }
                else if (softBody.Links.Count > 0)
                {
                    AlignedLinkArray links = softBody.Links;
                    int linkCount = links.Count;
                    int linkColor = System.Drawing.Color.Black.ToArgb();

                    device.VertexFormat = PositionColored.FVF;

                    PositionColored[] linkArray = new PositionColored[linkCount * 2];

                    for (int i = 0; i < linkCount; i++)
                    {
                        Link link = links[i];
                        linkArray[i * 2].Position = link.Nodes[0].X;
                        linkArray[i * 2].Color = linkColor;
                        linkArray[i * 2 + 1].Position = link.Nodes[1].X;
                        linkArray[i * 2 + 1].Color = linkColor;
                    }
                    device.DrawUserPrimitives(PrimitiveType.LineList, links.Count, linkArray);
                }
            }
        }