use of maspack.matrix.Line in project artisynth_core by artisynth.
the class ConstrainedTranslator3d method checkComponentSelection.
private boolean checkComponentSelection(Line ray, double distancePerPixel) {
Line draggerRay = new Line(ray);
draggerRay.inverseTransform(myXDraggerToWorld);
double lineDist = 5 * distancePerPixel;
double l;
Point3d p = new Point3d();
// check axes first
l = xAxis.nearestPoint(p, draggerRay);
if (l >= -mySize && l <= mySize) {
if (draggerRay.distance(p) < lineDist) {
return true;
}
}
l = yAxis.nearestPoint(p, draggerRay);
if (l >= -mySize && l <= mySize) {
if (draggerRay.distance(p) < lineDist) {
return true;
}
}
l = zAxis.nearestPoint(p, draggerRay);
if (l >= -mySize && l <= mySize) {
if (draggerRay.distance(p) < lineDist) {
return true;
}
}
return false;
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class MouseRayEvent method create.
public static MouseRayEvent create(MouseEvent e, GLViewer viewer) {
MouseRayEvent de = new MouseRayEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(), e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger());
de.myScreenWidth = viewer.getScreenWidth();
de.myScreenHeight = viewer.getScreenHeight();
double vph = viewer.getViewPlaneHeight();
double vpw = viewer.getViewPlaneWidth();
de.myViewPlaneHeight = vph;
de.myViewPlaneWidth = vpw;
de.myViewPlaneDistance = viewer.getViewPlaneDistance();
// vx and vy give the current cursor location in the viewplane
double vx = vpw * (-0.5 + de.getX() / (double) de.myScreenWidth);
double vy = vph * (0.5 - de.getY() / (double) de.myScreenHeight);
if (viewer.isOrthogonal()) {
de.myRay = new Line(vx, vy, de.myViewPlaneDistance, 0, 0, -1);
} else {
de.myRay = new Line(0, 0, 0, vx, vy, -de.myViewPlaneDistance);
}
RigidTransform3d XWorldToBase = new RigidTransform3d();
viewer.getViewMatrix(XWorldToBase);
de.myRay.inverseTransform(XWorldToBase);
de.myViewer = viewer;
return de;
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class Transrotator3d method intersectRayAndFixture.
protected void intersectRayAndFixture(Point3d p, Line ray) {
Line draggerRay = new Line(ray);
draggerRay.inverseTransform(myXDraggerToWorld);
switch(mySelectedComponent) {
case X_AXIS:
{
xAxis.nearestPoint(p, draggerRay);
p.y = p.z = 0;
break;
}
case Y_AXIS:
{
yAxis.nearestPoint(p, draggerRay);
p.x = p.z = 0;
break;
}
case Z_AXIS:
{
zAxis.nearestPoint(p, draggerRay);
p.x = p.y = 0;
break;
}
case XY_PLANE:
{
draggerRay.intersectPlane(p, xyPlane);
p.z = 0;
break;
}
case YZ_PLANE:
{
draggerRay.intersectPlane(p, yzPlane);
p.x = 0;
break;
}
case ZX_PLANE:
{
draggerRay.intersectPlane(p, zxPlane);
p.y = 0;
break;
}
default:
{
throw new InternalErrorException("unexpected case " + mySelectedComponent);
}
}
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class RigidBodyConnectorList method handleLocationEvent.
@Override
public void handleLocationEvent(GLViewer viewer, MouseRayEvent rayEvent) {
Point3d origin = new Point3d();
Line ray = rayEvent.getRay();
ray.nearestPoint(origin, myBodyA.getPose().p);
System.out.println("origin=" + origin);
createAndAddConnector(origin);
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class Jack3d method checkComponentSelection.
private int checkComponentSelection(MouseRayEvent e) {
Line draggerRay = new Line(e.getRay());
draggerRay.inverseTransform(myXDraggerToWorld);
// double distancePerPixel = e.distancePerPixel (myXDraggerToWorld.p);
// double lineDist = 5*distancePerPixel; // was 0.05*mySize
double lineDist = 5 * e.distancePerPixel(myXDraggerToWorld.p);
double minDist = Double.POSITIVE_INFINITY;
double l, d, tempDist;
int resultAxisOrPlane = NONE;
RigidTransform3d draggerToEye = new RigidTransform3d();
draggerToEye.mul(e.getViewer().getViewMatrix(), myXDraggerToWorld);
// Line resultAxis = new Line (0, 0, 0, 0, 0, 0);
Point3d p = new Point3d();
// check axes first
l = xAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= -mySize && l <= mySize && tempDist < lineDist) {
resultAxisOrPlane = X_AXIS;
minDist = tempDist;
}
l = yAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= -mySize && l <= mySize && tempDist < lineDist && tempDist < minDist) {
resultAxisOrPlane = Y_AXIS;
minDist = tempDist;
}
l = zAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= -mySize && l <= mySize && tempDist < lineDist && tempDist < minDist) {
resultAxisOrPlane = Z_AXIS;
minDist = tempDist;
}
if (resultAxisOrPlane != NONE) {
return resultAxisOrPlane;
}
// now check rotators, and if there is any that are selected and
// closer to the mouse than any of the axes, then select it.
double len = mySize;
d = draggerRay.intersectPlane(p, yzPlane);
tempDist = Math.abs(p.norm() - mySize);
if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
resultAxisOrPlane = X_ROTATE;
minDist = tempDist;
}
d = draggerRay.intersectPlane(p, zxPlane);
tempDist = Math.abs(p.norm() - mySize);
if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
resultAxisOrPlane = Y_ROTATE;
minDist = tempDist;
}
d = draggerRay.intersectPlane(p, xyPlane);
tempDist = Math.abs(p.norm() - mySize);
if (rotationSelectCheck(d, tempDist, lineDist, minDist)) {
resultAxisOrPlane = Z_ROTATE;
}
// return the axis or rotator that the mouse is closest to.
if (resultAxisOrPlane != NONE) {
return resultAxisOrPlane;
}
return resultAxisOrPlane;
}
Aggregations