Ejemplo n.º 1
0
 private void UpdateCollisionData(MeshCollisionData data, float distance, CollisionResult result, MeshTriangle triangle)
 {
     if (!data.HasCollided ||
         distance < data.CollisionDistance)
     {
         data.CollisionDistance = distance;
         data.CollisionResult = result;
         data.CollisionId = triangle.Id;
         data.Triangle = triangle;
         data.HasCollided = true;
     }
 }
Ejemplo n.º 2
0
        private MeshCollisionResult CollideInParallel(IEnumerable<MeshTriangle> triangles, Vector3 point, Vector3 direction)
        {
            var data = new MeshCollisionData();
            var lockingObject = new Mutex();

            Parallel.ForEach(triangles, triangle =>
            {
                var result = CollideTriangleWithRay(triangle, point, direction);
                if (!result.HasCollided)
                    return;

                var distance = result.CollisionPoint.Distance(point);
                var realTriangle = triangle.Translate(_mesh.Translation);
                result.CollisionPoint += _mesh.Translation;
                lock (lockingObject)
                {
                    UpdateCollisionData(data, distance, result, realTriangle);
                }
            });

            return data.GetCollisionResult();
        }
Ejemplo n.º 3
0
        private MeshCollisionResult CollideInSeries(IEnumerable<MeshTriangle> triangles, Vector3 point, Vector3 direction)
        {
            var data = new MeshCollisionData();

            foreach (var triangle in triangles)
            {
                var result = CollideTriangleWithRay(triangle, point, direction);
                if (!result.HasCollided)
                    continue;

                var realTriangle = triangle.Translate(_mesh.Translation);
                var distance = result.CollisionPoint.Distance(point);
                result.CollisionPoint += _mesh.Translation;
                result.CollisionMesh = _mesh;

                UpdateCollisionData(data, distance, result, realTriangle);
            }

            return data.GetCollisionResult();
        }