/// <summary> /// /// </summary> /// <param name="object1"></param> /// <param name="object2"></param> /// <returns></returns> public static CollisionImpact Touch(Object3d object1, Object3d object2) { if (object1 == null) { throw new ArgumentNullException("object1"); } if (object2 == null) { throw new ArgumentNullException("object2"); } /* Detect if two objects are touching * object1: The first object to be detected: class or subclass of Object3d * object2: The second object to be detected: class or subclass of Object3d * * imp: a collider with the impact time and faces touched on both objects: class collide */ //produce an imaginary collision object based on projecting object 1 in the direction of object 2 CollisionImpact imp = new CollisionImpact(); int[] zero = { 0, 0, 0 }; Isotope.Object3d sense_object1 = new Isotope.Object3d(zero, zero, 0, true); //Take the 2 centres of the objects int[] twos = { 2, 2, 2 }; int[] centre_object1 = Vector.AddVector(object1.GetPosition(), Vector.DivideVector(object1.GetSize(), twos)); int[] centre_object2 = Vector.AddVector(object2.GetPosition(), Vector.DivideVector(object2.GetSize(), twos)); //Find the projected vector between them int[] project_vector = Vector.MultiplyVector(Vector.Direction(centre_object1, centre_object2), twos); //Add the projected vector to the first objects position sense_object1.SetPosition(Vector.AddVector(object1.GetPosition(), project_vector)); Vector.CopyVector(object1.GetSize(), sense_object1.GetSize()); //collision detect the sense object with the object 2 imp = CollisionDetect(sense_object1, object2); return(imp); }
/// <summary> /// /// </summary> /// <param name="object1"></param> /// <param name="object2"></param> /// <returns></returns> public static CollisionImpact Touch(Object3d object1, Object3d object2) { if (object1 == null) { throw new ArgumentNullException("object1"); } if (object2 == null) { throw new ArgumentNullException("object2"); } /* Detect if two objects are touching object1: The first object to be detected: class or subclass of Object3d object2: The second object to be detected: class or subclass of Object3d imp: a collider with the impact time and faces touched on both objects: class collide */ //produce an imaginary collision object based on projecting object 1 in the direction of object 2 CollisionImpact imp = new CollisionImpact(); int[] zero ={ 0, 0, 0 }; Isotope.Object3d sense_object1 = new Isotope.Object3d(zero, zero, 0, true); //Take the 2 centres of the objects int[] twos ={ 2, 2, 2 }; int[] centre_object1 = Vector.AddVector(object1.GetPosition(), Vector.DivideVector(object1.GetSize(), twos)); int[] centre_object2 = Vector.AddVector(object2.GetPosition(), Vector.DivideVector(object2.GetSize(), twos)); //Find the projected vector between them int[] project_vector = Vector.MultiplyVector(Vector.Direction(centre_object1, centre_object2), twos); //Add the projected vector to the first objects position sense_object1.SetPosition(Vector.AddVector(object1.GetPosition(), project_vector)); Vector.CopyVector(object1.GetSize(), sense_object1.GetSize()); //collision detect the sense object with the object 2 imp = CollisionDetect(sense_object1, object2); return (imp); }