hyades.level.Level.GetEntityAt C# (CSharp) Method

GetEntityAt() public method

public GetEntityAt ( Microsoft.Xna.Framework.Ray ray, float depth ) : Entity
ray Microsoft.Xna.Framework.Ray
depth float
return Entity
        public Entity GetEntityAt(Ray ray, float depth)
        {
            Entity smallest = null;

            for (int i = 0; i < entities.Count; i++)
            {
                Entity entity = entities[i];

                // pick current layer only
                if (entity.position.Z != depth)
                    continue;

                if (!(entity is IHasModel))
                    continue;

                Model model = ((IHasModel)entity).GetModel();
                Matrix transform = entity.GetTransform();
                Matrix[] bones = new Matrix[model.Bones.Count];
                model.CopyAbsoluteBoneTransformsTo(bones);

                if (RayIntersectsModel(ray, model, transform, bones))
                {
                    if (smallest == null || entity.size.X < smallest.size.X && entity.size.Y < smallest.size.Y && entity.size.Z < smallest.size.Z)
                        smallest = entity;
                }
            }

            return smallest;
        }