use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class MatricesUBO method putMatrix.
public static void putMatrix(ByteBuffer buff, AffineTransform3dBase T) {
Matrix3dBase M = T.getMatrix();
Vector3d b = T.getOffset();
buff.putFloat((float) M.m00);
buff.putFloat((float) M.m10);
buff.putFloat((float) M.m20);
buff.putFloat((float) 0);
buff.putFloat((float) M.m01);
buff.putFloat((float) M.m11);
buff.putFloat((float) M.m21);
buff.putFloat((float) 0);
buff.putFloat((float) M.m02);
buff.putFloat((float) M.m12);
buff.putFloat((float) M.m22);
buff.putFloat((float) 0);
buff.putFloat((float) b.x);
buff.putFloat((float) b.y);
buff.putFloat((float) b.z);
buff.putFloat((float) 1);
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class LineSegment method computeFocalPoint.
/**
* Given a plane expressed in eye coordinates, compute a representative focal
* point (in eye coordinates) for this plane, and return the distance
* per-pixal for this focal point. Returning -1 means that the plane is
* invisible.
*
* <p>
* The method works by finding the centroid of the (clipped) polygon
* associated with the grid boundary, as seen in screen coordinates. This
* centroid is the projected back onto the plane.
*/
private double computeFocalPoint(Point3d focus, RigidTransform3d TGW, Renderer renderer) {
RigidTransform3d XGridToEye = new RigidTransform3d();
RigidTransform3d TWorldToEye = renderer.getViewMatrix();
XGridToEye.mul(TWorldToEye, TGW);
if (focus == null) {
focus = new Point3d();
}
if (renderer.isOrthogonal()) {
Plane plane = new Plane();
plane.set(XGridToEye);
computeFocalPoint(focus, plane, 0, 0, 1);
return renderer.getViewPlaneWidth() / renderer.getScreenWidth();
}
double near = renderer.getViewPlaneDistance();
double far = renderer.getFarPlaneDistance();
double vw = renderer.getViewPlaneWidth();
double vh = renderer.getViewPlaneHeight();
// double fov = renderer.getFieldOfViewY();
int height = renderer.getScreenHeight();
double nearDistPerPixel = renderer.getViewPlaneHeight() / height;
GridCentroidComputer newComp = new GridCentroidComputer(myMinSize, near, far);
Point3d cent = new Point3d();
if (!newComp.computeCentroid(cent, XGridToEye, vw, vh)) {
return -1;
}
double zmax = newComp.getZmax();
double zmin = newComp.getZmin();
RotationMatrix3d R = XGridToEye.R;
Plane plane = new Plane(new Vector3d(R.m02, R.m12, R.m22), new Point3d(XGridToEye.p));
double s = plane.intersectLine(focus, cent, Point3d.ZERO);
if (s == Double.POSITIVE_INFINITY) {
focus.scale(-(zmin + zmax) / (2 * near), cent);
}
double zref = -focus.z;
return zref / near * nearDistPerPixel;
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class LineSegment method drawAxisLabels.
private void drawAxisLabels(Renderer renderer, int xcnt, int ycnt, double majorSize, int numDivisions, double pixelSize) {
double log10 = Math.log10(majorSize);
int exp = (int) Math.floor(log10);
int base = (int) Math.round(Math.pow(10, log10 - exp));
renderer.setColor(getEffectiveLabelColor());
// minimum indices of the major cell divisions along x and y.
// maximum indices are the negatives of these
int min_x_idx = -(xcnt - 1) / (2 * numDivisions);
int min_y_idx = -(ycnt - 1) / (2 * numDivisions);
// Find offset of grid center relative to viewer center. (These aren't
// necessarily the same because of the need to align grid with major
// divisions.)
Point3d goff = new Point3d(renderer.getCenter());
goff.inverseTransform(XGridToWorld);
double sw = renderer.getScreenWidth() * pixelSize;
double sh = renderer.getScreenHeight() * pixelSize;
// Find indices of major divsions along which to draw x and y axis
// labels. These are the lowest and leftmost divisions that are visible
// in the viewer, with an extra tolerance (0.25*majorSize) to allow room
// for the labels themselves.
int x_label_idx = Math.max(-(int) ((sh / 2 - goff.y) / majorSize - 0.25), min_y_idx);
int y_label_idx = Math.max(-(int) ((sw / 2 - goff.x) / majorSize - 0.25), min_x_idx);
double emSize = myLabelSize * pixelSize;
// Find cordinates at grid center
Point3d gcenter = new Point3d();
Vector3d axisDirs = new Vector3d(1, 1, 1);
if (myUseWorldOrigin) {
gcenter.inverseTransform(XGridToWorld.R, XGridToWorld.p);
axisDirs.inverseTransform(XGridToWorld.R, axisDirs);
}
if (myXAxisLabeling != AxisLabeling.OFF) {
Vector3d pos = new Vector3d();
double y = x_label_idx * majorSize - emSize;
int izero = (int) Math.round(-gcenter.x / majorSize);
int sgnx = axisDirs.x > 0 ? 1 : -1;
int x_min = Math.max(y_label_idx - 1, min_x_idx);
int x_max = Math.min((int) (x_min + sw / majorSize + 0.5), -min_x_idx);
for (int i = x_min; i <= x_max; i++) {
String label = createLabel(base, exp, sgnx * (i - izero));
pos.set(i * majorSize + 2 * pixelSize, y, 0);
renderer.drawText(label, pos, emSize);
}
}
if (myYAxisLabeling != AxisLabeling.OFF) {
Vector3d pos = new Vector3d();
double x = y_label_idx * majorSize - 2 * pixelSize;
int jzero = (int) Math.round(-gcenter.y / majorSize);
int sgny = axisDirs.y > 0 ? 1 : -1;
int y_min = Math.max(x_label_idx - 1, min_y_idx);
int y_max = Math.min((int) (y_min + sh / majorSize + 0.5), -min_y_idx);
for (int j = y_min; j <= y_max; j++) {
String label = createLabel(base, exp, sgny * (j - jzero));
Rectangle2D bounds = renderer.getTextBounds(renderer.getDefaultFont(), label, emSize);
double y = j * majorSize + 2 * pixelSize;
pos.set(x - bounds.getWidth(), y, 0);
renderer.drawText(label, pos, emSize);
}
}
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class LineSegment method intersectBoundary.
private void intersectBoundary(ConvexPoly2d poly, RigidTransform3d XGridToEye, double nx, double ny, double nz, double d) {
Plane plane = new Plane(nx, ny, nz, d);
if (XGridToEye != RigidTransform3d.IDENTITY) {
plane.inverseTransform(XGridToEye);
}
Vector3d u = new Vector3d();
Point3d p = new Point3d();
Plane polyPlane = new Plane(0, 0, 1, 0);
if (polyPlane.intersectPlane(p, u, plane)) {
poly.intersectHalfPlane(u.y, -u.x, p.x * u.y - p.y * u.x);
}
}
use of maspack.matrix.Vector3d in project artisynth_core by artisynth.
the class Jack3d method updatePosition.
private void updatePosition(Point3d p0, Point3d p1) {
Vector3d planeNormal = null;
switch(mySelectedComponent) {
case X_AXIS:
case Y_AXIS:
case Z_AXIS:
{
Vector3d del = new Vector3d();
del.sub(p1, p0);
myXDraggerToWorld.mulXyz(del.x, del.y, del.z);
break;
}
case Z_ROTATE:
{
planeNormal = xyPlane.getNormal();
break;
}
case X_ROTATE:
{
planeNormal = yzPlane.getNormal();
break;
}
case Y_ROTATE:
{
planeNormal = zxPlane.getNormal();
break;
}
}
if (planeNormal != null) {
Vector3d cross = new Vector3d();
cross.cross(p0, p1);
double ang = Math.asin(cross.norm() / (p0.norm() * p1.norm()));
if (cross.dot(planeNormal) < 0) {
ang = -ang;
}
myXDraggerToWorld.R.mulAxisAngle(planeNormal, ang);
}
}
Aggregations