/*******************************************************************************
 * 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 java.lang.ref.WeakReference;

import org.jtrfp.trcl.AbstractSubmitter;
import org.jtrfp.trcl.Submitter;
import org.jtrfp.trcl.core.TR;
import org.jtrfp.trcl.obj.DEFObject;
import org.jtrfp.trcl.obj.WorldObject;

public class CollidesWithDEFObjects extends Behavior implements CollisionBehavior {
    private final double boundingRadius;
    private WeakReference<DEFObject> otherDEF;
    public CollidesWithDEFObjects(double boundingRadius){
	this.boundingRadius=boundingRadius;
    }
    @Override
    public void proposeCollision(WorldObject other){
	if(other instanceof DEFObject){
	    final double distance=TR.twosComplimentDistance(
		    other.getPositionWithOffset(), 
		    getParent().getPositionWithOffset());
	    otherDEF=new WeakReference<DEFObject>((DEFObject)other);
	    final double maxVtx = otherDEF.get().getModel().getMaximumVertexValue();
	    if(distance<(boundingRadius+maxVtx)){
		getParent().probeForBehaviors(sub, DEFObjectCollisionListener.class);
	    }
	}//end if(DEFObject)
    }//end _proposeCollision()
    
    private final Submitter<DEFObjectCollisionListener> sub = new AbstractSubmitter<DEFObjectCollisionListener>(){
	@Override
	public void submit(DEFObjectCollisionListener l){
	    DEFObject other = otherDEF.get();
	    if(other!=null)l.collidedWithDEFObject(other);
	}//end submit(...)
    };//end Submitter
}

@@ -769,21 +769,144 @@
 rcl.
-obj.DEFObject
+gpu.BasicModelSource;%0Aimport org.jtrfp.trcl.math.Vect3D;%0Aimport org.jtrfp.trcl.obj.DEFObject;%0Aimport org.jtrfp.trcl.obj.DEFObject.HitBox
 ;%0Aim
@@ -1115,16 +1115,73 @@
 herDEF;%0A
+    private final double %5B%5D workTriplet = new double%5B3%5D;%0A
     publ
@@ -1388,62 +1388,176 @@
 nal 
-double distance=TR.twosComplimentDistance(%0A%09%09    other
+DEFObject def = (DEFObject)other;%0A%09    final HitBox %5B%5D hitBoxes = def.getHitBoxes();%0A%09    final WorldObject parent = getParent();%0A%09   %0A%09    final double %5B%5D defPos = def
 .get
@@ -1580,28 +1580,46 @@
 et()
-, %0A%09
+;%0A
 %09    
-getP
+final double %5B%5D pPos   = p
 arent
-()
 .get
@@ -1638,18 +1638,23 @@
 Offset()
-)
 ;
+%0A%09    
 %0A%09    ot
@@ -1705,32 +1705,77 @@
 ct)other);%0A%09    
+if(hitBoxes == null)%7B// No custom hitboxes%0A%09%09
 final double max
@@ -1836,63 +1836,1005 @@
 );%0A%09
-    if(distance%3C(boundingRadius+maxVtx))%7B%0A%09%09getParent()
+%09 final double distance=TR.twosComplimentDistance(%0A%09%09%09    other.getPositionWithOffset(), %0A%09%09%09    parent.getPositionWithOffset());%0A%09%09    if(distance%3C(boundingRadius+maxVtx))%0A%09%09%09parent.probeForBehaviors(sub, DEFObjectCollisionListener.class);%0A%09    %7Delse%7B//Custom hitboxes%0A%09%09boolean doCollision = false;%0A%09%09BasicModelSource mSource = def.getModelSource();%0A%09%09if(mSource == null)%0A%09%09    throw new NullPointerException(%22DEF's model source intolerably null.%22);%0A%09%09for(HitBox box:hitBoxes)%7B%0A%09%09    final double limit = boundingRadius+box.getSize();%0A%09%09    final double %5B%5D vPos = Vect3D.add(mSource.getVertex(box.getVertexID()),defPos,workTriplet);%0A%09%09    Vect3D.subtract(workTriplet, pPos, vPos);%0A%09%09    Vect3D.abs(workTriplet, workTriplet);%0A%09%09    boolean localDoCollision = true;%0A%09%09    for(int i=0; i%3C3; i++)%0A%09%09     localDoCollision &= TR.rolloverDistance(workTriplet%5Bi%5D) %3C limit;%0A%09%09    doCollision %7C= localDoCollision;%0A%09%09%7D//end for(hitBoxes)%0A%09%09System.out.println(%22Custom hitbox: %22);%0A%09%09if(doCollision)%0A%09%09 parent
 .pro
@@ -2894,16 +2894,41 @@
 ;%0A%09    %7D
+//end if(custom hitboxes)
 %0A%09%7D//end

Add custom hitbox support to CollidesWithDEFObjects.