Rotate() public static méthode

public static Rotate ( System.Single angle, System.Vector3 axis ) : void
angle System.Single
axis System.Vector3
Résultat void
Exemple #1
0
        public void DrawRect(SColorF color, SRectF rect, bool allMonitors = true)
        {
            int loops = 1;

            if (allMonitors)
            {
                loops = CConfig.Config.Graphics.NumScreens;
            }
            for (int i = 0; i < loops; i++)
            {
                SRectF newrect = rect;
                newrect.X += CSettings.RenderW * i;

                GL.Enable(EnableCap.Blend);
                GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);

                GL.Begin(PrimitiveType.Quads);
                GL.MatrixMode(MatrixMode.Color);
                GL.PushMatrix();
                if (Math.Abs(newrect.Rotation) > 0.001)
                {
                    GL.Translate(0.5f, 0.5f, 0);
                    GL.Rotate(-newrect.Rotation, 0f, 0f, 1f);
                    GL.Translate(-0.5f, -0.5f, 0);
                }
                GL.Vertex3(newrect.X, newrect.Y, newrect.Z + CGraphics.ZOffset);
                GL.Vertex3(newrect.X, newrect.Y + newrect.H, newrect.Z + CGraphics.ZOffset);
                GL.Vertex3(newrect.X + newrect.W, newrect.Y + newrect.H, newrect.Z + CGraphics.ZOffset);
                GL.Vertex3(newrect.X + newrect.W, newrect.Y, newrect.Z + CGraphics.ZOffset);
                GL.End();
                GL.PopMatrix();
                GL.Disable(EnableCap.Blend);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        public void DrawRectReflection(SColorF color, SRectF rect, float space, float height)
        {
            if (rect.H < height)
            {
                height = rect.H;
            }

            float rx1 = rect.X;
            float rx2 = rect.X + rect.W;
            float ry1 = rect.Y + rect.H + space;
            float ry2 = rect.Y + rect.H + space + height;

            if (rx1 < rect.X)
            {
                rx1 = rect.X;
            }

            if (rx2 > rect.X + rect.W)
            {
                rx2 = rect.X + rect.W;
            }

            if (ry1 < rect.Y + space)
            {
                ry1 = rect.Y + space;
            }

            if (ry2 > rect.Y + rect.H + space + height)
            {
                ry2 = rect.Y + rect.H + space + height;
            }


            GL.Enable(EnableCap.Blend);
            GL.MatrixMode(MatrixMode.Color);
            GL.PushMatrix();
            if (Math.Abs(rect.Rotation) > 0.001)
            {
                GL.Translate(0.5f, 0.5f, 0);
                GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
                GL.Translate(-0.5f, -0.5f, 0);
            }

            GL.Begin(PrimitiveType.Quads);

            GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
            GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset);

            GL.Color4(color.R, color.G, color.B, 0f);
            GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset);
            GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset);

            GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
            GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset);

            GL.End();
            GL.PopMatrix();
            GL.Disable(EnableCap.Blend);
        }
Exemple #4
0
        protected override void _DrawTexture(COGLTexture texture, SDrawCoords dc, SColorF color, bool isReflection = false)
        {
            // Align textures to full pixels to reduce artefacts
            dc.Wx1 = (float)Math.Round(dc.Wx1);
            dc.Wy1 = (float)Math.Round(dc.Wy1);
            dc.Wx2 = (float)Math.Round(dc.Wx2);
            dc.Wy2 = (float)Math.Round(dc.Wy2);

            GL.BindTexture(TextureTarget.Texture2D, texture.Name);

            GL.Enable(EnableCap.Blend);

            GL.MatrixMode(MatrixMode.Texture);
            GL.PushMatrix();

            if (Math.Abs(dc.Rotation) > float.Epsilon)
            {
                GL.Translate(0.5f, 0.5f, 0);
                GL.Rotate(-dc.Rotation, 0f, 0f, 1f);
                GL.Translate(-0.5f, -0.5f, 0);
            }

            GL.Begin(PrimitiveType.Quads);

            GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
            GL.TexCoord2(dc.Tx1, dc.Ty1);
            GL.Vertex3(dc.Wx1, dc.Wy1, dc.Wz);

            if (isReflection)
            {
                GL.Color4(color.R, color.G, color.B, 0);
            }
            GL.TexCoord2(dc.Tx1, dc.Ty2);
            GL.Vertex3(dc.Wx1, dc.Wy2, dc.Wz);

            GL.TexCoord2(dc.Tx2, dc.Ty2);
            GL.Vertex3(dc.Wx2, dc.Wy2, dc.Wz);

            if (isReflection)
            {
                GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);
            }
            GL.TexCoord2(dc.Tx2, dc.Ty1);
            GL.Vertex3(dc.Wx2, dc.Wy1, dc.Wz);

            GL.End();

            GL.PopMatrix();

            GL.Disable(EnableCap.Blend);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Exemple #5
0
        public void DrawRect(SColorF color, SRectF rect)
        {
            GL.Enable(EnableCap.Blend);
            GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha);

            GL.Begin(PrimitiveType.Quads);
            GL.MatrixMode(MatrixMode.Color);
            GL.PushMatrix();
            if (Math.Abs(rect.Rotation) > 0.001)
            {
                GL.Translate(0.5f, 0.5f, 0);
                GL.Rotate(-rect.Rotation, 0f, 0f, 1f);
                GL.Translate(-0.5f, -0.5f, 0);
            }
            GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset);
            GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
            GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset);
            GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset);
            GL.End();
            GL.PopMatrix();
            GL.Disable(EnableCap.Blend);
        }
 public static void Rotate(double angle, Vector3d axis)
 {
     GL.Rotate((double)angle, axis.X, axis.Y, axis.Z);
 }
 public static void Rotate(Single angle, Vector3 axis)
 {
     GL.Rotate((Single)angle, axis.X, axis.Y, axis.Z);
 }
Exemple #8
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
        }
Exemple #9
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);
            }
        }