Skip to content

Commit e903149

Browse files
authored
Merge pull request #2414 from capdevon/capdevon-audio-listener
com.jme3.audio.Listener: format code + javadoc
2 parents 6f95af8 + 10add91 commit e903149

File tree

1 file changed

+105
-13
lines changed

1 file changed

+105
-13
lines changed

jme3-core/src/main/java/com/jme3/audio/Listener.java

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,11 @@
3434
import com.jme3.math.Quaternion;
3535
import com.jme3.math.Vector3f;
3636

37+
/**
38+
* Represents the audio listener in the 3D sound scene.
39+
* The listener defines the point of view from which sound is heard,
40+
* influencing spatial audio effects like panning and Doppler shift.
41+
*/
3742
public class Listener {
3843

3944
private final Vector3f location;
@@ -42,72 +47,159 @@ public class Listener {
4247
private float volume = 1;
4348
private AudioRenderer renderer;
4449

50+
/**
51+
* Constructs a new {@code Listener} with default parameters.
52+
*/
4553
public Listener() {
4654
location = new Vector3f();
4755
velocity = new Vector3f();
4856
rotation = new Quaternion();
4957
}
5058

59+
/**
60+
* Constructs a new {@code Listener} by copying the properties of another {@code Listener}.
61+
*
62+
* @param source The {@code Listener} to copy the properties from.
63+
*/
5164
public Listener(Listener source) {
52-
location = source.location.clone();
53-
velocity = source.velocity.clone();
54-
rotation = source.rotation.clone();
55-
volume = source.volume;
65+
this.location = source.location.clone();
66+
this.velocity = source.velocity.clone();
67+
this.rotation = source.rotation.clone();
68+
this.volume = source.volume;
69+
this.renderer = source.renderer; // Note: Renderer is also copied
5670
}
5771

72+
/**
73+
* Sets the {@link AudioRenderer} associated with this listener.
74+
* The renderer is responsible for applying the listener's parameters
75+
* to the audio output.
76+
*
77+
* @param renderer The {@link AudioRenderer} to associate with.
78+
*/
5879
public void setRenderer(AudioRenderer renderer) {
5980
this.renderer = renderer;
6081
}
6182

83+
/**
84+
* Gets the current volume of the listener.
85+
*
86+
* @return The current volume.
87+
*/
6288
public float getVolume() {
6389
return volume;
6490
}
6591

92+
/**
93+
* Sets the volume of the listener.
94+
* If an {@link AudioRenderer} is set, it will be notified of the volume change.
95+
*
96+
* @param volume The new volume.
97+
*/
6698
public void setVolume(float volume) {
6799
this.volume = volume;
68-
if (renderer != null)
69-
renderer.updateListenerParam(this, ListenerParam.Volume);
100+
updateListenerParam(ListenerParam.Volume);
70101
}
71102

103+
/**
104+
* Gets the current location of the listener in world space.
105+
*
106+
* @return The listener's location as a {@link Vector3f}.
107+
*/
72108
public Vector3f getLocation() {
73109
return location;
74110
}
75111

112+
/**
113+
* Gets the current rotation of the listener in world space.
114+
*
115+
* @return The listener's rotation as a {@link Quaternion}.
116+
*/
76117
public Quaternion getRotation() {
77118
return rotation;
78119
}
79120

121+
/**
122+
* Gets the current velocity of the listener.
123+
* This is used for Doppler effect calculations.
124+
*
125+
* @return The listener's velocity as a {@link Vector3f}.
126+
*/
80127
public Vector3f getVelocity() {
81128
return velocity;
82129
}
83130

131+
/**
132+
* Gets the left direction vector of the listener.
133+
* This vector is derived from the listener's rotation.
134+
*
135+
* @return The listener's left direction as a {@link Vector3f}.
136+
*/
84137
public Vector3f getLeft() {
85138
return rotation.getRotationColumn(0);
86139
}
87140

141+
/**
142+
* Gets the up direction vector of the listener.
143+
* This vector is derived from the listener's rotation.
144+
*
145+
* @return The listener's up direction as a {@link Vector3f}.
146+
*/
88147
public Vector3f getUp() {
89148
return rotation.getRotationColumn(1);
90149
}
91150

151+
/**
152+
* Gets the forward direction vector of the listener.
153+
* This vector is derived from the listener's rotation.
154+
*
155+
* @return The listener's forward direction.
156+
*/
92157
public Vector3f getDirection() {
93158
return rotation.getRotationColumn(2);
94159
}
95160

161+
/**
162+
* Sets the location of the listener in world space.
163+
* If an {@link AudioRenderer} is set, it will be notified of the position change.
164+
*
165+
* @param location The new location of the listener.
166+
*/
96167
public void setLocation(Vector3f location) {
97168
this.location.set(location);
98-
if (renderer != null)
99-
renderer.updateListenerParam(this, ListenerParam.Position);
169+
updateListenerParam(ListenerParam.Position);
100170
}
101171

172+
/**
173+
* Sets the rotation of the listener in world space.
174+
* If an {@link AudioRenderer} is set, it will be notified of the rotation change.
175+
*
176+
* @param rotation The new rotation of the listener.
177+
*/
102178
public void setRotation(Quaternion rotation) {
103179
this.rotation.set(rotation);
104-
if (renderer != null)
105-
renderer.updateListenerParam(this, ListenerParam.Rotation);
180+
updateListenerParam(ListenerParam.Rotation);
106181
}
107182

183+
/**
184+
* Sets the velocity of the listener.
185+
* This is used for Doppler effect calculations.
186+
* If an {@link AudioRenderer} is set, it will be notified of the velocity change.
187+
*
188+
* @param velocity The new velocity of the listener.
189+
*/
108190
public void setVelocity(Vector3f velocity) {
109191
this.velocity.set(velocity);
110-
if (renderer != null)
111-
renderer.updateListenerParam(this, ListenerParam.Velocity);
192+
updateListenerParam(ListenerParam.Velocity);
193+
}
194+
195+
/**
196+
* Updates the associated {@link AudioRenderer} with the specified listener parameter.
197+
*
198+
* @param param The {@link ListenerParam} to update on the renderer.
199+
*/
200+
private void updateListenerParam(ListenerParam param) {
201+
if (renderer != null) {
202+
renderer.updateListenerParam(this, param);
203+
}
112204
}
113205
}

0 commit comments

Comments
 (0)