[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30912] branches/soc-2010-nexyon: Audaspace: Refactored the complete 3D Device code giving a nicer API.

Joerg Mueller nexyon at gmail.com
Sat Jul 31 00:20:08 CEST 2010


Revision: 30912
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30912
Author:   nexyon
Date:     2010-07-31 00:20:08 +0200 (Sat, 31 Jul 2010)

Log Message:
-----------
Audaspace: Refactored the complete 3D Device code giving a nicer API.

Modified Paths:
--------------
    branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.h
    branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_I3DDevice.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_IDevice.h
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_Space.h
    branches/soc-2010-nexyon/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    branches/soc-2010-nexyon/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soc-2010-nexyon/source/gameengine/Ketsji/KX_SoundActuator.cpp

Added Paths:
-----------
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_3DMath.h

Modified: branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2010-07-30 22:10:34 UTC (rev 30911)
+++ branches/soc-2010-nexyon/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2010-07-30 22:20:08 UTC (rev 30912)
@@ -1099,215 +1099,448 @@
 /**************************** 3D Device Code **********************************/
 /******************************************************************************/
 
-AUD_Handle* AUD_OpenALDevice::play3D(AUD_IFactory* factory, bool keep)
+AUD_Vector3 AUD_OpenALDevice::getListenerLocation() const
 {
-	AUD_OpenALHandle* handle = (AUD_OpenALHandle*)play(factory, keep);
-	if(handle)
-		alSourcei(handle->source, AL_SOURCE_RELATIVE, 0);
-	return handle;
+	ALfloat p[3];
+	alGetListenerfv(AL_POSITION, p);
+	return AUD_Vector3(p[0], p[1], p[2]);
 }
 
-bool AUD_OpenALDevice::updateListener(AUD_3DData &data)
+void AUD_OpenALDevice::setListenerLocation(const AUD_Vector3& location)
 {
-	alListenerfv(AL_POSITION, (ALfloat*)data.position);
-	alListenerfv(AL_VELOCITY, (ALfloat*)data.velocity);
-	alListenerfv(AL_ORIENTATION, (ALfloat*)&(data.orientation[3]));
+	alListenerfv(AL_POSITION, (ALfloat*)location.get());
+}
 
-	return true;
+AUD_Vector3 AUD_OpenALDevice::getListenerVelocity() const
+{
+	ALfloat v[3];
+	alGetListenerfv(AL_VELOCITY, v);
+	return AUD_Vector3(v[0], v[1], v[2]);
 }
 
-bool AUD_OpenALDevice::setSetting(AUD_3DSetting setting, float value)
+void AUD_OpenALDevice::setListenerVelocity(const AUD_Vector3& velocity)
 {
-	switch(setting)
+	alListenerfv(AL_VELOCITY, (ALfloat*)velocity.get());
+}
+
+AUD_Quaternion AUD_OpenALDevice::getListenerOrientation() const
+{
+	// AUD_XXX not implemented yet
+	return AUD_Quaternion(0, 0, 0, 0);
+}
+
+void AUD_OpenALDevice::setListenerOrientation(const AUD_Quaternion& orientation)
+{
+	ALfloat direction[6];
+	direction[0] = -2 * (orientation.w() * orientation.y() +
+						 orientation.x() * orientation.z());
+	direction[1] = 2 * (orientation.x() * orientation.w() -
+						orientation.z() * orientation.y());
+	direction[2] = 2 * (orientation.x() * orientation.x() +
+						orientation.y() * orientation.y()) - 1;
+	direction[3] = 2 * (orientation.x() * orientation.y() -
+						orientation.w() * orientation.z());
+	direction[4] = 1 - 2 * (orientation.x() * orientation.x() +
+							orientation.z() * orientation.z());
+	direction[5] = 2 * (orientation.w() * orientation.x() +
+						orientation.y() * orientation.z());
+	alListenerfv(AL_ORIENTATION, direction);
+}
+
+float AUD_OpenALDevice::getSpeedOfSound() const
+{
+	return alGetFloat(AL_SPEED_OF_SOUND);
+}
+
+void AUD_OpenALDevice::setSpeedOfSound(float speed)
+{
+	alSpeedOfSound(speed);
+}
+
+float AUD_OpenALDevice::getDopplerFactor() const
+{
+	return alGetFloat(AL_DOPPLER_FACTOR);
+}
+
+void AUD_OpenALDevice::setDopplerFactor(float factor)
+{
+	alDopplerFactor(factor);
+}
+
+AUD_DistanceModel AUD_OpenALDevice::getDistanceModel() const
+{
+	switch(alGetInteger(AL_DISTANCE_MODEL))
 	{
-	case AUD_3DS_DISTANCE_MODEL:
-		if(value == AUD_DISTANCE_MODEL_NONE)
-			alDistanceModel(AL_NONE);
-		else if(value == AUD_DISTANCE_MODEL_INVERSE)
-			alDistanceModel(AL_INVERSE_DISTANCE);
-		else if(value == AUD_DISTANCE_MODEL_INVERSE_CLAMPED)
-			alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
-		else if(value == AUD_DISTANCE_MODEL_LINEAR)
-			alDistanceModel(AL_LINEAR_DISTANCE);
-		else if(value == AUD_DISTANCE_MODEL_LINEAR_CLAMPED)
-			alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
-		else if(value == AUD_DISTANCE_MODEL_EXPONENT)
-			alDistanceModel(AL_EXPONENT_DISTANCE);
-		else if(value == AUD_DISTANCE_MODEL_EXPONENT_CLAMPED)
-			alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
-		else
-			return false;
-		return true;
-	case AUD_3DS_DOPPLER_FACTOR:
-		alDopplerFactor(value);
-		return true;
-	case AUD_3DS_SPEED_OF_SOUND:
-		alSpeedOfSound(value);
-		return true;
+	case AL_INVERSE_DISTANCE:
+		return AUD_DISTANCE_MODEL_INVERSE;
+	case AL_INVERSE_DISTANCE_CLAMPED:
+		return AUD_DISTANCE_MODEL_INVERSE_CLAMPED;
+	case AL_LINEAR_DISTANCE:
+		return AUD_DISTANCE_MODEL_LINEAR;
+	case AL_LINEAR_DISTANCE_CLAMPED:
+		return AUD_DISTANCE_MODEL_LINEAR_CLAMPED;
+	case AL_EXPONENT_DISTANCE:
+		return AUD_DISTANCE_MODEL_EXPONENT;
+	case AL_EXPONENT_DISTANCE_CLAMPED:
+		return AUD_DISTANCE_MODEL_EXPONENT_CLAMPED;
 	default:
-		return false;
+		return AUD_DISTANCE_MODEL_INVALID;
 	}
 }
 
