⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segmentplanerenderer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    //**************************************************************//    //********************  Segment Plane Construction  ************//    //**************************************************************//    protected void createSegmentPlaneGeometry(Globe globe, SegmentPlane segmentPlane, RenderInfo renderInfo)    {        double[] altitudes = segmentPlane.getPlaneAltitudes();        LatLon[] locations = segmentPlane.getPlaneLocations();        int mask = segmentPlane.getPlaneOutlineMask();        renderInfo.planeReferenceCenter = globe.computePointFromPosition(            locations[0].getLatitude(), locations[0].getLongitude(), altitudes[0]);        int[] gridCellCounts = new int[2];        double[] gridCellParams = new double[2];        this.computePlaneParameterization(globe, segmentPlane, gridCellCounts, gridCellParams);        int uStacks = gridCellCounts[0];        int vStacks = gridCellCounts[1];        double uStep = gridCellParams[0];        double vStep = gridCellParams[1];        renderInfo.planeFillIndexCount = getPlaneFillIndexCount(uStacks, vStacks);        if (renderInfo.planeFillIndices == null            || renderInfo.planeFillIndices.capacity() < renderInfo.planeFillIndexCount)        {            renderInfo.planeFillIndices = BufferUtil.newIntBuffer(renderInfo.planeFillIndexCount);        }        renderInfo.planeOutlineIndexCount = getPlaneOutlineIndexCount(uStacks, vStacks, mask);        if (renderInfo.planeOutlineIndices == null            || renderInfo.planeOutlineIndices.capacity() < renderInfo.planeOutlineIndexCount)        {            renderInfo.planeOutlineIndices = BufferUtil.newIntBuffer(renderInfo.planeOutlineIndexCount);        }        renderInfo.planeGridIndexCount = getPlaneGridIndexCount(uStacks, vStacks);        if (renderInfo.planeGridIndices == null            || renderInfo.planeGridIndices.capacity() < renderInfo.planeGridIndexCount)        {            renderInfo.planeGridIndices = BufferUtil.newIntBuffer(renderInfo.planeGridIndexCount);        }        int vertexCount = getPlaneVertexCount(uStacks, vStacks);        int coordCount = 3 * vertexCount;        if (renderInfo.planeVertices == null || renderInfo.planeVertices.capacity() < coordCount)        {            renderInfo.planeVertices = BufferUtil.newDoubleBuffer(coordCount);        }        if (renderInfo.planeNormals == null || renderInfo.planeNormals.capacity() < coordCount)        {            renderInfo.planeNormals = BufferUtil.newDoubleBuffer(coordCount);        }        computePlaneFillIndices(uStacks, vStacks, renderInfo.planeFillIndices);        renderInfo.planeFillIndices.rewind();        computePlaneOutlineIndices(uStacks, vStacks, mask, renderInfo.planeOutlineIndices);        renderInfo.planeOutlineIndices.rewind();        computePlaneGridIndices(uStacks, vStacks, renderInfo.planeGridIndices);        renderInfo.planeGridIndices.rewind();        this.computePlaneVertices(globe, segmentPlane, uStacks, vStacks, uStep, vStep, renderInfo.planeReferenceCenter,            renderInfo.planeVertices);        renderInfo.planeVertices.rewind();        this.computePlaneNormals(globe, segmentPlane, renderInfo.planeFillIndexCount, vertexCount,            renderInfo.planeFillIndices, renderInfo.planeVertices, renderInfo.planeNormals);        renderInfo.planeNormals.rewind();    }    // TODO: consolidate the following geometry construction code with GeometryBuilder    protected static int getPlaneFillIndexCount(int uStacks, int vStacks)    {        int count = 2 * (uStacks + 1) * vStacks; // Triangle strips for each row.        if (vStacks > 1)            count += 2 * (vStacks - 1);          // Degenerate connection triangles.        return count;     }    protected static int getPlaneOutlineIndexCount(int uStacks, int vStacks, int mask)    {        int count = 0;        if ((mask & SegmentPlane.TOP) != 0)            count += 2 * uStacks;        if ((mask & SegmentPlane.BOTTOM) != 0)            count += 2 * uStacks;        if ((mask & SegmentPlane.LEFT) != 0)            count += 2 * vStacks;        if ((mask & SegmentPlane.RIGHT) != 0)            count += 2 * vStacks;        return count;    }    protected static int getPlaneGridIndexCount(int uStacks, int vStacks)    {        return 2 * uStacks * (vStacks - 1)  // Horizontal gridlines.             + 2 * vStacks * (uStacks - 1); // Vertical gridlines.    }    protected static int getPlaneVertexCount(int uStacks, int vStacks)    {        return (uStacks + 1) * (vStacks + 1);    }    protected static void computePlaneFillIndices(int uStacks, int vStacks, IntBuffer buffer)    {        int vertex;        for (int vi = 0; vi < vStacks; vi++)        {            if (vi != 0)            {                vertex = uStacks + (vi - 1) * (uStacks + 1);                buffer.put(vertex);                vertex = vi * (uStacks + 1) + (uStacks + 1);                buffer.put(vertex);            }            for (int ui = 0; ui <= uStacks; ui++)            {                vertex = ui + (vi + 1) * (uStacks + 1);                buffer.put(vertex);                vertex = ui + vi * (uStacks + 1);                buffer.put(vertex);            }        }    }    protected static void computePlaneOutlineIndices(int uStacks, int vStacks, int mask, IntBuffer buffer)    {        int vertex;        // Top edge.        if ((mask & SegmentPlane.TOP) != 0)        {            for (int ui = 0; ui < uStacks; ui++)            {                vertex = ui + vStacks * (uStacks + 1);                buffer.put(vertex);                vertex = (ui + 1) + vStacks * (uStacks + 1);                buffer.put(vertex);            }        }        // Bottom edge.        if ((mask & SegmentPlane.BOTTOM) != 0)        {            for (int ui = 0; ui < uStacks; ui++)            {                vertex = ui;                buffer.put(vertex);                vertex = (ui + 1);                buffer.put(vertex);            }        }        // Left edge.        if ((mask & SegmentPlane.LEFT) != 0)        {            for (int vi = 0; vi < vStacks; vi++)            {                vertex = vi * (uStacks + 1);                buffer.put(vertex);                vertex = (vi + 1) * (uStacks + 1);                buffer.put(vertex);            }        }        // Right edge.        if ((mask & SegmentPlane.RIGHT) != 0)        {            for (int vi = 0; vi < vStacks; vi++)            {                vertex = uStacks + vi * (uStacks + 1);                buffer.put(vertex);                vertex = uStacks + (vi + 1) * (uStacks + 1);                buffer.put(vertex);            }        }    }    protected static void computePlaneGridIndices(int uStacks, int vStacks, IntBuffer buffer)    {        int vertex;        // Horizontal gridlines.        for (int vi = 1; vi < vStacks; vi++)        {            for (int ui = 0; ui < uStacks; ui++)            {                vertex = ui + vi * (uStacks + 1);                buffer.put(vertex);                vertex = (ui + 1) + vi * (uStacks + 1);                buffer.put(vertex);            }        }        // Vertical gridlines.        for (int ui = 1; ui < uStacks; ui++)        {            for (int vi = 0; vi < vStacks; vi++)            {                vertex = ui + vi * (uStacks + 1);                buffer.put(vertex);                vertex = ui + (vi + 1) * (uStacks + 1);                buffer.put(vertex);            }        }    }    protected void computePlaneVertices(Globe globe, SegmentPlane segmentPlane,        int uStacks, int vStacks, double uStep, double vStep,        Vec4 referenceCenter, DoubleBuffer buffer)    {        int index = 0;                for (int vi = 0; vi <= vStacks; vi++)        {            double v = clamp(vi * vStep, 0, 1);            for (int ui = 0; ui <= uStacks; ui++)            {                double u = clamp(ui * uStep, 0, 1);                Position pos = this.computePositionOnPlane(null, globe, segmentPlane, u, v, false);                Vec4 vertex = globe.computePointFromPosition(pos);                vertex = vertex.subtract3(referenceCenter);                putVertex3(vertex, index++, buffer);            }        }    }    @SuppressWarnings({"UnusedDeclaration"})    protected void computePlaneNormals(Globe globe, SegmentPlane segmentPlane, int indexCount, int vertexCount,        IntBuffer indices, DoubleBuffer vertices, DoubleBuffer buffer)    {        double[] altitudes = segmentPlane.getPlaneAltitudes();        LatLon[] locations = segmentPlane.getPlaneLocations();        Vec4 p1 = globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[0]);        Vec4 p2 = globe.computePointFromPosition(locations[1].getLatitude(), locations[1].getLongitude(), altitudes[0]);        Vec4 p3 = globe.computePointFromPosition(locations[0].getLatitude(), locations[0].getLongitude(), altitudes[1]);        Vec4 e1 = p2.subtract3(p1);        Vec4 e2 = p3.subtract3(p1);        Vec4 normal = e1.cross3(e2).normalize3();        for (int v = 0; v < vertexCount; v++)        {            putVertex3(normal, v, buffer);        }    }    private static double clamp(double x, double min, double max)    {        return (x < min) ? min : ((x > max) ? max : x);    }    //**************************************************************//    //********************  Border Construction  *******************//    //**************************************************************//    // TODO: investigate necessary changes to create a general-use cylinder with caps, a height, and a radius.    @SuppressWarnings({"UnusedDeclaration"})    protected void createBorderGeometry(Globe globe, SegmentPlane segmentPlane, RenderInfo renderInfo)    {        int slices = 16;        int stacks = 32;        int loops = 8;        GeometryBuilder gb = new GeometryBuilder();        renderInfo.borderCylinderIndexCount = gb.getCylinderIndexCount(slices, stacks);        if (renderInfo.borderCylinderIndices == null            || renderInfo.borderCylinderIndices.capacity() < renderInfo.borderCylinderIndexCount)        {            renderInfo.borderCylinderIndices = BufferUtil.newIntBuffer(renderInfo.borderCylinderIndexCount);        }        renderInfo.borderCapIndexCount = gb.getDiskIndexCount(slices, loops);        if (renderInfo.borderCapIndices == null            || renderInfo.borderCapIndices.capacity() < renderInfo.borderCapIndexCount)        {            renderInfo.borderCapIndices = BufferUtil.newIntBuffer(renderInfo.borderCapIndexCount);        }        int cylinderVertexCount = gb.getCylinderVertexCount(slices, stacks);        int cylinderCoordCount = 3 * cylinderVertexCount;        if (renderInfo.borderCylinderVertices == null            || renderInfo.borderCylinderVertices.capacity() < cylinderCoordCount)        {            renderInfo.borderCylinderVertices = BufferUtil.newFloatBuffer(cylinderCoordCount);        }        if (renderInfo.borderCylinderNormals == null            || renderInfo.borderCylinderNormals.capacity() < cylinderCoordCount)        {            renderInfo.borderCylinderNormals = BufferUtil.newFloatBuffer(cylinderCoordCount);        }        int capVertexCount = gb.getDiskVertexCount(slices, loops);        int capCoordCount = 3 * capVertexCount;        if (renderInfo.borderCapVertices == null            || renderInfo.borderCapVertices.capacity() < capCoordCount)        {            renderInfo.borderCapVertices = BufferUtil.newFloatBuffer(capCoordCount);        }        if (renderInfo.borderCapNormals == null            || renderInfo.borderCapNormals.capacity() < capCoordCount)        {            renderInfo.borderCapNormals = BufferUtil.newFloatBuffer(capCoordCount);        }        int[] indices = new int[renderInfo.borderCylinderIndexCount];        gb.makeCylinderIndices(slices, stacks, indices);        renderInfo.borderCylinderIndices.put(indices);        renderInfo.borderCylinderIndices.rewind();        indices = new int[renderInfo.borderCapIndexCount];        gb.makeDiskIndices(slices, loops, indices);        renderInfo.borderCapIndices.put(indices);        renderInfo.borderCapIndices.rewind();        float[] vertices = new float[cylinderCoordCount];        gb.makeCylinderVertices(1.0f, 1.0f, slices, stacks, vertices);        renderInfo.borderCylinderVertices.put(vertices);        renderInfo.borderCylinderVertices.rewind();        float[] normals = new float[cylinderCoordCount];        gb.makeCylinderNormals(slices, stacks, normals);        renderInfo.borderCylinderNormals.put(normals);        renderInfo.borderCylinderNormals.rewind();        vertices = new float[capCoordCount];        gb.makeDiskVertices(0.0f, 1.0f, slices, loops, vertices);        renderInfo.borderCapVertices.put(vertices);        renderInfo.borderCapVertices.rewind();        normals = new float[capCoordCount];        gb.makeDiskNormals(slices, loops, normals);        renderInfo.borderCapNormals.put(normals);        renderInfo.borderCapNormals.rewind();    }    //**************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -