diff --git a/src/modules/audio/Audio.h b/src/modules/audio/Audio.h index 218ba7b03..92a2a4048 100644 --- a/src/modules/audio/Audio.h +++ b/src/modules/audio/Audio.h @@ -156,6 +156,44 @@ namespace audio **/ virtual float getVolume() const = 0; + /** + * Gets the position of the listener. + * @param v A float array of size 3 containing (x,y,z) in that order. + **/ + virtual void getPosition(float * v) const = 0; + + /** + * Sets the position of the listener. + * @param v A float array of size 3 containing [x,y,z] in that order. + **/ + virtual void setPosition(float * v) = 0; + + /** + * Gets the orientation of the listener. + * @param v A float array of size 6 containing [x,y,z] for the forward + * vector, followed by [x,y,z] for the up vector. + **/ + virtual void getOrientation(float * v) const = 0; + + /** + * Sets the orientation of the listener. + * @param v A float array of size 6 containing [x,y,z] for the forward + * vector, followed by [x,y,z] for the up vector. + **/ + virtual void setOrientation(float * v) = 0; + + /** + * Gets the velocity of the listener. + * @param v A float array of size 3 containing [x,y,z] in that order. + **/ + virtual void getVelocity(float * v) const = 0; + + /** + * Sets the velocity of the listener. + * @param v A float array of size 3 containing [x,y,z] in that order. + **/ + virtual void setVelocity(float * v) = 0; + }; // Audio } // audio diff --git a/src/modules/audio/Source.h b/src/modules/audio/Source.h index 074c465a7..d0c52a1cc 100644 --- a/src/modules/audio/Source.h +++ b/src/modules/audio/Source.h @@ -53,6 +53,14 @@ namespace audio virtual void setVolume(float volume) = 0; virtual float getVolume() const = 0; + + // all float * v must be of size 3 + virtual void setPosition(float * v) = 0; + virtual void getPosition(float * v) const = 0; + virtual void setVelocity(float * v) = 0; + virtual void getVelocity(float * v) const = 0; + virtual void setDirection(float * v) = 0; + virtual void getDirection(float * v) const = 0; void setLooping(bool looping); bool isLooping() const; diff --git a/src/modules/audio/null/Audio.cpp b/src/modules/audio/null/Audio.cpp index 02c5a8b97..91b8ed0fc 100644 --- a/src/modules/audio/null/Audio.cpp +++ b/src/modules/audio/null/Audio.cpp @@ -122,6 +122,30 @@ namespace null return volume; } + void Audio::getPosition(float * v) const + { + } + + void Audio::setPosition(float * v) + { + } + + void Audio::getOrientation(float * v) const + { + } + + void Audio::setOrientation(float * v) + { + } + + void Audio::getVelocity(float * v) const + { + } + + void Audio::setVelocity(float * v) + { + } + } // null } // audio } // love diff --git a/src/modules/audio/null/Audio.h b/src/modules/audio/null/Audio.h index e184a8b27..45303a18a 100644 --- a/src/modules/audio/null/Audio.h +++ b/src/modules/audio/null/Audio.h @@ -67,6 +67,13 @@ namespace null void setVolume(float volume); float getVolume() const; + void getPosition(float * v) const; + void setPosition(float * v); + void getOrientation(float * v) const; + void setOrientation(float * v); + void getVelocity(float * v) const; + void setVelocity(float * v); + }; // Audio } // null diff --git a/src/modules/audio/null/Source.cpp b/src/modules/audio/null/Source.cpp index 933032d42..dc35c564f 100644 --- a/src/modules/audio/null/Source.cpp +++ b/src/modules/audio/null/Source.cpp @@ -89,6 +89,30 @@ namespace null return volume; } + void Source::setPosition(float * v) + { + } + + void Source::getPosition(float * v) const + { + } + + void Source::setVelocity(float * v) + { + } + + void Source::getVelocity(float * v) const + { + } + + void Source::setDirection(float * v) + { + } + + void Source::getDirection(float * v) const + { + } + } // null } // audio } // love diff --git a/src/modules/audio/null/Source.h b/src/modules/audio/null/Source.h index cffbfac28..3b1f4aced 100644 --- a/src/modules/audio/null/Source.h +++ b/src/modules/audio/null/Source.h @@ -57,6 +57,13 @@ namespace null void setVolume(float volume); float getVolume() const; + void setPosition(float * v); + void getPosition(float * v) const; + void setVelocity(float * v); + void getVelocity(float * v) const; + void setDirection(float * v); + void getDirection(float * v) const; + }; // Source } // null diff --git a/src/modules/audio/openal/Audio.cpp b/src/modules/audio/openal/Audio.cpp index f0a992f0f..3603aa95a 100644 --- a/src/modules/audio/openal/Audio.cpp +++ b/src/modules/audio/openal/Audio.cpp @@ -175,6 +175,36 @@ namespace openal return volume; } + void Audio::getPosition(float * v) const + { + alGetListenerfv(AL_POSITION, v); + } + + void Audio::setPosition(float * v) + { + alListenerfv(AL_POSITION, v); + } + + void Audio::getOrientation(float * v) const + { + alGetListenerfv(AL_ORIENTATION, v); + } + + void Audio::setOrientation(float * v) + { + alListenerfv(AL_ORIENTATION, v); + } + + void Audio::getVelocity(float * v) const + { + alGetListenerfv(AL_VELOCITY, v); + } + + void Audio::setVelocity(float * v) + { + alListenerfv(AL_VELOCITY, v); + } + } // openal } // audio } // love diff --git a/src/modules/audio/openal/Audio.h b/src/modules/audio/openal/Audio.h index 939c96ec6..b6d3a2e87 100644 --- a/src/modules/audio/openal/Audio.h +++ b/src/modules/audio/openal/Audio.h @@ -96,6 +96,13 @@ namespace openal void setVolume(float volume); float getVolume() const; + void getPosition(float * v) const; + void setPosition(float * v); + void getOrientation(float * v) const; + void setOrientation(float * v); + void getVelocity(float * v) const; + void setVelocity(float * v); + }; // Audio } // openal diff --git a/src/modules/audio/openal/Source.cpp b/src/modules/audio/openal/Source.cpp index 5b3404ebd..6532e639b 100644 --- a/src/modules/audio/openal/Source.cpp +++ b/src/modules/audio/openal/Source.cpp @@ -163,6 +163,42 @@ namespace openal return volume; } + void Source::setPosition(float * v) + { + if(source) + alSourcefv(source, AL_POSITION, v); + } + + void Source::getPosition(float * v) const + { + if(source) + alGetSourcefv(source, AL_POSITION, v); + } + + void Source::setVelocity(float * v) + { + if(source) + alSourcefv(source, AL_VELOCITY, v); + } + + void Source::getVelocity(float * v) const + { + if(source) + alGetSourcefv(source, AL_VELOCITY, v); + } + + void Source::setDirection(float * v) + { + if(source) + alSourcefv(source, AL_DIRECTION, v); + } + + void Source::getDirection(float * v) const + { + if(source) + alGetSourcefv(source, AL_DIRECTION, v); + } + } // openal } // audio } // love diff --git a/src/modules/audio/openal/Source.h b/src/modules/audio/openal/Source.h index e609ae2a8..1f3332504 100644 --- a/src/modules/audio/openal/Source.h +++ b/src/modules/audio/openal/Source.h @@ -67,6 +67,13 @@ namespace openal void setVolume(float volume); float getVolume() const; + void setPosition(float * v); + void getPosition(float * v) const; + void setVelocity(float * v); + void getVelocity(float * v) const; + void setDirection(float * v); + void getDirection(float * v) const; + }; // Source } // openal diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index c2584dc23..412519936 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -140,6 +140,72 @@ namespace audio return 1; } + int _wrap_setPosition(lua_State * L) + { + float v[3]; + v[0] = (float)luaL_checknumber(L, 1); + v[1] = (float)luaL_checknumber(L, 2); + v[2] = (float)luaL_checknumber(L, 3); + instance->setPosition(v); + return 0; + } + + int _wrap_getPosition(lua_State * L) + { + float v[3]; + instance->getPosition(v); + lua_pushnumber(L, v[0]); + lua_pushnumber(L, v[1]); + lua_pushnumber(L, v[2]); + return 3; + } + + int _wrap_setOrientation(lua_State * L) + { + float v[6]; + v[0] = (float)luaL_checknumber(L, 1); + v[1] = (float)luaL_checknumber(L, 2); + v[2] = (float)luaL_checknumber(L, 3); + v[3] = (float)luaL_checknumber(L, 4); + v[4] = (float)luaL_checknumber(L, 5); + v[5] = (float)luaL_checknumber(L, 6); + instance->setOrientation(v); + return 0; + } + + int _wrap_getOrientation(lua_State * L) + { + float v[6]; + instance->getOrientation(v); + lua_pushnumber(L, v[0]); + lua_pushnumber(L, v[1]); + lua_pushnumber(L, v[2]); + lua_pushnumber(L, v[3]); + lua_pushnumber(L, v[4]); + lua_pushnumber(L, v[5]); + return 6; + } + + int _wrap_setVelocity(lua_State * L) + { + float v[3]; + v[0] = (float)luaL_checknumber(L, 1); + v[1] = (float)luaL_checknumber(L, 2); + v[2] = (float)luaL_checknumber(L, 3); + instance->setVelocity(v); + return 0; + } + + int _wrap_getVelocity(lua_State * L) + { + float v[3]; + instance->getVelocity(v); + lua_pushnumber(L, v[0]); + lua_pushnumber(L, v[1]); + lua_pushnumber(L, v[2]); + return 3; + } + // List of functions to wrap. static const luaL_Reg wrap_Audio_functions[] = { { "getNumSources", _wrap_getNumSources }, @@ -153,6 +219,14 @@ namespace audio { "rewind", _wrap_rewind }, { "setVolume", _wrap_setVolume }, { "getVolume", _wrap_getVolume }, + + { "setPosition", _wrap_setPosition }, + { "getPosition", _wrap_getPosition }, + { "setOrientation", _wrap_setOrientation }, + { "getOrientation", _wrap_getOrientation }, + { "setVelocity", _wrap_setVelocity }, + { "getVelocity", _wrap_getVelocity }, + { 0, 0 } }; diff --git a/src/modules/audio/wrap_Audio.h b/src/modules/audio/wrap_Audio.h index d7eba7c1f..b401dc7b6 100644 --- a/src/modules/audio/wrap_Audio.h +++ b/src/modules/audio/wrap_Audio.h @@ -42,6 +42,12 @@ namespace audio int _wrap_rewind(lua_State * L); int _wrap_setVolume(lua_State * L); int _wrap_getVolume(lua_State * L); + int _wrap_setPosition(lua_State * L); + int _wrap_getPosition(lua_State * L); + int _wrap_setOrientation(lua_State * L); + int _wrap_getOrientation(lua_State * L); + int _wrap_setVelocity(lua_State * L); + int _wrap_getVelocity(lua_State * L); int wrap_Audio_open(lua_State * L); } // audio diff --git a/src/modules/audio/wrap_Source.cpp b/src/modules/audio/wrap_Source.cpp index 4e06eae32..06817ae28 100644 --- a/src/modules/audio/wrap_Source.cpp +++ b/src/modules/audio/wrap_Source.cpp @@ -59,6 +59,72 @@ namespace audio return 1; } + int _wrap_Source_setPosition(lua_State * L) + { + Source * t = luax_checksource(L, 1); + float v[3]; + v[0] = (float)luaL_checknumber(L, 2); + v[1] = (float)luaL_checknumber(L, 3); + v[2] = (float)luaL_checknumber(L, 4); + t->setPosition(v); + return 0; + } + + int _wrap_Source_getPosition(lua_State * L) + { + Source * t = luax_checksource(L, 1); + float v[3]; + t->getPosition(v); + lua_pushnumber(L, v[0]); + lua_pushnumber(L, v[1]); + lua_pushnumber(L, v[2]); + return 3; + } + + int _wrap_Source_setVelocity(lua_State * L) + { + Source * t = luax_checksource(L, 1); + float v[3]; + v[0] = (float)luaL_checknumber(L, 2); + v[1] = (float)luaL_checknumber(L, 3); + v[2] = (float)luaL_checknumber(L, 4); + t->setVelocity(v); + return 0; + } + + int _wrap_Source_getVelocity(lua_State * L) + { + Source * t = luax_checksource(L, 1); + float v[3]; + t->getVelocity(v); + lua_pushnumber(L, v[0]); + lua_pushnumber(L, v[1]); + lua_pushnumber(L, v[2]); + return 3; + } + + int _wrap_Source_setDirection(lua_State * L) + { + Source * t = luax_checksource(L, 1); + float v[3]; + v[0] = (float)luaL_checknumber(L, 2); + v[1] = (float)luaL_checknumber(L, 3); + v[2] = (float)luaL_checknumber(L, 4); + t->setDirection(v); + return 0; + } + + int _wrap_Source_getDirection(lua_State * L) + { + Source * t = luax_checksource(L, 1); + float v[3]; + t->getDirection(v); + lua_pushnumber(L, v[0]); + lua_pushnumber(L, v[1]); + lua_pushnumber(L, v[2]); + return 3; + } + int _wrap_Source_setLooping(lua_State * L) { Source * t = luax_checksource(L, 1); @@ -73,7 +139,6 @@ namespace audio return 1; } - static const luaL_Reg wrap_Source_functions[] = { { "setPitch", _wrap_Source_setPitch }, { "getPitch", _wrap_Source_getPitch }, diff --git a/src/modules/audio/wrap_Source.h b/src/modules/audio/wrap_Source.h index 24e565ec3..5055b7b51 100644 --- a/src/modules/audio/wrap_Source.h +++ b/src/modules/audio/wrap_Source.h @@ -33,6 +33,12 @@ namespace audio int _wrap_Source_getPitch(lua_State * L); int _wrap_Source_setVolume(lua_State * L); int _wrap_Source_getVolume(lua_State * L); + int _wrap_Source_setPosition(lua_State * L); + int _wrap_Source_getPosition(lua_State * L); + int _wrap_Source_setVelocity(lua_State * L); + int _wrap_Source_getVelocity(lua_State * L); + int _wrap_Source_setDirection(lua_State * L); + int _wrap_Source_getDirection(lua_State * L); int _wrap_Source_setLooping(lua_State * L); int _wrap_Source_isLooping(lua_State * L); int wrap_Source_open(lua_State * L);