Search in sources :

Example 1 with FaceRenderProps

use of maspack.render.FaceRenderProps in project artisynth_core by artisynth.

the class TextLabeller3d method render.

// @Override
// public void renderx(GLRenderer renderer, int flags) {
// if (isSelectable() || !renderer.isSelecting()) {
// render(renderer, 0);
// }
// }
@Override
public void render(Renderer renderer, int flags) {
    if (!isSelectable() && renderer.isSelecting()) {
        return;
    }
    FaceRenderProps rprops = (FaceRenderProps) getRenderProps();
    rprops.getFaceColor(rgb);
    Point3d tmp = new Point3d();
    // for consistency, assume line top as 3/4 font size
    Rectangle2D box = renderer.getTextBounds(myFont, "X", myTextSize);
    double t = box.getY() + box.getHeight();
    double vc = box.getY() + box.getHeight() / 2;
    rEye.invert(renderer.getViewMatrix().R);
    rEye.getColumn(0, xdir);
    rEye.getColumn(1, ydir);
    myTransform.R.set(rEye);
    Shading oldShading = renderer.getShading();
    float[] loc = new float[3];
    for (LabelItem label : myItems) {
        renderPos.setZero();
        // text orientation computation
        box = renderer.getTextBounds(myFont, label.text, myTextSize);
        double w = box.getWidth();
        switch(hAlignment) {
            case LEFT:
                renderPos.add(xdir[0] * (myTextOffset.x), xdir[1] * (myTextOffset.x), xdir[2] * (myTextOffset.x));
                break;
            case CENTRE:
                renderPos.add(-xdir[0] * w / 2, -xdir[1] * w / 2, -xdir[2] * w / 2);
                break;
            case RIGHT:
                renderPos.add(-xdir[0] * (w + myTextOffset.x), -xdir[1] * (w + myTextOffset.x), -xdir[2] * (w + myTextOffset.x));
                break;
            default:
                break;
        }
        switch(vAlignment) {
            case BOTTOM:
                renderPos.add(ydir[0] * (myTextOffset.y), ydir[1] * (myTextOffset.y), ydir[2] * (myTextOffset.y));
                break;
            case CENTRE:
                renderPos.add(-ydir[0] * vc, -ydir[1] * vc, -ydir[2] * vc);
                break;
            case TOP:
                renderPos.add(-ydir[0] * (t + myTextOffset.y), -ydir[1] * (t + myTextOffset.y), -ydir[2] * (t + myTextOffset.y));
                break;
            default:
        }
        // renderPos.transform(rEye);
        tmp.set(label.pos);
        tmp.transform(label.trans);
        renderPos.add(tmp);
        myTransform.p.set(renderPos);
        renderer.pushModelMatrix();
        renderer.mulModelMatrix(myTransform);
        renderer.setShading(Shading.NONE);
        renderer.setColor(rgb[0], rgb[1], rgb[2], (float) rprops.getAlpha());
        renderer.drawText(myFont, label.text, loc, myTextSize);
        renderer.popModelMatrix();
        renderer.setShading(oldShading);
    }
}
Also used : FaceRenderProps(maspack.render.FaceRenderProps) Point3d(maspack.matrix.Point3d) Rectangle2D(java.awt.geom.Rectangle2D) Shading(maspack.render.Renderer.Shading)

Example 2 with FaceRenderProps

use of maspack.render.FaceRenderProps in project artisynth_core by artisynth.

the class HudPrintStream method render.

