/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package boids.physics;
import aspect.entity.Entity;
import aspect.physics.force.Force;
import aspect.physics.force.IntensityModel;
import aspect.util.Matrix4x4;
import aspect.util.Vector3;
import aspect.util.Trig;
/**
*
* @author MillerV
*/
public class Alignment implements Force {
public Entity ent;
public float strength;
public IntensityModel model;
public Alignment(Entity ent, float strength, IntensityModel model) {
this.ent = ent;
this.strength = strength;
this.model = model;
}
@Override
public Vector3 getForce(Entity ent2) {
if (ent2 == ent) {
return Vector3.zero();
}
Vector3 cur = ent2.rigidBody().vel.normalize();
Vector3 dest = ent.rigidBody().vel.normalize();
Vector3 cross = Vector3.cross(cur, dest).normalize();
Vector3 direction = Matrix4x4.identity().rotate(cross, -90).apply(cur);
float magnitude = model.multiplier(Vector3.distance(ent.pos, ent2.pos)) * Trig.sin(Vector3.angleBetween(cur, dest)) * strength;
if (magnitude == Float.NaN) {
return Vector3.zero();
}
return direction.times(magnitude);
}
}