Răsfoiți Sursa

Sound playback status accessor and 3D physics fixes

Ivan Safrin 14 ani în urmă
părinte
comite
774ec0b061

+ 6 - 0
Core/Contents/Include/PolySound.h

@@ -76,6 +76,12 @@ namespace Polycode {
 		* @param newPitch A Number 0-1.
 		*/		
 		void setPitch(Number newPitch);
+		
+		/**
+		* Returns true if the sound is playing.
+		* @return True if sound is playing, false if otherwise.
+		*/
+		bool isPlaying();
 				
 		void setIsPositional(bool isPositional);
 		

+ 7 - 0
Core/Contents/Source/PolySound.cpp

@@ -112,6 +112,13 @@ void Sound::Play(bool loop) {
 	alSourcePlay(soundSource);
 }
 
+bool Sound::isPlaying() {
+	ALenum state;
+	alGetSourcei(soundSource, AL_SOURCE_STATE, &state);
+	return (state == AL_PLAYING);
+}
+
+
 void Sound::setVolume(Number newVolume) {
 	alSourcef(soundSource, AL_GAIN, newVolume);
 }

+ 1 - 1
Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h

@@ -89,7 +89,7 @@ namespace Polycode {
 		
 		
 		void setVelocity(SceneEntity *entity, Vector3 velocity);
-		void warpEntity(SceneEntity *entity, Vector3 position);
+		void warpEntity(SceneEntity *entity, Vector3 position, bool resetRotation = false);
 		
 		PhysicsVehicle *addVehicleChild(SceneEntity *newEntity, Number mass, Number friction, int group  = 1);
 		

+ 1 - 1
Modules/Contents/3DPhysics/Include/PolyPhysicsSceneEntity.h

@@ -51,7 +51,7 @@ namespace Polycode {
 		int getType() { return type; }	
 		
 			void setVelocity(Vector3 velocity);
-			void warpTo(Vector3 position);
+			void warpTo(Vector3 position, bool resetRotation);
 			//@}
 			// ----------------------------------------------------------------------------------------------------------------
 			

+ 2 - 2
Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp

@@ -152,10 +152,10 @@ void PhysicsScene::setVelocity(SceneEntity *entity, Vector3 velocity) {
 	}
 }
 
-void PhysicsScene::warpEntity(SceneEntity *entity, Vector3 position) {
+void PhysicsScene::warpEntity(SceneEntity *entity, Vector3 position, bool resetRotation) {
 	PhysicsSceneEntity *physicsEntity = getPhysicsEntityBySceneEntity(entity);
 	if(physicsEntity) {
-		physicsEntity->warpTo(position);
+		physicsEntity->warpTo(position, resetRotation);
 	}
 }
 

+ 10 - 8
Modules/Contents/3DPhysics/Source/PolyPhysicsSceneEntity.cpp

@@ -237,18 +237,20 @@ void PhysicsSceneEntity::setVelocity(Vector3 velocity) {
 //	rigidBody->applyForce(btVector3(velocity.x, velocity.y, velocity.z), btVector3(0,0,0));
 }
 
-void PhysicsSceneEntity::warpTo(Vector3 position) {
+void PhysicsSceneEntity::warpTo(Vector3 position, bool resetRotation) {
 	btTransform transform;
+	transform.setIdentity();
 	
-	Matrix4 ent_mat = sceneEntity->getConcatenatedMatrix();
+	if(!resetRotation) {
+		Matrix4 ent_mat = sceneEntity->getConcatenatedMatrix();	
+		btScalar mat[16];
+		for(int i=0; i < 16; i++) {
+			mat[i] = ent_mat.ml[i];
+		}	
+		transform.setFromOpenGLMatrix(mat);	
+	}
 	
-	btScalar mat[16];
-	for(int i=0; i < 16; i++) {
-		mat[i] = ent_mat.ml[i];
-	}	
-	transform.setFromOpenGLMatrix(mat);	
 	transform.setOrigin(btVector3(position.x,position.y,position.z));	
-	
 	rigidBody->setCenterOfMassTransform(transform);
 }