use of artisynth.core.modelbase.HasCoordinateFrame in project artisynth_core by artisynth.
the class Main method computeDraggerToWorld.
protected double computeDraggerToWorld(RigidTransform3d TDW, List<ModelComponent> draggables, Dragger3dBase dragger) {
double radius = 0;
if (dragger != null) {
TDW.set(dragger.getDraggerToWorld());
}
HasCoordinateFrame singleCompWithFrame = null;
if (draggables.size() == 1 && draggables.get(0) instanceof HasCoordinateFrame) {
singleCompWithFrame = (HasCoordinateFrame) draggables.get(0);
}
Point3d pmin = null;
Point3d pmax = null;
if (dragger == null || singleCompWithFrame == null) {
// need to compute bounds if there is no dragger (to determine
// radius), or if there is no single component with a frame (to
// determine the transform).
pmin = new Point3d(inf, inf, inf);
pmax = new Point3d(-inf, -inf, -inf);
for (ModelComponent c : draggables) {
((Renderable) c).updateBounds(pmin, pmax);
}
radius = pmin.distance(pmax);
}
if (singleCompWithFrame != null) {
singleCompWithFrame.getPose(TDW);
if (dragger == null && getInitDraggersInWorldCoords()) {
TDW.R.setIdentity();
}
} else {
TDW.p.add(pmin, pmax);
TDW.p.scale(0.5);
}
return radius;
}
use of artisynth.core.modelbase.HasCoordinateFrame in project artisynth_core by artisynth.
the class Main method centerViewOnSelection.
void centerViewOnSelection() {
Point3d center = new Point3d();
Point3d pmin = new Point3d(inf, inf, inf);
Point3d pmax = new Point3d(-inf, -inf, -inf);
int n = 0;
ModelComponent firstComp = null;
for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
if (sel instanceof Renderable && !ComponentUtils.isAncestorSelected(sel)) {
if (firstComp == null) {
firstComp = sel;
}
((Renderable) sel).updateBounds(pmin, pmax);
n++;
}
}
if (n > 0) {
if (n == 1 && firstComp instanceof HasCoordinateFrame) {
RigidTransform3d X = new RigidTransform3d();
((HasCoordinateFrame) firstComp).getPose(X);
center.set(X.p);
} else {
center.add(pmin, pmax);
center.scale(0.5);
}
myViewer.setCenter(center);
rerender();
}
}
Aggregations