Beispiel #1
0
        /// <summary>
        /// Draws the Bounding Box and BoundingSphere
        /// </summary>
        /// <param name="world"></param>
        /// <param name="view"></param>
        /// <param name="projection"></param>
        public void DrawBounding(ref Matrix world, ref Matrix view, ref Matrix projection)
        {
            Vector3[] lines = BoundingBox.ToRenderLines();

            engine.DrawLines(lines, new Vector4(1, 0, 0, 1), ref world, ref view, ref projection);

            VerticesVector3Indices result = BoundingSphere.ToRenderLines(30);

            engine.DrawLines(result.Vertices, result.Indices, new AIOEngine.MathSpace.Vector4(0, 0, 1, 1), ref world, ref view, ref projection);
        }
Beispiel #2
0
        public VerticesVector3Indices ToRenderLines(int numSubdivisions)
        {
            VerticesVector3Indices r = new VerticesVector3Indices();

            // Reservamos memoria para los vértices
            int numVerticesPerCircle = numSubdivisions;
            int numVertices          = numVerticesPerCircle * 3;

            r.Vertices = new Vector3[numVertices];

            // Reservamos memoria para los índices
            int numIndicesPerCircle = numVerticesPerCircle * 2;
            int numIndices          = numIndicesPerCircle * 3;

            r.Indices = new uint[numIndices];

            int c1_offs = 0;
            int c2_offs = numVerticesPerCircle;
            int c3_offs = numVerticesPerCircle * 2;

            // Definimos los índices
            for (int i = 0; i < numVerticesPerCircle; i++)
            {
                int idx1, idx2;

                idx1 = i;

                if (i < numVerticesPerCircle - 1)
                {
                    idx2 = i + 1;
                }
                else
                {
                    idx2 = 0;
                }

                r.Indices[c1_offs * 2 + i * 2 + 0] = (ushort)(idx1 + c1_offs);
                r.Indices[c1_offs * 2 + i * 2 + 1] = (ushort)(idx2 + c1_offs);

                r.Indices[c2_offs * 2 + i * 2 + 0] = (ushort)(idx1 + c2_offs);
                r.Indices[c2_offs * 2 + i * 2 + 1] = (ushort)((idx2 > 0 ? idx2 : 0) + c2_offs);

                r.Indices[c3_offs * 2 + i * 2 + 0] = (ushort)(idx1 + c3_offs);
                r.Indices[c3_offs * 2 + i * 2 + 1] = (ushort)((idx2 > 0 ? idx2 : 0) + c3_offs);
            }

            float delta = (float)(2.0 * Math.PI) / numVerticesPerCircle;

            for (int i = 0; i < numVerticesPerCircle; i++)
            {
                float radians = delta * i;
                float cos     = (float)Math.Cos(radians) * Radius;
                float sin     = (float)Math.Sin(radians) * Radius;

                r.Vertices[c1_offs + i] = new Vector3(cos + center.X, sin + center.Y, center.Z);
                r.Vertices[c2_offs + i] = new Vector3(cos + center.X, center.Y, sin + center.Z);
                r.Vertices[c3_offs + i] = new Vector3(center.X, cos + center.Y, sin + center.Z);
            }

            return(r);
        }