1/*
2 * Copyright (c) 2009-2010 jMonkeyEngine
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 *   notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 *   notice, this list of conditions and the following disclaimer in the
14 *   documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17 *   may be used to endorse or promote products derived from this software
18 *   without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33package com.jme3.audio;
34
35import com.jme3.math.Quaternion;
36import com.jme3.math.Vector3f;
37
38public class Listener {
39
40    private Vector3f location;
41    private Vector3f velocity;
42    private Quaternion rotation;
43    private float volume = 1;
44    private AudioRenderer renderer;
45
46    public Listener(){
47        location = new Vector3f();
48        velocity = new Vector3f();
49        rotation = new Quaternion();
50    }
51
52    public Listener(Listener source){
53        location = source.location.clone();
54        velocity = source.velocity.clone();
55        rotation = source.rotation.clone();
56        volume = source.volume;
57    }
58
59    public void setRenderer(AudioRenderer renderer){
60        this.renderer = renderer;
61    }
62
63    public float getVolume() {
64        return volume;
65    }
66
67    public void setVolume(float volume) {
68        this.volume = volume;
69        if (renderer != null)
70            renderer.updateListenerParam(this, ListenerParam.Volume);
71    }
72
73    public Vector3f getLocation() {
74        return location;
75    }
76
77    public Quaternion getRotation() {
78        return rotation;
79    }
80
81    public Vector3f getVelocity() {
82        return velocity;
83    }
84
85    public Vector3f getLeft(){
86        return rotation.getRotationColumn(0);
87    }
88
89    public Vector3f getUp(){
90        return rotation.getRotationColumn(1);
91    }
92
93    public Vector3f getDirection(){
94        return rotation.getRotationColumn(2);
95    }
96
97    public void setLocation(Vector3f location) {
98        this.location.set(location);
99        if (renderer != null)
100            renderer.updateListenerParam(this, ListenerParam.Position);
101    }
102
103    public void setRotation(Quaternion rotation) {
104        this.rotation.set(rotation);
105        if (renderer != null)
106            renderer.updateListenerParam(this, ListenerParam.Rotation);
107    }
108
109    public void setVelocity(Vector3f velocity) {
110        this.velocity.set(velocity);
111        if (renderer != null)
112            renderer.updateListenerParam(this, ListenerParam.Velocity);
113    }
114}
115