<commit_before>package org.jtrfp.trcl.beh;

import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.trcl.beh.phy.RotationalMomentumBehavior;
import org.jtrfp.trcl.core.TR;
import org.jtrfp.trcl.math.Vect3D;
import org.jtrfp.trcl.obj.WorldObject;

public class HorizAimAtPlayerBehavior extends Behavior {
    private WorldObject chaseTarget;
    private double equatorialAccelleration=.004;
    private final double [] vectorToTargetVar = new double[3];
    public HorizAimAtPlayerBehavior(WorldObject chaseTarget){super();this.chaseTarget=chaseTarget;}
    @Override
    public void _tick(long timeInMillis){
	if(chaseTarget!=null){
	    WorldObject p = getParent();
	    final RotationalMomentumBehavior rmb = p.getBehavior().probeForBehavior(RotationalMomentumBehavior.class);
	    double [] vectorToTarget = Vect3D.normalize(TR.twosComplimentSubtract(chaseTarget.getPosition(), p.getPosition(),vectorToTargetVar),vectorToTargetVar);
	   // Vector3D vectorToTarget = chaseTarget.getPosition().subtract(p.getPosition()).normalize();
	    vectorToTarget[1]=0;
	    Vect3D.normalize(vectorToTarget);
	    Vect3D.negate(vectorToTarget);
	    //(vectorToTarget.getX(),0,vectorToTarget.getZ()).normalize().negate();
	    final Vector3D thisHeading=new Vector3D(p.getHeading().getX(),0,p.getHeading().getZ()).normalize();
	    Rotation rot = new Rotation(new Vector3D(vectorToTarget),thisHeading);
	    final Vector3D deltaVector=rot.applyTo(Vector3D.PLUS_K);
	    if(deltaVector.getZ()>0||deltaVector.getX()<0){rmb.accellerateEquatorialMomentum(-equatorialAccelleration);}
	    else{rmb.accellerateEquatorialMomentum(equatorialAccelleration);}
	}//end if(target!null)
    }
}//end ChaseBehavior<commit_msg>Added reversal mode and handedness to HorizAimAtPlayerBehavior.<commit_after>package org.jtrfp.trcl.beh;

import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.trcl.beh.phy.RotationalMomentumBehavior;
import org.jtrfp.trcl.core.TR;
import org.jtrfp.trcl.math.Vect3D;
import org.jtrfp.trcl.obj.WorldObject;

public class HorizAimAtPlayerBehavior extends Behavior {
    private WorldObject chaseTarget;
    private double equatorialAccelleration=.004;
    private final double [] vectorToTargetVar = new double[3];
    private boolean reverse = false;
    private boolean leftHanded = true;
    public HorizAimAtPlayerBehavior(WorldObject chaseTarget){super();this.chaseTarget=chaseTarget;}
    @Override
    public void _tick(long timeInMillis){
	if(chaseTarget!=null){
	    WorldObject p = getParent();
	    final RotationalMomentumBehavior rmb = p.getBehavior().probeForBehavior(RotationalMomentumBehavior.class);
	    double [] vectorToTarget = Vect3D.normalize(TR.twosComplimentSubtract(chaseTarget.getPosition(), p.getPosition(),vectorToTargetVar),vectorToTargetVar);
	   // Vector3D vectorToTarget = chaseTarget.getPosition().subtract(p.getPosition()).normalize();
	    vectorToTarget[1]=0;
	    Vect3D.normalize(vectorToTarget);
	    if(!reverse)Vect3D.negate(vectorToTarget);
	    //(vectorToTarget.getX(),0,vectorToTarget.getZ()).normalize().negate();
	    final Vector3D thisHeading=new Vector3D(p.getHeading().getX(),0,p.getHeading().getZ()).normalize();
	    Rotation rot = new Rotation(new Vector3D(vectorToTarget),thisHeading);
	    final Vector3D deltaVector=rot.applyTo(Vector3D.PLUS_K);
	    if((deltaVector.getZ()>0||deltaVector.getX()<0)==leftHanded){rmb.accellerateEquatorialMomentum(-equatorialAccelleration);}
	    else{rmb.accellerateEquatorialMomentum(equatorialAccelleration);}
	}//end if(target!null)
    }
    /**
     * @return the reverse
     */
    public boolean isReverse() {
        return reverse;
    }
    /**
     * @param reverse the reverse to set
     * @return 
     */
    public HorizAimAtPlayerBehavior setReverse(boolean reverse) {
        this.reverse = reverse;
        return this;
    }
    public void setTurnAcceleration(double accelleration) {
	equatorialAccelleration=accelleration;
    }
    /**
     * @return the leftHanded
     */
    public boolean isLeftHanded() {
        return leftHanded;
    }
    /**
     * @param leftHanded the leftHanded to set
     */
    public HorizAimAtPlayerBehavior setLeftHanded(boolean leftHanded) {
        this.leftHanded = leftHanded;
        return this;
    }
}//end ChaseBehavior
{'fraction_non_alphanumeric': 0.11575418994413408, 'fraction_numerical': 0.010279329608938547, 'mean_word_length': 4.7979274611398965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4043260', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1421, 'n_words': 215}