public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { Vector3 pos = lilB.center; Vector3 off = Vector3.zero; switch (test) { case BoundsTest.center: if (bigB.Contains(pos)){ return(Vector3.zero); } if(pos.x > bigB.max.x){ off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x){ off.x = pos.x - bigB.min.x; } if(pos.y > bigB.max.y){ off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y){ off.y = pos.y - bigB.min.y; } if(pos.z > bigB.max.z){ off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z){ off.z = pos.z - bigB.min.z; } return(off); } return(Vector3.zero); }
//Checks to see whether the Bounds bnd are within camBounds public static Vector3 ScreenBoundsCheck(Bounds bnd, BoundsTest test = BoundsTest.center) { return(BoundsInBoundsCheck(camBounds, bnd, test)); }
//Checks to see whether bounds lilB are within bounds bigB public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { //The behavior of this function is different based on the BoundsTest that has been selected. //get the center of lilb Vector3 pos = lilB.center; // Initialize the offset at [0,0,0] Vector3 off = Vector3.zero; switch (test) { //the center test determines what off (offset) would have to be applied to lilB to move its center back inside bigB case BoundsTest.center: if (bigB.Contains(pos)) { return(Vector3.zero); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); //the onScreen test determines what off would have to be applied to keep all of lilB inside bigB case BoundsTest.onScreen: if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); //The offScreen test determines what off would need to be applied to move any tiny part of lilB inside of bigB case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }
// Checks to see if bounds lilb are within Bounds bigB public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { // behavior needs to be different depending on the test selected Vector3 pos = lilB.center; // use center for measurement Vector3 off = Vector3.zero; // offset is 0,0,0 to start switch (test) { // what is offset to move center of lilB back inside bigB case BoundsTest.center: // trivial case - we are already inside if (bigB.Contains(pos)) { return(Vector3.zero); //no need to move } //otherwise adjust x,y,z components as needed if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); //------------------------- // what is the offset to keep ALL of lilB inside bigB case BoundsTest.onScreen: // trivial case - we are already inside if (bigB.Contains(lilB.max) && bigB.Contains(lilB.min)) { return(Vector3.zero); //no need to move } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); //------------------------- // what is the offset to keep ALL of lilB outside of bigB case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } // end switch BoundsTest return(Vector3.zero); // if we get here something went wrong } // end BoundsInBoundsCheck
// Tests to see whether lilB is inside bigB public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { // Get the center of lilB Vector3 pos = lilB.center; // Initialize the offset at [0,0,0] Vector3 off = Vector3.zero; switch (test) { // The center test determines what off (offset) would have to be applied to lilB to move its center back inside bigB case BoundsTest.center: // if the center is contained, return Vector3.zero if (bigB.Contains(pos)) { return(Vector3.zero); } // if not contained, find the offset if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); // The onScreen test determines what off would have to be applied to keep all of lilB inside bigB case BoundsTest.onScreen: // find whether bigB contains all of lilB if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } // if not, find the offset if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); // The offScreen test determines what off would need to be applied to move any tiny part of lilB inside of bigB case BoundsTest.offScreen: // find whether bigB contains any of lilB bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } // if not, find the offset if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }
// Checks to see whether the Bounds bnd are within the camBounds public static Vector3 ScreenBoundsCheck(Bounds bnd, BoundsTest test = BoundsTest.center) { return( BoundsInBoundsCheck( camBounds, bnd, test ) ); }
// Tests to see whether lilB is inside bigB public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen ) { // Get the center of lilB Vector3 pos = lilB.center; // Initialize the offset at [0,0,0] Vector3 off = Vector3.zero; switch (test) { // The center test determines what off (offset) would have to be applied to lilB to move its center back inside bigB case BoundsTest.center: // if the center is contained, return Vector3.zero if ( bigB.Contains( pos ) ) { return( Vector3.zero ); } // if not contained, find the offset if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return( off ); // The onScreen test determines what off would have to be applied to keep all of lilB inside bigB case BoundsTest.onScreen: // find whether bigB contains all of lilB if ( bigB.Contains( lilB.min ) && bigB.Contains( lilB.max ) ) { return( Vector3.zero ); } // if not, find the offset if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return( off ); // The offScreen test determines what off would need to be applied to move any tiny part of lilB inside of bigB case BoundsTest.offScreen: // find whether bigB contains any of lilB bool cMin = bigB.Contains( lilB.min ); bool cMax = bigB.Contains( lilB.max ); if ( cMin || cMax ) { return( Vector3.zero ); } // if not, find the offset if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return( off ); } return( Vector3.zero ); }
// checks to see whether bounds lilb are within bounds bigb public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { // behavior of this fn differs based on selected boundtest // get of lilb Vector3 pos = lilB.center; // initialize offset at 000 Vector3 off = Vector3.zero; switch (test) { // center test determines what offset is needed to move lilb center inside bigb case BoundsTest.center: if (bigB.Contains(pos)) { return(Vector3.zero); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); // onscreen test determines offset to keep all lilb in bigb case BoundsTest.onScreen: if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); // offscreen test determines offset to move any tiny part of lilb into bigb case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }
//checks to see if lilB are within bigB public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { //behavior depends on BoundsTest, selected onScreen by default Vector3 pos = lilB.center; Vector3 offset = Vector3.zero; switch (test) { //center test dertermine what offset is require to move lilB's center back into bigB case BoundsTest.center: if (bigB.Contains(pos)) { return(Vector3.zero); } if (pos.x > bigB.max.x) { offset.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { offset.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { offset.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { offset.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { offset.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { offset.z = pos.z - bigB.min.z; } return(offset); //the onScreen test determines what offset would have to be to keep all of lilB inside of bigB case BoundsTest.onScreen: if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } if (lilB.max.x > bigB.max.x) { offset.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { offset.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { offset.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { offset.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { offset.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { offset.z = lilB.min.z - bigB.min.z; } return(offset); //the offScreen test determines what offset would need to be to get any of lilB into bigB case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { offset.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { offset.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { offset.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { offset.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { offset.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { offset.z = lilB.max.z - bigB.min.z; } return(offset); } return(Vector3.zero); }
//根据test参数,依据不同的标准来检查边界框lilB是否在bigB中 //如果test通过,则返回Vector3(0,0,0),不然返回的是一个可以调整lilB通过test的一个offset向量 public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { //获取边界框lilB的中心 Vector3 pos = lilB.center; Vector3 off = Vector3.zero; switch (test) { case BoundsTest.center: //当test参数值为center时,需要确认lilB的center是否在bigB中 //如果不在,off需要将center调整到bigB之内 if (bigB.Contains(pos)) //test通过 { return(Vector3.zero); } //test不通过,需要调整,分别检查x/y/z坐标 if (pos.x > bigB.max.x) { //x坐标超了 off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { //y坐标超了 off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { //z坐标超了 off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); case BoundsTest.onScreen: //如果test参数值为onScreen,函数要判断是否lilB整体在bigB内 //如果不在,则off需要将lilB调整到bigB中 if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) //test通过 { return(Vector3.zero); } //test不通过,需要调整 if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); case BoundsTest.offScreen: //如果test的参数是offScreen,则需要lilB的一部分在bigB中,也就是得有交集 if (bigB.Contains(lilB.max) || bigB.Contains(lilB.min)) //test通过 { return(Vector3.zero); } //test未通过 if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }
public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test) { // behavior differs based on what bounds test has been passed //get center of lilB Vector3 pos = lilB.center; //init offset to 0,0,0 Vector3 off = Vector3.zero; switch (test) { // the center test det what what offset would be applied to lilB to move it's center inside bigB case BoundsTest.center: if (bigB.Contains(pos)) { return(Vector3.zero); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); // the onsereen test determines what offset would have to be applied to keep lilb inside bigb case BoundsTest.onScreen: if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); //the off screen testdet what offset is needed to get lilb inside bigb case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }
public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.OnScreen) { Vector3 pos = lilB.center; Vector3 off = Vector3.zero; switch (test) { case BoundsTest.Center: if (bigB.Contains(pos)) { return(Vector3.zero); } for (var i = 0; i < 3; i++) { if (pos[i] > bigB.max[i]) { off[i] = pos[i] - bigB.max[i]; } else if (pos[i] < bigB.min[i]) { off[i] = pos[i] - bigB.min[i]; } } return(off); case BoundsTest.OnScreen: if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } for (var i = 0; i < 3; i++) { if (lilB.max[i] > bigB.max[i]) { off[i] = lilB.max[i] - bigB.max[i]; } else if (lilB.min[i] < bigB.min[i]) { off[i] = lilB.min[i] - bigB.min[i]; } } return(off); case BoundsTest.OffScreen: if (bigB.Contains(lilB.min) || bigB.Contains(lilB.max)) { return(Vector3.zero); } for (var i = 0; i < 3; i++) { if (lilB.min[i] > bigB.max[i]) { off[i] = lilB.min[i] - bigB.max[i]; } else if (lilB.max[i] < bigB.min[i]) { off[i] = lilB.max[i] - bigB.min[i]; } } return(off); default: return(Vector3.zero); } }
public static Vector3 BoundsInBoundsCheck(Bounds littleBound, Bounds bigBound, BoundsTest test = BoundsTest.ONSCREEN) { Vector3 centerOfLittleBnd = littleBound.center; Vector3 offset = Vector3.zero; switch (test) { case BoundsTest.CENTER: if (bigBound.Contains(centerOfLittleBnd)) { return(Vector3.zero); } if (centerOfLittleBnd.x > bigBound.max.x) { offset.x = centerOfLittleBnd.x - bigBound.max.x; } else if (centerOfLittleBnd.x < bigBound.min.x) { offset.x = centerOfLittleBnd.x - bigBound.min.x; } if (centerOfLittleBnd.y > bigBound.max.y) { offset.y = centerOfLittleBnd.y - bigBound.max.y; } else if (centerOfLittleBnd.y < bigBound.min.y) { offset.y = centerOfLittleBnd.y - bigBound.min.y; } if (centerOfLittleBnd.z > bigBound.max.z) { offset.z = centerOfLittleBnd.z - bigBound.max.z; } else if (centerOfLittleBnd.z < bigBound.min.z) { offset.z = centerOfLittleBnd.z - bigBound.min.z; } return(offset); case BoundsTest.ONSCREEN: if (bigBound.Contains(littleBound.min) && bigBound.Contains(littleBound.max)) { return(Vector3.zero); } if (littleBound.max.x > bigBound.max.x) { offset.x = littleBound.max.x - bigBound.max.x; } else if (littleBound.min.x < bigBound.min.x) { offset.x = littleBound.min.x - bigBound.min.x; } if (littleBound.max.y > bigBound.max.y) { offset.y = littleBound.max.y - bigBound.max.y; } else if (littleBound.min.y < bigBound.min.y) { offset.y = littleBound.min.y - bigBound.min.y; } if (littleBound.max.z > bigBound.max.z) { offset.z = littleBound.max.z - bigBound.max.z; } else if (littleBound.min.z < bigBound.min.z) { offset.z = littleBound.min.z - bigBound.min.z; } return(offset); case BoundsTest.OFFSCREEN: bool cMin = bigBound.Contains(littleBound.min); bool cMax = bigBound.Contains(littleBound.max); if (cMin == true || cMax == true) { return(Vector3.zero); } if (littleBound.min.x > bigBound.max.x) { offset.x = littleBound.min.x - bigBound.max.x; } else if (littleBound.max.x < bigBound.min.x) { offset.x = littleBound.max.x - bigBound.min.x; } if (littleBound.min.y > bigBound.max.y) { offset.y = littleBound.min.y - bigBound.max.y; } else if (littleBound.max.y < bigBound.min.y) { offset.y = littleBound.max.y - bigBound.min.y; } if (littleBound.min.z > bigBound.max.z) { offset.z = littleBound.min.z - bigBound.max.z; } else if (littleBound.max.z < bigBound.min.z) { offset.z = littleBound.max.z - bigBound.min.z; } return(offset); } return(Vector3.zero); }
public static Vector3 ScreenBoundsCheck(Bounds bound, BoundsTest test = BoundsTest.CENTER) { return(BoundsInBoundsCheck(bound, camBounds, test)); }
public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { Vector3 pos = lilB.center; Vector3 off = Vector3.zero; switch (test) { case BoundsTest.center: if (bigB.Contains (pos)) { return Vector3.zero; } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return (off); case BoundsTest.onScreen: if (bigB.Contains (lilB.min) && bigB.Contains (lilB.max)) { return Vector3.zero; } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return off; case BoundsTest.offScreen: bool cMin = bigB.Contains (lilB.min); bool cMax = bigB.Contains (lilB.max); if (cMax || cMin) { return Vector3.zero; } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return off; } return Vector3.zero; }
// Checks to see whether a smaller object is inside a bigger object. public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen ) { Vector3 pos = lilB.center; Vector3 off = Vector3.zero; switch (test) { case BoundsTest.center: // What offset to move lilB into bigB if ( bigB.Contains( pos ) ) { return( Vector3.zero ); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return( off ); case BoundsTest.onScreen: //What offset keep all of lilB inside bigB if ( bigB.Contains( lilB.min ) && bigB.Contains( lilB.max ) ) { return( Vector3.zero ); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return( off ); case BoundsTest.offScreen: //What offset move any tiny part of lilB inside of bigB bool cMin = bigB.Contains( lilB.min ); bool cMax = bigB.Contains( lilB.max ); if ( cMin || cMax ) { return( Vector3.zero ); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return( off ); } return( Vector3.zero ); }
// Checks to see if bounds lilb are within Bounds bigB public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { // behavior needs to be different depending on the test selected Vector3 pos = lilB.center; // use center for measurement Vector3 off = Vector3.zero; // offset is 0,0,0 to start switch (test) { // what is offset to move center of lilB back inside bigB case BoundsTest.center: // trivial case - we are already inside if (bigB.Contains(pos)) { return (Vector3.zero); //no need to move } //otherwise adjust x,y,z components as needed if(pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if(pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if(pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return (off); //------------------------- // what is the offset to keep ALL of lilB inside bigB case BoundsTest.onScreen: // trivial case - we are already inside if (bigB.Contains(lilB.max) && bigB.Contains(lilB.min)) { return (Vector3.zero); //no need to move } if(lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if(lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if(lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return (off); //------------------------- // what is the offset to keep ALL of lilB outside of bigB case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return (Vector3.zero); } if(lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if(lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if(lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return (off); } // end switch BoundsTest return (Vector3.zero); // if we get here something went wrong }
public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { Vector3 pos = lilB.center; Vector3 off = Vector3.zero; switch (test) { case BoundsTest.center: if (bigB.Contains(pos)) { return(Vector3.zero); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); case BoundsTest.onScreen: if (bigB.Contains(lilB.min) && bigB.Contains(lilB.max)) { return(Vector3.zero); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }
// Checks to see whether Bounds lilB are within Bounds bigB public static Vector3 BoundsInBoundsCheck( Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen ) { // The behavior of this function is different based on the BoundsTest // that has been selected. // Get the center of lilB Vector3 pos = lilB.center; // Initialize the offset at [0,0,0] Vector3 off = Vector3.zero; switch (test) { // The center test determines what off (offset) would have to be applied // to lilB to move its center back inside bigB case BoundsTest.center: if ( bigB.Contains( pos ) ) { return( Vector3.zero ); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.min.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return( off ); // The onScreen test determines what off would have to be applied to // keep all of lilB inside bigB case BoundsTest.onScreen: if ( bigB.Contains( lilB.min ) && bigB.Contains( lilB.max ) ) { return( Vector3.zero ); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z > bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return( off ); // The offScreen test determines what off would need to be applied to // move any tiny part of lilB inside of bigB case BoundsTest.offScreen: bool cMin = bigB.Contains( lilB.min ); bool cMax = bigB.Contains( lilB.max ); if ( cMin || cMax ) { return( Vector3.zero ); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return( off ); } return( Vector3.zero ); }
// Test to see whether Bounds are on screen. public static Vector3 ScreenBoundsCheck(Bounds bnd, BoundsTest test = BoundsTest.center) { // Call the more generic BoundsInBoundsCheck with camBounds as bigB return(BoundsInBoundsCheck(camBounds, bnd, test)); }
// Test to see whether Bounds are on screen. public static Vector3 ScreenBoundsCheck(Bounds bnd, BoundsTest test = BoundsTest.center) { // Call the more generic BoundsInBoundsCheck with camBounds as bigB return( BoundsInBoundsCheck( camBounds, bnd, test ) ); }
// 检查边界款lilB是否位于边界框bigB之内 public static Vector3 BoundsInBoundsCheck(Bounds bigB, Bounds lilB, BoundsTest test = BoundsTest.onScreen) { //根据所选的BoundsTest,本函数的行为也会有所不同 //获取边界框lilB的中心 Vector3 pos = lilB.center; //INitialize the offset at [0,0,0] Vector3 off = Vector3.zero; switch (test) { //当test参数值为center时,函数将确定要将lilB的中心平移到bigB之内, //需要平移的方向和距离,用三维向量off表示 case BoundsTest.center: if (bigB.Contains(pos)) { return(Vector3.zero); } if (pos.x > bigB.max.x) { off.x = pos.x - bigB.max.x; } else if (pos.x < bigB.min.x) { off.x = pos.x - bigB.min.x; } if (pos.y > bigB.max.y) { off.y = pos.y - bigB.max.y; } else if (pos.y < bigB.max.y) { off.y = pos.y - bigB.min.y; } if (pos.z > bigB.max.z) { off.z = pos.z - bigB.max.z; } else if (pos.z < bigB.min.z) { off.z = pos.z - bigB.min.z; } return(off); //当test参数值为onScreen时,函数将确定要将lilB整体平移到bigB之内 //需要平移的方向和距离,用三维向量off表示 case BoundsTest.onScreen: if (bigB.Contains(lilB.max) && bigB.Contains(lilB.min)) { return(Vector3.zero); } if (lilB.max.x > bigB.max.x) { off.x = lilB.max.x - bigB.max.x; } else if (lilB.min.x < bigB.min.x) { off.x = lilB.min.x - bigB.min.x; } if (lilB.max.y > bigB.max.y) { off.y = lilB.max.y - bigB.max.y; } else if (lilB.min.y < bigB.min.y) { off.y = lilB.min.y - bigB.min.y; } if (lilB.max.z < bigB.max.z) { off.z = lilB.max.z - bigB.max.z; } else if (lilB.min.z < bigB.min.z) { off.z = lilB.min.z - bigB.min.z; } return(off); //当test参数值为offScreen时,函数将确定要将lilB的任意一部分 //平移到bigB之内需要平移的方向和距离,用三维向量off表示 case BoundsTest.offScreen: bool cMin = bigB.Contains(lilB.min); bool cMax = bigB.Contains(lilB.max); if (cMin || cMax) { return(Vector3.zero); } if (lilB.min.x > bigB.max.x) { off.x = lilB.min.x - bigB.max.x; } else if (lilB.max.x < bigB.min.x) { off.x = lilB.max.x - bigB.min.x; } if (lilB.min.y > bigB.max.y) { off.y = lilB.min.y - bigB.max.y; } else if (lilB.max.y < bigB.min.y) { off.y = lilB.max.y - bigB.min.y; } if (lilB.min.z > bigB.max.z) { off.z = lilB.min.z - bigB.max.z; } else if (lilB.max.z < bigB.min.z) { off.z = lilB.max.z - bigB.min.z; } return(off); } return(Vector3.zero); }