Exemplo n.º 1
0
        public Actor GetPickedObject(Camera3D camera, float distance, out Vector3 pos, out Vector3 normal)
        {
            Vector3 ray = GetMouseRayDirection(camera);
            ImmovableSkinPredicate pred = new ImmovableSkinPredicate();

            this.game.PhysicsManager.PhysicsSystem.CollisionSystem.SegmentIntersect(out frac, out skin, out pos, out normal,
                                                                                    new Segment(camera.Transform3D.Translation, ray * distance), pred);

            if (skin != null && skin.Owner != null)
            {
                return(skin.Owner.ExternalData as Actor);
            }

            return(null);
        }
        //used when in 1st person collidable camera mode
        //start distance allows us to start the ray outside the collidable skin of the 1st person colliable camera object
        //otherwise the only thing we would ever collide with would be ourselves!
        public Actor GetPickedObject(Camera3D camera, Vector2 screenPosition, float startDistance, float endDistance, out Vector3 pos, out Vector3 normal)
        {
            Vector3 ray = GetMouseRayDirection(camera, screenPosition);
            ImmovableSkinPredicate pred = new ImmovableSkinPredicate();

            this.physicsManager.PhysicsSystem.CollisionSystem.SegmentIntersect(out frac, out skin, out pos, out normal,
                                                                               new Segment(camera.Transform.Translation + startDistance * Vector3.Normalize(ray), ray * endDistance), pred);

            if (skin != null && skin.Owner != null)
            {
                return(skin.Owner.ExternalData as Actor);
            }

            return(null);
        }
        //used when in 1st person collidable camera mode
        //start distance allows us to start the ray outside the collidable skin of the 1st person colliable camera object
        //otherwise the only thing we would ever collide with would be ourselves!
        public Actor GetPickedObject(Camera3D camera, float startDistance, float distance,
                   out Vector3 pos, out Vector3 normal)
        {
            Vector3 ray = GetMouseRayDirection(camera);
            ImmovableSkinPredicate pred = new ImmovableSkinPredicate();

            this.game.PhysicsManager.PhysicsSystem.CollisionSystem.SegmentIntersect(
                out frac, out skin, out pos, out normal,
                new Segment(camera.Transform3D.Translation + startDistance * Vector3.Normalize(ray), ray * distance), pred);

            if (skin != null && skin.Owner != null)
            {
                return skin.Owner.ExternalData as Actor;
            }

            return null;
        }