本文整理汇总了C#中IContact.ContactMade方法的典型用法代码示例。如果您正苦于以下问题:C# IContact.ContactMade方法的具体用法?C# IContact.ContactMade怎么用?C# IContact.ContactMade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContact
的用法示例。
在下文中一共展示了IContact.ContactMade方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Collide
public void Collide(ref Vector3 position, float radius, IContact contact, int loopCount = 5)
{
trianglesTested = 0;
this.loopCount = 0;
foreach (ITriangleSelector triangleSelector in selectors)
{
BoundingBox bounds;
bounds.Min.X = position.X - radius * 1.25f;
bounds.Min.Y = position.Y - radius * 1.25f;
bounds.Min.Z = position.Z - radius * 1.25f;
bounds.Max.X = position.X + radius * 1.25f;
bounds.Max.Y = position.Y + radius * 1.25f;
bounds.Max.Z = position.Z + radius * 1.25f;
triangleSelector.Select(bounds, triangles);
for (int i = 0; i != loopCount; i++, this.loopCount++)
{
Vector3 resolvedPosition = Vector3.Zero;
Vector3 iPoint = Vector3.Zero;
Triangle iTriangle;
int iEdge = -1;
float iMin = float.MaxValue;
bool collided = false;
iTriangle.A = Vector3.Zero;
iTriangle.B = Vector3.Zero;
iTriangle.C = Vector3.Zero;
iTriangle.Normal = Vector3.Zero;
iTriangle.Dist = 0;
for (int j = 0; j != triangles.Count; j++)
{
Triangle triangle = triangles[j];
Vector3 point;
Nullable<float> t = triangle.Intersect(position, -triangle.Normal, out point);
bool hit = false;
trianglesTested++;
if (t.HasValue)
{
if (t.Value > 0 && t.Value < iMin && t.Value < radius)
{
resolvedPosition = point + triangle.Normal * radius;
iTriangle = triangle;
iPoint = point;
iEdge = -1;
iMin = t.Value;
collided = true;
hit = true;
}
}
if (!hit)
{
for (int k = 0; k != 3; k++)
{
Vector3 a = triangle[k];
Vector3 b = triangle[(k + 1) % 3];
Vector3 a2b = b - a;
Vector3 a2p = position - a;
Vector3 c = a;
float s = Vector3.Dot(a2b, a2p);
if (s > 0)
{
s /= a2b.LengthSquared();
if (s < 1)
{
c = a + s * a2b;
}
else
{
c = b;
}
}
Vector3 d = position - c;
float len = d.Length();
if (len < radius && len < iMin)
{
resolvedPosition = c + Vector3.Normalize(d) * radius;
iTriangle = triangle;
iPoint = c;
iEdge = k;
iMin = len;
collided = true;
}
}
}
}
if (collided)
{
if (contact.ContactMade(triangleSelector, iTriangle, iPoint, iEdge))
{
position = resolvedPosition;
}
}
//.........这里部分代码省略.........