Exemplo n.º 1
0
        private void Update(EvaluationContext context)
        {
            System.Numerics.Vector2 size = Size.GetValue(context);
            System.Numerics.Vector2 clip = NearFarClip.GetValue(context);
            Matrix cameraToClipSpace     = Matrix.OrthoRH(size.X, size.Y, clip.X, clip.Y);

            var     pos           = Position.GetValue(context);
            Vector3 eye           = new Vector3(pos.X, pos.Y, pos.Z);
            var     t             = Target.GetValue(context);
            Vector3 target        = new Vector3(t.X, t.Y, t.Z);
            var     u             = Up.GetValue(context);
            Vector3 up            = new Vector3(u.X, u.Y, u.Z);
            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;
        }
Exemplo n.º 2
0
        private void Update(EvaluationContext context)
        {
            Reference.DirtyFlag.Clear();
            LastObjectToWorld = context.ObjectToWorld;

            var fov         = MathUtil.DegreesToRadians(Fov.GetValue(context));
            var aspectRatio = AspectRatio.GetValue(context);

            if (aspectRatio < 0.0001f)
            {
                aspectRatio = (float)context.RequestedResolution.Width / context.RequestedResolution.Height;
            }
            System.Numerics.Vector2 clip = NearFarClip.GetValue(context);
            CameraToClipSpace = Matrix.PerspectiveFovRH(fov, aspectRatio, clip.X, clip.Y);

            var positionValue     = Position.GetValue(context);
            var eye               = new Vector3(positionValue.X, positionValue.Y, positionValue.Z);
            var targetValue       = Target.GetValue(context);
            var target            = new Vector3(targetValue.X, targetValue.Y, targetValue.Z);
            var upValue           = Up.GetValue(context);
            var up                = new Vector3(upValue.X, upValue.Y, upValue.Z);
            var worldToCameraRoot = Matrix.LookAtRH(eye, target, up);

            var rollRotation = Matrix.RotationAxis(new Vector3(0, 0, 1), -(float)Roll.GetValue(context));

            var pOffset = PositionOffset.GetValue(context);
            var additionalTranslation = Matrix.Translation(pOffset.X, pOffset.Y, pOffset.Z);

            var rOffset            = RotationOffset.GetValue(context);
            var additionalRotation = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rOffset.Y),
                                                                 MathUtil.DegreesToRadians(rOffset.X),
                                                                 MathUtil.DegreesToRadians(rOffset.Z));

            WorldToCamera = worldToCameraRoot * rollRotation * additionalTranslation * additionalRotation;


            if (context.BypassCameras)
            {
                Command.GetValue(context);
                Log.Debug($"Bypassing {SymbolChildId}", SymbolChildId);
                return;
            }

            // Set properties and evaluate sub tree
            var prevWorldToCamera     = context.WorldToCamera;
            var prevCameraToClipSpace = context.CameraToClipSpace;

            context.WorldToCamera     = WorldToCamera;
            context.CameraToClipSpace = CameraToClipSpace;

            Command.GetValue(context);

            context.CameraToClipSpace = prevCameraToClipSpace;
            context.WorldToCamera     = prevWorldToCamera;
        }
Exemplo n.º 3
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     positionValue = Position.GetValue(context);
            Vector3 eye           = new Vector3(positionValue.X, positionValue.Y, positionValue.Z);
            var     targetValue   = Target.GetValue(context);
            Vector3 target        = new Vector3(targetValue.X, targetValue.Y, targetValue.Z);
            var     upValue       = Up.GetValue(context);
            Vector3 up            = new Vector3(upValue.X, upValue.Y, upValue.Z);
            Matrix  worldToCamera = Matrix.LookAtRH(eye, target, up);

            //var worldToCamera = Matrix.LookAtLH(position, target, new Vector3(0, 1, 0));
            var rollRotation = Matrix.RotationAxis(new Vector3(0, 0, 1), -(float)Roll.GetValue(context));

            var pOffset = PositionOffset.GetValue(context);
            var additionalTranslation = Matrix.Translation(pOffset.X, pOffset.Y, pOffset.Z);

            var rOffset            = RotationOffset.GetValue(context);
            var additionalRotation = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rOffset.Y),
                                                                 MathUtil.DegreesToRadians(rOffset.X),
                                                                 MathUtil.DegreesToRadians(rOffset.Z));


            var worldToCamera2 = worldToCamera * rollRotation * additionalTranslation * additionalRotation;

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

            context.WorldToCamera     = worldToCamera2;
            context.CameraToClipSpace = cameraToClipSpace;

            Command.GetValue(context);

            context.CameraToClipSpace = prevCameraToClipSpace;
            context.WorldToCamera     = prevWorldToCamera;
        }
Exemplo n.º 4
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));
            }
        }