use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class GL2Viewer method drawPoints.
@Override
public void drawPoints(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.POINTS, 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
drawRawPoints(gl, robj, gidx, 0, robj.numPoints(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);
}
}
use of maspack.matrix.AffineTransform3d 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);
}
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class GL2Viewer method maybeUpdateMatrices.
// Made public for debugging purposes
public void maybeUpdateMatrices(GL2 gl) {
if (!viewMatrixValidP || !modelMatrixValidP) {
// create modelview matrix:
AffineTransform3d mvmatrix = new AffineTransform3d();
mvmatrix.mul(viewMatrix, modelMatrix);
// update modelview matrix
GLSupport.transformToGLMatrix(GLMatrix, mvmatrix);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadMatrixd(GLMatrix, 0);
viewMatrixValidP = true;
modelMatrixValidP = true;
}
if (!projectionMatrixValidP) {
// update projection matrix
GLSupport.transformToGLMatrix(GLMatrix, projectionMatrix);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadMatrixd(GLMatrix, 0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
projectionMatrixValidP = true;
}
if (!textureMatrixValidP) {
// update texture matrix
GLSupport.transformToGLMatrix(GLMatrix, textureMatrix);
gl.glMatrixMode(GL2.GL_TEXTURE);
gl.glLoadMatrixd(GLMatrix, 0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
textureMatrixValidP = true;
}
// gl.glMatrixMode(mmode[0]); // revert
}
use of maspack.matrix.AffineTransform3d 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();
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class MatricesUBO method updateMatrices.
public void updateMatrices(GL3 gl, Matrix4d proj, RigidTransform3d view, AffineTransform3dBase model, Matrix3d modelNormal, AffineTransform2dBase texture) {
ByteBuffer buff = getBuffer();
// model view
AffineTransform3d modelview = new AffineTransform3d(view);
modelview.mul(model);
// pvm matrix
buff.position(getByteOffset(PVM_IDX));
mul(proj, modelview, buff);
// model-view
buff.position(getByteOffset(VM_IDX));
putMatrix(buff, modelview);
// model matrix
buff.position(getByteOffset(M_IDX));
putMatrix(buff, model);
// normal
buff.position(getByteOffset(NORMAL_IDX));
mul4x4(view.R, modelNormal, buff);
// texture
buff.position(getByteOffset(TEXTURE_IDX));
putMatrix(buff, texture);
buff.flip();
update(gl, buff);
}
Aggregations