📄 conesound.java
字号:
/* * $RCSfile: ConeSound.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.5 $ * $Date: 2007/02/09 17:17:56 $ * $State: Exp $ */package javax.media.j3d;import java.lang.Math;import javax.vecmath.Point2f;import javax.vecmath.Point3f;import javax.vecmath.Vector3f;/** * The ConeSound node object defines a PointSound node whose sound source is * directed along a specific vector in space. A ConeSound source is attenuated * by gain scale factors and filters based on the angle between the vector from * the source to the listener, and the ConeSound's direction vector. This * attenuation is either a single spherical distance gain attenuation (as for * a general PointSound source) or dual front and back distance gain * attenuations defining elliptical attenuation areas. The angular filter and the * active AuralAttribute component filter define what filtering is applied to * the sound source. (See AuralAtttribute class for more details on filtering.) * This node has the same attributes as a PointSound node with the addition of a * direction vector and an array of points each containing: angular distance (in * radians), gain scale factor, and filter (which for now consists of a lowpass * filter cutoff frequency). Similar to the definition of the back distance gain * array for PointSounds, a piece-wise linear curve (defined in terms of * radians from the axis) specifies the slope of these additional attenuation * values. * <P> * Distance Gain attuation * <P><UL> * A cone sound node can have one or two distance attenuation arrays. * If none are set, no distance gain attenuation is performed (equivalent * to using a distance gain of 1.0 for all distances). If only one distance * attenuation array is set, sphere attenuation is assumed. If both a front * and back distance attenuation are set, elliptical attenuation regions * are defined. *<P> * Use PointSound setDistanceGain() method to set the front distance * attenuation array separate from the back distance attenuation array. * A front distance attenuation array defines monotonically-increasing * distances from the sound source origin along the position direction * vector. A back distance attenuation array (if given) defines * monotonically-increasing distances from the sound source origin along the * negative direction vector. The two arrays must be of the same length. * The backDistance[i] gain values must be less than or equal to * the frontDistance[i] gain values. * <P> * Gain scale factors are associated with distances from the listener to * the sound source via an array of (distance, gain-scale-factor) pairs. * The gain scale factor applied to the sound source is the linear * interpolated gain value between the distance value range that includes * the current distance from the listener to the sound source. *<P> * The getDistanceGainLength method defined for PointSound returns the length * of the all distance gain attenuation arrays, including the back distance * gain arrays. Arrays passed into getDistanceGain methods should all * be at least this size. * </UL> <P> * Direction Methods * <P><UL> * This value is the sound source's direction vector. It is the axis from * which angular distance is measured. * </UL><P> * Angular Attenuation * <P><UL> * Besides sound (linear) distance attenuation a ConeSound can optionally * define angular gain and filter attenuation. * <P> * This attenuation is defined * as a triple of (angular distance, gain-scale-factor, filter). The * distance is measured as the angle in radians between the ConeSound's * direction vector and the vector from the sound source position to the * listener. Both the gain scale factor and filter applied to the sound * source is the linear interpolation of values between the distance value * range that includes the angular distance from the sound source axis. *<P> * If this is not set, no angular gain attenuation or filtering is performed * (equivalent to using an angular gain scale factor of 1.0 and an angular * filter of Sound.NO_FILTER for all distances). * <P> * If angular distance from the listener-sound-position vector and a sound's * direction vector is less than the first distance in the array, only the first * gain scale factor and first filter are applied to the sound source. * This creates a conical region around the listener within which the sound * is uniformly attenuated by first gain and first filter in the array. * <P> * If the distance from the listener-sound-position vector and the sound's * direction vector is greater than the last distance in the array, the last gain * scale factor and last filter are applied to the sound source. * <P> * Distance elements in this array of points is a monotonically-increasing * set of floating point numbers measured from 0 to p radians. Gain scale * factors elements in this list of points can be any positive floating * point numbers. While for most applications this list of gain scale * factors will usually be monotonically-decreasing, they do not have to be. * The filter (for now) is a single simple frequency cutoff value. * <P> * The getAngularAttenuationArrayLength method returns the length of the angular * attenuation arrays. Arrays passed into getAngularAttenuation methods * should all be at least this size. *</UL> */ public class ConeSound extends PointSound { // Constants // // These flags, when enabled using the setCapability method, allow an // application to invoke methods that respectively read and write direction // and angular attenuation array. These capability flags are enforced only // when the node is part of a live or compiled scene graph. /** * Specifies that this ConeSound allows access to its object's direction * information. */ public static final int ALLOW_DIRECTION_READ = CapabilityBits.CONE_SOUND_ALLOW_DIRECTION_READ; /** * Specifies that this ConeSound allows writing to its object's direction * information. */ public static final int ALLOW_DIRECTION_WRITE = CapabilityBits.CONE_SOUND_ALLOW_DIRECTION_WRITE; /** * Specifies that this ConeSound allows access to its object's cone params * information. */ public static final int ALLOW_ANGULAR_ATTENUATION_READ = CapabilityBits.CONE_SOUND_ALLOW_ANGULAR_ATTENUATION_READ; /** * Specifies that this ConeSound allows writing to its object's cone params * information. */ public static final int ALLOW_ANGULAR_ATTENUATION_WRITE = CapabilityBits.CONE_SOUND_ALLOW_ANGULAR_ATTENUATION_WRITE; // Array for setting default read capabilities private static final int[] readCapabilities = { ALLOW_DIRECTION_READ, ALLOW_ANGULAR_ATTENUATION_READ }; /** * Constructs and initializes a new ConeSound node using default * parameters. The following default values are used: * <ul> * Direction vector: (0.0, 0.0, 1.0) <br> * Angular attenuation: * ((0.0, 1.0, Sound.NO_FILTER),(p/2, 0.0, Sound.NO_FILTER)) <br> * </ul> */ public ConeSound() { // Uses default values defined in ConeSoundRetained.java super(); // set default read capabilities setDefaultReadCapabilities(readCapabilities); } /** * Constructs a ConeSound node object using only the provided parameter * values for sound, overall initial gain, position, and direction. The * remaining fields are set to the default values above. This form uses * Point3f as input for its position and Vector3f for direction. * @param soundData sound source data associated with this node * @param initialGain amplitude scale factor applied to sound * @param position 3D location of source * @param direction 3D vector defining cone's axis */ public ConeSound(MediaContainer soundData, float initialGain, Point3f position, Vector3f direction) { super(soundData, initialGain, position ); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((ConeSoundRetained)this.retained).setDirection(direction); } /** * Constructs a ConeSound node object using only the provided parameter * values for sound, overall initial gain, position, and direction. The * remaining fields are set to the default values above. This form uses * individual float parameters for the elements of the position and * direction vectors. * @param soundData sound source data * @param initialGain amplitude scale factor applied to sound * @param posX x coordinate of location of source * @param posY y coordinate of location of source * @param posZ z coordinate of location of source * @param dirX x coordinate cones' axii vector * @param dirY y coordinate cones' axii vector * @param dirZ z coordinate cones' axii vector */ public ConeSound(MediaContainer soundData, float initialGain, float posX, float posY, float posZ, float dirX, float dirY, float dirZ) { super(soundData, initialGain, posX, posY, posZ ); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((ConeSoundRetained)this.retained).setDirection(dirX, dirY, dirZ); } /** * Constructs a ConeSound node object using all the provided PointSound * parameter values. This form uses points or vectors as input for its * position, direction, and front/back distance attenuation arrays. *<P> * Unlike the single distance gain attenuation array for PointSounds which * define spherical areas about the sound source between which gains are * linearly interpolated, this directed ConeSound can have two distance gain * attenuation arrays that define ellipsoidal attenuation areas. See the * setDistanceGain PointSound method for details on how the separate distance * and distanceGain arrays are interpreted. *<P> * The ConeSound's direction vector and angular measurements are defined in * the local coordinate system of the node. * @param soundData sound source data associated with this node * @param initialGain amplitude scale factor applied to sound * @param loopCount number of times sound is looped * @param release flag denoting playing sound to end * @param continuous denotes that sound silently plays when disabled * @param enable sound switched on/off * @param region scheduling bounds * @param priority playback ranking value * @param position 3D location of source * @param frontDistanceAttenuation array of (distance,gain) pairs controlling * attenuation values along the positive direction axis * @param backDistanceAttenuation array of (distance,gain) pairs controlling * attenuation values along the negative direction axis * @param direction vector defining cones' axii */ public ConeSound(MediaContainer soundData, float initialGain, int loopCount, boolean release, boolean continuous, boolean enable, Bounds region, float priority, Point3f position, Point2f[] frontDistanceAttenuation, Point2f[] backDistanceAttenuation, Vector3f direction) { super(soundData, initialGain, loopCount, release, continuous, enable, region, priority, position, frontDistanceAttenuation ); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((ConeSoundRetained)this.retained).setBackDistanceGain( backDistanceAttenuation); ((ConeSoundRetained)this.retained).setDirection(direction); } /** * Constructs a ConeSound node object using the provided parameter values. * This form uses individual float parameters for the elements of the * position, direction, and two distance attenuation arrays. * Unlike the single distance gain attenuation array for PointSounds, which * define spherical areas about the sound source between which gains are * linearly interpolated, this directed ConeSound can have two distance * gain attenuation arrays that define ellipsoidal attenuation areas. * See the setDistanceGain PointSound method for details on how the * separate distance and distanceGain arrays are interpreted. * The ConeSound's direction vector and angular measurements are defined * in the local coordinate system of the node. * @param soundData sound source data associated with this node * @param initialGain amplitude scale factor applied to sound * @param loopCount number of times sound is looped * @param release flag denoting playing sound to end * @param continuous denotes that sound silently plays when disabled * @param enable sound switched on/off * @param region scheduling bounds * @param priority playback ranking value * @param posX x coordinate of location of source * @param posY y coordinate of location of source * @param posZ z coordinate of location of source * @param frontDistance array of front distance values used for attenuation * @param frontDistanceGain array of front gain scale factors used for attenuation * @param backDistance array of back distance values used for attenuation * @param backDistanceGain array of back gain scale factors used for attenuation * @param dirX x coordinate cones' axii vector * @param dirY y coordinate cones' axii vector * @param dirZ z coordinate cones' axii vector */ public ConeSound(MediaContainer soundData, float initialGain, int loopCount, boolean release, boolean continuous, boolean enable, Bounds region, float priority, float posX, float posY, float posZ,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -