001: /*
002: * BackgroundSoundBehavior.java
003: *
004: * Created on 3 July 2006, 02:04
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package org.jdesktop.j3d.apps.sound;
011:
012: import java.util.Enumeration;
013: import javax.media.j3d.Behavior;
014: import javax.media.j3d.BoundingSphere;
015: import javax.media.j3d.RenderingAttributes;
016: import javax.media.j3d.Sound;
017: import javax.media.j3d.WakeupCondition;
018: import javax.media.j3d.WakeupOnElapsedFrames;
019: import javax.vecmath.Point3d;
020:
021: /**
022: *
023: * @author dave
024: */
025: public class SoundBehavior extends Behavior {
026:
027: private WakeupCondition condition = new WakeupOnElapsedFrames(0);
028: private Sound sound;
029:
030: private boolean boundsVisible = true;
031: private boolean distanceAttenuationVisible = true;
032: private boolean angularAttenuationVisible = true;
033: private RenderingAttributes boundsRenderingAttributes;
034: private RenderingAttributes distanceAttenuationRenderingAttributes;
035: private RenderingAttributes angularAttenuationRenderingAttributes;
036:
037: /** Creates a new instance of BackgroundSoundBehavior */
038: public SoundBehavior(Sound sound,
039: RenderingAttributes boundsRenderingAttributes) {
040: this .sound = sound;
041: this .boundsRenderingAttributes = boundsRenderingAttributes;
042: setSchedulingBounds(new BoundingSphere(new Point3d(),
043: Double.POSITIVE_INFINITY));
044: }
045:
046: /** Creates a new instance of BackgroundSoundBehavior */
047: public SoundBehavior(Sound sound,
048: RenderingAttributes boundsRenderingAttributes,
049: RenderingAttributes distanceAttenuationRenderingAttributes) {
050: this .sound = sound;
051: this .boundsRenderingAttributes = boundsRenderingAttributes;
052: this .distanceAttenuationRenderingAttributes = distanceAttenuationRenderingAttributes;
053: setSchedulingBounds(new BoundingSphere(new Point3d(),
054: Double.POSITIVE_INFINITY));
055: }
056:
057: /** Creates a new instance of BackgroundSoundBehavior */
058: public SoundBehavior(Sound sound,
059: RenderingAttributes boundsRenderingAttributes,
060: RenderingAttributes distanceAttenuationRenderingAttributes,
061: RenderingAttributes angularAttenuationRenderingAttributes) {
062: this .sound = sound;
063: this .boundsRenderingAttributes = boundsRenderingAttributes;
064: this .distanceAttenuationRenderingAttributes = distanceAttenuationRenderingAttributes;
065: this .angularAttenuationRenderingAttributes = angularAttenuationRenderingAttributes;
066: setSchedulingBounds(new BoundingSphere(new Point3d(),
067: Double.POSITIVE_INFINITY));
068: }
069:
070: public void initialize() {
071: wakeupOn(condition);
072: }
073:
074: public void processStimulus(Enumeration enumeration) {
075: if (boundsRenderingAttributes.getVisible() != isBoundsVisible())
076: boundsRenderingAttributes.setVisible(isBoundsVisible());
077: if (distanceAttenuationRenderingAttributes != null) {
078: if (distanceAttenuationRenderingAttributes.getVisible() != isDistanceAttenuationVisible())
079: distanceAttenuationRenderingAttributes
080: .setVisible(isDistanceAttenuationVisible());
081: }
082: if (angularAttenuationRenderingAttributes != null) {
083: if (angularAttenuationRenderingAttributes.getVisible() != isAngularAttenuationVisible())
084: angularAttenuationRenderingAttributes
085: .setVisible(isAngularAttenuationVisible());
086: }
087: wakeupOn(condition);
088: }
089:
090: public boolean isBoundsVisible() {
091: return boundsVisible;
092: }
093:
094: public void setBoundsVisible(boolean boundsVisible) {
095: this .boundsVisible = boundsVisible;
096: }
097:
098: public boolean isDistanceAttenuationVisible() {
099: return distanceAttenuationVisible;
100: }
101:
102: public void setDistanceAttenuationVisible(
103: boolean distanceAttenuationVisible) {
104: this .distanceAttenuationVisible = distanceAttenuationVisible;
105: }
106:
107: public boolean isAngularAttenuationVisible() {
108: return angularAttenuationVisible;
109: }
110:
111: public void setAngularAttenuationVisible(
112: boolean angularAttenuationVisible) {
113: this.angularAttenuationVisible = angularAttenuationVisible;
114: }
115:
116: }
|