/** * 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); }
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))); } }
setWorldToView(_unitSphereToView.times(_worldToUnitSphere));
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())); } }
public void testMatrixPoint() { int ntrial = 10; for (int itrial=0; itrial<ntrial; ++itrial) { Matrix44 a,ata,aat; a = randomMatrix33(); ata = a.transposeTimes(a); aat = a.timesTranspose(a); Point3 p3 = randomPoint3(); assertEquals(ata.times(p3),a.transposeTimes(a.times(p3))); assertEquals(aat.times(p3),a.times(a.transposeTimes(p3))); a = randomMatrix44(); ata = a.transposeTimes(a); aat = a.timesTranspose(a); Point4 p4 = randomPoint4(); assertEquals(ata.times(p4),a.transposeTimes(a.times(p4))); assertEquals(aat.times(p4),a.times(a.transposeTimes(p4))); } }
/** * Gets the view-independent location of the center of this handle. * @return the center point. */ public Point3 getLocation() { return _transform.times(new Point3()); }
/** * Gets a line segment in local coordinates for the specified event. * The endpoints A and B of the line segment lie on the near and far * clipping planes, respectively. * @param event the mouse event. * @return the line segment. */ protected Segment getMouseSegment(MouseEvent event) { int x = event.getX(); int y = event.getY(); Point3 near = new Point3(x,y,0); Point3 far = new Point3(x,y,1); near = _pixelToLocal.times(near); far = _pixelToLocal.times(far); return new Segment(near,far); }
private void duringTranslate(MouseEvent e) { int x = e.getX(); int y = e.getY(); Point3 p = new Point3(x,y,_zmouse); Vector3 t = _translate.plus(_translateM.times(p).minus(_translateP)); _view.setTranslate(t); }
/** * 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)); } }
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)); }
/** * Constructs a new pick result in the specified context. * @param pc the pick context. * @param point the picked point, in local coordinates. */ public PickResult(PickContext pc, Point3 point) { _event = pc.getMouseEvent(); _nodes = pc.getNodes(); _localToWorld = pc.getLocalToWorld(); _localToPixel = pc.getLocalToPixel(); _worldToPixel = pc.getWorldToPixel(); _pointLocal = new Point3(point); _pointWorld = _localToWorld.times(point); _pointPixel = _localToPixel.times(point); _depthPixel = _pointPixel.z; }
protected void draw(DrawContext dc) { Matrix44 localToPixel = dc.getLocalToPixel(); Point3 p = localToPixel.times(new Point3(0,0,0)); int w = dc.getViewCanvas().getWidth(); int h = dc.getViewCanvas().getHeight();
Matrix44 viewToCube = _canvas.getViewToCube(); Matrix44 unitSphereToView = _view.getUnitSphereToView(); Matrix44 unitSphereToCube = viewToCube.times(unitSphereToView); Matrix44 cubeToUnitSphere = unitSphereToCube.inverse(); Vector3 translate = view.getTranslate(); Matrix44 m = Matrix44.translate(translate).times(cubeToUnitSphere); double xc = 0.0; double yc = 0.0; translate.plusEquals(m.times(c2).minus(m.times(c1))); view.setTranslate(translate);