Пример #1
0
        // Desinne le chemin d'un point A à B
        private void DrawChemin(SpriteBatch sp, System.Numerics.Vector2 depart, System.Numerics.Vector2 fin)
        {
            graph = Graph.TabToGraph(grid);
            Noeud        d       = graph.getNoeud(depart);
            Noeud        f       = graph.getNoeud(fin);
            List <Noeud> chemins = graph.rechercherChemin(d, f);



            foreach (var n in chemins)
            {
                Rectangle rect = new Rectangle(OriginX + (int)n.Position.X * TileWidth, OriginY + (int)n.Position.Y * TileHeight, TileWidth, TileHeight);
                sp.Draw(sol, rect, Color.Green);
            }
        }
Пример #2
0
        private void Update(EvaluationContext context)
        {
            float fov         = MathUtil.DegreesToRadians(Fov.GetValue(context));
            float aspectRatio = AspectRatio.GetValue(context);

            if (aspectRatio < 0.0001f)
            {
                aspectRatio = (float)context.RequestedResolution.Width / context.RequestedResolution.Height;
            }
            System.Numerics.Vector2 clip = NearFarClip.GetValue(context);

            Matrix cameraToClipSpace = Matrix.PerspectiveFovRH(fov, aspectRatio, clip.X, clip.Y);

            // var pos = Position.GetValue(context);
            // Vector3 eye = new Vector3(pos.X, pos.Y, pos.Z);

            Vector3 p                = new Vector3(0, 0, Radius.GetValue(context));
            var     seed             = Seed.GetValue(context);
            var     wobbleSpeed      = WobbleSpeed.GetValue(context);
            var     wobbleComplexity = (int)MathUtils.Clamp(WobbleComplexity.GetValue(context), 1, 8);

            //var offset =
            var rotOffset = RotationOffset.GetValue(context);

            // Orbit rotation
            System.Numerics.Vector3 t = Center.GetValue(context);
            Vector3 target            = new Vector3(t.X, t.Y, t.Z);

            var rot = Matrix.RotationYawPitchRoll(
                ComputeAngle(SpinAngleAndWobble, 1)
                + MathUtil.DegreesToRadians((float)(SpinRate.GetValue(context)
                                                    * (EvaluationContext.BeatTime + SpinOffset.GetValue(context)) * 360
                                                    + MathUtils.PerlinNoise(0, 1, 6, seed) * 360))
                ,
                -ComputeAngle(OrbitAngleAndWobble, 2),
                0);
            var p2  = Vector3.Transform(p, rot);
            var eye = new Vector3(p2.X, p2.Y, p2.Z);

            // View rotation
            var viewDirection = target - eye;

            var rotateAim = Matrix.RotationYawPitchRoll(
                ComputeAngle(AimYawAngleAndWobble, 3) + rotOffset.X * MathUtils.ToRad,
                ComputeAngle(AimPitchAngleAndWobble, 4) + rotOffset.Y * MathUtils.ToRad,
                rotOffset.Z * MathUtils.ToRad);


            var adjustedViewDirection = Vector3.TransformNormal(viewDirection, rotateAim);

            target = eye + adjustedViewDirection;


            // Computing matrix
            var     u  = Up.GetValue(context);
            Vector3 up = new Vector3(u.X, u.Y, u.Z);

            var roll = ComputeAngle(AimRollAngleAndWobble, 5);
            var rotateAroundViewDirection = Matrix.RotationAxis(adjustedViewDirection, roll);

            up = Vector3.TransformNormal(up, rotateAroundViewDirection);

            Matrix worldToCamera = Matrix.LookAtRH(eye, target, up);

            var prevCameraToClipSpace = context.CameraToClipSpace;

            context.CameraToClipSpace = cameraToClipSpace;

            var prevWorldToCamera = context.WorldToCamera;

            context.WorldToCamera = worldToCamera;
            Command.GetValue(context);

            context.CameraToClipSpace = prevCameraToClipSpace;
            context.WorldToCamera     = prevWorldToCamera;


            float ComputeAngle(Slot <Vector2> angleAndWobbleInput, int seedIndex)
            {
                var angleAndWobble = angleAndWobbleInput.GetValue(context);
                var wobble         = Math.Abs(angleAndWobble.Y) < 0.001f
                                 ? 0
                                 : (MathUtils.PerlinNoise((float)EvaluationContext.BeatTime * wobbleSpeed,
                                                          1, wobbleComplexity, seed - 123 * seedIndex) - 0.5f) * 2 * angleAndWobble.Y;

                return(MathUtil.DegreesToRadians(angleAndWobble.X + wobble));
            }
        }