import javax.vecmath.Vector3d;

import de.simflex.units.PermanentUnit;
import de.simflex.util.attribute.Attribute;

/**
* Verteilwagen
*
*
*/
public class Car extends PermanentUnit {

    protected PermanentUnit get, put;
    /**
    * the driving direction
    */
    protected Vector3d direction;
    public static Attribute[] attribute = {
        new Attribute( "Direction", "direction", "Car", Vector3d.class, Attribute.WRITABLE )
    };
    
    public Car( ){
        super( );
        direction = new Vector3d( 1,0,0 );
        setVrmlFile( "verteilwagen2.wrl" );
    }
    
    public double moveTo( PermanentUnit dest ){
		Vector3d dir = new Vector3d( direction );
		dir.scale( 1/direction.length( ) );
		if(debug)System.out.println( this + " dir " + dir + " length " + dir.length( ) );
		double w = dir.dot( connection( dest ) );
		if(debug)System.out.println( this + " Factor " + w );
		Vector3d destPos = new Vector3d( direction );
		destPos.scale( w );
		if(debug)System.out.println( this + " Vector " + destPos );
		Vector3d ziel = new Vector3d( getPosition( ) );
		ziel.add( destPos );
		moveAbsolute( ziel );  
		return w;  	
    }
        
    /* (non-Javadoc)
	* @see de.simflex.units.PermanentUnit#whereToGo(de.simflex.units.PermanentUnit)
	*/
	public PermanentUnit whereToGo( PermanentUnit pu ){
        return (PermanentUnit)getChild( 0 );
    }
    
    /**
    * Sets the Vector of the direction in which the car should drive
    * 
    * @param v 
    */
    public void setDirection( Vector3d v ){
    	direction = v;
    }
    
	/**
	* Returns the Vector of the direction in which the car should drive
	* 
	*/
    public Vector3d getDirection( ){
    	return direction;
    }
}