Search in sources :

Example 1 with VectorTransformer3d

use of maspack.matrix.VectorTransformer3d in project artisynth_core by artisynth.

the class SDGridTest method render.

@Override
public void render(Renderer renderer, int flags) {
    if (sdgrid != null) {
        Shading savedShading = renderer.getShading();
        renderer.setShading(Shading.NONE);
        renderer.setPointSize(5);
        VectorTransformer3d TGL = sdgrid.getGridToLocalTransformer();
        Vector3i res = sdgrid.getResolution();
        // Draw 4 vertical lines.
        renderer.beginDraw(DrawMode.LINES);
        renderer.addVertex(gridToLocal(TGL, res.x, res.y, res.z));
        renderer.addVertex(gridToLocal(TGL, res.x, res.y, 0));
        renderer.addVertex(gridToLocal(TGL, 0, res.y, res.z));
        renderer.addVertex(gridToLocal(TGL, 0, res.y, 0));
        renderer.addVertex(gridToLocal(TGL, 0, 0, res.z));
        renderer.addVertex(gridToLocal(TGL, 0, 0, 0));
        renderer.addVertex(gridToLocal(TGL, res.x, 0, res.z));
        renderer.addVertex(gridToLocal(TGL, res.x, 0, 0));
        // Draw a diagonal line from max to min.
        renderer.addVertex(gridToLocal(TGL, 0, 0, 0));
        renderer.addVertex(gridToLocal(TGL, res.x, res.y, res.z));
        renderer.endDraw();
        double[] phi = sdgrid.getDistances();
        // Draw the vertices on the grid.
        Vector3d coords = new Vector3d();
        for (int i = 0; i < phi.length; i++) {
            Vector3i vxyz = new Vector3i();
            sdgrid.vertexToXyzIndices(vxyz, i);
            sdgrid.getLocalVertexCoords(coords, vxyz);
            if (phi[i] <= 0) {
                renderer.setColor(Color.BLUE);
                renderer.drawPoint(coords);
            } else {
                renderer.setColor(Color.RED);
                renderer.drawPoint(coords);
            }
        }
        renderer.setPointSize(1);
        renderer.setShading(savedShading);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Vector3i(maspack.matrix.Vector3i) Shading(maspack.render.Renderer.Shading) VectorTransformer3d(maspack.matrix.VectorTransformer3d)

Aggregations

Vector3d (maspack.matrix.Vector3d)1 Vector3i (maspack.matrix.Vector3i)1 VectorTransformer3d (maspack.matrix.VectorTransformer3d)1 Shading (maspack.render.Renderer.Shading)1