📄 viewer.java
字号:
/* * $RCSfile: Viewer.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. * * $Revision: 1.9 $ * $Date: 2007/02/09 17:20:45 $ * $State: Exp $ */package com.sun.j3d.utils.universe;import java.awt.event.*;import java.awt.*;import java.net.URL;import java.util.*;import javax.media.j3d.*;import javax.swing.*;import com.sun.j3d.audioengines.AudioEngine3DL2;import java.lang.reflect.Constructor;/** * The Viewer class holds all the information that describes the physical * and virtual "presence" in the Java 3D universe. The Viewer object * consists of: * <UL> * <LI>Physical Objects</LI> * <UL> * <LI>Canvas3D's - used to render with.</LI> * <LI>PhysicalEnvironment - holds characteristics of the hardware platform * being used to render on.</LI> * <LI>PhysicalBody - holds the physical characteristics and personal * preferences of the person who will be viewing the Java 3D universe.</LI> * </UL> * <LI>Virtual Objects</LI> * <UL> * <LI>View - the Java 3D View object.</LI> * <LI>ViewerAvatar - the geometry that is used by Java 3D to represent the * person viewing the Java 3D universe.</LI> * </UL> * </UL> * If the Viewer object is created without any Canvas3D's, or indirectly * through a configuration file, it will create the Canvas3D's as needed. * The default Viewer creates one Canvas3D. If the Viewer object creates * the Canvas3D's, it will also create a JPanel and JFrame for each Canvas3D. * * Dynamic video resize is a new feature in Java 3D 1.3.1. * This feature provides a means for doing swap synchronous resizing * of the area that is to be magnified (or passed through) to the * output video resolution. This functionality allows an application * to draw into a smaller viewport in the framebuffer in order to reduce * the time spent doing pixel fill. The reduced size viewport is then * magnified up to the video output resolution using the SUN_video_resize * extension. This extension is only implemented in XVR-4000 and later * hardware with back end video out resizing capability. * * If video size compensation is enable, the line widths, point sizes and pixel * operations will be scaled internally with the resize factor to approximately * compensate for video resizing. The location of the pixel ( x, y ) in the * resized framebuffer = ( floor( x * factor + 0.5 ), floor( y * factor + 0.5 ) ) * * <p> * @see Canvas3D * @see PhysicalEnvironment * @see PhysicalBody * @see View * @see ViewerAvatar */public class Viewer { private static final boolean debug = false; private static PhysicalBody physicalBody = null; private static PhysicalEnvironment physicalEnvironment = null; private View view = null; private ViewerAvatar avatar = null; private Canvas3D[] canvases = null; private JFrame[] j3dJFrames = null; private JPanel[] j3dJPanels = null; private Window[] j3dWindows = null; private ViewingPlatform viewingPlatform = null; static HashMap viewerMap = new HashMap(5); private float dvrFactor = 1.0f; private boolean doDvr = false; private boolean doDvrResizeCompensation = true; /** * Get the Viewer associated with the view object. * * @param view The View object for inquiry. * @return The Viewer object associated with this View object. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public static Viewer getViewer(View view) { Viewer viewer = null; synchronized (viewerMap) { //System.out.println("Viewer.getViewer viewerMap's size is " + viewerMap.size()); viewer = (Viewer) (viewerMap.get(view)); } return viewer; } /** * Removes the entry associated with the view object. * * @param view The View object to be removed. * @return The Viewer object associated with this View object. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public static Viewer removeViewerMapEntry(View view) { Viewer viewer = null; synchronized (viewerMap) { viewer = (Viewer) (viewerMap.remove(view)); } // System.out.println("viewerMap.size() " + viewerMap.size()); return viewer; } /** * Removes all Viewer mappings from the Viewer map. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public static void clearViewerMap() { synchronized (viewerMap) { viewerMap.clear(); } // System.out.println("clearViewerMap - viewerMap.size() " + viewerMap.size()); } /** * Returns a status flag indicating whether or not dynamic video size * is enabled. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public boolean isDvrEnabled() { return doDvr; } /** * Turns on or off dynamic video size. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @param dvr enables or disables dynamic video size. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public void setDvrEnable(boolean dvr) { doDvr = dvr; view.repaint(); } /** * Retrieves the dynamic video resize factor of this * viewer. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public float getDvrFactor() { return dvrFactor; } /** * Set the dynamic video resize factor for this viewer. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @param dvr set the dynamic video resize factor for this viewer. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public void setDvrFactor(float dvr) { dvrFactor = dvr; view.repaint(); } /** * Turns on or off dynamic video resize compensation. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @param dvrRCE enables or disables dynamic video resize compensation. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public void setDvrResizeCompensationEnable(boolean dvrRCE) { doDvrResizeCompensation = dvrRCE; view.repaint(); } /** * Returns a status flag indicating whether or not dynamic video resize * compensation is enabled. * * Note: This method is targeted for SUN framebuffer XVR-4000 and later * hardware that support video size extension. * * @since Java 3D 1.3.1 */ // To support a back door for DVR support. public boolean getDvrResizeCompensationEnable() { return doDvrResizeCompensation; } /** * Creates a default viewer object. The default values are used to create * the PhysicalBody and PhysicalEnvironment. A single RGB, double buffered * and depth buffered Canvas3D object is created. The View is created * with a front clip distance of 0.1f and a back clip distance of 10.0f. */ public Viewer() { // Call main constructor with default values. this(null, null, null, true); } /** * Creates a default viewer object. The default values are used to create * the PhysicalBody and PhysicalEnvironment. The View is created * with a front clip distance of 0.1f and a back clip distance of 10.0f. * * @param userCanvas the Canvas3D object to be used for rendering; * if this is null then a single RGB, double buffered and depth buffered * Canvas3D object is created * @since Java3D 1.1 */ public Viewer(Canvas3D userCanvas) { // Call main constructor. this(userCanvas == null ? null : new Canvas3D[] {userCanvas}, null, null, true); } /** * Creates a default viewer object. The default values are used to create * the PhysicalBody and PhysicalEnvironment. The View is created * with a front clip distance of 0.1f and a back clip distance of 10.0f. * * @param userCanvases the Canvas3D objects to be used for rendering; * if this is null then a single RGB, double buffered and depth buffered * Canvas3D object is created * @since Java3D 1.3 */ public Viewer(Canvas3D[] userCanvases) { this(userCanvases, null, null, true); } /** * Creates a viewer object. The Canvas3D objects, PhysicalEnvironment, and * PhysicalBody are taken from the arguments. * * @param userCanvases the Canvas3D objects to be used for rendering; * if this is null then a single RGB, double buffered and depth buffered * Canvas3D object is created * @param userBody the PhysicalBody to use for this Viewer; if it is * null, a default PhysicalBody object is created * @param userEnvironment the PhysicalEnvironment to use for this Viewer; * if it is null, a default PhysicalEnvironment object is created * @param setVisible determines if the Frames should be set to visible once created * @since Java3D 1.3 */ public Viewer(Canvas3D[] userCanvases, PhysicalBody userBody, PhysicalEnvironment userEnvironment, boolean setVisible ) { if (userBody == null) { physicalBody = new PhysicalBody(); } else { physicalBody = userBody; } if (userEnvironment == null) { physicalEnvironment = new PhysicalEnvironment(); } else { physicalEnvironment = userEnvironment; } // Create Canvas3D object if none was passed in. if (userCanvases == null) { GraphicsConfiguration config = ConfiguredUniverse.getPreferredConfiguration(); canvases = new Canvas3D[1]; canvases[0] = new Canvas3D(config); try { canvases[0].setFocusable( true );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -