use of maspack.matrix.Line in project artisynth_core by artisynth.
the class Jack3d method intersectRayAndFixture.
private void intersectRayAndFixture(Point3d p, Line ray) {
Line draggerRay = new Line(ray);
draggerRay.inverseTransform(myXDraggerToWorld);
switch(mySelectedComponent) {
case X_AXIS:
{
double l = 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 Z_ROTATE:
{
draggerRay.intersectPlane(p, xyPlane);
p.z = 0;
break;
}
case X_ROTATE:
{
draggerRay.intersectPlane(p, yzPlane);
p.x = 0;
break;
}
case Y_ROTATE:
{
draggerRay.intersectPlane(p, zxPlane);
p.y = 0;
break;
}
default:
{
throw new InternalErrorException("unexpected case");
}
}
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class Translator3d method intersectRayAndFixture.
private void intersectRayAndFixture(Point3d p, Line ray) {
Line draggerRay = new Line(ray);
draggerRay.inverseTransform(myXDraggerToWorld);
switch(mySelectedComponent) {
case X_AXIS:
{
double l = 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 Translator3d 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 >= 0 && l <= mySize && tempDist < lineDist) {
resultAxisOrPlane = X_AXIS;
minDist = tempDist;
}
l = yAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= 0 && l <= mySize && tempDist < lineDist && tempDist < minDist) {
resultAxisOrPlane = Y_AXIS;
minDist = tempDist;
}
l = zAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= 0 && l <= mySize && tempDist < lineDist && tempDist < minDist) {
resultAxisOrPlane = Z_AXIS;
minDist = tempDist;
}
if (resultAxisOrPlane != NONE) {
return resultAxisOrPlane;
}
// now check if the mouse is on any of the planes. If true,
// then return the selected plane closest to the user.
double len = myPlaneBoxRelativeSize * mySize;
minDist = inf;
d = draggerRay.intersectPlane(p, xyPlane);
if (d != inf && p.x >= 0 && p.x <= len && p.y >= 0 && p.y <= len) {
p.transform(draggerToEye);
resultAxisOrPlane = XY_PLANE;
minDist = p.z;
}
d = draggerRay.intersectPlane(p, yzPlane);
if (d != inf && p.y >= 0 && p.y <= len && p.z >= 0 && p.z <= len) {
p.transform(draggerToEye);
if (p.z < minDist) {
resultAxisOrPlane = YZ_PLANE;
minDist = p.z;
}
}
d = draggerRay.intersectPlane(p, zxPlane);
if (d != inf && p.z >= 0 && p.z <= len && p.x >= 0 && p.x <= len) {
p.transform(draggerToEye);
if (p.z < minDist) {
resultAxisOrPlane = ZX_PLANE;
}
}
return resultAxisOrPlane;
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class Transrotator3d method findRotation.
/**
* Given a ray intersecting one of the rotational dragger components, find
* the intersection point p on the component (in dragger coordinates),
* along with the corresponding rotation R.
*/
protected void findRotation(RotationMatrix3d R, Point3d p, Line ray) {
Line draggerRay = new Line(ray);
draggerRay.inverseTransform(myXDraggerToWorld0);
switch(mySelectedComponent) {
case X_ROTATE:
{
draggerRay.intersectPlane(p, yzPlane);
R.setAxisAngle(xAxis.getDirection(), Math.atan2(p.z, p.y));
break;
}
case Y_ROTATE:
{
draggerRay.intersectPlane(p, zxPlane);
R.setAxisAngle(yAxis.getDirection(), Math.atan2(p.x, p.z));
break;
}
case Z_ROTATE:
{
draggerRay.intersectPlane(p, xyPlane);
R.setAxisAngle(zAxis.getDirection(), Math.atan2(p.y, p.x));
break;
}
default:
{
throw new InternalErrorException("unexpected case " + mySelectedComponent);
}
}
double mag = p.norm();
if (mag != 0) {
p.scale(myRotatorRelativeSize * mySize / mag);
}
}
use of maspack.matrix.Line in project artisynth_core by artisynth.
the class Transrotator3d method checkComponentSelection.
private int checkComponentSelection(MouseRayEvent e) {
double distancePerPixel = e.distancePerPixel(myXDraggerToWorld.p);
Line draggerRay = new Line(e.getRay());
draggerRay.inverseTransform(myXDraggerToWorld);
// was 0.05*mySize
double lineDist = 5 * distancePerPixel;
double minDist = Double.POSITIVE_INFINITY;
double l, d, tempDist;
int resultAxisOrPlane = NONE;
RigidTransform3d draggerToEye = new RigidTransform3d();
draggerToEye.mul(e.getViewer().getViewMatrix(), myXDraggerToWorld);
Point3d p = new Point3d();
// First find the axis the mouse is within the bounds of. When within
// multiple bounds, select the axis that the mouse is closest to.
l = xAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= 0 && l <= mySize && tempDist < lineDist) {
resultAxisOrPlane = X_AXIS;
minDist = tempDist;
}
l = yAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= 0 && l <= mySize && tempDist < lineDist && tempDist < minDist) {
resultAxisOrPlane = Y_AXIS;
minDist = tempDist;
}
l = zAxis.nearestPoint(p, draggerRay);
tempDist = draggerRay.distance(p);
if (l >= 0 && l <= mySize && tempDist < lineDist && tempDist < minDist) {
resultAxisOrPlane = Z_AXIS;
minDist = tempDist;
}
// 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 = myRotatorRelativeSize * mySize;
d = draggerRay.intersectPlane(p, yzPlane);
tempDist = Math.abs(p.norm() - len);
if (rotationSelectCheck(d, tempDist, minDist, lineDist) && p.y >= 0 && p.z >= 0) {
resultAxisOrPlane = X_ROTATE;
minDist = tempDist;
}
d = draggerRay.intersectPlane(p, zxPlane);
tempDist = Math.abs(p.norm() - len);
if (rotationSelectCheck(d, tempDist, minDist, lineDist) && p.x >= 0 && p.z >= 0) {
resultAxisOrPlane = Y_ROTATE;
minDist = tempDist;
}
d = draggerRay.intersectPlane(p, xyPlane);
tempDist = Math.abs(p.norm() - len);
if (rotationSelectCheck(d, tempDist, minDist, lineDist) && p.x >= 0 && p.y >= 0) {
resultAxisOrPlane = Z_ROTATE;
minDist = tempDist;
}
// return the axis or rotator that the mouse is closest to.
if (resultAxisOrPlane != NONE) {
return resultAxisOrPlane;
}
// now check if the mouse is on any of the planes. If true,
// then return the selected plane closest to the user.
len = myPlaneBoxRelativeSize * mySize;
minDist = Double.POSITIVE_INFINITY;
d = draggerRay.intersectPlane(p, xyPlane);
if (d != Double.POSITIVE_INFINITY && p.x >= 0 && p.x <= len && p.y >= 0 && p.y <= len) {
p.transform(draggerToEye);
resultAxisOrPlane = XY_PLANE;
minDist = p.z;
}
d = draggerRay.intersectPlane(p, yzPlane);
if (d != Double.POSITIVE_INFINITY && p.y >= 0 && p.y <= len && p.z >= 0 && p.z <= len) {
p.transform(draggerToEye);
if (p.z < minDist) {
resultAxisOrPlane = YZ_PLANE;
minDist = p.z;
}
}
d = draggerRay.intersectPlane(p, zxPlane);
if (d != Double.POSITIVE_INFINITY && p.z >= 0 && p.z <= len && p.x >= 0 && p.x <= len) {
p.transform(draggerToEye);
if (p.z < minDist) {
resultAxisOrPlane = ZX_PLANE;
}
}
return resultAxisOrPlane;
}
Aggregations