Search in sources :

Example 46 with AffineTransform3d

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

the class GL2Viewer method drawLines.

@Override
public void drawLines(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.LINES, 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
            drawRawLines(gl, robj, gidx, 0, robj.numLines(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)

Aggregations

AffineTransform3d (maspack.matrix.AffineTransform3d)46 Vector3d (maspack.matrix.Vector3d)14 RigidTransform3d (maspack.matrix.RigidTransform3d)13 Point3d (maspack.matrix.Point3d)7 PolygonalMesh (maspack.geometry.PolygonalMesh)5 AxisAngle (maspack.matrix.AxisAngle)5 Matrix3d (maspack.matrix.Matrix3d)4 RotationMatrix3d (maspack.matrix.RotationMatrix3d)4 InstanceTransformType (maspack.render.RenderInstances.InstanceTransformType)4 RenderProps (maspack.render.RenderProps)4 RigidBody (artisynth.core.mechmodels.RigidBody)3 Point (java.awt.Point)3 IOException (java.io.IOException)3 RenderObject (maspack.render.RenderObject)3 CollisionManager (artisynth.core.mechmodels.CollisionManager)2 MechModel (artisynth.core.mechmodels.MechModel)2 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Vertex3d (maspack.geometry.Vertex3d)2