⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orbitbehavior.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		    // that behavior remains stable and not dependent on OS settings.		    // If getWheelRotation() was used for calculating the zoom, 		    // the zooming speed could act differently on different platforms, 		    // if, for example, the user sets his mouse wheel to jump 10 lines 		    // or a block.		    int zoom = 			((int)(((java.awt.event.MouseWheelEvent)evt).getWheelRotation() 			       * wheelZoomFactor));		    doZoomOperations( zoom );		    motion = true;		}	    }	}   }        /*extraction of the zoom algorithms so that there is no code duplication or source 'uglyfication'.     */    private void doZoomOperations( int ychange ) {	if (proportionalZoom) {	    if (reverseZoom) {		if ((distanceFromCenter -		     (zoomMul*ychange*distanceFromCenter/100.0)) >		    minRadius) {		    distanceFromCenter -= (zoomMul*ychange*					   distanceFromCenter/100.0);		}		else {		    distanceFromCenter = minRadius;		}			    	    }	    else {		if ((distanceFromCenter +		     (zoomMul*ychange*distanceFromCenter/100.0))		    > minRadius) {		    distanceFromCenter += (zoomMul*ychange*					   distanceFromCenter/100.0);		}		else {		    distanceFromCenter = minRadius;		}	    }	}	else {	    if (stopZoom) {		if (reverseZoom) {		    if ((distanceFromCenter - ychange*zoomMul) > minRadius) {			distanceFromCenter -= ychange*zoomMul;		    }		    else {			distanceFromCenter = minRadius;		    }		}		else {		    if ((distanceFromCenter + ychange*zoomMul) > minRadius) {			distanceFromCenter += ychange * zoomMul;		    }		    else {			distanceFromCenter = minRadius;		    }		}	    }	    else {		if (reverseZoom) {		    distanceFromCenter -= ychange*zoomMul;		}		else {		    distanceFromCenter += ychange*zoomMul;		}	    }	}    }						    /**     * Sets the ViewingPlatform for this behavior.  This method is     * called by the ViewingPlatform.     * If a sub-calls overrides this method, it must call     * super.setViewingPlatform(vp).     * NOTE: Applications should <i>not</i> call this method.         */    public void setViewingPlatform(ViewingPlatform vp) {        super.setViewingPlatform( vp );	if (vp!=null) {	    resetView();	    integrateTransforms();	}     }        /**     * Reset the orientation and distance of this behavior to the current     * values in the ViewPlatform Transform Group     */    private void resetView() {	Vector3d centerToView = new Vector3d();        targetTG.getTransform( targetTransform );        targetTransform.get( rotMatrix, transVector );        centerToView.sub( transVector, rotationCenter );        distanceFromCenter = centerToView.length();	startDistanceFromCenter = distanceFromCenter;        targetTransform.get( rotMatrix );        rotateTransform.set( rotMatrix );		// compute the initial x/y/z offset	temp1.set(centerToView);	rotateTransform.invert();	rotateTransform.mul(temp1);	rotateTransform.get(centerToView);	xtrans = centerToView.x;	ytrans = centerToView.y;	ztrans = centerToView.z;	// reset rotMatrix	rotateTransform.set( rotMatrix );    }        protected synchronized void integrateTransforms() {	// Check if the transform has been changed by another	// behavior	targetTG.getTransform(currentXfm) ;	if (! targetTransform.equals(currentXfm))	    resetView() ;            	longditudeTransform.rotY( longditude );            	latitudeTransform.rotX( latitude );	rotateTransform.mul(rotateTransform, latitudeTransform);	rotateTransform.mul(rotateTransform, longditudeTransform);	distanceVector.z = distanceFromCenter - startDistanceFromCenter;	temp1.set(distanceVector);	temp1.mul(rotateTransform, temp1);	// want to look at rotationCenter	transVector.x = rotationCenter.x + xtrans;	transVector.y = rotationCenter.y + ytrans;	transVector.z = rotationCenter.z + ztrans;	translation.set(transVector);	targetTransform.mul(temp1, translation);	// handle rotationCenter	temp1.set(centerVector);	temp1.mul(targetTransform);           	invertCenterVector.x = -centerVector.x;	invertCenterVector.y = -centerVector.y;	invertCenterVector.z = -centerVector.z;            	temp2.set(invertCenterVector);	targetTransform.mul(temp1, temp2);	targetTG.setTransform(targetTransform);	// reset yaw and pitch angles	longditude = 0.0;	latitude = 0.0;            }    /**     * Sets the center around which the View rotates.     * The default is (0,0,0).     * @param center The Point3d to set the center of rotation to     */    public synchronized void setRotationCenter(Point3d center) {	rotationCenter.x = center.x;	rotationCenter.y = center.y;	rotationCenter.z = center.z;	centerVector.set(rotationCenter);    }    /**     * Property which sets the center around which the View rotates.     * Used by ConfiguredUniverse.     * @param center array of length 1 containing an instance of Point3d     * @since Java 3D 1.3     */    public void RotationCenter(Object[] center) {	if (! (center.length == 1 && center[0] instanceof Point3d))	    throw new IllegalArgumentException		("RotationCenter must be a single Point3d");		setRotationCenter((Point3d)center[0]);    }        /**     * Places the value of the center around which the View rotates     * into the Point3d.     * @param center The Point3d     */    public void getRotationCenter(Point3d center) {	center.x = rotationCenter.x;	center.y = rotationCenter.y;	center.z = rotationCenter.z;    }    // TODO    // Need to add key factors for Rotate, Translate and Zoom    // Method calls should just update MAX_KEY_ANGLE, KEY_TRANSLATE and    // KEY_ZOOM    //    // Methods also need to correctly set sign of variables depending on    // the Reverse settings.        /**     * Sets the rotation x and y factors.  The factors are used to determine     * how many radians to rotate the view for each pixel of mouse movement.     * The view is rotated factor * 0.01 radians for each pixel of mouse     * movement.  The default factor is 1.0.     * @param xfactor The x movement multiplier     * @param yfactor The y movement multiplier     **/       public synchronized void setRotFactors(double xfactor, double yfactor) {	rotXFactor = xfactor;	rotYFactor = yfactor;	rotXMul = NOMINAL_ROT_FACTOR * xfactor;	rotYMul = NOMINAL_ROT_FACTOR * yfactor;    }    /**     * Property which sets the rotation x and y factors.     * Used by ConfiguredUniverse.     * @param factors array of length 2 containing instances of Double     * @since Java 3D 1.3     */    public void RotFactors(Object[] factors) {	if (! (factors.length == 2 &&	       factors[0] instanceof Double && factors[1] instanceof Double))	    throw new IllegalArgumentException		("RotFactors must be two Doubles");		setRotFactors(((Double)factors[0]).doubleValue(),		      ((Double)factors[1]).doubleValue());    }        /**     * Sets the rotation x factor.  The factors are used to determine     * how many radians to rotate the view for each pixel of mouse movement.     * The view is rotated factor * 0.01 radians for each pixel of mouse     * movement.  The default factor is 1.0.     * @param xfactor The x movement multiplier     **/       public synchronized void setRotXFactor(double xfactor) {	rotXFactor = xfactor;	rotXMul = NOMINAL_ROT_FACTOR * xfactor;    }    /**     * Property which sets the rotation x factor.     * Used by ConfiguredUniverse.     * @param xFactor array of length 1 containing instance of Double     * @since Java 3D 1.3     */    public void RotXFactor(Object[] xFactor) {	if (! (xFactor.length == 1 && xFactor[0] instanceof Double))	    throw new IllegalArgumentException("RotXFactor must be a Double");		setRotXFactor(((Double)xFactor[0]).doubleValue());    }        /**     * Sets the rotation y factor.  The factors are used to determine     * how many radians to rotate the view for each pixel of mouse movement.     * The view is rotated factor * 0.01 radians for each pixel of mouse     * movement.  The default factor is 1.0.     * @param yfactor The y movement multiplier     **/       public synchronized void setRotYFactor(double yfactor) {	rotYFactor = yfactor;	rotYMul = NOMINAL_ROT_FACTOR * yfactor;    }    /**     * Property which sets the rotation y factor.     * Used by ConfiguredUniverse.     * @param yFactor array of length 1 containing instance of Double     * @since Java 3D 1.3     */    public void RotYFactor(Object[] yFactor) {	if (! (yFactor.length == 1 && yFactor[0] instanceof Double))	    throw new IllegalArgumentException("RotYFactor must be a Double");		setRotYFactor(((Double)yFactor[0]).doubleValue());    }        /**     * Sets the translation x and y factors.  The factors are used to determine     * how many units to translate the view for each pixel of mouse movement.     * The view is translated factor * 0.01 units for each pixel of mouse     * movement.  The default factor is 1.0.     * @param xfactor The x movement multiplier     * @param yfactor The y movement multiplier     **/       public synchronized void setTransFactors(double xfactor,						 double yfactor) {	transXFactor = xfactor;	transYFactor = yfactor;	transXMul = NOMINAL_TRANS_FACTOR * xfactor;	transYMul = NOMINAL_TRANS_FACTOR * yfactor;    }    /**     * Property which sets the translation x and y factors.     * Used by ConfiguredUniverse.     * @param factors array of length 2 containing instances of Double     * @since Java 3D 1.3     */    public void TransFactors(Object[] factors) {	if (! (factors.length == 2 &&	       factors[0] instanceof Double && factors[1] instanceof Double))	    throw new IllegalArgumentException		("TransFactors must be two Doubles");		setTransFactors(((Double)factors[0]).doubleValue(),			((Double)factors[1]).doubleValue());    }        /**     * Sets the translation x factor.  The factors are used to determine     * how many units to translate the view for each pixel of mouse movement.     * The view is translated factor * 0.01 units for each pixel of mouse     * movement.  The default factor is 1.0.     * @param xfactor The x movement multiplier     **/       public synchronized void setTransXFactor(double xfactor) {	transXFactor = xfactor;	transXMul = NOMINAL_TRANS_FACTOR * xfactor;    }    /**     * Property which sets the translation x factor.     * Used by ConfiguredUniverse.     * @param xFactor array of length 1 containing instance of Double     * @since Java 3D 1.3     */    public void TransXFactor(Object[] xFactor) {	if (! (xFactor.length == 1 && xFactor[0] instanceof Double))	    throw new IllegalArgumentException("TransXFactor must be a Double");		setTransXFactor(((Double)xFactor[0]).doubleValue());    }        /**     * Sets the translation y factor.  The factors are used to determine     * how many units to translate the view for each pixel of mouse movement.     * The view is translated factor * 0.01 units for each pixel of mouse     * movement.  The default factor is 1.0.     * @param yfactor The y movement multiplier     **/       public synchronized void setTransYFactor(double yfactor) {	transYFactor = yfactor;	transYMul = NOMINAL_TRANS_FACTOR * yfactor;    }    /**     * Property which sets the translation y factor.     * Used by ConfiguredUniverse.     * @param yFactor array of length 1 containing instance of Double

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -