use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class GLViewer method setModelMatrix2d.
// John Lloyd: didn't work well - not enough depth buffer precision
// close to the far plane
// /**
// * Add a depth offset to the projection matrix.
// * Each integer represents enough depth to account for one bin in the depth
// * buffer. Negative values bring following objects closer to the screen.
// * This is to account for z-fighting.
// *
// * @param zOffset value to offset depth buffer
// */
// public void addDepthOffset(double zOffset) {
// // compute depth buffer precision
// double deps = 2.0/(1 << (myFrustum.depthBits-1));
// // Let n and f be the far and near plane distances (positive values),
// // and z the z value in eye coordinates. Then the change in z
// // corresponding to deps is
// //
// // delta z = - ((f-n) z^2)/(2 f n) deps
// //
// // We take z to be about 1/10 the distance to the far plane, which
// // corresponds roughly to where the center is when autoFit is used.
// Vector3d dp = new Vector3d();
// double f = myFrustum.far;
// double n = myFrustum.near;
// dp.scale (zOffset*(f-n)*f*deps/(2*n), getEyeZDirection());
// synchronized (modelMatrix) {
// modelMatrix.addTranslation (dp.x, dp.y, dp.z);
// }
// invalidateModelMatrix();
// }
// public void setModelMatrix2d (double width, double height) {
// setModelMatrix2d (0, width, 0, height);
// }
/**
* {@inheritDoc}
*/
public void setModelMatrix2d(double left, double right, double bottom, double top) {
AffineTransform3d XMW = new AffineTransform3d();
double w = right - left;
double h = top - bottom;
XMW.A.m00 = 2 / w;
XMW.A.m11 = 2 / h;
XMW.p.set(-(left + right) / w, -(top + bottom) / h, 0);
setModelMatrix(XMW);
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class StlRenderer method mulModelMatrix.
@Override
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());
}
}
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class StlRenderer method drawTriangles.
@Override
public void drawTriangles(RenderObject robj, int gidx, RenderInstances rinst) {
int idx = 0;
int[] buff = rinst.getInstances();
InstanceTransformType[] types = InstanceTransformType.values();
rinst.readLock();
robj.readLock();
for (int i = 0; i < rinst.numInstances(); ++i) {
pushModelMatrix();
int type = buff[idx++];
int tidx = buff[idx++];
int sidx = buff[idx++];
InstanceTransformType tt = types[type];
switch(tt) {
case POINT:
{
// point
float[] pnt = rinst.getPoint(tidx);
translateModelMatrix(pnt[0], pnt[1], pnt[2]);
break;
}
case FRAME:
{
RigidTransform3d frame = rinst.getFrame(tidx);
mulModelMatrix(frame);
break;
}
case AFFINE:
{
AffineTransform3d affine = rinst.getAffine(tidx);
mulModelMatrix(affine);
break;
}
}
Double s = rinst.getScale(sidx);
if (s != null && s.doubleValue() != 1.0) {
scaleModelMatrix(s);
}
drawTriangles(robj);
popModelMatrix();
}
robj.readUnlock();
rinst.readUnlock();
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class RigidBodyCollision method build.
public void build(String[] args) throws IOException {
try {
mechmod = new MechModel();
mechmod.setMaxStepSize(0.005);
boxes = new ArrayList<RigidBody>();
table = new RigidBody("table");
table.setDynamic(false);
table.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
AffineTransform3d trans = new AffineTransform3d();
trans.setIdentity();
trans.applyScaling(4, 2, 0.5);
table.transformGeometry(trans);
table.setPose(new RigidTransform3d(new Vector3d(0, 0, 0.8077474533228615), new AxisAngle()));
table.setInertia(SpatialInertia.createBoxInertia(1, 1, 1, 1));
mechmod.addRigidBody(table);
boxes.add(table);
if (wireFrame) {
setWireFrame(table);
}
// middle box in pile
box0 = new RigidBody("box0");
box0.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.5, 0.5, 0.5);
box0.transformGeometry(trans);
box0.setInertia(SpatialInertia.createBoxInertia(4, 1, 1, 1));
addBox(box0, Color.GREEN);
if (wireFrame) {
setWireFrame(box0);
}
// long thin box, bottom of pile
box1 = new RigidBody("box1");
box1.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.6, 0.1, 1.9);
box1.transformGeometry(trans);
box1.setInertia(SpatialInertia.createBoxInertia(1, 1, 0.1, 4));
addBox(box1, Color.YELLOW);
if (wireFrame) {
setWireFrame(box1);
}
// left hand box falling on unsupported end of
box2 = new RigidBody("box2");
// box1
box2.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.5, 0.5, 0.5);
box2.transformGeometry(trans);
box2.setInertia(SpatialInertia.createBoxInertia(20, 1, 1, 1));
addBox(box2, Color.BLUE);
if (wireFrame) {
setWireFrame(box2);
}
// top box in pile
box3 = new RigidBody("box3");
box3.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.4, 0.4, 0.4);
box3.transformGeometry(trans);
box3.setInertia(SpatialInertia.createBoxInertia(0.5, 0.5, 0.5, 4));
addBox(box3, Color.CYAN);
// box3.getMesh().name = "box3";
if (wireFrame) {
setWireFrame(box3);
}
// solo box off to the right.
box4 = new RigidBody("box4");
box4.setMesh(new PolygonalMesh(new File(rbpath + "box.obj")), null);
trans.setIdentity();
trans.applyScaling(0.6, 0.6, 0.3);
box4.transformGeometry(trans);
box4.setInertia(SpatialInertia.createBoxInertia(0.5, 0.5, 0.5, 4));
box4.setPose(new RigidTransform3d(new Vector3d(1, 0.0, 5), new AxisAngle(0, 0, 0, 0)));
addBox(box4, Color.RED);
// box4.getMesh().name = "box4";
if (wireFrame) {
setWireFrame(box4);
}
mechmod.setDefaultCollisionBehavior(true, 0.05);
reset();
addModel(mechmod);
ControlPanel panel = new ControlPanel();
panel.addWidget(mechmod, "integrator");
panel.addWidget(mechmod, "maxStepSize");
addControlPanel(panel);
Main.getMain().arrangeControlPanels(this);
CollisionManager cm = mechmod.getCollisionManager();
RenderProps.setVisible(cm, true);
RenderProps.setLineWidth(cm, 3);
RenderProps.setLineColor(cm, Color.RED);
cm.setDrawContactNormals(true);
// addBreakPoint (0.74);
for (int i = 1; i <= 10; i++) {
addWayPoint(0.1 * i);
}
// setWaypointChecking (true);
} catch (IOException e) {
throw e;
}
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class MeshBase method transform.
/**
* Applies an affine transformation to the vertices of this mesh. The
* topology of the mesh remains unchanged.
*
* @param X
* affine transformation
*/
public void transform(AffineTransform3dBase X) {
for (Vertex3d vertex : myVertices) {
vertex.pnt.transform(X);
}
if (myNormalsExplicitP) {
Matrix3d A = new Matrix3d(X.getMatrix());
if (X instanceof AffineTransform3d) {
A.invert();
A.transpose();
}
for (int i = 0; i < myNormals.size(); i++) {
Vector3d nrm = myNormals.get(i);
A.mul(nrm, nrm);
nrm.normalize();
}
} else {
// auto normals will be regenerated
clearNormals();
}
invalidateBoundingInfo();
notifyModified();
}
Aggregations