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

This commit is contained in:
Alex Szpakowski
2013-10-11 02:25:48 -03:00
parent 2710c6c488
commit 7f3cd7f044
7 changed files with 54 additions and 0 deletions
+16
View File
@@ -39,6 +39,7 @@ Source::Source(Pool *pool, love::sound::SoundData *soundData)
, valid(false)
, pitch(1.0f)
, volume(1.0f)
, relativePosition(false)
, looping(false)
, paused(false)
, minVolume(0.0f)
@@ -68,6 +69,7 @@ Source::Source(Pool *pool, love::sound::Decoder *decoder)
, valid(false)
, pitch(1.0f)
, volume(1.0f)
, relativePosition(false)
, looping(false)
, paused(false)
, minVolume(0.0f)
@@ -402,6 +404,19 @@ void Source::getDirection(float *v) const
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)
@@ -535,6 +550,7 @@ void Source::reset()
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
+3
View File
@@ -78,6 +78,8 @@ public:
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;
@@ -126,6 +128,7 @@ private:
float position[3];
float velocity[3];
float direction[3];
bool relativePosition;
bool looping;
bool paused;
float minVolume;