예제 #1
0
파일: MainWindow.cs 프로젝트: vjoensen/A5k
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            HandleKeyboard();
            Input.mousePosition = mousePos;
            ;
            //mousePos.X = this.PointToClient(new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y)).X-this.Width/2;
            //mousePos.Y = -this.PointToClient(new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y)).Y+this.Height/2;

            mousePos.X = Noesis.Mouse.GetPosition(xaml).X - this.Width / 2;
            mousePos.Y = -Noesis.Mouse.GetPosition(xaml).Y + this.Height / 2;

            for (int i = spaceObjects.Count - 1; i >= 0; i--)
            {
                if (spaceObjects[i].isDead())
                {
                    spaceObjects.RemoveAt(i);
                }
            }

            enemyAI.Update();

            List <SpaceObject> newSO = new List <SpaceObject>();

            player.Update(newSO);
            foreach (SpaceObject so in spaceObjects)
            {
                so.Update(newSO);
            }
            CheckCollisions();
            spaceObjects.AddRange(newSO);
            view.Update();
            globalTime += e.Time;
            nView.Update(globalTime);
        }
예제 #2
0
파일: MainWindow.cs 프로젝트: vjoensen/A5k
        protected override void OnLoad(System.EventArgs e)
        {
            Noesis.GUI.Init();
            //EmbeddedXaml[] xamls = new EmbeddedXaml[]
            //{
            //        new EmbeddedXaml { filename = "Reflections.xaml", resource = "Reflections" }
            //};
            //Noesis.GUI.SetXamlProvider(new LocalXamlProvider("."));



            // Data loading
            Noesis.GUI.SetXamlProvider(new NoesisApp.LocalXamlProvider("."));
            //Noesis.Grid xaml = (Noesis.Grid)Noesis.GUI.LoadXaml("UI\\UItest0.xaml");
            xaml = new Noesis.Grid();
            Noesis.GUI.LoadComponent(xaml, "UI\\UItest03.xaml");
            //MyGrid xaml = new MyGrid();

            Noesis.StackPanel sp = (Noesis.StackPanel)xaml.FindName("BottomMenu");
            sp.DataContext = new ViewModel();



            Noesis.Button button = (Noesis.Button)xaml.FindName("button");

            button.Click += (object sender, Noesis.RoutedEventArgs args) =>
            {
                System.Console.WriteLine("Button was clicked");
            };


            // create view
            nView = Noesis.GUI.CreateView(xaml);

            nView.SetSize(this.Width, this.Height);
            // get OpenGL rendering device
            Noesis.RenderDevice device = new Noesis.RenderDeviceGL();

            // init renderer as OpenGL
            renderer = nView.Renderer;
            renderer.Init(device);


            nView.Update(0.001); // Ensures view is updated before first render call (avoids crash)


            CursorVisible = true;



            mousePos            = new Vector2(this.PointToClient(new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y)).X, this.PointToClient(new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y)).Y);
            Input.mousePosition = mousePos;
            //GL.Disable()
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);


            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);


            spritedrawer  = new SpriteDrawer(view);
            cursorTexture = SpriteDrawer.LoadTexture("PNG\\crosshair010.png", true, false);



            texture = SpriteDrawer.LoadTexture("PNG\\playerShip1_red.png", true, false);

            player  = new PlayerShip(0, 0, 0, texture, SpriteDrawer.LoadTexture("PNG\\Lasers\\laserBlue01.png", true, false), view);
            enemyAI = new AI(spaceObjects, player);
            Ship enemy1 = new Ship(200, 200, 0, SpriteDrawer.LoadTexture("PNG\\ufoBlue.png", true, false));

            player.setTarget(enemy1);


            enemyAI.takeControl(enemy1);
            spaceObjects.Add(enemy1);


            Closed += OnClosed;
        }
