Fix AudioNode issues when using velocityFromTranslation and small refactoring (#875)

* Fix AudioNode issues when using velocityFromTranslation and small refactoring

* Fix audionode fix
accellbaker
Riccardo Balbo 6 years ago committed by Stephen Gold
parent 9c949891b0
commit f12d7e4e60
  1. 30
      jme3-core/src/main/java/com/jme3/audio/AudioNode.java

@ -722,25 +722,14 @@ public class AudioNode extends Node implements AudioSource {
@Override
public void updateGeometricState() {
super.updateGeometricState();
if (channel < 0) {
return;
}
if (channel < 0 || this.getParent() == null) return;
Vector3f currentWorldTranslation = worldTransform.getTranslation();
if (Float.isNaN(previousWorldTranslation.x)
|| !previousWorldTranslation.equals(currentWorldTranslation)) {
if (!previousWorldTranslation.equals(currentWorldTranslation)) {
getRenderer().updateSourceParam(this, AudioParam.Position);
if (velocityFromTranslation) {
velocity.set(currentWorldTranslation).subtractLocal(previousWorldTranslation);
velocity.multLocal(1f / lastTpf);
if (velocityFromTranslation && !Float.isNaN(previousWorldTranslation.x)) {
velocity.set(currentWorldTranslation).subtractLocal(previousWorldTranslation).multLocal(1f / lastTpf);
getRenderer().updateSourceParam(this, AudioParam.Velocity);
}
previousWorldTranslation.set(currentWorldTranslation);
}
}
@ -748,10 +737,6 @@ public class AudioNode extends Node implements AudioSource {
@Override
public AudioNode clone(){
AudioNode clone = (AudioNode) super.clone();
clone.direction = direction.clone();
clone.velocity = velocity.clone();
return clone;
}
@ -760,10 +745,11 @@ public class AudioNode extends Node implements AudioSource {
*/
@Override
public void cloneFields( Cloner cloner, Object original ) {
super.cloneFields(cloner, original);
super.cloneFields(cloner, original);
this.direction = cloner.clone(direction);
this.velocity = cloner.clone(velocity);
this.direction=cloner.clone(direction);
this.velocity=velocityFromTranslation?new Vector3f():cloner.clone(velocity);
this.previousWorldTranslation=Vector3f.NAN.clone();
// Change in behavior: the filters were not cloned before meaning
// that two cloned audio nodes would share the same filter instance.

Loading…
Cancel
Save