Search in sources :

Example 31 with RigidTransform3d

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

the class GL2Viewer method drawTriangles.

@Override
public void drawTriangles(RenderObject robj, int gidx, RenderInstances rinst) {
    boolean selecting = isSelecting();
    boolean hasColors = ((robj.hasColors() || rinst.hasColors()) && hasVertexColoring());
    boolean useColors = hasColors && !selecting && (myActiveColor == ActiveColor.DEFAULT);
    boolean useHSV = isHSVColorInterpolationEnabled();
    // update state
    maybeUpdateState(gl);
    // if use vertex colors, get them to track glColor
    int savedShading = 0;
    if (useColors) {
        savedShading = enableVertexColoring(useHSV);
    }
    boolean useDisplayList = (!selecting || !hasColors) && (!robj.isTransient());
    GL2VersionedObject gvo = null;
    boolean compile = true;
    if (useDisplayList) {
        RenderInstancesKey key = new RenderInstancesKey(rinst.getIdentifier(), robj.getIdentifier(), DrawType.TRIANGLES, gidx);
        // get snapshot of version information
        RenderInstancesFingerprint fingerprint = new RenderInstancesFingerprint(rinst.getVersionInfo(), robj.getVersionInfo());
        gvo = myGLResources.getVersionedObject(key);
        if (gvo == null || gvo.disposeInvalid(gl)) {
            gvo = myGLResources.allocateVersionedObject(gl, key, fingerprint);
            compile = true;
        } else {
            compile = !(gvo.compareExchangeFingerPrint(fingerprint));
        }
    }
    if (compile) {
        if (gvo != null) {
            gvo.beginCompile(gl);
        }
        // prevent writes to robj and rinst
        robj.readLock();
        rinst.readLock();
        int ninstances = rinst.numInstances();
        int[] instances = rinst.getInstances();
        int ipos = rinst.getInstanceTypeOffset();
        int tpos = rinst.getInstanceTransformOffset();
        int cpos = rinst.getInstanceColorOffset();
        int spos = rinst.getInstanceScaleOffset();
        int stride = rinst.getInstanceStride();
        InstanceTransformType[] type = RenderInstances.getTransformTypes();
        boolean hasInstanceScales = rinst.hasScales();
        boolean hasInstanceColors = useColors && rinst.hasColors();
        for (int i = 0; i < ninstances; ++i) {
            int iidx = instances[ipos];
            int tidx = instances[tpos];
            int cidx = instances[cpos];
            int sidx = instances[spos];
            gl.glPushMatrix();
            // transform
            switch(type[iidx]) {
                case AFFINE:
                    {
                        AffineTransform3d aff = rinst.getAffine(tidx);
                        mulTransform(gl, aff);
                        break;
                    }
                case FRAME:
                    {
                        RigidTransform3d frame = rinst.getFrame(tidx);
                        mulTransform(gl, frame);
                        break;
                    }
                case POINT:
                    {
                        float[] trans = rinst.getPoint(tidx);
                        gl.glTranslatef(trans[0], trans[1], trans[2]);
                        break;
                    }
            }
            if (hasInstanceScales && (sidx >= 0)) {
                Double s = rinst.getScale(sidx);
                gl.glScaled(s, s, s);
            }
            if (hasInstanceColors && (cidx >= 0)) {
                byte[] c = rinst.getColor(cidx);
                gl.glColor4ub(c[0], c[1], c[2], c[3]);
            }
            // draw raw object
            drawRawTriangles(gl, robj, gidx, 0, robj.numTriangles(gidx), robj.hasNormals(), !hasInstanceColors && useColors, !selecting & robj.hasTextureCoords(), useHSV);
            gl.glPopMatrix();
            ipos += stride;
            tpos += stride;
            cpos += stride;
            spos += stride;
        }
        robj.readUnlock();
        rinst.readUnlock();
        if (gvo != null) {
            gvo.endCompile(gl);
            gvo.draw(gl);
        }
    } else {
        gvo.draw(gl);
    }
    // disable color tracking
    if (useColors) {
        disableVertexColoring(useHSV, savedShading);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) InstanceTransformType(maspack.render.RenderInstances.InstanceTransformType) Point(java.awt.Point) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 32 with RigidTransform3d

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

the class GLViewer method mulModelMatrix.

public void mulModelMatrix(AffineTransform3dBase trans) {
    synchronized (modelMatrix) {
        if (trans instanceof RigidTransform3d) {
            RigidTransform3d rigid = (RigidTransform3d) trans;
            modelMatrix.mul(rigid);
            modelNormalMatrix.mul(rigid.R);
        } else {
            AffineTransform3d aff = new AffineTransform3d(modelMatrix);
            aff.mul(trans);
            modelMatrix = aff;
            modelNormalMatrix = computeInverseTranspose(aff.getMatrix());
        }
    }
    invalidateModelMatrix();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 33 with RigidTransform3d

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

the class GLViewer method setAlignedEyeOrientation.

/**
 * Adjusts the orientation the eye frame with respect to world
 * coordinates. The grid is adjusted to align with the nearest set
 * of aligned axes.
 * The distance between the center and the eye frame is unchanged.
 *
 * @param REW
 * desired rotational transform from eye to world coordinates
 */
protected void setAlignedEyeOrientation(RotationMatrix3d REW) {
    Vector3d xdir = new Vector3d();
    Vector3d ydir = new Vector3d();
    Vector3d zdir = new Vector3d();
    REW.getColumn(0, xdir);
    REW.getColumn(1, ydir);
    REW.getColumn(2, zdir);
    // new eye to world transfrom
    RigidTransform3d X = new RigidTransform3d();
    X.R.set(REW);
    double d = getEye().distance(myViewState.myCenter);
    X.p.scaledAdd(d, zdir, myViewState.myCenter);
    myViewState.myUp.set(ydir);
    setEyeToWorld(X);
    X.p.setZero();
    // adjust X.R to the nearest axis-aligned orientation
    int xmaxIdx = xdir.maxAbsIndex();
    double v = xdir.get(xmaxIdx) > 0 ? 1 : -1;
    xdir.setZero();
    xdir.set(xmaxIdx, v);
    ydir.set(xmaxIdx, 0);
    int ymaxIdx = ydir.maxAbsIndex();
    v = ydir.get(ymaxIdx) > 0 ? 1 : -1;
    ydir.setZero();
    ydir.set(ymaxIdx, v);
    X.R.setXYDirections(xdir, ydir);
    myGrid.setGridToWorld(X);
    myGrid.setUseWorldOrigin(true);
    myGrid.setLockAxesToWorld(true);
    myGrid.setXAxisColor(getAxisColor(0));
    myGrid.setYAxisColor(getAxisColor(1));
    myGrid.setZAxisColor(getAxisColor(2));
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d)

Example 34 with RigidTransform3d

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

the class GL3Viewer method getLineTransform.

private RigidTransform3d getLineTransform(float[] p0, float[] p1) {
    RigidTransform3d X = new RigidTransform3d();
    Vector3d utmp = new Vector3d();
    utmp.set(p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]);
    X.p.set(p0[0], p0[1], p0[2]);
    X.R.setZDirection(utmp);
    return X;
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d)

Example 35 with RigidTransform3d

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

the class GL3Viewer method drawCone.

private void drawCone(float[] pnt0, float[] pnt1, double r, boolean capped) {
    // compute required rotation
    RigidTransform3d lineRot = getLineTransform(pnt0, pnt1);
    double dx = pnt1[0] - pnt0[0];
    double dy = pnt1[1] - pnt0[1];
    double dz = pnt1[2] - pnt0[2];
    float h = (float) (Math.sqrt(dx * dx + dy * dy + dz * dz));
    pushModelMatrix();
    mulModelMatrix(lineRot);
    scaleModelMatrix(r, r, h);
    maybeUpdateState(gl);
    updateProgram(gl, RenderingMode.DEFAULT, true, false, false);
    int nSlices = getSurfaceResolution();
    GL3Object cone = myPrimitiveManager.getAcquiredCone(gl, nSlices, capped);
    cone.draw(gl);
    cone.release();
    popModelMatrix();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Point(java.awt.Point)

Aggregations

RigidTransform3d (maspack.matrix.RigidTransform3d)206 Vector3d (maspack.matrix.Vector3d)56 Point3d (maspack.matrix.Point3d)48 PolygonalMesh (maspack.geometry.PolygonalMesh)21 MechModel (artisynth.core.mechmodels.MechModel)19 RigidBody (artisynth.core.mechmodels.RigidBody)18 AxisAngle (maspack.matrix.AxisAngle)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 AffineTransform3d (maspack.matrix.AffineTransform3d)13 FemModel3d (artisynth.core.femmodels.FemModel3d)11 RenderProps (maspack.render.RenderProps)11 FemNode3d (artisynth.core.femmodels.FemNode3d)9 Color (java.awt.Color)7 Point (java.awt.Point)7 Matrix3d (maspack.matrix.Matrix3d)7 Shading (maspack.render.Renderer.Shading)7 LinearMaterial (artisynth.core.materials.LinearMaterial)6 Renderable (maspack.render.Renderable)6 ArrayList (java.util.ArrayList)5 Vector2d (maspack.matrix.Vector2d)5