4141 */
4242public class Listener {
4343
44- private final Vector3f location ;
45- private final Vector3f velocity ;
46- private final Quaternion rotation ;
47- private float volume = 1 ;
44+ private final Vector3f location = new Vector3f () ;
45+ private final Vector3f velocity = new Vector3f () ;
46+ private final Quaternion rotation = new Quaternion () ;
47+ private float volume = 1f ;
4848 private AudioRenderer renderer ;
4949
50+
5051 /**
5152 * Constructs a new {@code Listener} with default parameters.
5253 */
5354 public Listener () {
54- location = new Vector3f ();
55- velocity = new Vector3f ();
56- rotation = new Quaternion ();
5755 }
5856
5957 /**
@@ -62,9 +60,9 @@ public Listener() {
6260 * @param source The {@code Listener} to copy the properties from.
6361 */
6462 public Listener (Listener source ) {
65- this .location = source .location . clone ( );
66- this .velocity = source .velocity . clone ( );
67- this .rotation = source .rotation . clone ( );
63+ this .location . set ( source .location );
64+ this .velocity . set ( source .velocity );
65+ this .rotation . set ( source .rotation );
6866 this .volume = source .volume ;
6967 this .renderer = source .renderer ; // Note: Renderer is also copied
7068 }
@@ -109,6 +107,17 @@ public Vector3f getLocation() {
109107 return location ;
110108 }
111109
110+ /**
111+ * Gets the current location of the listener in world space.
112+ *
113+ * @param store The vector to store the result in.
114+ * @return The listener's location as a {@link Vector3f}.
115+ */
116+ public Vector3f getLocation (Vector3f store ) {
117+ if (store == null ) store = new Vector3f ();
118+ return store .set (location );
119+ }
120+
112121 /**
113122 * Gets the current rotation of the listener in world space.
114123 *
@@ -118,6 +127,17 @@ public Quaternion getRotation() {
118127 return rotation ;
119128 }
120129
130+ /**
131+ * Gets the current rotation of the listener in world space.
132+ *
133+ * @param store The quaternion to store the result in.
134+ * @return The listener's rotation as a {@link Quaternion}.
135+ */
136+ public Quaternion getRotation (Quaternion store ) {
137+ if (store == null ) store = new Quaternion ();
138+ return store .set (rotation );
139+ }
140+
121141 /**
122142 * Gets the current velocity of the listener.
123143 * This is used for Doppler effect calculations.
@@ -128,14 +148,35 @@ public Vector3f getVelocity() {
128148 return velocity ;
129149 }
130150
151+ /**
152+ * Gets the current velocity of the listener.
153+ *
154+ * @param store The vector to store the result in.
155+ * @return The listener's velocity as a {@link Vector3f}.
156+ */
157+ public Vector3f getVelocity (Vector3f store ) {
158+ if (store == null ) store = new Vector3f ();
159+ return store .set (velocity );
160+ }
161+
131162 /**
132163 * Gets the left direction vector of the listener.
133164 * This vector is derived from the listener's rotation.
134165 *
135166 * @return The listener's left direction as a {@link Vector3f}.
136167 */
137168 public Vector3f getLeft () {
138- return rotation .getRotationColumn (0 );
169+ return getLeft (null );
170+ }
171+
172+ /**
173+ * Gets the left direction vector of the listener. This vector is derived from the listener's rotation.
174+ *
175+ * @param store The vector to store the result in.
176+ * @return The listener's left direction as a {@link Vector3f}.
177+ */
178+ public Vector3f getLeft (Vector3f store ) {
179+ return rotation .getRotationColumn (0 , store );
139180 }
140181
141182 /**
@@ -145,7 +186,18 @@ public Vector3f getLeft() {
145186 * @return The listener's up direction as a {@link Vector3f}.
146187 */
147188 public Vector3f getUp () {
148- return rotation .getRotationColumn (1 );
189+ return getUp (null );
190+ }
191+
192+ /**
193+ * Gets the up direction vector of the listener.
194+ * This vector is derived from the listener's rotation.
195+ *
196+ * @param store The vector to store the result in.
197+ * @return The listener's up direction as a {@link Vector3f}.
198+ */
199+ public Vector3f getUp (Vector3f store ) {
200+ return rotation .getRotationColumn (1 , store );
149201 }
150202
151203 /**
@@ -155,7 +207,18 @@ public Vector3f getUp() {
155207 * @return The listener's forward direction.
156208 */
157209 public Vector3f getDirection () {
158- return rotation .getRotationColumn (2 );
210+ return getDirection (null );
211+ }
212+
213+ /**
214+ * Gets the forward direction vector of the listener.
215+ * This vector is derived from the listener's rotation.
216+ *
217+ * @param store The vector to store the result in.
218+ * @return The listener's forward direction.
219+ */
220+ public Vector3f getDirection (Vector3f store ) {
221+ return rotation .getRotationColumn (2 , store );
159222 }
160223
161224 /**
0 commit comments