public override bool TestCollsionVsOBB(OBBCollisionHull2D other, ref Collision c) { // AABB-OBB part two twice // 1.... return(false); }
public override bool TestCollisionVsOBB(OBBCollisionHull2D other, ref Collision c) { return(other.TestCollisionVsCircle(this, ref c)); // TODO: modify c to get right contact data. // contact points will be the same // normals will be in opposite direction. }
public override bool TestCollsionVsOBB(OBBCollisionHull2D other, ref Collision c) { // same as above twice // first, test AABB vs max extents of OBB // then, multiply by OBB inverse matrix, do test again // 1.... return(false); }
public override bool TestCollsionVsOBB(OBBCollisionHull2D other) { // same as above twice // first, test AABB vs max extents of OBB // then, multiply by OBB inverse matrix, do test again // 1.... if (((this.position.x < other.position.x + other.rectWidth && this.position.x + this.rectWidth > other.position.x && this.position.y < other.position.y + other.rectHeight && this.position.y + this.rectHeight > other.position.y))) { return(true); } return(false); }
public override bool TestCollsionVsOBB(OBBCollisionHull2D other /*,ref Collision c*/) { // AABB-OBB part two twice // 1.... // then, multiply by OBB inverse matrix, do test again // 1.... if (((this.position.x < other.position.x + other.rectWidth && this.position.x + this.rectWidth > other.position.x && this.position.y < other.position.y + other.rectHeight && this.position.y + this.rectHeight > other.position.y))) { return(true); } return(false); }
public override bool TestCollsionVsOBB(OBBCollisionHull2D other /*,ref Collision c*/) { // same as above but first.. // transform circle posistion by multiplying by box world matrix inverse // 1.... float checkX = Mathf.Clamp(this.position.x, other.position.x - (other.rectWidth * 0.5f), other.position.x + (other.rectWidth * 0.5f)); // check y max and min float checkY = Mathf.Clamp(this.position.y, other.position.y - (other.rectHeight * 0.5f), other.position.y + (other.rectHeight * 0.5f)); checkX = this.position.x - checkX; checkY = this.position.y - checkY; float distance = (checkX * checkX) + (checkY * checkY); if ((distance) <= (radius * radius)) { return(true); } else { return(false); } //float rectOffsetX = 1f; //float rectOffsetY = 1f; //if (localX >= -rectOffsetX && localX <= other.rectWidth + rectOffsetX && localY >= -rectOffsetY && localY <= other.rectHeight + rectOffsetY) //{ // return true; //} //else //{ // return false; //} }
public override bool TestCollsionVsOBB(OBBCollisionHull2D other, ref Collision c) { // same as above but first.. // transform circle posistion by multiplying by box world matrix inverse // 1.... float relX = this.position.x - other.position.x; float relY = this.position.y - other.position.y; float angle = 45.0f; float angleCos = Mathf.Cos(angle); float angleSin = Mathf.Sin(angle); float localX = angleCos * relX - angleSin * relX; float localY = angleSin * relY + angleCos * relY; float rectOffsetX = 45; float rectOffsetY = 45; if ((localX >= -rectOffsetX && localX <= rectWidth - rectOffsetX) && (localY >= -rectOffsetY && localY <= rectHeight - rectOffsetY)) { Debug.Log("hit"); return(true); } return(false); }
// Start is called before the first frame update void Start() { otherCircle = colliderTarget.GetComponent <CirlceCollisionHull2D>(); otherRect = colliderTarget.GetComponent <AABBCollisionHull2D>(); otherOBB = colliderTarget.GetComponent <OBBCollisionHull2D>(); }
public abstract bool TestCollsionVsOBB(OBBCollisionHull2D other);
public override bool TestCollisionVsOBB(OBBCollisionHull2D other, ref Collision c) { return(other.TestCollisionVsAABB(this, ref c)); //updatePosition(); //other.updatePosition(); //// init corners. //Vector2 myBLC = Vector2.zero; //Vector2 myTRC = myBLC; //Vector2 oBLC = myBLC; //Vector2 oTRC = myBLC; //getDimensions(ref myBLC, ref myTRC); //// not needed other.getDimensions(ref oBLC, ref oTRC); //// same as above, but first... //// take axis extents of non-axis aligned box (make a bigger aabb) and run above test. //// then, transform AABB into OBB's space, find max extents, run above test. //// 1. get obb min / max //// 2. transform obb min / max - breaks encapsulation? //// 3. do AABB vs AABB //// 4. if false RETURN //// 5. transform ABB into OBB's space //// 6. find max extents //// 7. Run AABB vs AABB //// 1 & 2 & 3 //bool isColiding = checkOverlap(myTRC, myBLC, other.xyMax(), other.xyMin()); //// if not possibly colliding //if (!isColiding) //{ // // 4 // return isColiding; //} //// 5 //// project corners along OBB's axii //// Project along up axis, get x Min, x max, y min, y max. //Vector2 axis = other.transform.up; //Vector2 mXMinYMax = new Vector2(myBLC.x, myTRC.y); //Vector2 mXMaxYMin = new Vector2(myTRC.x, myBLC.y); //// Project corners along first axis //Vector2 xyMinProj = other.project(myBLC, axis); //Vector2 xyMaxProj = other.project(myTRC, axis); //Vector2 XminYmaxProj = other.project(mXMinYMax, axis); //Vector2 XmaxYminProj = other.project(mXMaxYMin, axis); //float yMin = Mathf.Min(xyMinProj.y, xyMaxProj.y, XminYmaxProj.y, XmaxYminProj.y); //float yMax = Mathf.Max(xyMinProj.y, xyMaxProj.y, XminYmaxProj.y, XmaxYminProj.y); //float xMin = Mathf.Min(xyMinProj.x, xyMaxProj.x, XminYmaxProj.x, XmaxYminProj.x); //float xMax = Mathf.Max(xyMinProj.x, xyMaxProj.x, XminYmaxProj.x, XmaxYminProj.x); //// convert to terms to test in checkOverlap function //Vector2 myXYMax = new Vector2(xMax, yMax); //Vector2 myXYMin = new Vector2(xMin, yMin); //// TODO: need to project obb corners too. //// also other.xyMax() isn't actually a corner. //bool isCollidingOnUpAxis = checkOverlap(myXYMax, myXYMin, other.xyMax(), other.xyMin()); //// Project corners along second axis //axis = other.transform.right; //xyMinProj = other.project(myBLC, axis); //xyMaxProj = other.project(myTRC, axis); //XminYmaxProj = other.project(mXMinYMax, axis); //XmaxYminProj = other.project(mXMaxYMin, axis); //yMin = Mathf.Min(xyMinProj.y, xyMaxProj.y, XminYmaxProj.y, XmaxYminProj.y); //yMax = Mathf.Max(xyMinProj.y, xyMaxProj.y, XminYmaxProj.y, XmaxYminProj.y); //xMin = Mathf.Min(xyMinProj.x, xyMaxProj.x, XminYmaxProj.x, XmaxYminProj.x); //xMax = Mathf.Max(xyMinProj.x, xyMaxProj.x, XminYmaxProj.x, XmaxYminProj.x); //// convert to terms to test in checkOverlap function //myXYMax = new Vector2(xMax, yMax); //myXYMin = new Vector2(xMin, yMin); //bool isCollidingOnRightAxis = checkOverlap(myXYMax, myXYMin, other.xyMax(), other.xyMin()); //isColiding = isCollidingOnRightAxis && isCollidingOnUpAxis; //return isColiding; }
public virtual bool TestCollisionVsOBB(OBBCollisionHull2D other, ref Collision c) { return(false); }
public abstract bool TestCollsionVsOBB(OBBCollisionHull2D other /*,ref Collision c*/);
public override bool TestCollisionVsOBB(OBBCollisionHull2D other, ref Collision c) { if (pauseForDebug) { pauseForDebug = false; } updatePosition(); other.updatePosition(); // TODO: remove extra OBB corners when projecting onto axis where they'll be duplicated. // see vs Circle // same as AABB-OBB part2, twice Vector2 XminYmin = Vector2.zero; Vector2 XmaxYmax = Vector2.zero; Vector2 XminYMax = Vector2.zero; Vector2 XmaxYmin = Vector2.zero; Vector2 oXYMax = Vector2.zero, oXYMin = Vector2.zero; Vector2 mXYMax = Vector2.zero, mXYMin = Vector2.zero; // 1. project others corners onto this up axis XminYmin = other.topRightTranslated(); XmaxYmax = other.botRightTranslated(); XminYMax = other.botLeftTranslated(); XmaxYmin = other.topLeftTranslated(); projectCornersOnAxis(transform.up, ref oXYMax, ref oXYMin); // project this corners onto this up axis XminYmin = topRightTranslated(); XmaxYmax = botRightTranslated(); XminYMax = botLeftTranslated(); XmaxYmin = topLeftTranslated(); projectCornersOnAxis(transform.up, ref mXYMax, ref mXYMin); // check for overlap bool isCollidingOnThisUpAxis = AABBCollisionHull2D.checkOverlap(oXYMax, oXYMin, mXYMax, mXYMin); // 2. project others corners onto this right axis XminYmin = other.topRightTranslated(); XmaxYmax = other.botRightTranslated(); XminYMax = other.botLeftTranslated(); XmaxYmin = other.topLeftTranslated(); projectCornersOnAxis(transform.right, ref oXYMax, ref oXYMin); //project this corners onto this right axis XminYmin = topRightTranslated(); XmaxYmax = botRightTranslated(); XminYMax = botLeftTranslated(); XmaxYmin = topLeftTranslated(); projectCornersOnAxis(transform.right, ref mXYMax, ref mXYMin); // check for overlap bool isCollidingOnThisRightAxis = AABBCollisionHull2D.checkOverlap(oXYMax, oXYMin, mXYMax, mXYMin); // 3. project others corners onto others up axis XminYmin = other.topRightTranslated(); XmaxYmax = other.botRightTranslated(); XminYMax = other.botLeftTranslated(); XmaxYmin = other.topLeftTranslated(); projectCornersOnAxis(other.transform.up, ref oXYMax, ref oXYMin); // project this corners onto others up axis XminYmin = topRightTranslated(); XmaxYmax = botRightTranslated(); XminYMax = botLeftTranslated(); XmaxYmin = topLeftTranslated(); projectCornersOnAxis(other.transform.up, ref mXYMax, ref mXYMin); bool isCollidingOnOtherUpAxis = AABBCollisionHull2D.checkOverlap(oXYMax, oXYMin, mXYMax, mXYMin); // 4. project others corners onto others right axis XminYmin = other.topRightTranslated(); XmaxYmax = other.botRightTranslated(); XminYMax = other.botLeftTranslated(); XmaxYmin = other.topLeftTranslated(); projectCornersOnAxis(other.transform.right, ref oXYMax, ref oXYMin); // project this corners onto others right axis XminYmin = topRightTranslated(); XmaxYmax = botRightTranslated(); XminYMax = botLeftTranslated(); XmaxYmin = topLeftTranslated(); projectCornersOnAxis(other.transform.right, ref mXYMax, ref mXYMin); bool isCollidingOnOtherRightAxis = AABBCollisionHull2D.checkOverlap(oXYMax, oXYMin, mXYMax, mXYMin); // internal function to project corners onto given axis void projectCornersOnAxis(Vector2 axis, ref Vector2 XYMax, ref Vector2 XYMin) { Vector2 oXminYminProj = project(XminYmin, axis); Vector2 oXmaxYmaxProj = project(XmaxYmax, axis); Vector2 oXminYmaxProj = project(XminYMax, axis); Vector2 oXmaxYminProj = project(XmaxYmin, axis); // get min / max // TODO: I'm not sure just taking the min is right, but it might work anyway. // it might not actually be a point on the axis. float yMin = Mathf.Min(oXminYminProj.y, oXmaxYmaxProj.y, oXminYmaxProj.y, oXmaxYminProj.y); float yMax = Mathf.Max(oXminYminProj.y, oXmaxYmaxProj.y, oXminYmaxProj.y, oXmaxYminProj.y); float xMin = Mathf.Min(oXminYminProj.x, oXmaxYmaxProj.x, oXminYmaxProj.x, oXmaxYminProj.x); float xMax = Mathf.Max(oXminYminProj.x, oXmaxYmaxProj.x, oXminYmaxProj.x, oXmaxYminProj.x); // convert to terms to test in checkOverlap function XYMax = new Vector2(xMax, yMax); XYMin = new Vector2(xMin, yMin); }; // TODO: short circuit if false; // Also get rid of repeated assigns to XminYmin etc. return(isCollidingOnThisUpAxis && isCollidingOnThisRightAxis && isCollidingOnOtherUpAxis && isCollidingOnOtherRightAxis); }