use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class GLViewer method getZRange.
// Sanchez, July 2013:
// used to adjust selection volume, or else the orthogonal
// view scale sometimes too large to properly detect selections
protected void getZRange(Vector2d zRange) {
if (!isOrthogonal()) {
zRange.x = myFrustum.near;
zRange.y = myFrustum.far;
return;
}
Point3d pmin = new Point3d();
Point3d pmax = new Point3d();
getBounds(pmin, pmax);
Vector3d zdir = getEyeZDirection();
// John Lloyd, June 2016. Try to get a more robust estimate of the
// view volume, based on the center and maximum "radius" of the
// bounding box
Point3d cent = new Point3d();
Vector3d diag = new Vector3d();
cent.add(pmax, pmin);
cent.scale(0.5);
diag.sub(pmax, pmin);
cent.transform(getViewMatrix());
double worldDist = -cent.z;
double radius = diag.norm() / 2;
if (radius == 0) {
// can happen if model contains only one or more co-located points
radius = worldDist * 0.01;
}
// add 20% to radius for good measure
zRange.y = worldDist + 1.2 * radius;
zRange.x = worldDist - 1.2 * radius;
// // find max z depth
// double worldDist = Math.abs(getEye().dot(zdir));
// double [] x = {pmin.x, pmax.x};
// double [] y = {pmin.y, pmax.y};
// double [] z = {pmin.z, pmax.z};
// double minz = Double.POSITIVE_INFINITY;
// double maxz = Double.NEGATIVE_INFINITY;
// for (int i=0; i<2; i++) {
// for (int j=0; j<2; j++) {
// for (int k=0; k<2; k++) {
// double d = x[i]*zdir.x + y[j]*zdir.y + z[k]*zdir.z;
// maxz = Math.max(maxz, d);
// minz = Math.min(minz, d);
// }
// }
// }
// // add 50% for good measure
// double d = maxz-minz;
// minz = minz-d/2;
// maxz = maxz+d/2;
// zRange.y = maxz + worldDist;
// zRange.x = 2*(minz + worldDist)-zRange.y;
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class GLViewer method setAxisLength.
public void setAxisLength(double len) {
if (len == AUTO_FIT) {
Point3d pmin = new Point3d();
Point3d pmax = new Point3d();
getBounds(pmin, pmax);
Vector3d vdiag = new Vector3d();
vdiag.sub(pmax, pmin);
axisLength = vdiag.norm() / 2;
} else {
axisLength = len;
}
}
use of maspack.matrix.Vector3d 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));
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class GLViewer method autoFitOrtho.
/*
* {@inheritDoc}
*/
public void autoFitOrtho() {
if (hasRenderables()) {
Point3d pcenter = new Point3d();
double r = estimateRadiusAndCenter(pcenter);
// if radius is zero, set default to radius 1
if (Math.abs(r) == 0 || Double.isInfinite(r) || Double.isNaN(r)) {
r = 1;
}
myViewState.myCenter.set(pcenter);
Vector3d zdir = getEyeZDirection();
// use sine instead of tangent since we want frustum to be tangent to
// to the sphere implied by r
double d = r / Math.sin(Math.toRadians(myFrustum.fov) / 2);
Point3d eye = getEye();
eye.scaledAdd(d, zdir, myViewState.myCenter);
setEye(eye);
double far = 40 * r;
double near = far / 1000;
setOrthogonal(2 * r, near, far);
setGridSizeAndPosition(pcenter, r);
if (isVisible()) {
rerender();
}
}
}
use of maspack.matrix.Vector3d 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;
}
Aggregations