예제 #3
0
파일: Program.cs 프로젝트: pdan1/Tutorials
        private static void Main()
        {
            Noesis.Log.SetLogCallback((level, channel, message) =>
            {
                if (channel == "")
                {
                    // [TRACE] [DEBUG] [INFO] [WARNING] [ERROR]
                    string[] prefixes = new string[] { "T", "D", "I", "W", "E" };
                    string prefix     = (int)level < prefixes.Length ? prefixes[(int)level] : " ";
                    Console.WriteLine("[NOESIS/" + prefix + "] " + message);
                }
            });

            // Noesis initialization. This must be the first step before using any NoesisGUI functionality
            Noesis.GUI.Init("LICENSE_NAME", "LICENSE_KEY");

            // Setup theme
            NoesisApp.Application.SetThemeProviders();
            Noesis.GUI.LoadApplicationResources("Theme/NoesisTheme.DarkBlue.xaml");

            // For simplicity purposes we are not using resource providers in this sample. ParseXaml() is
            // enough if there is no extra XAML dependencies
            Noesis.Grid xaml = (Noesis.Grid)Noesis.GUI.ParseXaml(@"
                <Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                    <Grid.Background>
                        <LinearGradientBrush StartPoint=""0,0"" EndPoint=""0,1"">
                            <GradientStop Offset=""0"" Color=""#FF123F61""/>
                            <GradientStop Offset=""0.6"" Color=""#FF0E4B79""/>
                            <GradientStop Offset=""0.7"" Color=""#FF106097""/>
                        </LinearGradientBrush>
                    </Grid.Background>
                    <Viewbox>
                        <StackPanel Margin=""50"">
                            <Button Content=""Hello World!"" Margin=""0,30,0,0""/>
                            <Rectangle Height=""5"" Margin=""-10,20,-10,0"">
                                <Rectangle.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Offset=""0"" Color=""#40000000""/>
                                        <GradientStop Offset=""1"" Color=""#00000000""/>
                                    </RadialGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                        </StackPanel>
                    </Viewbox>
                </Grid>");

            // View creation to render and interact with the user interface
            // We transfer the ownership to a global pointer instead of a Ptr<> because there is no way
            // in GLUT to do shutdown and we don't want the Ptr<> to be released at global time
            Noesis.View view = Noesis.GUI.CreateView(xaml);
            view.SetFlags(Noesis.RenderFlags.PPAA | Noesis.RenderFlags.LCD);

            // Creation of the system window
            RenderForm form = new RenderForm("NoesisGUI - IntegrationSharpDX D3D11")
            {
                Width  = 1000,
                Height = 600,
                Icon   = new System.Drawing.Icon("Noesis.ico")
            };

            view.SetSize(form.ClientSize.Width, form.ClientSize.Height);

            // SwapChain description
            SwapChainDescription desc = new SwapChainDescription()
            {
                BufferCount     = 1,
                ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height,
                                                      new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = form.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device and SwapChain
            Device    device;
            SwapChain swapChain;

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
            DeviceContext context = device.ImmediateContext;

            Factory factory = swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
            factory.Dispose();

            // Renderer initialization with a Direct3D11 device
            view.Renderer.Init(new Noesis.RenderDeviceD3D11(context.NativePointer));

            // New RenderTargetView from the backbuffer
            Texture2D        backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
            RenderTargetView renderView = new RenderTargetView(device, backBuffer);

            backBuffer.Dispose();

            // Register window events
            form.SizeChanged += (s, e) =>
            {
                context.OutputMerger.SetRenderTargets(null, (RenderTargetView)null);
                renderView.Dispose();

                swapChain.ResizeBuffers(0, 0, 0, Format.Unknown, SwapChainFlags.None);

                backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
                renderView = new RenderTargetView(device, backBuffer);
                backBuffer.Dispose();

                view.SetSize(form.ClientSize.Width, form.ClientSize.Height);
            };
            form.MouseMove += (s, e) => { view.MouseMove(e.X, e.Y); };
            form.MouseDown += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    view.MouseButtonDown(e.X, e.Y, Noesis.MouseButton.Left);
                }
            };
            form.MouseUp += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    view.MouseButtonUp(e.X, e.Y, Noesis.MouseButton.Left);
                }
            };

            // Main loop
            DateTime start = DateTime.Now;

            RenderLoop.Run(form, () =>
            {
                // Update view (layout, animations, ...)
                view.Update((DateTime.Now - start).TotalSeconds);

                // Offscreen rendering phase populates textures needed by the on-screen rendering
                view.Renderer.UpdateRenderTree();
                view.Renderer.RenderOffscreen();

                // If you are going to render here with your own engine you need to restore the GPU state
                // because noesis changes it. In this case only framebuffer and viewport need to be restored
                context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
                context.OutputMerger.SetTargets(renderView);
                context.ClearRenderTargetView(renderView, Color.Black);

                // Rendering is done in the active framebuffer
                view.Renderer.Render();

                // Present and swap buffers
                swapChain.Present(0, PresentFlags.None);
            });

            // Release all resources
            renderView.Dispose();
            context.ClearState();
            context.Flush();
            device.Dispose();
            context.Dispose();
            swapChain.Dispose();
        }
예제 #4
0
 static void OnTick(double timeInSeconds)
 {
     _view.Update(timeInSeconds);
 }