#import "Gravitator.h"

static inline Vector3 multFloatVector3(float f, Vector3 v) {
    return (Vector3){f * v.x, f * v.y, f * v.z};
}

@implementation Gravitator

//apply gravity to all objects in array
-(void) applyGravity {
    int i = 0;

    //receivers must have velocity vector

    for (i = 0; i < count; i++) {
        
        //cursed

        //need to check collision

        if ( [array[i] isStatic] ) {
            continue;
        }

        if ( ![array[i] onSurface] ) {
            [array[i] setForce: multFloatVector3( [(PhysObject *)array[i] mass], acceleration)];
        }

        //[array[i] setForce: multFloatVector3( [(PhysObject *)array[i] mass], acceleration)];
        [(PhysObject *)array[i] setVelocity: Vector3Add([array[i] force], [(PhysObject *)array[i] velocity])];
        [(PhysObject *)array[i] setPos: Vector3Add( [(PhysObject *)array[i] velocity], [(PhysObject *)array[i] pos] )];
    }


}

@end