Exemple #1
0
 private void EscapeAction(Input.Key key, Input.KeyAction action)
 {
     if (action == Input.KeyAction.Press)
     {
         Application.Exit();
     }
 }
Exemple #2
0
 private void F2Action(Input.Key key, Input.KeyAction action)
 {
     if (action == Input.KeyAction.Press)
     {
         reverseY = !reverseY;
     }
 }
Exemple #3
0
        private void ChangedOptionValueAction(Input.Key key, Input.KeyAction action)
        {
            if (action != Input.KeyAction.Press && action != Input.KeyAction.Repeat)
            {
                return;
            }

            if (options.Count == 0)
            {
                return;
            }

            int value = 1;

            if (Input.IsKeyPressed(Input.Key.LeftShift))
            {
                value = 3;
            }

            if (key == Input.Key.Kp8)
            {
                options[currentOption].Changed(value);
            }
            if (key == Input.Key.Kp2)
            {
                options[currentOption].Changed(-value);
            }

            Console.WriteLine($"{options[currentOption].Name} = {options[currentOption].Value}");
        }
Exemple #4
0
        private void ChangeFOVAction(Input.Key key, Input.KeyAction action)
        {
            if (action != Input.KeyAction.Repeat && action != Input.KeyAction.Press)
            {
                return;
            }

            var camera = this.Entity.GetComponent <Camera>();
            var fov    = camera.FieldOfView;

            if (key == Input.Key.Equal)
            {
                fov += 1.0f;
                if (fov > 170.0f)
                {
                    fov = 170.0f;
                }
            }
            else
            {
                fov -= 1.0f;
                if (fov < 10.0f)
                {
                    fov = 10.0f;
                }
            }

            camera.FieldOfView = fov;
        }
Exemple #5
0
 private void ResizeUp(Input.Key key, Input.KeyAction action)
 {
     if (action == Input.KeyAction.Press && light != null)
     {
         light.TextureSize = light.TextureSize * 2;
         Console.WriteLine("Pressed: " + light.TextureSize);
     }
 }
Exemple #6
0
 private void BoostAction(Input.Key key, Input.KeyAction action)
 {
     if (action == Input.KeyAction.Press)
     {
         this.boost = BoostMultiplier;
     }
     if (action == Input.KeyAction.Release)
     {
         this.boost = 1.0f;
     }
 }
Exemple #7
0
        private void ChangeShader2(Input.Key key, Input.KeyAction action)
        {
            if (action == Input.KeyAction.Press)
            {
                var resourceManager = ResourceManager.Instance;
                var renderable      = this.Entity.GetComponent <Renderable>();

                renderable.UseDeferredShader(resourceManager.GetResource <Shader>("TestDeferred2"));

                renderable.DeferredShader.Material.DiffuseTexture = resourceManager.GetResource <Texture>("Numbers");

                renderable.Mesh = resourceManager.GetResource <Mesh>("Skull");
            }
        }
Exemple #8
0
        private void CurrentOptionAction(Input.Key key, Input.KeyAction action)
        {
            if (action != Input.KeyAction.Press)
            {
                return;
            }

            if (options.Count == 0)
            {
                return;
            }

            Console.WriteLine($"Current option: {options[currentOption].Name} = {options[currentOption].Value}");
        }
Exemple #9
0
        private void ChangeShader1(Input.Key key, Input.KeyAction action)
        {
            if (action == Input.KeyAction.Press)
            {
                var resourceManager = ResourceManager.Instance;
                var renderable      = this.Entity.GetComponent <Renderable>();

                renderable.UseDeferredShader(resourceManager.GetResource <Shader>("TestDeferred1"));

                renderable.DeferredShader.Material.Diffuse = new Vector3f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());

                renderable.Mesh = resourceManager.GetResource <Mesh>("EngineQ/Cube");

                Console.WriteLine($"Set diffuse color to {renderable.DeferredShader.Material.Diffuse}");
            }
        }
Exemple #10
0
        private void HitAction(Input.MouseButton button, Input.KeyAction action)
        {
            if (action == Input.KeyAction.Press)
            {
                var screenSize = Application.ScreenSize;
                var pos        = Input.MousePosition;

                Console.WriteLine(pos);

                var camera = this.Entity.Scene.ActiveCamera;

                var ray = camera.GetViewRay(new Vector2(2.0f * (float)pos.X / (float)screenSize.X - 1.0f, -2.0f * (float)pos.Y / (float)screenSize.Y + 1.0f));

                float dist = Utils.SegmentToRayDistance(new Segment(capsuleA, capsuleB), ray);

                Console.WriteLine($"Capsule pressed: {dist <= capsuleRadius}");

                //	Console.WriteLine($"Dir: {this.Transform.Rotation * Vector3.Forward}");
                //	Console.WriteLine($"Casted ray: {ray}");
            }
        }
Exemple #11
0
        private void ChangedOptionAnction(Input.Key key, Input.KeyAction action)
        {
            if (action != Input.KeyAction.Press && action != Input.KeyAction.Repeat)
            {
                return;
            }

            if (options.Count == 0)
            {
                Console.WriteLine("<No options>");
                return;
            }

            if (key == Input.Key.Kp4)
            {
                currentOption = (currentOption + 1) % options.Count;
            }
            if (key == Input.Key.Kp6)
            {
                currentOption = (currentOption + options.Count - 1) % options.Count;
            }

            Console.WriteLine($"Selected option: {options[currentOption].Name} = {options[currentOption].Value}");
        }
Exemple #12
0
        private void ArrowPressAction(Input.MouseButton button, Input.KeyAction action)
        {
            if (action == Input.KeyAction.Press)
            {
                var ray = this.Entity.Scene.ActiveCamera.GetViewRay(new Vector2(2.0f, -2.0f) * Input.MousePosition / (Vector2)Application.ScreenSize + new Vector2(-1.0f, 1.0f));

                Transform minTransform = null;
                float     distance;
                float     minDistance = float.PositiveInfinity;

                if (HittestArrow(this.arrowX, ray, out distance))
                {
                    if (minDistance > distance)
                    {
                        minDistance  = distance;
                        minTransform = arrowX;
                    }
                }
                if (HittestArrow(this.arrowY, ray, out distance))
                {
                    if (minDistance > distance)
                    {
                        minDistance  = distance;
                        minTransform = arrowY;
                    }
                }
                if (HittestArrow(this.arrowZ, ray, out distance))
                {
                    if (minDistance > distance)
                    {
                        minDistance  = distance;
                        minTransform = arrowZ;
                    }
                }

                if (minTransform != null)
                {
                    this.arrowDir = minTransform.GlobalRotation * Vector3.Up;

                    Vector3 cameraDir = (this.Entity.Scene.ActiveCamera.Entity.Transform.GlobalPosition - this.Transform.GlobalPosition).Normalized;

                    Vector3 localUp     = Vector3.CrossProduct(arrowDir, cameraDir).Normalized;
                    Vector3 planeNormal = Vector3.CrossProduct(arrowDir, localUp);

                    //	Console.WriteLine($"Arrow dir    {arrowDir}");
                    //	Console.WriteLine($"Plane normal {planeNormal}");
                    //	Console.WriteLine($"Local up     {localUp}");

                    if (Utils.RayPlaneIntersection(new Plane(this.Transform.GlobalPosition, planeNormal), ray, out distance))
                    {
                        this.initialRayIntersection = ray.GetPoint(distance);
                        this.initialPosition        = this.Transform.GlobalPosition;
                        this.initialRotation        = this.Transform.GlobalRotation;
                        this.initialScale           = this.Transform.Scale.X;

                        if (Input.IsKeyPressed(Input.Key.LeftShift))
                        {
                            this.rotate = true;
                        }
                        else if (Input.IsKeyPressed(Input.Key.LeftAlt))
                        {
                            this.scale = true;
                        }
                        else
                        {
                            this.move = true;
                        }
                    }
                }
            }

            if (action == Input.KeyAction.Release)
            {
                move      = false;
                rotate    = false;
                scale     = false;
                transform = null;
            }
        }
Exemple #13
0
        private void LeftMouseAction(Input.MouseButton button, Input.KeyAction action)
        {
            if (action == Input.KeyAction.Press)
            {
                lastMousePosition = Input.MousePosition;
            }

            if (action == Input.KeyAction.Release)
            {
                var pos        = Input.MousePosition;
                var screenSize = Application.ScreenSize;

                if ((this.lastMousePosition - pos).Length < 10.0f)
                {
                    var ray = camera.GetViewRay(new Vector2(2.0f * (float)pos.X / (float)screenSize.X - 1.0f, -2.0f * (float)pos.Y / (float)screenSize.Y + 1.0f));

                    float    closestDistance = float.PositiveInfinity;
                    Collider closestCollider = null;

                    var scene = this.Entity.Scene;
                    for (int i = 0; i < scene.EntitiesCount; ++i)
                    {
                        var entity = scene.GetEntity(i);

                        var collider = entity.GetComponent <Collider>();
                        if (collider == null)
                        {
                            continue;
                        }

                        float distance = 0.0f;
                        if (collider.RayCast(ray, out distance))
                        {
                            if (closestDistance > distance)
                            {
                                closestDistance = distance;
                                closestCollider = collider;
                            }
                        }
                    }

                    if (closestCollider != null)
                    {
                        Console.WriteLine($"Pressed at {closestCollider.Entity.Name}");

                        var arrows = scene.FindEntity("Arrows");

                        arrows.Transform.Position = closestCollider.Entity.Transform.GlobalPosition;
                        arrows.Transform.Rotation = closestCollider.Entity.Transform.GlobalRotation;

                        arrows.GetComponent <ArrowsController>().SetTransform(closestCollider.Entity.Transform);
                    }
                    else
                    {
                        var arrows = scene.FindEntity("Arrows");

                        var cameraRay = camera.GetViewRay(Application.NormalizeScreenPoint(Input.MousePosition));

                        arrows.Transform.GlobalPosition = cameraRay.Origin + cameraRay.Direction * 3.0f;


                        arrows.GetComponent <ArrowsController>().SetTransform(null);

                        Console.WriteLine("No collider found");
                    }
                }
            }
        }
Exemple #14
0
 private void SwitchAction(Input.Key key, Input.KeyAction action)
 {
     mode = (mode + 1) % 3;
 }