<commit_before>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2014 <NAME>
 * 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.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.MatrixUtils;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
import org.jtrfp.trcl.obj.WorldObject;

public class MatchDirection extends Behavior {
    private WorldObject target;
    private RealMatrix lookAtMatrix4x4 = MatrixUtils.createRealIdentityMatrix(4);
    private RealMatrix topMatrix4x4    = MatrixUtils.createRealIdentityMatrix(4);
    @Override
    public void tick(long tickTimeMillis){
	if(target!=null){
	    double [] hdg = target.getHeadingArray();
	    final RealVector newHeading = lookAtMatrix4x4.operate(new ArrayRealVector(new double [] {hdg[0],hdg[1],hdg[2],1.}));
	    hdg = newHeading.toArray();
	    getParent().setHeading(new Vector3D(hdg[0], hdg[1], hdg[2]).normalize());
	    double [] top = target.getTopArray();
	    final RealVector newTop = topMatrix4x4.operate(new ArrayRealVector(new double [] {top[0],top[1],top[2],1.}));
	    top = newTop.toArray();
	    getParent().setTop(new Vector3D(top[0], top[1], top[2]).normalize());
	}//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;
    }
    public RealMatrix getLookAtMatrix4x4() {
        return lookAtMatrix4x4;
    }
    public void setLookAtMatrix4x4(RealMatrix lookAtMatrix4x4) {
        this.lookAtMatrix4x4 = lookAtMatrix4x4;
    }
    public RealMatrix getTopMatrix4x4() {
        return topMatrix4x4;
    }
    public void setTopMatrix4x4(RealMatrix topMatrix4x4) {
        this.topMatrix4x4 = topMatrix4x4;
    }
    
}//end MatchDirection<commit_msg>Add chaining support to MatchDirection's matrix methods.<commit_after>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2014 <NAME>
 * 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.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.MatrixUtils;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
import org.jtrfp.trcl.obj.WorldObject;

public class MatchDirection extends Behavior {
    private WorldObject target;
    private RealMatrix lookAtMatrix4x4 = MatrixUtils.createRealIdentityMatrix(4);
    private RealMatrix topMatrix4x4    = MatrixUtils.createRealIdentityMatrix(4);
    @Override
    public void tick(long tickTimeMillis){
	if(target!=null){
	    double [] hdg = target.getHeadingArray();
	    final RealVector newHeading = lookAtMatrix4x4.operate(new ArrayRealVector(new double [] {hdg[0],hdg[1],hdg[2],1.}));
	    hdg = newHeading.toArray();
	    getParent().setHeading(new Vector3D(hdg[0], hdg[1], hdg[2]).normalize());
	    double [] top = target.getTopArray();
	    final RealVector newTop = topMatrix4x4.operate(new ArrayRealVector(new double [] {top[0],top[1],top[2],1.}));
	    top = newTop.toArray();
	    getParent().setTop(new Vector3D(top[0], top[1], top[2]).normalize());
	}//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;
    }
    public RealMatrix getLookAtMatrix4x4() {
        return lookAtMatrix4x4;
    }
    public MatchDirection setLookAtMatrix4x4(RealMatrix lookAtMatrix4x4) {
        this.lookAtMatrix4x4 = lookAtMatrix4x4;
        return this;
    }
    public RealMatrix getTopMatrix4x4() {
        return topMatrix4x4;
    }
    public MatchDirection setTopMatrix4x4(RealMatrix topMatrix4x4) {
        this.topMatrix4x4 = topMatrix4x4;
        return this;
    }
    
}//end MatchDirection
{'fraction_non_alphanumeric': 0.166308803435487, 'fraction_numerical': 0.02576615264493461, 'mean_word_length': 3.898661567877629, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558194', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1525, 'n_words': 347}