Scale() public static method

public static Scale ( System.Vector3 scale ) : void
scale System.Vector3
return void
Esempio n. 1
0
        private void DrawBegin(RectangleF dstRect)
        {
            GL.Enable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.DepthTest);
            GL.Color4(Color);
            GL.Viewport(0, 0, Width, Height);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            var w = MMW.Width;
            var h = MMW.Height;

            GL.Ortho(0, w, h, 0, -1, 1);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            var trans = new Vector3(dstRect.X + dstRect.Width * CenterPivot.X, dstRect.Y + dstRect.Height * CenterPivot.Y, 0.0f);

            GL.Translate(trans);
            GL.Scale(Scale.X, Scale.Y, 1.0f);
            GL.Rotate(Rotate.Z, 0.0f, 0.0f, 1.0f);
            GL.Rotate(Rotate.X, 1.0f, 0.0f, 0.0f);
            GL.Rotate(Rotate.Y, 0.0f, 1.0f, 0.0f);
            GL.Translate(-trans);
            GL.Translate(dstRect.X - 0.5f, dstRect.Y - 0.5f, 0.0f);
        }
Esempio n. 2
0
 public static void Scale(Vector3d scale)
 {
     GL.Scale(scale.X, scale.Y, scale.Z);
 }
Esempio n. 3
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);
#if TEST
#else
            GL.Clear(TK.ClearBufferMask.DepthBufferBit | TK.ClearBufferMask.ColorBufferBit);

            if (ortho)
            {
                modelView = Matrix4.CreateOrthographic(width, height, -height, height);
                GL.MatrixMode(TK.MatrixMode.Projection);
                GL.PushMatrix();
                GL.LoadMatrix(ref modelView);
                GL.Scale(scale_factor, scale_factor, scale_factor);
            }
            else
            {
                modelView = Matrix4.LookAt(eye, target, up);
                GL.MatrixMode(TK.MatrixMode.Modelview);
                GL.PushMatrix();
                GL.LoadMatrix(ref modelView);
            }
            GL.PushMatrix();
            GL.Rotate(offsetX, 0.0f, 1.0f, 0.0f);
            GL.Rotate(offsetY, 1.0f, 0.0f, 0.0f);

            DrawGrid();

            #region Draw 3D Polyhedrons

            GL.Color3(0.0, 0.5, 1.0);

            GL.Enable(TK.EnableCap.Light0);
            GL.Enable(TK.EnableCap.Lighting);

            int i = 0;
            foreach (Body body in bodies)
            {
                float[] color = colors[i % colors.Count()];
                color[3] = 0.9f;
                GL.Color4(color);
                body.Draw();
                color[3] = 0.25f;
                GL.Color4(color);
                body.getBSphere().Draw();
                i++;
            }

            if (picked != -1)
            {
                GL.Color3(colors[picked % colors.Count()]);
                GL.PolygonMode(TK.MaterialFace.FrontAndBack, TK.PolygonMode.Line);
                foreach (Body body in bodies.ElementAt(picked).getBSphere().cells)
                {
                    body.Draw();
                }
                GL.PolygonMode(TK.MaterialFace.FrontAndBack, TK.PolygonMode.Fill);
            }

            GL.Disable(TK.EnableCap.Lighting);
            GL.Disable(TK.EnableCap.Light0);
            #endregion

            #region Draw Gizmos
            drawCollisionIntervals();
            #endregion

            GL.PopMatrix();
            GL.PopMatrix();

            SwapBuffers();

            showFPS();
            //showInfo();
#endif
        }
