/** * Gets the cube-to-pixel transform. * @return the cube-to-pixel transform. */ public Matrix44 getCubeToPixel() { return new Matrix44(_cubeToPixel); }
/** * Constructs a constrained mouse. * @param localToPixel the transform from local to pixel coordinates. */ public MouseConstrained(Matrix44 localToPixel) { //_localToPixel = new Matrix44(localToPixel); _pixelToLocal = localToPixel.inverse(); }
/** * Updates this drag context for the specified mouse event. Updates the * current mouse event and the current point's local, world, and pixel * coordinates. Mouse motion listeners call this method as the mouse is * dragged. * @param event the mouse event. */ public void update(MouseEvent event) { _event = event; _pointPixel.x = event.getX(); _pointPixel.y = event.getY(); _pointLocal = _pixelToLocal.times(_pointPixel); _pointWorld = _pixelToWorld.times(_pointPixel); }
/** * Returns a new translation matrix. * @param tv the translation vector. * @return the translation matrix. */ public static Matrix44 translate(Vector3 tv) { return (new Matrix44()).setTranslate(tv); }
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())); } }
Matrix44 cubeToPixel = Matrix44.identity(); cubeToPixel.timesEquals(Matrix44.translate(0.5*w,0.5*h,0.5)); cubeToPixel.timesEquals(Matrix44.scale(0.5*w,-0.5*h,0.5)); canvas.setCubeToPixel(cubeToPixel); double znear = max(d-maxscale*r,0.1); double zfar = max(d+maxscale*r,100.0*znear); viewToCube = Matrix44.perspective(fovy,aspect,znear,zfar); distance = d; } else { double znear = 0.0; double zfar = 2.0*maxscale*r; viewToCube = Matrix44.ortho(left,right,bottom,top,znear,zfar); distance = d; _unitSphereToView = Matrix44.identity(); _unitSphereToView.timesEquals(Matrix44.translate(0,0,-distance)); _unitSphereToView.timesEquals(Matrix44.rotateX(_elevation)); _unitSphereToView.timesEquals(Matrix44.rotateY(-_azimuth)); _unitSphereToView.timesEquals(Matrix44.scale(_scale,_scale,_scale)); _unitSphereToView.timesEquals(Matrix44.translate(_translate)); _worldToUnitSphere = Matrix44.identity(); World world = getWorld(); if (world!=null) { double sz = s*as.z; if (ao==AxesOrientation.XRIGHT_YUP_ZOUT) {
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)); } }
public void testMatrixVector() { int ntrial = 10; for (int itrial=0; itrial<ntrial; ++itrial) { Vector3 v = randomVector3(); Matrix44 a = randomMatrix33(); Matrix44 ata = a.transposeTimes(a); assertEquals(ata.times(v),a.transposeTimes(a.times(v))); Matrix44 aat = a.timesTranspose(a); assertEquals(aat.times(v),a.times(a.transposeTimes(v))); } }
/** * 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) { _localToWorldStack.push(new Matrix44(_localToWorld)); _localToWorld.timesEquals(transform); }
/** * Gets the view-to-pixel transform. * @return the view-to-pixel transform. */ public Matrix44 getViewToPixel() { return getCubeToPixel().timesEquals(_viewToCube); }
/** * Returns a new rotation matrix. * The rotation is about a specified vector axis. * @param ra the angle of rotation, in degrees. * @param rv the vector axis of rotation. * @return the rotation matrix. */ public static Matrix44 rotate(double ra, Vector3 rv) { return (new Matrix44()).setRotate(ra,rv); }
/** * Returns a new rotation matrix. * The rotation is about the z axis. * @param ra the angle of rotation, in degrees. * @return the rotation matrix. */ public static Matrix44 rotateZ(double ra) { return (new Matrix44()).setRotateZ(ra); }
/** * Returns a new scaling matrix. * @param sx the x component of the scaling. * @param sy the y component of the scaling. * @param sz the z component of the scaling. * @return the scaling matrix. */ public static Matrix44 scale(double sx, double sy, double sz) { return (new Matrix44()).setScale(sx,sy,sz); }
/** * Returns a new rotation matrix. * The rotation is about the x axis. * @param ra the angle of rotation, in degrees. * @return the rotation matrix. */ public static Matrix44 rotateX(double ra) { return (new Matrix44()).setRotateX(ra); }
/** * Returns a new rotation matrix. * The rotation is about the y axis. * @param ra the angle of rotation, in degrees. * @return the rotation matrix. */ public static Matrix44 rotateY(double ra) { return (new Matrix44()).setRotateY(ra); }