// @Override
// public void renderx(GLRenderer renderer, int flags) {
// if (isSelectable() || !renderer.isSelecting()) {
// render(renderer, 0);
// }
// }
@Override
public void render(Renderer renderer, int flags) {
    if (!isSelectable() && renderer.isSelecting()) {
        return;
    }
    FaceRenderProps rprops = (FaceRenderProps) getRenderProps();
    // Position is assumed to be ([0,1], [0,1])
    int sw = renderer.getScreenWidth();
    int sh = renderer.getScreenHeight();
    renderPos.set(myPos.x * sw, myPos.y * sh);
    // print from top to bottom
    // for consistency, assume line top as 0.75 font size
    Rectangle2D box = renderer.getTextBounds(myFont, "X", myTextSize);
    double t = box.getHeight() + box.getY();
    // double vc = box.getY ()+box.getHeight ()/2;
    double b = box.getY();
    double a;
    double dy = myTextSize * myLineSpacing;
    int nLines;
    if (isFullScreen) {
        nLines = (int) Math.floor(((double) sh - myTextSize) / dy + 1);
        nLines = Math.min(myNumLines, nLines);
    } else {
        nLines = Math.min(myNumLines, myMaxDisplayLines);
    }
    switch(vAlignment) {
        case TOP:
            renderPos.add(0, -t);
            break;
        case CENTRE:
            a = -t + (myTextSize + dy * (nLines - 1)) / 2;
            renderPos.add(0, a);
            break;
        case BOTTOM:
            a = -b + (dy * (nLines - 1));
            renderPos.add(0, a);
            break;
    }
    if (isFullScreen) {
        // we don't want the last text line to go below the bottom of the
        // screen
        a = renderPos.y - (nLines - 1) * dy + b;
        if (a < 0) {
            renderPos.y -= a;
        }
    }
    // boolean saved2d = renderer.is2DRendering();
    // if (!saved2d) {
    // renderer.begin2DRendering(sw, sh);
    // }
    // render lines top to bottom
    float[] rgb = new float[3];
    rprops.getFaceColor(rgb);
    renderer.setColor(rgb[0], rgb[1], rgb[2], (float) rprops.getAlpha());
    myScrollOffset = Math.min(myScrollOffset, myNumLines - nLines);
    int offset = myScrollOffset;
    // if last line is just a newline, then offset by one
    if ("".equals(myTextLines[myLineIdx]) && (myScrollOffset < myNumLines - nLines)) {
        offset = Math.min(offset + 1, myNumLines - nLines);
    }
    int j = 0;
    String str;
    float[] loc = new float[3];
    for (int i = 0; i < nLines; i++) {
        // text left computation
        j = (myLineIdx + i + 2 * myBufferSize - nLines - offset + 1) % myBufferSize;
        str = myTextLines[j];
        box = renderer.getTextBounds(myFont, str, myTextSize);
        double w = box.getWidth();
        // double h = box.getHeight();
        double dx = 0;
        switch(hAlignment) {
            case CENTRE:
                dx = -w / 2;
                break;
            case LEFT:
                dx = 0;
                break;
            case RIGHT:
                dx = -w;
                break;
        }
        loc[0] = (float) (renderPos.x + dx);
        loc[1] = (float) (renderPos.y - i * dy);
        renderer.drawText(myFont, str, loc, myTextSize);
    }
// if (!saved2d) {
// renderer.end2DRendering();
// }
}
Also used : FaceRenderProps(maspack.render.FaceRenderProps) Rectangle2D(java.awt.geom.Rectangle2D)

Example 3 with FaceRenderProps

use of maspack.render.FaceRenderProps in project artisynth_core by artisynth.

the class TextComponent2d method render.

@Override
public void render(Renderer renderer, int flags) {
    if (!isSelectable() && renderer.isSelecting()) {
        return;
    }
    // text orientation computation
    Rectangle2D box = renderer.getTextBounds(myFont, myText, myTextSize);
    double t = box.getHeight() + box.getY();
    double vc = box.getCenterY() + box.getHeight() / 2;
    double w = box.getWidth();
    // Position is assumed to be ([0,1], [0,1])
    int sw = renderer.getScreenWidth();
    int sh = renderer.getScreenHeight();
    renderPos.setZero();
    switch(hAlignment) {
        case CENTRE:
            renderPos.add(-w / 2, 0);
            break;
        case RIGHT:
            renderPos.add(-w, 0);
            break;
        default:
            break;
    }
    switch(vAlignment) {
        case CENTRE:
            renderPos.add(0, -vc);
            break;
        case TOP:
            renderPos.add(0, -t);
            break;
        case BOTTOM:
            // renderPos.add(0, -b);
            break;
    }
    // account for non-zero orientation
    double rad = Math.toRadians(myOrientation);
    double ctheta = Math.cos(rad);
    double stheta = Math.sin(rad);
    renderPos.rotate(ctheta, stheta, renderPos);
    if (myPos.x <= 1) {
        renderPos.x += myPos.x * sw;
    } else {
        renderPos.x += myPos.x;
    }
    if (myPos.y <= 1) {
        renderPos.y += myPos.y * sh;
    } else {
        renderPos.y += myPos.y;
    }
    myTransform.R.m00 = ctheta;
    myTransform.R.m10 = stheta;
    myTransform.R.m01 = -stheta;
    myTransform.R.m11 = ctheta;
    myTransform.p.set(renderPos.x, renderPos.y, 0);
    FaceRenderProps rprops = (FaceRenderProps) getRenderProps();
    renderer.setFaceColoring(rprops, (flags & Renderer.HIGHLIGHT) != 0);
    // boolean saved2d = renderer.is2DRendering();
    // if (!saved2d) {
    // renderer.begin2DRendering(sw, sh);
    // }
    renderer.pushModelMatrix();
    renderer.mulModelMatrix(myTransform);
    final float[] ZERO = { 0, 0, 0 };
    renderer.drawText(myFont, myText, ZERO, myTextSize);
    renderer.popModelMatrix();
// if (!saved2d) {
// renderer.end2DRendering();
// }
}
Also used : FaceRenderProps(maspack.render.FaceRenderProps) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)3 FaceRenderProps (maspack.render.FaceRenderProps)3 Point3d (maspack.matrix.Point3d)1 Shading (maspack.render.Renderer.Shading)1