/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2014 Chuck Ritola
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/

package org.jtrfp.trcl.beh;

import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.trcl.obj.WorldObject;

public class MatchDirection extends Behavior {
    private WorldObject target;
    @Override
    public void tick(long tickTimeMillis){
	if(target!=null){
	    final double [] hdg = target.getHeadingArray();
	    getParent().setHeading(new Vector3D(hdg[0], hdg[1], hdg[2]));
	    final double [] top = target.getTopArray();
	    getParent().setTop(new Vector3D(top[0], top[1], top[2]));
	}//end if(!null)
    }//end _tick(...)
    /**
     * @return the target
     */
    public WorldObject getTarget() {
        return target;
    }
    /**
     * @param target the target to set
     */
    public void setTarget(WorldObject target) {
        this.target = target;
    }
}//end MatchDirection

@@ -685,114 +685,488 @@
 org.
-jtrfp.trcl.obj.WorldObject;%0A%0Apublic class MatchDirection extends Behavior %7B%0A    private WorldObject target
+apache.commons.math3.linear.ArrayRealVector;%0Aimport org.apache.commons.math3.linear.MatrixUtils;%0Aimport org.apache.commons.math3.linear.RealMatrix;%0Aimport org.apache.commons.math3.linear.RealVector;%0Aimport org.jtrfp.trcl.obj.WorldObject;%0A%0Apublic class MatchDirection extends Behavior %7B%0A    private WorldObject target;%0A    private RealMatrix lookAtMatrix4x4 = MatrixUtils.createRealIdentityMatrix(4);%0A    private RealMatrix topMatrix4x4    = MatrixUtils.createRealIdentityMatrix(4)
 ;%0A  
@@ -1240,30 +1240,24 @@
 null)%7B%0A%09    
-final 
 double %5B%5D hd
@@ -1278,32 +1278,187 @@
 HeadingArray();%0A
+%09    final RealVector newHeading = lookAtMatrix4x4.operate(new ArrayRealVector(new double %5B%5D %7Bhdg%5B0%5D,hdg%5B1%5D,hdg%5B2%5D,1.%7D));%0A%09    hdg = newHeading.toArray();%0A
 %09    getParent()
@@ -1505,24 +1505,36 @@
  hdg%5B2%5D)
+.normalize()
 );%0A%09    
 final do
@@ -1525,22 +1525,16 @@
 );%0A%09    
-final 
 double %5B
@@ -1555,32 +1555,176 @@
 .getTopArray();%0A
+%09    final RealVector newTop = topMatrix4x4.operate(new ArrayRealVector(new double %5B%5D %7Btop%5B0%5D,top%5B1%5D,top%5B2%5D,1.%7D));%0A%09    top = newTop.toArray();%0A
 %09    getParent()
@@ -1767,16 +1767,28 @@
  top%5B2%5D)
+.normalize()
 );%0A%09%7D//e
@@ -2069,16 +2069,407 @@
 ;%0A    %7D%0A
+    public RealMatrix getLookAtMatrix4x4() %7B%0A        return lookAtMatrix4x4;%0A    %7D%0A    public void setLookAtMatrix4x4(RealMatrix lookAtMatrix4x4) %7B%0A        this.lookAtMatrix4x4 = lookAtMatrix4x4;%0A    %7D%0A    public RealMatrix getTopMatrix4x4() %7B%0A        return topMatrix4x4;%0A    %7D%0A    public void setTopMatrix4x4(RealMatrix topMatrix4x4) %7B%0A        this.topMatrix4x4 = topMatrix4x4;%0A    %7D%0A    %0A
 %7D//end M

Add adjustment matrices to MatchDirection.