示例#1
0
        private void MoveSphere(Vector2 mouseScreenPos)
        {
            // Borrowed from Stride documentation
            var     invViewProj = Matrix.Invert(playerInputCamera.ViewProjectionMatrix);
            Vector3 sPos;

            sPos.X = mouseScreenPos.X * 2f - 1f;
            sPos.Y = 1f - mouseScreenPos.Y * 2f;
            sPos.Z = 0f;

            var vectorNear = Vector3.Transform(sPos, invViewProj);

            vectorNear /= vectorNear.W;
            sPos.Z      = 1f;
            var vectorFar = Vector3.Transform(sPos, invViewProj);

            vectorFar /= vectorFar.W;

            resultList.Clear();
            this.GetSimulation().RaycastPenetrating(vectorNear.XYZ(), vectorFar.XYZ(),
                                                    resultList, CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags.CustomFilter10);

            if (!resultList.Any())
            {
                Log.Debug($"Destination point could not be found, are you clicking ground?");
                return;
            }

            var targetPosition = resultList.First().Point;

            sphere.Transform.Position = new Vector3(targetPosition.X, .5f, targetPosition.Z);
            Log.Debug($"Sphere position has been updated.");
        }