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

📄 conesoundretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Retrieves this sound's direction and places it in the     * vector provided.     * @return direction vector (axis of cones)     */    void getDirection(Vector3f direction)    {        if (staticTransform != null) {            Transform3D invTransform = staticTransform.getInvTransform();            invTransform.transform(this.direction, direction);        } else {            direction.set(this.direction);        }    }    void getXformDirection(Vector3f direction)    {        direction.set(this.xformDirection);    }    // ***************************    //    // Angular Attenuation    //    // ***************************    /**       * Sets this sound's angular gain attenuation (not including filter)     * @param attenuation array containing angular distance and gain     */      void setAngularAttenuation(Point2f[] attenuation) {        int attenuationLength = 0;        this.filterType = NO_FILTERING;        if (attenuation == null) {            this.angularDistance = null;            this.angularGain = null;        }        else {            attenuationLength = attenuation.length;            if (attenuationLength == 0) {                this.angularDistance = null;                this.angularGain = null;            }            else {                this.angularDistance = new float[attenuationLength];                this.angularGain = new float[attenuationLength];                for (int i = 0; i < attenuationLength; i++) {                   this.angularDistance[i] = attenuation[i].x;                   this.angularGain[i] = attenuation[i].y;                }            } // lengths not zero        } // arrays not null        Point3f [] attenuation3f = new Point3f[attenuationLength];         for (int i=0; i<attenuationLength; i++) {              attenuation3f[i] = new Point3f(this.angularDistance[i],                                            this.angularGain[i],                                             Sound.NO_FILTER);         }        dispatchAttribChange(ANGULAR_ATTENUATION_DIRTY_BIT, attenuation3f);	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}     }    /**       * Sets this sound's angular attenuation including both gain and filter.     * @param attenuation array containing angular distance, gain and filter     */      void setAngularAttenuation(Point3f[] attenuation) {        if (attenuation == null) {            this.angularDistance = null;            this.angularGain = null;            this.frequencyCutoff = null;            this.filterType = NO_FILTERING;        }        else {            int attenuationLength = attenuation.length;            if (attenuationLength == 0) {                this.angularDistance = null;                this.angularGain = null;                this.frequencyCutoff = null;                this.filterType = NO_FILTERING;            }            else {                this.angularDistance = new float[attenuationLength];                this.angularGain = new float[attenuationLength];                this.frequencyCutoff = new float[attenuationLength];                this.filterType = LOW_PASS;                for (int i = 0; i < attenuationLength; i++) {                   this.angularDistance[i] = attenuation[i].x;                   this.angularGain[i] = attenuation[i].y;                   this.frequencyCutoff[i] = attenuation[i].z;                }            } // lengths not zero        } // arrays not null        dispatchAttribChange(ANGULAR_ATTENUATION_DIRTY_BIT, attenuation);	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}    }    /**     * Sets angular attenuation including gain and filter using separate arrays     * @param distance array containing angular distance     * @param filter array containing angular low-pass frequency cutoff values     */      void setAngularAttenuation(float[] distance, float[] gain, float[] filter) {        int distanceLength = 0;        if (distance == null || gain == null || filter == null) {            this.angularDistance = null;            this.angularGain = null;            this.frequencyCutoff = null;            this.filterType = NO_FILTERING;        }        else {            distanceLength = distance.length;            int gainLength = gain.length;            if (distanceLength == 0 || gainLength == 0) {                this.angularDistance = null;                this.angularGain = null;                this.frequencyCutoff = null;                this.filterType = NO_FILTERING;            }            else {                int filterLength = filter.length;                this.angularDistance = new float[distanceLength];                this.angularGain = new float[distanceLength];                this.frequencyCutoff = new float[distanceLength];                // Copy the distance array into nodes field                System.arraycopy(distance, 0, this.angularDistance, 0, distanceLength);                // Copy the gain array an array of same length as the distance array                if (distanceLength <= gainLength) {                    System.arraycopy(gain, 0, this.angularGain, 0, distanceLength);                }                else {                    System.arraycopy(gain, 0, this.angularGain, 0, gainLength);                    /**                     * Extend gain array to length of distance array by                     * replicate last gain values.                     */                      for (int i=gainLength; i< distanceLength; i++) {                        this.angularGain[i] = gain[gainLength - 1];                    }                }                // Copy the filter array an array of same length as the distance array                if (filterLength == 0)                    this.filterType = NO_FILTERING;                else {                    this.filterType = LOW_PASS;                    if (distanceLength <= filterLength) {                        System.arraycopy(filter, 0, this.frequencyCutoff,0, distanceLength);                    }                    else {                        System.arraycopy(filter, 0, this.frequencyCutoff, 0, filterLength);			// Extend filter array to length of distance array by			// replicate last filter values.                        for (int i=filterLength; i< distanceLength; i++) {                            this.frequencyCutoff[i] = filter[filterLength - 1];                        }                    }                }            }  // length not zero        } // arrays not null        Point3f [] attenuation = new Point3f[distanceLength];        for (int i=0; i<distanceLength; i++) {             if (this.filterType != NO_FILTERING) {                 attenuation[i] = new Point3f(this.angularDistance[i],                                          this.angularGain[i],                                          this.frequencyCutoff[i]);             }             else {                 attenuation[i] = new Point3f(this.angularDistance[i],                                          this.angularGain[i],                                          Sound.NO_FILTER);             }        }        dispatchAttribChange(ANGULAR_ATTENUATION_DIRTY_BIT, attenuation);	if (source != null && source.isLive()) {	    notifySceneGraphChanged(false);	}    }    /**     * Retrieves angular attenuation array length.     * All arrays are forced to same size     * @exception CapabilityNotSetException if appropriate capability is     * not set and this object is part of live or compiled scene graph     */      int getAngularAttenuationLength() {       if (angularDistance == null)           return 0;       else            return (this.angularDistance.length);    }     /**     * Retrieves angular attenuation including gain and filter in a single array     * @param attenuation applied to gain when listener is between cones     */      void getAngularAttenuation(Point3f[] attenuation) {        /// use attenuation array allocated by user - don't new it        // The three angular attenuation arrays length should be the same        if (this.angularDistance == null || this.angularGain == null)            return;        if (attenuation == null)            return;        int distanceLength = this.angularDistance.length;        if (attenuation.length < distanceLength)            distanceLength = attenuation.length;        for (int i=0; i< distanceLength; i++) {            attenuation[i].x = this.angularDistance[i];            attenuation[i].y = this.angularGain[i];            if (filterType == NO_FILTERING || this.frequencyCutoff == null)                attenuation[i].z = Sound.NO_FILTER;            else if (filterType == LOW_PASS)                attenuation[i].z = this.frequencyCutoff[i];        }    }    /**     * Retrieves angular attenuation including gain and filter      * returned as separate arrays     * @param distance array containing angular distance     * @param gain array containing angular gain attenuation     * @param filter array containing angular low-pass frequency cutoff values     */      void getAngularAttenuation(float[] distance, float[] gain, float[] filter) {        // use attenuation array allocated by user - don't new it        if (distance == null || gain == null || filter == null)            return;        if (this.angularDistance == null || this.angularGain == null)            return;        int distanceLength = this.angularDistance.length;        if (distance.length < distanceLength)            distanceLength = distance.length;        System.arraycopy(this.angularDistance, 0, distance, 0, distanceLength);        int gainLength = this.angularGain.length;        if (gain.length < gainLength)            gainLength = gain.length;        System.arraycopy(this.angularGain, 0, gain, 0, gainLength);        int filterLength = 0;        if (this.frequencyCutoff == null || filterType == NO_FILTERING)            filterLength = filter.length;        else {            filterLength = this.frequencyCutoff.length;            if (filter.length < filterLength)                filterLength = filter.length;        }        if (filterType == NO_FILTERING || this.frequencyCutoff == null) {            for (int i=0; i< filterLength; i++)                 filter[i] = Sound.NO_FILTER;        }        if (filterType == LOW_PASS) {            System.arraycopy(this.frequencyCutoff, 0, filter,0, filterLength);        }    }    /**       * This updates the Direction fields of cone sound.     *     * Neither Angular gain Attenuation and Filtering fields, nor     * back distance gain not maintained in mirror object     */      void updateMirrorObject(Object[] objs) {        if (debugFlag)            debugPrint("PointSoundRetained:updateMirrorObj()");        Transform3D trans = null;        int component = ((Integer)objs[1]).intValue();        int numSnds = ((Integer)objs[2]).intValue();         SoundRetained[] mSnds = (SoundRetained[]) objs[3];        if (component == -1) {            // update every field            initMirrorObject(((ConeSoundRetained)objs[2]));            return;        }        if ((component & DIRECTION_DIRTY_BIT) != 0) {            for (int i = 0; i < numSnds; i++) {                    ConeSoundRetained cone = (ConeSoundRetained)mSnds[i];                cone.direction = (Vector3f)objs[4];                cone.getLastLocalToVworld().transform(cone.direction,                                                      cone.xformDirection);                    cone.xformDirection.normalize();            }        }        // call the parent's mirror object update routine        super.updateMirrorObject(objs);    }    synchronized void initMirrorObject(ConeSoundRetained ms) {        super.initMirrorObject(ms);        ms.direction.set(this.direction);        ms.xformDirection.set(this.xformDirection);    }    // Called on the mirror object    void updateTransformChange() {	Transform3D lastLocalToVworld = getLastLocalToVworld();        super.updateTransformChange();        lastLocalToVworld.transform(direction, xformDirection);        xformDirection.normalize();        // set flag looked at by Scheduler to denote Transform change          // this flag will force resneding transformed direction to AudioDevice         if (debugFlag)             debugPrint("ConeSound xformDirection is (" + xformDirection.x + ", "                    + xformDirection.y + ", "+ xformDirection.z + ")");     }     void mergeTransform(TransformGroupRetained xform) {        super.mergeTransform(xform);	xform.transform.transform(direction);    }}

⌨️ 快捷键说明

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