void realityCheck(ContactInfo cantactInfo) { ContactInfo info = cantactInfo; SURFACE otherSurface = info.otherSurface; SURFACE selfSurface = info.selfSurface; VERTEX vertex = info.selfVertex; if (vertex != null)//point contact surface { bool inSurface = Math3D.isProjectInSurface(vertex.pos, otherSurface.points[0].pos, otherSurface.points[1].pos); bool offContact = offContactSurface(vertex, otherSurface); if (!inSurface || offContact) { deleteContact(info); } } else if (selfSurface != null)//surface contact surface { bool surface0InSurface1 = surfaceInSurface(otherSurface, selfSurface); bool surface1InSurface0 = surfaceInSurface(selfSurface, otherSurface); bool OffContact = offContactSurface(selfSurface.points[0], otherSurface); if (((!surface0InSurface1) && (!surface1InSurface0)) || OffContact) { deleteContact(info); } } }
public void init(SURFACE s) { surface = s; VERTEX[] surfacePoints = s.points; Vector3 right = surfacePoints[1].pos - surfacePoints[0].pos; original = Quaternion.AngleAxis(90, Vector3.forward) * right.normalized; direct = original; }
public SURFACE otherSurface; //correspond to the surface of CollideInfo public void reset() { other = null; extraObj = null; coupleContactInfo = null; blockDirect = Vector3.zero; selfVertex = null; selfSurface = null; otherSurface = null; }
public void copy(ContactInfo otherInfo) { self = otherInfo.self; other = otherInfo.other; extraObj = otherInfo.extraObj; coupleContactInfo = otherInfo.coupleContactInfo; blockDirect = otherInfo.blockDirect; selfVertex = otherInfo.selfVertex; otherSurface = otherInfo.otherSurface; }
public Tile() { surface = SURFACE.GRASS; posX = 0; posZ = 0; elevation = 0f; hasWater = false; isSource = false; waterDepth = 0; waterVelocity = 0; }
public Tile(SURFACE s, int x, int z) { surface = s; posX = x; posZ = z; elevation = 0f; hasWater = false; isSource = false; waterDepth = 0; waterVelocity = 0; }
protected bool surfaceInSurface(SURFACE surface0, SURFACE surface1) { VERTEX[] contactVertexs = surface0.points; for (int j = 0; j < contactVertexs.Length; j++) { if (Math3D.isProjectInSurface(contactVertexs[j].pos, surface1.points[0].pos, surface1.points[1].pos)) { return(true); } } return(false); }
public void init() { minCollideTime = -1; collidePoint = Vector3.zero; collideSurfaceP0 = Vector3.zero; collideSurfaceP1 = Vector3.zero; intersectPoint = Vector3.zero; vertex = null; surface = null; node = null; reachGoalobj = null; }
bool offContactSurface(VERTEX vertex, SURFACE surface) { Vector3 beginVec = vertex.pos - surface.points[0].pos; float distDot = Vector3.Dot(beginVec, surface.normal.direct); //Debug.Log ( distDot ); float distLimit = 0.00001f; if (distDot > distLimit || distDot < -distLimit) { return(true); } return(false); }
protected void createSurfaces() { chooseSurfaceToCreate(); surfaceVertexIndex = new int[, ] { { 0, 1 }, //up { 1, 2 }, //right { 2, 3 }, //down { 3, 0 }//left }; surfaceNum = needSurfaceIndex.Length; _surfaces = new SURFACE[surfaceNum]; for (int i = 0; i < surfaceNum; i++) { _surfaces[i] = new SURFACE(); } }
public void collideWithOtherBox(ABox other) { calculateGlobalspeedAndRelateVec(this, other); //if (!isObjsMatchCondition ( other )) // return; for (int k = 0; k < other._surfaces.Length; k++) { SURFACE surface = other._surfaces[k]; for (int j = 0; j < _vertexs.Length; j++) { VERTEX vertex = _vertexs[j]; vertexContactSurface(vertex, surface); } } CollideManager.totalCollideObjNumPerFrame++; }
//collide will ocur after this time public void vertexContactSurface(VERTEX vertex, SURFACE surface) { //ignore vertexs which is back to surface bool isFacing = false; for (int i = 0; i < vertex.normals.Count; i++) { Vector3 vertexNormal = vertex.normals[i].direct; float facingDot = Vector3.Dot(vertexNormal, surface.normal.direct); float threshold = 0.000001f; if (facingDot > -threshold && facingDot < threshold) { facingDot = 0; } if (facingDot < 0) { isFacing = true; break; } } if (!isFacing) { return; } //check if under surface Vector3 beginVec = surface.points[0].pos - vertex.pos; float dist = Vector3.Dot(beginVec, surface.normal.direct); if (dist > 0)//ignore the surfaces which is back to vertex { return; } // relateVec intersect surface Vector3 perpendicularVec = surface.normal.direct * dist; float angle = Vector3.Angle(-relateVec, perpendicularVec); if (angle >= 90)//parallel { return; } float length = Mathf.Abs(dist) / Mathf.Cos(Mathf.Deg2Rad * angle); Vector3 intersectPoint = vertex.pos - relateVec.normalized * length; //contactsurface float collideTime = length / relateVec.magnitude; surface.belongToObj.computeGlobalSpeed(); Vector3 surfaceGlobalSpeedVec = surface.belongToObj.globalSpeedVec; Vector3 collideSurfaceP0 = surface.points[0].pos + surfaceGlobalSpeedVec * collideTime; Vector3 collideSurfaceP1 = surface.points[1].pos + surfaceGlobalSpeedVec * collideTime; //Vector3 collideSurfaceNormal = surface.normal.direct; //check if in contact surface Vector3 collidePoint = vertex.pos + globalSpeedVec * collideTime; if (Math3D.isProjectInSurface(collidePoint, collideSurfaceP0, collideSurfaceP1)) //will contact in future { CollideInfo info = CollideManager.collideInfo; if (info.minCollideTime == -1 || collideTime < info.minCollideTime) { info.minCollideTime = collideTime; info.collidePoint = collidePoint; info.collideSurfaceP0 = collideSurfaceP0; info.collideSurfaceP1 = collideSurfaceP1; info.intersectPoint = intersectPoint; info.vertex = vertex; info.surface = surface; info.node = null; info.reachGoalobj = null; } } }