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

📄 backgroundretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $RCSfile: BackgroundRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.8 $ * $Date: 2007/04/12 17:34:03 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.util.ArrayList;import java.awt.geom.AffineTransform;import java.awt.image.AffineTransformOp;import java.awt.image.BufferedImage;/** * The Background leaf node defines either a solid background color * or a background image that is used to fill the window at the * beginning of each new frame.  It also specifies an application * region in which this background is active. */class BackgroundRetained extends LeafRetained {    static final int COLOR_CHANGED		= 0x00001;    static final int IMAGE_CHANGED		= 0x00002;    static final int GEOMETRY_CHANGED		= 0x00004;    static final int BOUNDS_CHANGED		= 0x00008;    static final int BOUNDINGLEAF_CHANGED	= 0x00010;    static final int IMAGE_SCALE_CHANGED        = 0x00020;    // Background color or image.  If non-null, the image overrides the    // color.    Color3f		color = new Color3f(0.0f, 0.0f, 0.0f);    ImageComponent2DRetained	image = null;    Texture2DRetained           texture = null;        // the image scale mode if image is used.    int imageScaleMode = Background.SCALE_NONE;         /**     * The Boundary object defining the lights's application region.     */      Bounds applicationRegion = null;    /**      * The bounding leaf reference     */    BoundingLeafRetained boundingLeaf = null;    /**      * Background geometry branch group     */    BranchGroup geometryBranch = null;    /**     * The transformed value of the applicationRegion.     */    Bounds transformedRegion = null;    /**     * The state structure used for Background Geometry     */    SetLiveState setLiveState = null;    /**     * The locale of this Background node since we don't have mirror object     *  when clearLive is called     * locale is set to null, we still want locale to have a     * non-null value, since renderingEnv structure may be using the     * locale     */    Locale cachedLocale = null;    // This is true when this background is referenced in an immediate mode context    boolean inImmCtx = false;    // list of light nodes for background geometry    ArrayList lights = new ArrayList();    // list of fog nodes for background geometry    ArrayList fogs = new ArrayList();    // a list of background geometry atoms    ArrayList bgGeometryAtomList = new ArrayList();    // false is background geometry atoms list has changed    boolean bgGeometryAtomListDirty = true;    // an array of background geometry atoms    GeometryAtom[] bgGeometryAtoms = null;    // Target threads to be notified when light changes    // Note, the rendering env structure only get notified    // when there is a bounds related change    final static int targetThreads = J3dThread.UPDATE_RENDERING_ENVIRONMENT |                                     J3dThread.UPDATE_RENDER;    // Is true, if the background is viewScoped    boolean isViewScoped = false;        BackgroundRetained () {        this.nodeType = NodeRetained.BACKGROUND;	localBounds = new BoundingBox();	((BoundingBox)localBounds).setLower( 1.0, 1.0, 1.0);	((BoundingBox)localBounds).setUpper(-1.0,-1.0,-1.0);    }    /**     * Initializes the background color to the specified color.       * This color is used     * if the image is null.     * @param color the new background color     */    final void initColor(Color3f color) {	this.color.set(color);    }    /**     * Sets the background color to the specified color.  This color is used     * if the image is null.     * @param color the new background color     */    final void setColor(Color3f color) {	initColor(color);	if (source.isLive()) {	    sendMessage(COLOR_CHANGED, new Color3f(color));	}    }    /**     * Initializes the background color to the specified color.       * This color is used     * if the image is null.     * @param r the red component of the background color     * @param g the green component of the background color     * @param b the blue component of the background color     */    final void initColor(float r, float g, float b) {	this.color.x = r;	this.color.y = g;	this.color.z = b;    }    /**     * Sets the background color to the specified color.  This color is used     * if the image is null.     * @param r the red component of the background color     * @param g the green component of the background color     * @param b the blue component of the background color     */    final void setColor(float r, float g, float b) {	setColor(new Color3f(r, g, b));    }    /**     * Retrieves the background color.     * @param color the vector that will receive the current background color     */    final void getColor(Color3f color) {	color.set(this.color);    }    /**     * Initialize the image scale mode to the specified mode     * @imageScaleMode the image scale mode to the used     */    final void initImageScaleMode(int imageScaleMode){	this.imageScaleMode = imageScaleMode;    }        /**     * Sets the image scale mode for this Background node.     * @param imageScaleMode the image scale mode     */    final void setImageScaleMode(int imageScaleMode){	initImageScaleMode(imageScaleMode);	if(source.isLive()){	    sendMessage(IMAGE_SCALE_CHANGED, new Integer(imageScaleMode));	}    }        /**     * gets the image scale mode for this Background node.     */    final int getImageScaleMode(){	return imageScaleMode;    }        /**     * Initializes the background image to the specified image.       * @param image new ImageCompoent2D object used as the background image     */    final void initImage(ImageComponent2D img) {        int texFormat;        if (img == null) {            image = null;            texture = null;            return;        }        if (img.retained != image ) {            image = (ImageComponent2DRetained) img.retained;            image.setEnforceNonPowerOfTwoSupport(true);            switch(image.getNumberOfComponents()) {                case 1:                    texFormat = Texture.INTENSITY;                    break;                case 2:                    texFormat = Texture.LUMINANCE_ALPHA;                    break;                case 3:                    texFormat = Texture.RGB;                    break;                case 4:                    texFormat = Texture.RGBA;                    break;                default:                    assert false;                    return;            }            Texture2D tex2D = new Texture2D(Texture.BASE_LEVEL, texFormat,                    img.getWidth(), img.getHeight());            texture = (Texture2DRetained) tex2D.retained;            // Background is special case of Raster.            texture.setUseAsRaster(true);            // Fix to issue 373 : ImageComponent.set(BufferedImage) ignored when used by Background            image.addUser(texture);            texture.initImage(0,img);        }    }    /**     * Sets the background image to the specified image.       * @param image new ImageCompoent3D object used as the background image     */    final void setImage(ImageComponent2D img) {	if (source.isLive()) {	    if (texture != null) {		texture.clearLive(refCount);	    }	}		initImage(img);        if (source.isLive()) {            if (texture != null) {                texture.setLive(inBackgroundGroup, refCount);            }                        sendMessage(IMAGE_CHANGED,                    (texture != null ? texture.mirror : null));                    }    }    /**     * Retrieves the background image.     * @return the current background image     */    final ImageComponent2D getImage() {        return (image == null ? null : 		(ImageComponent2D)image.source);    }    /**     * Initializes the background geometry branch group to the specified branch.       * @param branch new branch group object used for background geometry     */      final void initGeometry(BranchGroup branch) {        geometryBranch = branch;    }    /**     * Sets the background geometry branch group to the specified branch.       * @param branch new branch group object used for background geometry     */      final void setGeometry(BranchGroup branch) {        int numMessages = 0;        int i;        if (source.isLive()) {	    J3dMessage m[];            if (geometryBranch != null)                numMessages+=2; // REMOVE_NODES, ORDERED_GROUP_REMOVED            if (branch != null)                numMessages+=2; // INSERT_NODES, ORDERED_GROUP_INSERTED            m = new J3dMessage[numMessages];            for (i=0; i<numMessages; i++) {                m[i] = new J3dMessage();            }            i = 0;            if (geometryBranch != null) {                clearGeometryBranch((BranchGroupRetained)geometryBranch.retained);                m[i].threads = (J3dThread.UPDATE_RENDER | 				J3dThread.UPDATE_RENDERING_ENVIRONMENT);                m[i].type = J3dMessage.ORDERED_GROUP_REMOVED;                m[i].universe = universe;                m[i].args[0] = setLiveState.ogList.toArray();                m[i].args[1] = setLiveState.ogChildIdList.toArray();		m[i].args[3] = setLiveState.ogCIOList.toArray();		m[i].args[4] = setLiveState.ogCIOTableList.toArray();                i++;                m[i].threads = setLiveState.notifyThreads;                m[i].type = J3dMessage.REMOVE_NODES;                m[i].universe = universe;                m[i].args[0] = setLiveState.nodeList.toArray();                i++;            }            if (branch != null) {                setGeometryBranch((BranchGroupRetained)branch.retained);                m[i].threads = (J3dThread.UPDATE_RENDER | 				J3dThread.UPDATE_RENDERING_ENVIRONMENT);                m[i].type = J3dMessage.ORDERED_GROUP_INSERTED;                m[i].universe = universe;                m[i].args[0] = setLiveState.ogList.toArray();                m[i].args[1] = setLiveState.ogChildIdList.toArray();		m[i].args[2] = setLiveState.ogOrderedIdList.toArray();		m[i].args[3] = setLiveState.ogCIOList.toArray();		m[i].args[4] = setLiveState.ogCIOTableList.toArray();                i++;                m[i].threads = setLiveState.notifyThreads;                m[i].type = J3dMessage.INSERT_NODES;                m[i].universe = universe;                m[i].args[0] = setLiveState.nodeList.toArray();            }            VirtualUniverse.mc.processMessage(m);	    // Free up memory	    setLiveState.reset(null);        }        initGeometry(branch);    }    /**     * Retrieves the background geometry branch group.     * @return the current background geometry branch group     */    final BranchGroup getGeometry() {        return geometryBranch;    }    /**     * Initializes the Background's application region.     * @param region a region that contains the Backgound's new application bounds     */      final void initApplicationBounds(Bounds region) {	if (region != null) {	    applicationRegion = (Bounds) region.clone();	} else {	    applicationRegion = null;	}    }    /**     * Set the Background's application region.     * @param region a region that contains the Backgound's new application bounds     */      final void setApplicationBounds(Bounds region) {	initApplicationBounds(region);	// Don't send the message if there is a valid boundingleaf	if (boundingLeaf == null) {	    J3dMessage createMessage = new J3dMessage();	    createMessage.threads = targetThreads | 		J3dThread.UPDATE_RENDERING_ENVIRONMENT;	    createMessage.type = J3dMessage.BACKGROUND_CHANGED;	    createMessage.universe = universe;	    createMessage.args[0] = this;	    createMessage.args[1]= new Integer(BOUNDS_CHANGED);	    if (region != null) 		createMessage.args[2] = region.clone();	    else		createMessage.args[2] = null;	    VirtualUniverse.mc.processMessage(createMessage);	}    }    /**  

⌨️ 快捷键说明

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