-float AUD_OpenALDevice::getSetting(AUD_3DSetting setting)
+void AUD_OpenALDevice::setDistanceModel(AUD_DistanceModel model)
 {
-	switch(setting)
+	switch(model)
 	{
-	case AUD_3DS_DISTANCE_MODEL:
-		switch(alGetInteger(AL_DISTANCE_MODEL))
-		{
-			case AL_NONE:
-				return AUD_DISTANCE_MODEL_NONE;
-			case AL_INVERSE_DISTANCE:
-				return AUD_DISTANCE_MODEL_INVERSE;
-			case AL_INVERSE_DISTANCE_CLAMPED:
-				return AUD_DISTANCE_MODEL_INVERSE_CLAMPED;
-			case AL_LINEAR_DISTANCE:
-				return AUD_DISTANCE_MODEL_LINEAR;
-			case AL_LINEAR_DISTANCE_CLAMPED:
-				return AUD_DISTANCE_MODEL_LINEAR_CLAMPED;
-			case AL_EXPONENT_DISTANCE:
-				return AUD_DISTANCE_MODEL_EXPONENT;
-			case AL_EXPONENT_DISTANCE_CLAMPED:
-				return AUD_DISTANCE_MODEL_EXPONENT_CLAMPED;
-		}
-	case AUD_3DS_DOPPLER_FACTOR:
-		return alGetFloat(AL_DOPPLER_FACTOR);
-	case AUD_3DS_SPEED_OF_SOUND:
-		return alGetFloat(AL_SPEED_OF_SOUND);
+	case AUD_DISTANCE_MODEL_INVERSE:
+		alDistanceModel(AL_INVERSE_DISTANCE);
+		break;
+	case AUD_DISTANCE_MODEL_INVERSE_CLAMPED:
+		alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
+		break;
+	case AUD_DISTANCE_MODEL_LINEAR:
+		alDistanceModel(AL_LINEAR_DISTANCE);
+		break;
+	case AUD_DISTANCE_MODEL_LINEAR_CLAMPED:
+		alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
+		break;
+	case AUD_DISTANCE_MODEL_EXPONENT:
+		alDistanceModel(AL_EXPONENT_DISTANCE);
+		break;
+	case AUD_DISTANCE_MODEL_EXPONENT_CLAMPED:
+		alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
+		break;
 	default:
-		return std::numeric_limits<float>::quiet_NaN();
+		alDistanceModel(AL_NONE);
 	}
 }
 
-bool AUD_OpenALDevice::updateSource(AUD_Handle* handle, AUD_3DData &data)
+AUD_Vector3 AUD_OpenALDevice::getSourceLocation(AUD_Handle* handle)
 {
-	bool result = false;
-
+	AUD_Vector3 result = AUD_Vector3(0, 0, 0);
+	ALfloat p[3];
 	lock();
 
 	if(isValid(handle))
 	{
-		int source = ((AUD_OpenALHandle*)handle)->source;
-		alSourcefv(source, AL_POSITION, (ALfloat*)data.position);
-		alSourcefv(source, AL_VELOCITY, (ALfloat*)data.velocity);
-		alSourcefv(source, AL_DIRECTION, (ALfloat*)&(data.orientation[3]));
-		result = true;
+		alGetSourcefv(((AUD_OpenALHandle*)handle)->source, AL_POSITION, p);
+		result = AUD_Vector3(p[0], p[1], p[2]);
 	}
 
 	unlock();
+	return result;
+}
 