Esempio n. 4
0
        static void Main()
        {
            Console.WriteLine("Entering");

            using (var game = new GameWindow(1920, 1080, new GraphicsMode(ColorFormat.Empty, 8, 0, 6), "Heart of Gold", GameWindowFlags.Default)) {
                game.Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);
                var size = 500;
                var zoom = 1.0;
                game.Load += (sender, e) => { game.VSync = VSyncMode.On;
                                              GL.PointSize(10); };
                game.MouseWheel += delegate(object sender, MouseWheelEventArgs args) {
                    if (args.Delta > 0)
                    {
                        zoom *= 1.1;
                    }
                    //zoom += args.Delta/10.0;
                    else
                    {
                        zoom /= 1.1;
                    }
                    //zoom += args.Delta/10.0;

                    if (zoom <= 0.1)
                    {
                        zoom = 0.1;
                    }

                    //var aspect = game.Width / (double)game.Height;

                    //GL.Viewport(0, 0, game.Width, game.Height);
                    //GL.Ortho(-xsize, xsize, ysize, -ysize, 0, 4.0);
                };
                game.Resize += (sender, e) =>
                               GL.Viewport(0, 0, game.Width, game.Height);

                #region Heights

                var matrix = new double[size, size];
                //var r = new Random();

                #endregion


                #region Color

                Console.WriteLine("Initializing color...");
                var cmatrix = new Color[size, size];
                using (var b = (Bitmap)Image.FromFile(@"E:\Downloads\Untitled5.png")) {
                    for (var i = 0; i < size; i++)
                    {
                        Console.Write($"\rOn column {i,4} of {size}");
                        for (var j = 0; j < size; j++)
                        {
                            matrix[i, j]  = ((double)b.GetPixel(i, j).A + 1);                           // / 8.0;
                            cmatrix[i, j] = Color.FromArgb(255, b.GetPixel(i, j));
                        }
                    }
                }
                Console.WriteLine();
                #endregion


                bool wDown = false,
                     aDown = false,
                     sDown = false,
                     dDown = false;
                game.KeyDown += (sender, args) => {
                    switch (args.Key)
                    {
                    case Key.W:
                        wDown = true;
                        break;

                    case Key.A:
                        aDown = true;
                        break;

                    case Key.S:
                        sDown = true;
                        break;

                    case Key.D:
                        dDown = true;
                        break;
                    }
                };
                var translate = Vector2.Zero;
                game.KeyUp += (sender, args) => {
                    switch (args.Key)
                    {
                    case Key.Escape:
                        game.Exit();
                        break;

                    case Key.R:
                        zoom = 1;
                        break;

                    case Key.W:
                        if (wDown)
                        {
                            translate += new Vector2(1f, 1f);
                        }
                        wDown = false;
                        break;

                    case Key.A:
                        if (aDown)
                        {
                            translate += new Vector2(1f, -1f);
                        }
                        aDown = false;
                        break;

                    case Key.S:
                        if (sDown)
                        {
                            translate += new Vector2(-1f, -1f);
                        }
                        sDown = false;
                        break;

                    case Key.D:
                        if (dDown)
                        {
                            translate += new Vector2(-1f, 1f);
                        }
                        dDown = false;
                        break;
                    }
                };

                double time = 0, sin = 0;

                game.UpdateFrame +=
                    (sender, e) => {
                    time      += e.Time;
                    sin        = (Math.Sin(time / 4) + 1) / 2;
                    game.Title = $"Heart of Gold - {game.RenderFrequency:000.00}fps - {game.UpdateFrequency:000.00}tps";
                };

                var items = new List <BufferElement>(size * size * 12);
                Console.WriteLine("Prepping buffer elements...");
                //First half
                var side = matrix.GetLength(0);
                var half = side / 2;
                for (var i = 0; i < side; i++)
                {
                    Console.Write($"\rCreating row {i,4} of {side}");
                    int x = i, y = 0;
                    while (x >= 0)
                    {
                        var hasleft  = y != side - 1;
                        var hasright = x != side - 1;
                        var left     = hasleft ? (double?)matrix[x, y + 1] : -2;
                        var right    = hasright ? (double?)matrix[x + 1, y] : -2;
                        items.AddRange(AddOne(matrix[x, y], x - half, y - half, cmatrix[x--, y++], left, right));
                    }
                }
                // Pt 2
                for (var i = 1; i <= side - 1; i++)
                {
                    Console.Write($"\rCreating column {i,4} of {side}");
                    int x = side - 1, y = i;
                    while (y < side)
                    {
                        var hasleft = y != side - 1; var hasright = x != side - 1;
                        var left  = hasleft ? (double?)matrix[x, y + 1] : -2;
                        var right = hasright ? (double?)matrix[x + 1, y] : -2;
                        items.AddRange(AddOne(matrix[x, y], x - half, y - half, cmatrix[x--, y++], left, right));
                    }
                }
                Console.WriteLine("\rCreating vertex buffer object...           ");
                Action a = delegate {
                    GL.EnableClientState(ArrayCap.VertexArray);
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.VertexPointer(3, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0));
                    GL.ColorPointer(3, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector3.SizeInBytes));
                };
                var terrain = new VertexBuffer <BufferElement>(items.ToArray(), a, BufferUsageHint.StaticDraw);
                Console.WriteLine("Done!");
                game.RenderFrame += delegate {
                    // render graphics
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();

                    GL.Ortho(size, -size, size, -size, -double.MaxValue, double.MaxValue);

                    GL.Scale(1 * zoom, (game.Width / (double)game.Height) * zoom, 1 * zoom);
                    GL.Rotate(90 * sin, 1, 0, 0);
                    GL.Rotate(45, 0, 0, 1);
                    GL.Translate(translate.X, translate.Y, -matrix[(int)-translate.X + half, (int)-translate.Y + half]);

                    terrain.Render(PrimitiveType.Quads);

                    //GL.Begin(PrimitiveType.LineLoop);

                    //DrawOne(matrix[(int) -translate.X + half, (int) -translate.Y + half], (int) -translate.X, (int) -translate.Y,
                    //	Color.Black);
                    //GL.End();

                    game.SwapBuffers();
                };
                game.WindowState = WindowState.Maximized;
                game.Run(60.0, 60);
            }
        }