/** * Constructs a constrained mouse. * @param localToPixel the transform from local to pixel coordinates. */ public MouseConstrained(Matrix44 localToPixel) { //_localToPixel = new Matrix44(localToPixel); _pixelToLocal = localToPixel.inverse(); }
/** * Transforms this plane, given the specified transform matrix. * If the inverse of the transform matrix is known, the method * {@link #transformWithInverse(Matrix44)} is more efficient. * <p> * Let M denote the matrix that transforms points p from old to new * coordinates; i.e., p' = M*p, where p' denotes a transformed point. * In old coordinates, the plane P = (a,b,c,d) satisfies the equation * a*x + b*y + c*z + d = 0, for all points p = (x,y,z) within the plane. * This method returns a new transformed plane P' = (a',b',c',d') that * satisfies the equation a'*x' + b'*y' + c'*z' + d' = 0 for all * transformed points p' = (x',y',z') within the transformed plane. * @param m the transform matrix. */ public void transform(Matrix44 m) { transformWithInverse(m.inverse()); }
/** * Constructs a drag context for the specified pick result. * @param pr the pick result. */ public DragContext(PickResult pr) { _event = pr.getMouseEvent(); _canvas = pr.getViewCanvas(); _view = pr.getView(); _world = pr.getWorld(); _pointLocal = pr.getPointLocal(); _pointWorld = pr.getPointWorld(); _pointPixel = pr.getPointPixel(); _localToWorld = pr.getLocalToWorld(); _localToPixel = pr.getLocalToPixel(); _worldToPixel = pr.getWorldToPixel(); _pixelToLocal = _localToPixel.inverse(); _pixelToWorld = _worldToPixel.inverse(); }
/** * Saves the local-to-world transform before appending a transform. * The specified transform matrix is post-multiplied with the current * local-to-world transform, such that the specified transform is applied * first when transforming local coordinates to world coordinates. * @param transform the transform to append. */ public void pushLocalToWorld(Matrix44 transform) { super.pushLocalToWorld(transform); _pickSegmentStack.push(new Segment(_pickSegment)); _pickSegment.transform(transform.inverse()); _nearPoint = _pickSegment.getA(); _farPoint = _pickSegment.getB(); }
private void beginTranslate(MouseEvent e) { _xmouse = e.getX(); _ymouse = e.getY(); _canvas = (ViewCanvas)e.getSource(); _canvas.addMouseMotionListener(_mml); _view = (OrbitView)_canvas.getView(); // The mouse z coordinate, read from the depth buffer. The value 1.0 // corresponds to the far clipping plane, which indicates that the // mouse was not pressed on any object rendered into the z-buffer. // In this case, we use the middle value pixel z value 0.5. _zmouse = _canvas.getPixelZ(_xmouse,_ymouse); if (_zmouse==1.0) _zmouse = 0.5; // Pixel-to-unit-sphere transform. Matrix44 cubeToPixel = _canvas.getCubeToPixel(); Matrix44 viewToCube = _canvas.getViewToCube(); Matrix44 viewToPixel = cubeToPixel.times(viewToCube); Matrix44 unitSphereToView = _view.getUnitSphereToView(); Matrix44 unitSphereToPixel = viewToPixel.times(unitSphereToView); Matrix44 pixelToUnitSphere = unitSphereToPixel.inverse(); // The current translate vector. _translate = _view.getTranslate(); // The matrix inverse of the unit-sphere-to-pixel transform, but // with the current translate part removed, because that is the // part that we will change during translate. _translateM = Matrix44.translate(_translate).times(pixelToUnitSphere); // The transformed 3-D pixel (mouse) coordinates. _translateP = _translateM.times(new Point3(_xmouse,_ymouse,_zmouse)); }
/** * Computes the transform matrix for this handle in the specified context. * The context is view-dependent, as is the computed transform matrix. * This matrix includes the view-dependent scaling required for the * handle to have the correct size in pixels. * @param tc the transform context. * @return the transform matrix for this handle. */ private Matrix44 computeTransform(TransformContext tc) { View view = tc.getView(); Tuple3 as = view.getAxesScale(); Matrix44 localToPixel = tc.getLocalToPixel().times(_transform); Matrix44 pixelToLocal = localToPixel.inverse(); Point3 p = new Point3(0.0,0.0,0.0); Point3 q = localToPixel.times(p); q.x += getSize(); q = pixelToLocal.times(q); double dx = (q.x-p.x)*as.x; double dy = (q.y-p.y)*as.y; double dz = (q.z-p.z)*as.z; double d = Math.sqrt(dx*dx+dy*dy+dz*dz); double r = _boundingSphereChildren.getRadius(); double s = d/r; double sx = s/as.x; double sy = s/as.y; double sz = s/as.z; return _transform.times(Matrix44.scale(sx,sy,sz)); } }
Matrix44 unitSphereToView = _view.getUnitSphereToView(); Matrix44 unitSphereToCube = viewToCube.times(unitSphereToView); Matrix44 cubeToUnitSphere = unitSphereToCube.inverse(); Vector3 translate = view.getTranslate(); Matrix44 m = Matrix44.translate(translate).times(cubeToUnitSphere);
public void testMatrix() { int ntrial = 10; for (int itrial=0; itrial<ntrial; ++itrial) { Matrix44 i = Matrix44.identity(); Matrix44 a = randomMatrix44(); Matrix44 at = a.transpose(); assertEquals(a,at.transpose()); Matrix44 ai = a.inverse(); assertEquals(a,ai.inverse()); assertEquals(i,a.times(ai)); assertEquals(i,a.transpose().timesTranspose(ai)); assertEquals(i,a.transposeTimes(ai.transpose())); Matrix44 ac = new Matrix44(a); assertEquals(i,ac.timesEquals(ai)); ac = new Matrix44(a); assertEquals(i,ac.transposeEquals().timesTranspose(ai)); ac = new Matrix44(a); assertEquals(i,ac.transposeTimesEquals(ai.transpose())); } }