19 - A Star Is Born/script.js
//finds the projection axes for the two objects

finds the projection axes for the two objects
finds the projection axes for the two objects
function findAxes(o1, o2){
    let axes = [];
    if(o1 instanceof Circle && o2 instanceof Circle){
        axes.push(o2.pos.subtr(o1.pos).unit());
        return axes;
    }
    if(o1 instanceof Circle){
        axes.push(closestVertexToPoint(o2, o1.pos).subtr(o1.pos).unit());
    }
    if(o1 instanceof Line){
        axes.push(o1.dir.normal());
    }   
    if (o1 instanceof Rectangle){
        axes.push(o1.dir.normal());
        axes.push(o1.dir);
    }
    if (o1 instanceof Triangle){
        axes.push(o1.vertex[1].subtr(o1.vertex[0]).normal());
        axes.push(o1.vertex[2].subtr(o1.vertex[1]).normal());
        axes.push(o1.vertex[0].subtr(o1.vertex[2]).normal());
    }
    if (o2 instanceof Circle){
        axes.push(closestVertexToPoint(o1, o2.pos).subtr(o2.pos).unit());
    }
    if (o2 instanceof Line){
        axes.push(o2.dir.normal());
    }   
    if (o2 instanceof Rectangle){
        axes.push(o2.dir.normal());
        axes.push(o2.dir);
    }
    if (o2 instanceof Triangle){
        axes.push(o2.vertex[1].subtr(o2.vertex[0]).normal());
        axes.push(o2.vertex[2].subtr(o2.vertex[1]).normal());
        axes.push(o2.vertex[0].subtr(o2.vertex[2]).normal());
    }
    return axes;
}
function findAxes ( o1 , o2 ) { let axes = [ ] ; if ( o1 instanceof Circle && o2 instanceof Circle ) { axes . push ( o2 . pos . subtr ( o1 . pos ) . unit ( ) ) ; return axes ; } if ( o1 instanceof Circle ) { axes . push ( closestVertexToPoint ( o2 , o1 . pos ) . subtr ( o1 . pos ) . unit ( ) ) ; } if ( o1 instanceof Line ) { axes . push ( o1 . dir . normal ( ) ) ; } if ( o1 instanceof Rectangle ) { axes . push ( o1 . dir . normal ( ) ) ; axes . push ( o1 . dir ) ; } if ( o1 instanceof Triangle ) { axes . push ( o1 . vertex [ 1 ] . subtr ( o1 . vertex [ 0 ] ) . normal ( ) ) ; axes . push ( o1 . vertex [ 2 ] . subtr ( o1 . vertex [ 1 ] ) . normal ( ) ) ; axes . push ( o1 . vertex [ 0 ] . subtr ( o1 . vertex [ 2 ] ) . normal ( ) ) ; } if ( o2 instanceof Circle ) { axes . push ( closestVertexToPoint ( o1 , o2 . pos ) . subtr ( o2 . pos ) . unit ( ) ) ; } if ( o2 instanceof Line ) { axes . push ( o2 . dir . normal ( ) ) ; } if ( o2 instanceof Rectangle ) { axes . push ( o2 . dir . normal ( ) ) ; axes . push ( o2 . dir ) ; } if ( o2 instanceof Triangle ) { axes . push ( o2 . vertex [ 1 ] . subtr ( o2 . vertex [ 0 ] ) . normal ( ) ) ; axes . push ( o2 . vertex [ 2 ] . subtr ( o2 . vertex [ 1 ] ) . normal ( ) ) ; axes . push ( o2 . vertex [ 0 ] . subtr ( o2 . vertex [ 2 ] ) . normal ( ) ) ; } return axes ; }
finds the projection axes for the two objects
finds the projection axes for the two objects