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

📄 conesoundretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $RCSfile: ConeSoundRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.4 $ * $Date: 2007/02/09 17:17:56 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.Vector3f;import javax.vecmath.Vector3d;import javax.vecmath.Point2f;import javax.vecmath.Point3f;/** * A ConeSoundRetained node defines a point sound source located at some * location  * in space whose amplitude is constrained not only by maximum and minimum * amplitude * spheres but by two concentric cone volumes directed down an vector radiating * from the sound's location. */ class ConeSoundRetained extends PointSoundRetained {    /**     * The Cone Sound's direction vector.  This is the cone axis.     */    Vector3f	direction = new Vector3f(0.0f, 0.0f, 1.0f);    // The transformed direction of this sound    Vector3f xformDirection = new Vector3f(0.0f, 0.0f, 1.0f);    // Sound's gain is attenuated for listener locations off-angle from    // the source source direction.    // This can be set of three numbers:    //     angular distance in radians    //     gain scale factor    //     filtering (currently the only filtering supported is lowpass)    // For now the only supported filterType will be LOW_PASS frequency cutoff.    // At some time full FIR filtering will be supported.    static final int  NO_FILTERING  = -1;    static final int  LOW_PASS      =  1;    // Pairs of distances and gain scale factors that define piecewise linear    // gain BACK attenuation between each pair.    // These are used for defining elliptical attenuation regions.    float[]     backAttenuationDistance = null;    float[]     backAttenuationGain = null;    float[]	angularDistance = {0.0f, ((float)(Math.PI) * 0.5f)};    float[]	angularGain     = {1.0f, 0.0f};    int         filterType      = NO_FILTERING;    float[]     frequencyCutoff = {Sound.NO_FILTER, Sound.NO_FILTER};    ConeSoundRetained() {        this.nodeType = NodeRetained.CONESOUND;    }    // *********************    //    // Distance Gain methods    //    // *********************    /**     * Sets this sound's distance gain elliptical attenuation -      * where gain scale factor is applied to sound based on distance listener     * is from sound source.     * @param frontAttenuation defined by pairs of (distance,gain-scale-factor)     * @param backAttenuation defined by pairs of (distance,gain-scale-factor)     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */      void setDistanceGain(Point2f[] frontAttenuation,                                      Point2f[] backAttenuation ) {        this.setDistanceGain(frontAttenuation);        this.setBackDistanceGain(backAttenuation);    }    /**     * Sets this sound's distance gain attenuation as an array of Point2fs.     * @param frontDistance array of monotonically-increasing floats     * @param frontGain array of non-negative scale factors     * @param backDistance array of monotonically-increasing floats     * @param backGain array of non-negative scale factors     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */      void setDistanceGain(float[] frontDistance, float[] frontGain,                                      float[] backDistance, float[] backGain) {        this.setDistanceGain(frontDistance, frontGain);        this.setBackDistanceGain(backDistance, backGain);    }    /**     * Sets this sound's back distance gain attenuation - where gain scale      * factor is applied to sound based on distance listener along the negative     * sound direction axis from sound source.     * @param attenuation defined by pairs of (distance,gain-scale-factor)     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */      void setBackDistanceGain(Point2f[] attenuation)    {        // if attenuation array null set both attenuation components to null        if (attenuation == null) {            this.backAttenuationDistance = null;            this.backAttenuationGain = null;        }        else {            int attenuationLength = attenuation.length;            if (attenuationLength == 0) {                this.backAttenuationDistance = null;                this.backAttenuationGain = null;            }            else {                this.backAttenuationDistance = new float[attenuationLength];                this.backAttenuationGain = new float[attenuationLength];                for (int i = 0; i < attenuationLength; i++) {                    this.backAttenuationDistance[i] = attenuation[i].x;                    this.backAttenuationGain[i] = attenuation[i].y;                }            }        }        dispatchAttribChange(BACK_DISTANCE_GAIN_DIRTY_BIT, attenuation);	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}    }    /**     * Sets this sound's back distance gain attenuation as an array of Point2fs.     * @param distance array of monotonically-increasing floats     * @param gain array of non-negative scale factors     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */      void setBackDistanceGain(float[] distance, float[] gain)    {        int distanceLength = 0;        // if distance or gain arrays are null then treat both as null        if (distance == null || gain == null) {            this.backAttenuationDistance = null;            this.backAttenuationGain = null;        }        else {            // now process the back attenuation values            int gainLength = gain.length;            distanceLength = distance.length;            if (distanceLength == 0 || gainLength == 0) {                this.backAttenuationDistance = null;                this.backAttenuationGain = null;            }            else {                this.backAttenuationDistance = new float[distanceLength];                this.backAttenuationGain = new float[distanceLength];                // Copy the distance array into nodes field                System.arraycopy(distance, 0, this.backAttenuationDistance,                                           0, distanceLength);                      // Copy the gain array an array of same length as the distance array                if (distanceLength <= gainLength) {                    System.arraycopy(gain, 0, this.backAttenuationGain,                                            0, distanceLength);                }                else {                    System.arraycopy(gain, 0, this.backAttenuationGain, 0, gainLength);		    // Extend gain array to length of distance array		    // replicate last gain values.                    for (int i=gainLength; i< distanceLength; i++) {                        this.backAttenuationGain[i] = gain[gainLength - 1];                    }                }            }        }         Point2f [] attenuation = new Point2f[distanceLength];         for (int i=0; i<distanceLength; i++) {              attenuation[i] = new Point2f(this.backAttenuationDistance[i],                                          this.backAttenuationGain[i]);        }         dispatchAttribChange(BACK_DISTANCE_GAIN_DIRTY_BIT, attenuation);	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}    }    /**     * Gets this sound's elliptical distance attenuation     * @param frontAttenuation arrays containing forward distances attenuation pairs     * @param backAttenuation arrays containing backward distances attenuation pairs     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */     void getDistanceGain(Point2f[] frontAttenuation,                    Point2f[] backAttenuation) {         this.getDistanceGain(frontAttenuation);        this.getBackDistanceGain(backAttenuation);    }    /**     * Gets this sound's elliptical distance gain attenuation values in separate arrays     * @param frontDistance array of float distances along the sound axis     * @param fronGain array of non-negative scale factors associated with front distances     * @param backDistance array of float negative distances along the sound axis     * @param backGain array of non-negative scale factors associated with back distances     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */     void getDistanceGain(float[] frontDistance, float[] frontGain,                                      float[] backDistance, float[] backGain) {         this.getDistanceGain( frontDistance, frontGain);        this.getBackDistanceGain( backDistance, backGain);    }    /**       * Retieves sound's back distance attenuation     * Put the contents of the two separate distance and gain arrays into     * an array of Point2f.     * @param attenuation containing distance attenuation pairs     */      void getBackDistanceGain(Point2f[] attenuation) {        // Write into arrays passed in, don't do a new        if (attenuation == null)            return;        if (this.backAttenuationDistance == null ||            this.backAttenuationGain == null)            return;        // These two array length should be the same        // can assume lengths are non-zero        int distanceLength = this.backAttenuationDistance.length;        int attenuationLength = attenuation.length;        if (distanceLength < attenuationLength)            distanceLength = attenuationLength;        for (int i=0; i< distanceLength; i++) {            attenuation[i].x = this.backAttenuationDistance[i];            attenuation[i].y = this.backAttenuationGain[i];        }    }    /**       * Retieves this sound's back attenuation distance and gain arrays,      * returned in separate arrays.     * @param distance array of monotonically-increasing floats.     * @param gain array of amplitude scale factors associated with distances.     */      void getBackDistanceGain(float[] distance, float[] gain) {        // write into arrays passed in, don't do a new        if (distance == null || gain == null)            return;        if (this.backAttenuationDistance == null ||             this.backAttenuationGain == null)            return;        // backAttenuationDistance and backAttenuationGain array length should        // be the same        // can assume length is non-zero        int attenuationLength = this.backAttenuationDistance.length;        int distanceLength = distance.length;        if (attenuationLength > distanceLength)            attenuationLength = distanceLength;        System.arraycopy(this.backAttenuationDistance, 0, distance, 0, attenuationLength);        attenuationLength = this.backAttenuationGain.length;        int gainLength = gain.length;        if (attenuationLength > gainLength)            attenuationLength = gainLength;        System.arraycopy(this.backAttenuationGain, 0, gain, 0, attenuationLength);    }    // *********************    //    // Direction Methods    //    // *********************    /**     * Sets this sound's direction from the vector provided.     * @param direction the new direction     */    void setDirection(Vector3f direction) {	if (staticTransform != null) {	    staticTransform.transform.transform(direction, this.direction);	} else {	    this.direction.set(direction);		}        dispatchAttribChange(DIRECTION_DIRTY_BIT, 				(new Vector3f(this.direction)));	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}    }    /**     * Sets this sound's direction from the three values provided.     * @param x the new x direction     * @param y the new y direction     * @param z the new z direction     */    void setDirection(float x, float y, float z) {	direction.x = x;	direction.y = y;	direction.z = z;	if (staticTransform != null) {	    staticTransform.transform.transform(direction);	}         dispatchAttribChange(DIRECTION_DIRTY_BIT, (new Vector3f(direction)));	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}    }

⌨️ 快捷键说明

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