📄 pointsound.java
字号:
/* * $RCSfile: PointSound.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:18:16 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.Point2f;import javax.vecmath.Point3f;/** * The PointSound node (a sub-class of the Sound node) defines a spatially * located sound source whose waves radiate uniformly in all directions from * a given location in space. It has the same attributes as a Sound object * with the addition of a location and the specification of distance-based * gain attenuation for listener positions between an array of distances. *<P> * A sound's amplitude is attenuated based on the distance between the listener * and the sound source position. A piecewise linear curve (defined in terms of * pairs of distance and gain scale factor) specifies the gain scale factor slope. * * The PointSound's location and attenuation distances are defined in the local * coordinate system of the node. *<P> * Distance Gain Attenuation * <UL> * 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. If the distance from the listener to * the sound source is less than the first distance in the array, the first * gain scale factor is applied to the sound source. This creates a * spherical region around the listener within which all sound gain is * uniformly scaled by the first gain in the array. If the distance from * the listener to the sound source is greater than the last distance in * the array, the last gain scale factor is applied to the sound source. *<P> * Distance elements in this array of Point2f is a monotonically-increasing * set of floating point numbers measured from the location of the sound * source. Gain scale factors elements in this list of pairs 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. * If this * is not set, no distance gain attenuation is performed (equivalent to * using a distance gain of 1.0 for all distances). *<P> * getDistanceGainLength method returns the length of the distance gain * attenuation arrays. Arrays passed into getDistanceGain methods should all * be at least this size. *<P> * There are two methods for getDistanceGain, one returning an array of * points, the other returning separate arrays for each attenuation * component.</UL> */public class PointSound extends Sound { // Constants // // These flags, when enabled using the setCapability method, allow an // application to invoke methods that respectively read and write the position // and the distance gain array. These capability flags are enforced only when // the node is part of a live or compiled scene graph /** * Specifies that this node allows access to its object's position * information. */ public static final int ALLOW_POSITION_READ = CapabilityBits.POINT_SOUND_ALLOW_POSITION_READ; /** * Specifies that this node allows writing to its object's position * information. */ public static final int ALLOW_POSITION_WRITE = CapabilityBits.POINT_SOUND_ALLOW_POSITION_WRITE; /** * Specifies that this node allows access to its object's distance * gain attenuation information. */ public static final int ALLOW_DISTANCE_GAIN_READ = CapabilityBits.POINT_SOUND_ALLOW_DISTANCE_GAIN_READ; /** * Specifies that this node allows writing to its object's distance * gain attenuation information. */ public static final int ALLOW_DISTANCE_GAIN_WRITE = CapabilityBits.POINT_SOUND_ALLOW_DISTANCE_GAIN_WRITE; // Array for setting default read capabilities private static final int[] readCapabilities = { ALLOW_POSITION_READ, ALLOW_DISTANCE_GAIN_READ }; /** * Constructs and initializes a new PointSound node using default * parameters. The following default values are used: * <ul> * position vector: (0.0, 0.0, 0.0)<br> * Back attenuation: null<br> * distance gain attenuation: null (no attenuation performed)<br> * </ul> */ public PointSound() { // Uses default values defined for Sound and PointSound nodes super(); // set default read capabilities setDefaultReadCapabilities(readCapabilities); } /** * Constructs a PointSound node object using only the provided parameter * values for sound data, sample gain, and position. The remaining fields * are set to the above default values. This form uses a point as input for * its position. * @param soundData sound data associated with this sound source node * @param initialGain amplitude scale factor applied to sound source * @param position 3D location of source */ public PointSound(MediaContainer soundData, float initialGain, Point3f position) { super(soundData, initialGain); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((PointSoundRetained)this.retained).setPosition(position); } /** * Constructs a PointSound node object using only the provided parameter * values for sound data, sample gain, and position. The remaining fields * are set to to the above default values. This form uses individual float * parameters for the elements of the position point. * @param soundData sound data associated with this sound source node * @param initialGain amplitude scale factor applied to sound source data * @param posX x coordinate of location of source * @param posY y coordinate of location of source * @param posZ z coordinate of location of source */ public PointSound(MediaContainer soundData, float initialGain, float posX, float posY, float posZ ) { super(soundData, initialGain); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((PointSoundRetained)this.retained).setPosition(posX,posY,posZ); } // The next four constructors fill all this classes fields with the provided // arguments values. // See the header for the setDistanceGain method for details on how the // those arrays are interpreted. /** * Construct a PointSound object accepting Point3f as input for the position * and accepting an array of Point2f for the distance attenuation values * where each pair in the array contains a distance and a gain scale factor. * @param soundData sound data associated with this sound source node * @param initialGain amplitude scale factor applied to sound source * @param loopCount number of times loop is looped * @param release flag denoting playing sound data 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 distanceGain array of (distance,gain) pairs controling attenuation */ public PointSound(MediaContainer soundData, float initialGain, int loopCount, boolean release, boolean continuous, boolean enable, Bounds region, float priority, Point3f position, Point2f[] distanceGain) { super(soundData, initialGain, loopCount, release, continuous, enable, region, priority ); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((PointSoundRetained)this.retained).setPosition(position); ((PointSoundRetained)this.retained).setDistanceGain(distanceGain); } /** * Construct a PointSound object accepting individual float parameters for * the elements of the position point, and accepting an array of Point2f for * the distance attenuation values where each pair in the array contains a * distance and a gain scale factor. * @param soundData sound data associated with this sound source node * @param initialGain amplitude scale factor applied to sound source * @param loopCount number of times loop 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 distanceGain array of (distance,gain) pairs controling attenuation */ public PointSound(MediaContainer soundData, float initialGain, int loopCount, boolean release, boolean continuous, boolean enable, Bounds region, float priority, float posX, float posY, float posZ, Point2f[] distanceGain) { super(soundData, initialGain, loopCount, release, continuous, enable, region, priority ); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((PointSoundRetained)this.retained).setPosition(posX,posY,posZ); ((PointSoundRetained)this.retained).setDistanceGain(distanceGain); } /** * Construct a PointSound object accepting points as input for the position. * and accepting separate arrays for the distance and gain scale factors * components of distance attenuation. * @param soundData sound data associated with this sound source node * @param initialGain amplitude scale factor applied to sound source * @param loopCount number of times loop is looped * @param release flag denoting playing sound data 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 attenuationDistance array of distance values used for attenuation * @param attenuationGain array of gain scale factors used for attenuation */ public PointSound(MediaContainer soundData, float initialGain, int loopCount, boolean release, boolean continuous, boolean enable, Bounds region, float priority, Point3f position, float[] attenuationDistance, float[] attenuationGain) { super(soundData, initialGain, loopCount, release, continuous, enable, region, priority ); // set default read capabilities setDefaultReadCapabilities(readCapabilities); ((PointSoundRetained)this.retained).setPosition(position);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -