/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package factories;
import graphics.common.Point;
import graphics.common.Vector;
import graphics.common.Vector2D;
import graphics.common.Vector3D;
import utils.GlobalData;
/**
*
* @author Freezerburn
*/
public class Vectors {
private static final GetVector[] getters = new GetVector[] { new Vectors.Get2D(), new Vectors.Get3D() };
public static Vector get( double xPart, double yPart, double zPart ) {
return getters[ GlobalData.GRAPHICS_DIMENSIONS.getValue() ].get( xPart, yPart, zPart );
}
public static Vector get( double xPart, double yPart ) {
return get( xPart, yPart, 0.0 );
}
public static Vector get() {
return get( 0.0, 0.0, 0.0 );
}
public static Vector get( Vector v ) {
return get( v.getXPart(), v.getYPart(), v.getZPart() );
}
public static Vector get( Point p1, Point p2 ) {
return get( p2.getX() - p1.getX(),
p2.getY() - p1.getY(),
p2.getZ() - p1.getZ() );
}
public static Vector crossProduct( Vector v1, Vector v2 ) {
Vector ret = get();
ret.setXPart( v1.getYPart() * v2.getZPart() - v1.getZPart() * v2.getYPart() );
ret.setYPart( v1.getZPart() * v2.getXPart() - v1.getXPart() * v2.getZPart() );
ret.setZPart( v1.getXPart() * v2.getYPart() - v1.getYPart() * v2.getXPart() );
return ret;
}
public static Vector normalize( Vector v ) {
Vector ret = Vectors.get( v );
ret.scalarDivide( v.getLen() );
return ret;
}
private interface GetVector {
public Vector get( double xPart, double yPart, double zPart );
}
private static class Get2D implements GetVector {
@Override
public Vector get( double xPart, double yPart, double zPart ) {
return new Vector2D( xPart, yPart );
}
}
private static class Get3D implements GetVector {
@Override
public Vector get( double xPart, double yPart, double zPart ) {
return new Vector3D( xPart, yPart, zPart );
}
}
}