// Path: src/com/htssoft/sploosh/presentation/FluidTracer.java
// public class FluidTracer {
// 	/**
// 	 * Position of the fluid tracer at the current time.
// 	 * */
// 	public final Vector3f position = new Vector3f();
// 	
// 	/**
// 	 * This is an intertial component, which may be affected
// 	 * by outside forces.
// 	 * 
// 	 * The reynolds ratio below determines how much affect
// 	 * this component has versus vorticity advection.
// 	 * */
// 	public final Vector3f inertia = new Vector3f();
// 	
// 	/**
// 	 * How much contribution does the vorticity advection
// 	 * have versus the vorticity.
// 	 * */
// 	public float reynoldsRatio = 1f;
// 	
// 	/**
// 	 * Particle's physical radius.
// 	 * */
// 	public float radius = 0.1f;
// 	
// 	/**
// 	 * The coefficient of drag.
// 	 * */
// 	public float drag = 0.8f;
// 	
// 	/**
// 	 * Target lifetime of this tracer in seconds.
// 	 * */
// 	public float lifetime = 0f;
// 	
// 	/**
// 	 * How many seconds has this tracer lived?
// 	 * */
// 	public float age;
// 	
// 	public void clear(){
// 		position.zero();
// 		inertia.zero();
// 	}
// }


import java.util.List;
import com.htssoft.sploosh.presentation.FluidTracer;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
package com.htssoft.sploosh;



public class TracerMath {
	/**
	 * Given a list of vortons, compute the field velocity there.
	 * */
	public static void computeVelocityFromVortons(Vector3f position, List<Vorton> influences, 
											  Vector3f store, Vector3f temp1, Vector3f temp2){
		store.zero();
		for (int i = 0; i < influences.size(); i++){
			Vorton v = influences.get(i);
			computeVelocityContribution(position, v, store, temp1, temp2);
		}
		store.multLocal(VortonSpace.ONE_OVER_4_PI);
	}

	/**
	 * Given a vorton, find its influence on the field velocity.
	 * */
	public static void computeVelocityContribution(Vector3f position, Vorton v, Vector3f accum, Vector3f temp1, Vector3f temp2){
		temp2.set(position).subtractLocal(v.getPosition());
		float dist2 = temp2.lengthSquared() + VortonSpace.AVOID_SINGULARITY;
		float oneOverDist = 1f / FastMath.sqrt(dist2);
		float distLaw;
		if (dist2 < VortonSpace.VORTON_RADIUS_SQ){
			distLaw = oneOverDist / VortonSpace.VORTON_RADIUS_SQ;
		}
		else {
			 distLaw = oneOverDist / dist2;
		}
		
		temp1.set(v.getVort()).multLocal(VortonSpace.FOUR_THIRDS_PI * VortonSpace.VORTON_RADIUS_CUBE).crossLocal(temp2).multLocal(distLaw);
		accum.addLocal(temp1);
	}

// Path: src/com/htssoft/sploosh/presentation/FluidTracer.java
// public class FluidTracer {
// 	/**
// 	 * Position of the fluid tracer at the current time.
// 	 * */
// 	public final Vector3f position = new Vector3f();
// 	
// 	/**
// 	 * This is an intertial component, which may be affected
// 	 * by outside forces.
// 	 * 
// 	 * The reynolds ratio below determines how much affect
// 	 * this component has versus vorticity advection.
// 	 * */
// 	public final Vector3f inertia = new Vector3f();
// 	
// 	/**
// 	 * How much contribution does the vorticity advection
// 	 * have versus the vorticity.
// 	 * */
// 	public float reynoldsRatio = 1f;
// 	
// 	/**
// 	 * Particle's physical radius.
// 	 * */
// 	public float radius = 0.1f;
// 	
// 	/**
// 	 * The coefficient of drag.
// 	 * */
// 	public float drag = 0.8f;
// 	
// 	/**
// 	 * Target lifetime of this tracer in seconds.
// 	 * */
// 	public float lifetime = 0f;
// 	
// 	/**
// 	 * How many seconds has this tracer lived?
// 	 * */
// 	public float age;
// 	
// 	public void clear(){
// 		position.zero();
// 		inertia.zero();
// 	}
// }


// Path: src/com/htssoft/sploosh/TracerMath.java
import java.util.List;
import com.htssoft.sploosh.presentation.FluidTracer;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;

package com.htssoft.sploosh;



public class TracerMath {
	/**
	 * Given a list of vortons, compute the field velocity there.
	 * */
	public static void computeVelocityFromVortons(Vector3f position, List<Vorton> influences, 
											  Vector3f store, Vector3f temp1, Vector3f temp2){
		store.zero();
		for (int i = 0; i < influences.size(); i++){
			Vorton v = influences.get(i);
			computeVelocityContribution(position, v, store, temp1, temp2);
		}
		store.multLocal(VortonSpace.ONE_OVER_4_PI);
	}

	/**
	 * Given a vorton, find its influence on the field velocity.
	 * */
	public static void computeVelocityContribution(Vector3f position, Vorton v, Vector3f accum, Vector3f temp1, Vector3f temp2){
		temp2.set(position).subtractLocal(v.getPosition());
		float dist2 = temp2.lengthSquared() + VortonSpace.AVOID_SINGULARITY;
		float oneOverDist = 1f / FastMath.sqrt(dist2);
		float distLaw;
		if (dist2 < VortonSpace.VORTON_RADIUS_SQ){
			distLaw = oneOverDist / VortonSpace.VORTON_RADIUS_SQ;
		}
		else {
			 distLaw = oneOverDist / dist2;
		}
		
		temp1.set(v.getVort()).multLocal(VortonSpace.FOUR_THIRDS_PI * VortonSpace.VORTON_RADIUS_CUBE).crossLocal(temp2).multLocal(distLaw);
		accum.addLocal(temp1);
	}

	public static void moveTracer(FluidTracer tracer, Vector3f fluidVelocity, ThreadVars vars, float tpf){