//added by jed zhu private int CheckCollision(BulletXActor actA, int ia, int ib, int ic, Vector3 vNormal, Vector3[] vertBase) { Vector3 perPlaneNormal; float fPerPlaneDist; OpenMetaverse.Vector3 v = actA.Position; Vector3 v3 = BulletXMaths.PhysicsVectorToXnaVector3(v); //check AB Vector3 v1; v1 = vertBase[ib] - vertBase[ia]; Vector3.Cross(ref vNormal, ref v1, out perPlaneNormal); Vector3.Normalize(ref perPlaneNormal, out perPlaneNormal); if (Vector3.Dot((vertBase[ic] - vertBase[ia]), perPlaneNormal) < 0) perPlaneNormal = -perPlaneNormal; fPerPlaneDist = Vector3.Dot(perPlaneNormal, vertBase[ia]) - 0.50f; if ((Vector3.Dot(perPlaneNormal, v3) - fPerPlaneDist) < 0) return 0; fPerPlaneDist = Vector3.Dot(perPlaneNormal, vertBase[ic]) + 0.50f; if ((Vector3.Dot(perPlaneNormal, v3) - fPerPlaneDist) > 0) return 0; //check BC v1 = vertBase[ic] - vertBase[ib]; Vector3.Cross(ref vNormal, ref v1, out perPlaneNormal); Vector3.Normalize(ref perPlaneNormal, out perPlaneNormal); if (Vector3.Dot((vertBase[ia] - vertBase[ib]), perPlaneNormal) < 0) perPlaneNormal = -perPlaneNormal; fPerPlaneDist = Vector3.Dot(perPlaneNormal, vertBase[ib]) - 0.50f; if ((Vector3.Dot(perPlaneNormal, v3) - fPerPlaneDist) < 0) return 0; fPerPlaneDist = Vector3.Dot(perPlaneNormal, vertBase[ia]) + 0.50f; if ((Vector3.Dot(perPlaneNormal, v3) - fPerPlaneDist) > 0) return 0; //check CA v1 = vertBase[ia] - vertBase[ic]; Vector3.Cross(ref vNormal, ref v1, out perPlaneNormal); Vector3.Normalize(ref perPlaneNormal, out perPlaneNormal); if (Vector3.Dot((vertBase[ib] - vertBase[ic]), perPlaneNormal) < 0) perPlaneNormal = -perPlaneNormal; fPerPlaneDist = Vector3.Dot(perPlaneNormal, vertBase[ic]) - 0.50f; if ((Vector3.Dot(perPlaneNormal, v3) - fPerPlaneDist) < 0) return 0; fPerPlaneDist = Vector3.Dot(perPlaneNormal, vertBase[ib]) + 0.50f; if ((Vector3.Dot(perPlaneNormal, v3) - fPerPlaneDist) > 0) return 0; return 1; }
//added by jed zhu //return value 1: need second check //return value 0: no need check private int preCheckCollision(BulletXActor actA, Vector3 vNormal, float fDist) { float fstartSide; OpenMetaverse.Vector3 v = actA.Position; Vector3 v3 = BulletXMaths.PhysicsVectorToXnaVector3(v); fstartSide = Vector3.Dot(vNormal, v3) - fDist; if (fstartSide > 0) return 0; else return 1; }