Alex Szpakowski avatar Alex Szpakowski committed 35ba38e

Added Source:setRelativePosition and Source:hasRelativePosition, if enabled the Source's position will always be relative to the listener instead of absolute.

Comments (0)

Files changed (7)

src/modules/audio/Source.h

 	virtual void setDirection(float *v) = 0;
 	virtual void getDirection(float *v) const = 0;
 
+	virtual void setRelativePosition(bool relative) = 0;
+	virtual bool hasRelativePosition() const = 0;
+
 	virtual void setLooping(bool looping) = 0;
 	virtual bool isLooping() const = 0;
 	virtual bool isStatic() const = 0;

src/modules/audio/null/Source.cpp

 {
 }
 
+void Source::setRelativePosition(bool relative)
+{
+	relativePosition = relative;
+}
+
+bool Source::hasRelativePosition() const
+{
+	return relativePosition;
+}
+
 void Source::setLooping(bool looping)
 {
 	this->looping = looping;

src/modules/audio/null/Source.h

 	virtual void getVelocity(float *v) const;
 	virtual void setDirection(float *v);
 	virtual void getDirection(float *v) const;
+	virtual void setRelativePosition(bool relative);
+	virtual bool hasRelativePosition() const;
 	void setLooping(bool looping);
 	bool isLooping() const;
 	bool isStatic() const;
 
 	float pitch;
 	float volume;
+	bool relativePosition;
 	bool looping;
 	float minVolume;
 	float maxVolume;

src/modules/audio/openal/Source.cpp

 	, valid(false)
 	, pitch(1.0f)
 	, volume(1.0f)
+	, relativePosition(false)
 	, looping(false)
 	, paused(false)
 	, minVolume(0.0f)
 	, valid(false)
 	, pitch(1.0f)
 	, volume(1.0f)
+	, relativePosition(false)
 	, looping(false)
 	, paused(false)
 	, minVolume(0.0f)
 		setFloatv(v, direction);
 }
 
+void Source::setRelativePosition(bool relative)
+{
+	if (valid)
+		alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
+
+	relativePosition = relative;
+}
+
+bool Source::hasRelativePosition() const
+{
+	return relativePosition;
+}
+
 void Source::setLooping(bool looping)
 {
 	if (valid && type == TYPE_STATIC)
 	alSourcef(source, AL_ROLLOFF_FACTOR, rolloffFactor);
 	alSourcef(source, AL_MAX_DISTANCE, maxDistance);
 	alSourcei(source, AL_LOOPING, isStatic() && isLooping() ? AL_TRUE : AL_FALSE);
+	alSourcei(source, AL_SOURCE_RELATIVE, relativePosition ? AL_TRUE : AL_FALSE);
 }
 
 void Source::setFloatv(float *dst, const float *src) const

src/modules/audio/openal/Source.h

 	virtual void getVelocity(float *v) const;
 	virtual void setDirection(float *v);
 	virtual void getDirection(float *v) const;
+	virtual void setRelativePosition(bool relative);
+	virtual bool hasRelativePosition() const;
 	void setLooping(bool looping);
 	bool isLooping() const;
 	bool isStatic() const;
 	float position[3];
 	float velocity[3];
 	float direction[3];
+	bool relativePosition;
 	bool looping;
 	bool paused;
 	float minVolume;

src/modules/audio/wrap_Source.cpp

 	return 3;
 }
 
+int w_Source_setRelativePosition(lua_State *L)
+{
+	Source *t = luax_checksource(L, 1);
+	t->setRelativePosition(luax_toboolean(L, 2));
+	return 0;
+}
+
+int w_Source_hasRelativePosition(lua_State *L)
+{
+	Source *t = luax_checksource(L, 1);
+	luax_pushboolean(L, t->hasRelativePosition());
+	return 1;
+}
+
 int w_Source_setLooping(lua_State *L)
 {
 	Source *t = luax_checksource(L, 1);
 	{ "setDirection", w_Source_setDirection },
 	{ "getDirection", w_Source_getDirection },
 
+	{ "setRelativePosition", w_Source_setRelativePosition },
+	{ "hasRelativePosition", w_Source_hasRelativePosition },
+
 	{ "setLooping", w_Source_setLooping },
 	{ "isLooping", w_Source_isLooping },
 	{ "isStopped", w_Source_isStopped },

src/modules/audio/wrap_Source.h

 int w_Source_getVelocity(lua_State *L);
 int w_Source_setDirection(lua_State *L);
 int w_Source_getDirection(lua_State *L);
+int w_Source_setRelativePosition(lua_State *L);
+int w_Source_hasRelativePosition(lua_State *L);
 int w_Source_setLooping(lua_State *L);
 int w_Source_isLooping(lua_State *L);
 int w_Source_isStopped(lua_State *L);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.