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

📄 jsdirectionalsample.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        minDistanceArray[factorIndex] + ", " +                         minFactorArray[factorIndex]);                }                returnValue =  (                    ( (distanceArray[factorIndex] -                               minDistanceArray[factorIndex]) /                          (maxDistanceArray[factorIndex] -                               minDistanceArray[factorIndex]) ) *                      (maxFactorArray[factorIndex] -                               minFactorArray[factorIndex]) ) +                    minFactorArray[factorIndex] ;                if (debugFlag)                       debugPrint("    findFactor returns ****** " +                               returnValue + " ******");                return (float)returnValue;            }            /* Otherwise, for distanceToHead between distance intersection             * values, we need to calculate two factors - one for the             * ellipse defined by lowIndex min/max factor arrays, and             * the other by highIndex min/max factor arrays.  Then the             * distance Ratio (defined above) is applied, using these             * two factor values, to get the final return value.             */ 	    double highFactorValue = 1.0;            double lowFactorValue  = 0.0;            highFactorValue =                 ( ((distanceArray[highIndex] - minDistanceArray[highIndex]) /                   (maxDistanceArray[highIndex]-minDistanceArray[highIndex])) *                  (maxFactorArray[highIndex] - minFactorArray[highIndex]) ) +                minFactorArray[highIndex] ;            if (debugFlag) {                 debugPrint( "    highFactorValue calculated w/ highIndex " +                        highIndex);                debugPrint( "    d.A. max pair for highIndex " +                        maxDistanceArray[highIndex] + ", " +                         maxFactorArray[highIndex]);                debugPrint( "    d.A. min pair for lowIndex " +                        minDistanceArray[highIndex] + ", " +                         minFactorArray[highIndex]);                debugPrint( "    highFactorValue " + highFactorValue);            }            lowFactorValue =                ( ((distanceArray[lowIndex] - minDistanceArray[lowIndex]) /                   (maxDistanceArray[lowIndex] - minDistanceArray[lowIndex])) *                  (maxFactorArray[lowIndex] - minFactorArray[lowIndex]) ) +                minFactorArray[lowIndex] ;            if (debugFlag) {                 debugPrint( "    lowFactorValue calculated w/ lowIndex " +                        lowIndex);                debugPrint( "    d.A. max pair for lowIndex " +                        maxDistanceArray[lowIndex] + ", " +                         maxFactorArray[lowIndex]);                debugPrint( "    d.A. min pair for lowIndex " +                        minDistanceArray[lowIndex] + ", " +                         minFactorArray[lowIndex]);                debugPrint( "    lowFactorValue " + lowFactorValue);            }            /*             * calculate gain scale factor based on the ratio distance             * between ellipses the distanceToHead lies between.             */            /*             * ratio: distance from listener to sound source             *        between lowIndex and highIndex times             *        attenuation value between lowIndex and highIndex             * gives linearly interpolationed attenuation value             */            if (debugFlag) {                 debugPrint( "    ratio calculated using distanceArray" +                       lowIndex + ", highIndex " + highIndex);                debugPrint( "    calculated pair for lowIndex " +                        distanceArray[lowIndex]+", "+ lowFactorValue);                debugPrint( "    calculated pair for highIndex " +                        distanceArray[highIndex]+", "+ highFactorValue );            }             returnValue =                ( ( (distanceToHead - distanceArray[lowIndex]) /                    (distanceArray[highIndex] - distanceArray[lowIndex]) ) *                  (highFactorValue - lowFactorValue) ) +                factorArray[lowIndex] ;            if (debugFlag)                   debugPrint("    findFactor returns ******" +                            returnValue + " ******");            return (float)returnValue;        }     }    /**     * CalculateDistanceAttenuation       *      * Simply calls ConeSound specific 'findFactor()' with      * both front and back attenuation linear distance and gain scale factor     * arrays.      */      float calculateDistanceAttenuation(float distance) {        float factor = findFactor(distance, this.attenuationDistance,                       this.attenuationGain, this.backAttenuationDistance,                       this.backAttenuationGain);        if (factor < 0.0f)            return 1.0f;        else            return factor;    }    /**     * CalculateAngularGain       *        * Simply calls generic (for PointSound) 'findFactor()' with      * a single set of angular attenuation distance and gain scalefactor arrays.     */      float calculateAngularGain() {        float angle = findAngularOffset();        float factor = findFactor(angle, this.angularDistance, this.angularGain);        if (factor < 0.0f)            return 1.0f;        else            return factor;    }      /* *****************     *        *  Find Angular Offset     *        * *****************/    /*        *  Calculates the angle from the sound's direction axis and the ray from     *  the sound origin to the listener'center ear.     *  For Cone Sounds this value is the arc cosine of dot-product between     *  the sound direction vector and the vector (sound position,centerEar)     *  all in Virtual World coordinates space.     *  Center ear position is in Virtual World coordinates.     *  Assumes that calculation done in VWorld Space...     *  Assumes that xformPosition is already calculated...     */      float findAngularOffset() {        Vector3f unitToEar = new Vector3f();        Vector3f unitDirection = new Vector3f();        Point3f  xformPosition = positions[currentIndex];        Point3f  xformCenterEar = centerEars[currentIndex];        float   dotProduct;        float   angle;        /*          * TODO: (Question) is assumption that xformed values available O.K.         * TODO: (Performance) save this angular offset and only recalculate         *          if centerEar or sound position have changed.          */        unitToEar.x = xformCenterEar.x - xformPosition.x;        unitToEar.y = xformCenterEar.y - xformPosition.y;        unitToEar.z = xformCenterEar.z - xformPosition.z;        unitToEar.normalize();        unitDirection.normalize(this.direction);        dotProduct = unitToEar.dot(unitDirection);        angle = (float)(Math.acos((double)dotProduct));        if (debugFlag)            debugPrint("           angle from cone direction = " + angle);        return(angle);    }     /************     *        *  Calculate Filter     *        * *****************/    /*        *  Calculates the low-pass cutoff frequency filter value applied to the     *  a sound based on both:     *      Distance Filter (from Aural Attributes) based on distance     *         between the sound and the listeners position     *      Angular Filter (for Directional Sounds) based on the angle     *         between a sound's projected direction and the     *         vector between the sounds position and center ear.     *  The lowest of these two filter is used.     *  This filter value is stored into the sample's filterFreq field.     */      void calculateFilter(float distance, AuralParameters attribs) {        // setting filter cutoff freq to 44.1kHz which, in this        // implementation, is the same as not performing filtering        float   distanceFilter = 44100.0f;        float   angularFilter  = 44100.0f;        int arrayLength = attribs.getDistanceFilterLength();        int filterType = attribs.getDistanceFilterType();        boolean distanceFilterFound = false;        boolean angularFilterFound = false;        if ((filterType == AuralParameters.NO_FILTERING) && arrayLength > 0) {            double[] distanceArray = new double[arrayLength];            float[]  cutoffArray = new float[arrayLength];            attribs.getDistanceFilter(distanceArray, cutoffArray);            if (debugFlag) {                debugPrint("distanceArray    cutoffArray");                for (int i=0; i<arrayLength; i++)                    debugPrint((float)distanceArray[i] + ", " + cutoffArray[i]);            }            // Calculate angle from direction axis towards listener            float angle = findAngularOffset();             distanceFilter = findFactor((double)angle,                   angularDistance, angularFilterCutoff);            if (distanceFilter < 0.0f)                distanceFilterFound = false;            else                distanceFilterFound = true;        }        else {            distanceFilterFound = false;            distanceFilter = -1.0f;        }         if (debugFlag)            debugPrint("    calculateFilter arrayLength = " + arrayLength);         // Angular filter of directional sound sources.        arrayLength = angularDistance.length;        filterType = angularFilterType;        if ((filterType != AuralParameters.NO_FILTERING) && arrayLength > 0) {            angularFilter = findFactor((double)distance,                   angularDistance, angularFilterCutoff);            if (angularFilter < 0.0f)                angularFilterFound = false;            else                angularFilterFound = true;        }        else  {            angularFilterFound = false;            angularFilter = -1.0f;        }         filterFlag = distanceFilterFound || angularFilterFound;        if (distanceFilter < 0.0f)            filterFreq = angularFilter;        else if (angularFilter < 0.0f)            filterFreq = distanceFilter;        else // both filter frequencies are > 0            filterFreq = Math.min(distanceFilter, angularFilter);        if (debugFlag)            debugPrint("    calculateFilter flag,freq = " + filterFlag +           "," + filterFreq );    }}

⌨️ 快捷键说明

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