From b936c22f91f15b22a26ebbeb28a903577002cb4a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 21 Nov 2017 19:16:58 -0800 Subject: [PATCH] Pass 3D parameters as Vector3s instead of individual components --- include/AL/alure2.h | 14 +++++++------- src/context.cpp | 19 +++++++++---------- src/context.h | 6 +++--- src/source.cpp | 47 ++++++++++++++++++----------------------------- src/source.h | 8 ++++---- 5 files changed, 41 insertions(+), 53 deletions(-) diff --git a/include/AL/alure2.h b/include/AL/alure2.h index 805b969..040b7c3 100644 --- a/include/AL/alure2.h +++ b/include/AL/alure2.h @@ -690,7 +690,7 @@ public: void set3DParameters(const Vector3 &position, const Vector3 &velocity, const std::pair &orientation); /** Specifies the listener's 3D position. */ - void setPosition(ALfloat x, ALfloat y, ALfloat z); + void setPosition(const Vector3 &position); void setPosition(const ALfloat *pos); /** @@ -698,14 +698,14 @@ public: * OpenAL, this does not actually alter the listener's position, and * instead just alters the pitch as determined by the doppler effect. */ - void setVelocity(ALfloat x, ALfloat y, ALfloat z); + void setVelocity(const Vector3 &velocity); void setVelocity(const ALfloat *vel); /** * Specifies the listener's 3D orientation, using position-relative 'at' * and 'up' direction vectors. */ - void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2); + void setOrientation(const std::pair &orientation); void setOrientation(const ALfloat *at, const ALfloat *up); void setOrientation(const ALfloat *ori); @@ -967,7 +967,7 @@ public: void set3DParameters(const Vector3 &position, const Vector3 &velocity, const std::pair &orientation); /** Specifies the source's 3D position. */ - void setPosition(ALfloat x, ALfloat y, ALfloat z); + void setPosition(const Vector3 &position); void setPosition(const ALfloat *pos); Vector3 getPosition() const; @@ -976,7 +976,7 @@ public: * this does not actually alter the source's position, and instead just * alters the pitch as determined by the doppler effect. */ - void setVelocity(ALfloat x, ALfloat y, ALfloat z); + void setVelocity(const Vector3 &velocity); void setVelocity(const ALfloat *vel); Vector3 getVelocity() const; @@ -984,7 +984,7 @@ public: * Specifies the source's 3D facing direction. Deprecated in favor of * setOrientation. */ - void setDirection(ALfloat x, ALfloat y, ALfloat z); + void setDirection(const Vector3 &direction); void setDirection(const ALfloat *dir); Vector3 getDirection() const; @@ -994,7 +994,7 @@ public: * property comes from, this also affects the facing direction, superceding * setDirection. */ - void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2); + void setOrientation(const std::pair &orientation); void setOrientation(const ALfloat *at, const ALfloat *up); void setOrientation(const ALfloat *ori); std::pair getOrientation() const; diff --git a/src/context.cpp b/src/context.cpp index 46967b7..9e4e64a 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -1597,11 +1597,11 @@ void ListenerImpl::set3DParameters(const Vector3 &position, const Vector3 &veloc alListenerfv(AL_ORIENTATION, orientation.first.getPtr()); } -DECL_THUNK3(void, Listener, setPosition,, ALfloat, ALfloat, ALfloat) -void ListenerImpl::setPosition(ALfloat x, ALfloat y, ALfloat z) +DECL_THUNK1(void, Listener, setPosition,, const Vector3&) +void ListenerImpl::setPosition(const Vector3 &position) { CheckContext(mContext); - alListener3f(AL_POSITION, x, y, z); + alListenerfv(AL_POSITION, position.getPtr()); } DECL_THUNK1(void, Listener, setPosition,, const ALfloat*) @@ -1611,11 +1611,11 @@ void ListenerImpl::setPosition(const ALfloat *pos) alListenerfv(AL_POSITION, pos); } -DECL_THUNK3(void, Listener, setVelocity,, ALfloat, ALfloat, ALfloat) -void ListenerImpl::setVelocity(ALfloat x, ALfloat y, ALfloat z) +DECL_THUNK1(void, Listener, setVelocity,, const Vector3&) +void ListenerImpl::setVelocity(const Vector3 &velocity) { CheckContext(mContext); - alListener3f(AL_VELOCITY, x, y, z); + alListenerfv(AL_VELOCITY, velocity.getPtr()); } DECL_THUNK1(void, Listener, setVelocity,, const ALfloat*) @@ -1625,12 +1625,11 @@ void ListenerImpl::setVelocity(const ALfloat *vel) alListenerfv(AL_VELOCITY, vel); } -DECL_THUNK6(void, Listener, setOrientation,, ALfloat, ALfloat, ALfloat, ALfloat, ALfloat, ALfloat) -void ListenerImpl::setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2) +DECL_THUNK1(void, Listener, setOrientation,, const Vector3Pair&) +void ListenerImpl::setOrientation(const std::pair &orientation) { CheckContext(mContext); - ALfloat ori[6] = { x1, y1, z1, x2, y2, z2 }; - alListenerfv(AL_ORIENTATION, ori); + alListenerfv(AL_ORIENTATION, orientation.first.getPtr()); } DECL_THUNK2(void, Listener, setOrientation,, const ALfloat*, const ALfloat*) diff --git a/src/context.h b/src/context.h index 8a3f14e..fb91797 100644 --- a/src/context.h +++ b/src/context.h @@ -88,13 +88,13 @@ public: void set3DParameters(const Vector3 &position, const Vector3 &velocity, const std::pair &orientation); - void setPosition(ALfloat x, ALfloat y, ALfloat z); + void setPosition(const Vector3 &position); void setPosition(const ALfloat *pos); - void setVelocity(ALfloat x, ALfloat y, ALfloat z); + void setVelocity(const Vector3 &velocity); void setVelocity(const ALfloat *vel); - void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2); + void setOrientation(const std::pair &orientation); void setOrientation(const ALfloat *at, const ALfloat *up); void setOrientation(const ALfloat *ori); diff --git a/src/source.cpp b/src/source.cpp index 7091ed9..9ccd895 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -1026,15 +1026,13 @@ void SourceImpl::set3DParameters(const Vector3 &position, const Vector3 &velocit } -DECL_THUNK3(void, Source, setPosition,, ALfloat, ALfloat, ALfloat) -void SourceImpl::setPosition(ALfloat x, ALfloat y, ALfloat z) +DECL_THUNK1(void, Source, setPosition,, const Vector3&) +void SourceImpl::setPosition(const Vector3 &position) { CheckContext(mContext); if(mId != 0) - alSource3f(mId, AL_POSITION, x, y, z); - mPosition[0] = x; - mPosition[1] = y; - mPosition[2] = z; + alSourcefv(mId, AL_POSITION, position.getPtr()); + mPosition = position; } DECL_THUNK1(void, Source, setPosition,, const ALfloat*) @@ -1048,15 +1046,13 @@ void SourceImpl::setPosition(const ALfloat *pos) mPosition[2] = pos[2]; } -DECL_THUNK3(void, Source, setVelocity,, ALfloat, ALfloat, ALfloat) -void SourceImpl::setVelocity(ALfloat x, ALfloat y, ALfloat z) +DECL_THUNK1(void, Source, setVelocity,, const Vector3&) +void SourceImpl::setVelocity(const Vector3 &velocity) { CheckContext(mContext); if(mId != 0) - alSource3f(mId, AL_VELOCITY, x, y, z); - mVelocity[0] = x; - mVelocity[1] = y; - mVelocity[2] = z; + alSourcefv(mId, AL_VELOCITY, velocity.getPtr()); + mVelocity = velocity; } DECL_THUNK1(void, Source, setVelocity,, const ALfloat*) @@ -1070,15 +1066,13 @@ void SourceImpl::setVelocity(const ALfloat *vel) mVelocity[2] = vel[2]; } -DECL_THUNK3(void, Source, setDirection,, ALfloat, ALfloat, ALfloat) -void SourceImpl::setDirection(ALfloat x, ALfloat y, ALfloat z) +DECL_THUNK1(void, Source, setDirection,, const Vector3&) +void SourceImpl::setDirection(const Vector3 &direction) { CheckContext(mContext); if(mId != 0) - alSource3f(mId, AL_DIRECTION, x, y, z); - mDirection[0] = x; - mDirection[1] = y; - mDirection[2] = z; + alSourcefv(mId, AL_DIRECTION, direction.getPtr()); + mDirection = direction; } DECL_THUNK1(void, Source, setDirection,, const ALfloat*) @@ -1092,23 +1086,18 @@ void SourceImpl::setDirection(const ALfloat *dir) mDirection[2] = dir[2]; } -DECL_THUNK6(void, Source, setOrientation,, ALfloat, ALfloat, ALfloat, ALfloat, ALfloat, ALfloat) -void SourceImpl::setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2) +DECL_THUNK1(void, Source, setOrientation,, const Vector3Pair&) +void SourceImpl::setOrientation(const std::pair &orientation) { CheckContext(mContext); if(mId != 0) { - ALfloat ori[6] = { x1, y1, z1, x2, y2, z2 }; if(mContext->hasExtension(AL::EXT_BFORMAT)) - alSourcefv(mId, AL_ORIENTATION, ori); - alSourcefv(mId, AL_DIRECTION, ori); + alSourcefv(mId, AL_ORIENTATION, orientation.first.getPtr()); + alSourcefv(mId, AL_DIRECTION, orientation.first.getPtr()); } - mDirection[0] = mOrientation[0][0] = x1; - mDirection[1] = mOrientation[0][1] = y1; - mDirection[2] = mOrientation[0][2] = z1; - mOrientation[1][0] = x2; - mOrientation[1][1] = y2; - mOrientation[1][2] = z2; + mDirection = mOrientation[0] = orientation.first; + mOrientation[1] = orientation.second; } DECL_THUNK2(void, Source, setOrientation,, const ALfloat*, const ALfloat*) diff --git a/src/source.h b/src/source.h index 0173f91..f270f54 100644 --- a/src/source.h +++ b/src/source.h @@ -142,19 +142,19 @@ public: void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction); void set3DParameters(const Vector3 &position, const Vector3 &velocity, const std::pair &orientation); - void setPosition(ALfloat x, ALfloat y, ALfloat z); + void setPosition(const Vector3 &position); void setPosition(const ALfloat *pos); Vector3 getPosition() const { return mPosition; } - void setVelocity(ALfloat x, ALfloat y, ALfloat z); + void setVelocity(const Vector3 &velocity); void setVelocity(const ALfloat *vel); Vector3 getVelocity() const { return mVelocity; } - void setDirection(ALfloat x, ALfloat y, ALfloat z); + void setDirection(const Vector3 &direction); void setDirection(const ALfloat *dir); Vector3 getDirection() const { return mDirection; } - void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2); + void setOrientation(const std::pair &orientation); void setOrientation(const ALfloat *at, const ALfloat *up); void setOrientation(const ALfloat *ori); std::pair getOrientation() const -- 2.11.4.GIT