/* */ package com.sun.j3d.utils.picking;
/* */
/* */ import java.awt.event.MouseEvent;
/* */ import javax.media.j3d.BranchGroup;
/* */ import javax.media.j3d.Canvas3D;
/* */ import javax.media.j3d.Locale;
/* */ import javax.media.j3d.PickConeRay;
/* */ import javax.media.j3d.PickCylinderRay;
/* */ import javax.media.j3d.PickRay;
/* */ import javax.media.j3d.Transform3D;
/* */ import javax.media.j3d.View;
/* */ import javax.vecmath.Point3d;
/* */ import javax.vecmath.Vector3d;
/* */
/* */ public class PickCanvas extends PickTool
/* */ {
/* */ Canvas3D canvas;
/* 85 */ float tolerance = 2.0F;
/* */ int save_xpos;
/* */ int save_ypos;
/* */
/* */ public PickCanvas(Canvas3D c, BranchGroup b)
/* */ {
/* 92 */ super(b);
/* 93 */ this.canvas = c;
/* */ }
/* */
/* */ public PickCanvas(Canvas3D c, Locale l)
/* */ {
/* 99 */ super(l);
/* 100 */ this.canvas = c;
/* */ }
/* */
/* */ public Canvas3D getCanvas()
/* */ {
/* 107 */ return this.canvas;
/* */ }
/* */
/* */ public void setTolerance(float t)
/* */ {
/* 117 */ if (t < 0.0F) {
/* 118 */ throw new IllegalArgumentException();
/* */ }
/* 120 */ this.tolerance = t;
/* */
/* 122 */ if ((this.pickShape != null) && (!this.userDefineShape))
/* */ {
/* 124 */ this.pickShape = null;
/* 125 */ setShapeLocation(this.save_xpos, this.save_ypos);
/* */ }
/* */ }
/* */
/* */ public float getTolerance()
/* */ {
/* 132 */ return this.tolerance;
/* */ }
/* */
/* */ public void setShapeLocation(MouseEvent mevent)
/* */ {
/* 140 */ setShapeLocation(mevent.getX(), mevent.getY());
/* */ }
/* */
/* */ public void setShapeLocation(int xpos, int ypos)
/* */ {
/* 148 */ Transform3D motion = new Transform3D();
/* 149 */ Point3d eyePosn = new Point3d();
/* 150 */ Point3d mousePosn = new Point3d();
/* 151 */ Vector3d mouseVec = new Vector3d();
/* 152 */ boolean isParallel = false;
/* 153 */ double radius = 0.0D;
/* 154 */ double spreadAngle = 0.0D;
/* */
/* 156 */ this.save_xpos = xpos;
/* 157 */ this.save_ypos = ypos;
/* 158 */ this.canvas.getCenterEyeInImagePlate(eyePosn);
/* 159 */ this.canvas.getPixelLocationInImagePlate(xpos, ypos, mousePosn);
/* */
/* 161 */ if ((this.canvas.getView() != null) && (this.canvas.getView().getProjectionPolicy() == 0))
/* */ {
/* 167 */ eyePosn.x = mousePosn.x;
/* 168 */ eyePosn.y = mousePosn.y;
/* 169 */ isParallel = true;
/* */ }
/* */
/* 173 */ Vector3d eyeToCanvas = new Vector3d();
/* 174 */ eyeToCanvas.sub(mousePosn, eyePosn);
/* 175 */ double distanceEyeToCanvas = eyeToCanvas.length();
/* */
/* 177 */ Point3d deltaImgPlate = new Point3d();
/* 178 */ this.canvas.getPixelLocationInImagePlate(xpos + 1, ypos, deltaImgPlate);
/* */
/* 180 */ Vector3d ptToDelta = new Vector3d();
/* 181 */ ptToDelta.sub(mousePosn, deltaImgPlate);
/* 182 */ double distancePtToDelta = ptToDelta.length();
/* 183 */ distancePtToDelta *= this.tolerance;
/* */
/* 185 */ this.canvas.getImagePlateToVworld(motion);
/* */
/* 192 */ motion.transform(eyePosn);
/* 193 */ this.start = new Point3d(eyePosn);
/* 194 */ motion.transform(mousePosn);
/* 195 */ mouseVec.sub(mousePosn, eyePosn);
/* 196 */ mouseVec.normalize();
/* */
/* 204 */ if (this.tolerance == 0.0D) {
/* 205 */ if ((this.pickShape != null) && ((this.pickShape instanceof PickRay)))
/* 206 */ ((PickRay)this.pickShape).set(eyePosn, mouseVec);
/* */ else {
/* 208 */ this.pickShape = new PickRay(eyePosn, mouseVec);
/* */ }
/* */
/* */ }
/* 213 */ else if (isParallel)
/* */ {
/* 215 */ distancePtToDelta *= motion.getScale();
/* 216 */ if ((this.pickShape != null) && ((this.pickShape instanceof PickCylinderRay)))
/* */ {
/* 218 */ ((PickCylinderRay)this.pickShape).set(eyePosn, mouseVec, distancePtToDelta);
/* */ }
/* */ else {
/* 221 */ this.pickShape = new PickCylinderRay(eyePosn, mouseVec, distancePtToDelta);
/* */ }
/* */
/* */ }
/* */ else
/* */ {
/* 228 */ spreadAngle = Math.atan(distancePtToDelta / distanceEyeToCanvas);
/* */
/* 230 */ if ((this.pickShape != null) && ((this.pickShape instanceof PickConeRay)))
/* */ {
/* 232 */ ((PickConeRay)this.pickShape).set(eyePosn, mouseVec, spreadAngle);
/* */ }
/* */ else
/* 235 */ this.pickShape = new PickConeRay(eyePosn, mouseVec, spreadAngle);
/* */ }
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.utils.picking.PickCanvas
* JD-Core Version: 0.6.2
*/