示例#1
0
        public static FloatBuffer getDirectBuffer(float[] values, int Length)
        {
            directFloatBuffer.clear();
            directFloatBuffer.limit(Length);
            directFloatBuffer.put(values, 0, Length);
            directFloatBuffer.rewind();

            return(directFloatBuffer);
        }
示例#2
0
        /**
         * Expands a buffer of indexed triangle fan vertices to a buffer of non-indexed general-triangle vertices.
         *
         * @param indices the triangle indices.
         * @param inBuf   the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ...
         * @param outBuf  the buffer in which to place the expanded triangle vertices. The buffer must have a limit
         *                sufficient to hold the output vertices.
         *
         * @throws ArgumentException if the index list or the input or output buffer is null, or if the output buffer
         *                                  size is insufficient.
         */
        public static void expandTriangleFan(List <int> indices, FloatBuffer inBuf, FloatBuffer outBuf)
        {
            if (indices == null)
            {
                string msg = Logging.getMessage("nullValue.ListIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            if (inBuf == null || outBuf == null)
            {
                string msg = Logging.getMessage("nullValue.BufferIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            int nunTriangles = indices.Count - 2;

            if (nunTriangles * 3 * 3 > outBuf.limit() - outBuf.position())
            {
                string msg = Logging.getMessage("generic.BufferSize", outBuf.limit() - outBuf.position());
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            int   k   = indices[0] * 3;
            float v0x = inBuf.get(k);
            float v0y = inBuf.get(k + 1);
            float v0z = inBuf.get(k + 2);

            for (int i = 1; i < indices.Count - 1; i++)
            {
                outBuf.put(v0x).put(v0y).put(v0z);

                k = indices[i] * 3;
                outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2));

                k = indices[i + 1] * 3;
                outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2));
            }
        }
示例#3
0
        /**
         * Expands a buffer of indexed triangle strip vertices to a buffer of non-indexed general-triangle vertices.
         *
         * @param indices the triangle indices.
         * @param inBuf   the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ...
         * @param outBuf  the buffer in which to place the expanded triangle vertices. The buffer must have a limit
         *                sufficient to hold the output vertices.
         *
         * @throws ArgumentException if the index list or the input or output buffer is null, or if the output buffer
         *                                  size is insufficient.
         */
        public static void expandTriangleStrip(List <int> indices, FloatBuffer inBuf, FloatBuffer outBuf)
        {
            if (indices == null)
            {
                string msg = Logging.getMessage("nullValue.ListIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            if (inBuf == null || outBuf == null)
            {
                string msg = Logging.getMessage("nullValue.BufferIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            int nunTriangles = indices.Count - 2;

            if (nunTriangles * 3 * 3 > outBuf.limit() - outBuf.position())
            {
                string msg = Logging.getMessage("generic.BufferSize", outBuf.limit() - outBuf.position());
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            for (int i = 2; i < indices.Count; i++)
            {
                int k = indices[i - 2] * 3;
                outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2));

                k = indices[i % 2 == 0 ? i : i - 1] * 3;
                outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2));

                k = indices[i % 2 == 0 ? i - 1 : i] * 3;
                outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2));
            }
        }
示例#4
0
        public static FloatBuffer getDirectBuffer(int size, FloatBuffer buffer)
        {
            if (buffer == null)
            {
                return(buffer);
            }

            size = Round4(size);

            if (buffer.Direct)
            {
                buffer.limit((size >> 2) + buffer.position());
                return(buffer);
            }

            FloatBuffer directBuffer = allocateDirectBuffer(size).asFloatBuffer();

            directBuffer.put((FloatBuffer)((FloatBuffer)buffer).slice().limit(size >> 2));
            directBuffer.rewind();

            return(directBuffer);
        }
示例#5
0
        /**
         * Compute the intersections of a line with a collection of triangles.
         *
         * @param line     the line to intersect.
         * @param vertices the triangles, arranged in a buffer as GL_TRIANGLES (9 floats per triangle).
         *
         * @return the list of intersections with the line and the triangles, or null if there are no intersections.
         *
         * @throws ArgumentException if the line or vertex buffer is null.
         */
        public static List <Intersection> intersectTriangles(Line line, FloatBuffer vertices)
        {
            if (line == null)
            {
                string msg = Logging.getMessage("nullValue.LineIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            if (vertices == null)
            {
                string msg = Logging.getMessage("nullValue.BufferIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            List <Intersection> intersections = null;

            vertices.rewind();

            while (vertices.limit() - vertices.position() >= 9)
            {
                Intersection intersection = intersect(line,
                                                      vertices.get(), vertices.get(), vertices.get(),
                                                      vertices.get(), vertices.get(), vertices.get(),
                                                      vertices.get(), vertices.get(), vertices.get());

                if (intersection != null)
                {
                    if (intersections == null)
                    {
                        intersections = new List <Intersection>();
                    }
                    intersections.Add(intersection);
                }
            }

            return(intersections);
        }