+bool AUD_OpenALDevice::setSourceLocation(AUD_Handle* handle, const AUD_Vector3& location)
+{
+	lock();
+	bool result = isValid(handle);
+
+	if(result)
+		alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_POSITION,
+				   (ALfloat*)location.get());
+
+	unlock();
 	return result;
 }
 
-bool AUD_OpenALDevice::setSourceSetting(AUD_Handle* handle,
-										AUD_3DSourceSetting setting,
-										float value)
+AUD_Vector3 AUD_OpenALDevice::getSourceVelocity(AUD_Handle* handle)
 {
+	AUD_Vector3 result = AUD_Vector3(0, 0, 0);
+	ALfloat v[3];
 	lock();
 
-	bool result = false;
-
 	if(isValid(handle))
 	{
-		int source = ((AUD_OpenALHandle*)handle)->source;
+		alGetSourcefv(((AUD_OpenALHandle*)handle)->source, AL_VELOCITY, v);
+		result = AUD_Vector3(v[0], v[1], v[2]);
+	}
 
-		switch(setting)
-		{
-		case AUD_3DSS_CONE_INNER_ANGLE:
-			alSourcef(source, AL_CONE_INNER_ANGLE, value);
-			result = true;
-			break;
-		case AUD_3DSS_CONE_OUTER_ANGLE:
-			alSourcef(source, AL_CONE_OUTER_ANGLE, value);
-			result = true;
-			break;
-		case AUD_3DSS_CONE_OUTER_GAIN:
-			alSourcef(source, AL_CONE_OUTER_GAIN, value);
-			result = true;
-			break;
-		case AUD_3DSS_IS_RELATIVE:
-			alSourcei(source, AL_SOURCE_RELATIVE, value > 0.0f);
-			result = true;
-			break;
-		case AUD_3DSS_MAX_DISTANCE:
-			alSourcef(source, AL_MAX_DISTANCE, value);
-			result = true;
-			break;
-		case AUD_3DSS_MAX_GAIN:
-			alSourcef(source, AL_MAX_GAIN, value);
-			result = true;
-			break;
-		case AUD_3DSS_MIN_GAIN:
-			alSourcef(source, AL_MIN_GAIN, value);
-			result = true;
-			break;
-		case AUD_3DSS_REFERENCE_DISTANCE:
-			alSourcef(source, AL_REFERENCE_DISTANCE, value);
-			result = true;
-			break;
-		case AUD_3DSS_ROLLOFF_FACTOR:
-			alSourcef(source, AL_ROLLOFF_FACTOR, value);
-			result = true;
-			break;
-		default:
-			break;
-		}
+	unlock();
+	return result;
+}
+
+bool AUD_OpenALDevice::setSourceVelocity(AUD_Handle* handle, const AUD_Vector3& velocity)
+{
+	lock();
+	bool result = isValid(handle);
+
+	if(result)
+		alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_VELOCITY,
+				   (ALfloat*)velocity.get());
+
+	unlock();
+	return result;
+}
+
+AUD_Quaternion AUD_OpenALDevice::getSourceOrientation(AUD_Handle* handle)
+{
+	// AUD_XXX not implemented yet
+	return AUD_Quaternion(0, 0, 0, 0);
+}
+
+bool AUD_OpenALDevice::setSourceOrientation(AUD_Handle* handle, const AUD_Quaternion& orientation)
+{
+	lock();
+	bool result = isValid(handle);
+
+	if(result)
+	{
+		ALfloat direction[3];
+		direction[0] = -2 * (orientation.w() * orientation.y() +
+							 orientation.x() * orientation.z());
+		direction[1] = 2 * (orientation.x() * orientation.w() -
+							orientation.z() * orientation.y());
+		direction[2] = 2 * (orientation.x() * orientation.x() +
+							orientation.y() * orientation.y()) - 1;
+		alSourcefv(((AUD_OpenALHandle*)handle)->source, AL_DIRECTION,
+				   direction);
 	}
 
 	unlock();
 	return result;
 }
 
-float AUD_OpenALDevice::getSourceSetting(AUD_Handle* handle,
-										 AUD_3DSourceSetting setting)
+bool AUD_OpenALDevice::isRelative(AUD_Handle* handle)
 {
+	int result = std::numeric_limits<float>::quiet_NaN();;
+
+	lock();
+
+	if(isValid(handle))
+		alGetSourcei(((AUD_OpenALHandle*)handle)->source, AL_SOURCE_RELATIVE,
+					 &result);
+
+	unlock();
+	return result;
+}
+
+bool AUD_OpenALDevice::setRelative(AUD_Handle* handle, bool relative)
+{
+	lock();
+	bool result = isValid(handle);
+
+	if(result)
+		alSourcei(((AUD_OpenALHandle*)handle)->source, AL_SOURCE_RELATIVE,
+				  relative);
+
+	unlock();
+	return result;
+}
+
+float AUD_OpenALDevice::getVolumeMaximum(AUD_Handle* handle)
+{
 	float result = std::numeric_limits<float>::quiet_NaN();;
 
 	lock();
 
 	if(isValid(handle))
-	{
-		int source = ((AUD_OpenALHandle*)handle)->source;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list