private void glControl_OpenGLInitialized(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
 {
     args.OpenGL.ClearColor(135.0f/255, 206.0f/255, 250.0f/255, 1.0f);
     _graphics = new Drawing.GLImmediateGraphicsController(args.OpenGL, new GLThingSize(glControl));
     _grid = new Drawing.CanvasGridRenderer(_graphics);
     _controls = new Drawing.PlotterControls(glControl, _grid);
 }
Exemple #2
1
        private void openGLControlTimerBased_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            //  Get the OpenGL object, just to clean up the code.
            var gl = openGLControlTimerBased.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
         
            gl.LoadIdentity();
            gl.Translate(0f, 0.0f, -7.0f);				// Move Right And Into The Screen

            gl.Rotate(rquad, 1.0f, 1.0f, 1.0f);			// Rotate The Cube On X, Y & Z

            gl.Begin(OpenGL.GL_QUADS);					// Start Drawing The Cube

            gl.Color(0.0f, 1.0f, 0.0f);			// Set The Color To Green
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)


            gl.Color(1.0f, 0.5f, 0.0f);			// Set The Color To Orange
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Top Right Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Top Left Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Bottom)
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Bottom)

            gl.Color(1.0f, 0.0f, 0.0f);			// Set The Color To Red
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Front)
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Front)

            gl.Color(1.0f, 1.0f, 0.0f);			// Set The Color To Yellow
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Back)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Back)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Back)
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Back)

            gl.Color(0.0f, 0.0f, 1.0f);			// Set The Color To Blue
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Left)

            gl.Color(1.0f, 0.0f, 1.0f);			// Set The Color To Violet
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Right)
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Right)
            gl.End();						// Done Drawing The Q

            gl.Flush();

            rtri += 3.0f;// 0.2f;						// Increase The Rotation Variable For The Triangle 
            rquad -= 3.0f;// 0.15f;						// Decrease The Rotation Variable For The Quad 
        }
Exemple #3
1
        private void openGLControl2_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            //  Get the OpenGL object, just to clean up the code.
            var gl = openGLControlManual.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();

            gl.Translate(0f, 0.0f, -6.0f);
            gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);

            gl.Begin(OpenGL.GL_TRIANGLES);

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Left Of Triangle (Front)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Right Of Triangle (Front)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Left Of Triangle (Right)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Right Of Triangle (Right)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Left Of Triangle (Back)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Right Of Triangle (Back)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Left Of Triangle (Left)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Right Of Triangle (Left)
            gl.End();						// Done Drawing The Pyramid
        }
Exemple #4
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            if ( _trail > 1)
            {
                for ( int t = 0; t<_trail;t++ )
                {
                    PointFloat trailPos = GetPosition();
                    PointFloat vel = GetVelocity();
                    PointFloat dit = new PointFloat(trailPos.x - vel.x*t, trailPos.y - vel.y*t);
                    PointFloat[] pointData = RenderLogics.RectPoint(dit, GetSize(), GetRotation());

                    GetTexture().UseTexure(gl);
                    gl.Begin(OpenGL.GL_QUADS);
                    byte[] col = GetColor();
                    gl.Color(col[0], col[1], col[2]);
                    gl.TexCoord(0, 0);
                    gl.Vertex(pointData[1].x, pointData[1].y);
                    gl.TexCoord(0, 1);
                    gl.Vertex(pointData[0].x, pointData[0].y);
                    gl.TexCoord(1, 1);
                    gl.Vertex(pointData[3].x, pointData[3].y);
                    gl.TexCoord(1, 0);
                    gl.Vertex(pointData[2].x, pointData[2].y);
                    gl.End();
                }
            }
            base.Draw(gl);
        }
Exemple #5
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            base.Draw(gl);
            if(_data == null){

            }
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
            gl.Begin(OpenGL.GL_QUAD_STRIP);
            for (int i = 0; i < _data.Length; i++ )
            {
                gl.Color(_data[i], _data[i], _data[i]);
                _x = ((GetSize().x / 256f) * i) + CamController.X - (GetSize().x / 2f);
                gl.Vertex(_x, GetPosition().y + _data[i] * _height);
                //gl.Vertex(_x, GetPosition().y + _data[i] * _height - 1.0f);
                gl.Vertex(_x, GetPosition().y);
            }
            gl.End();
            gl.Begin(OpenGL.GL_QUAD_STRIP);
            for (int i = 0; i < _data.Length; i++)
            {
                gl.Color(_data[i] - 0.5f, _data[i] - 0.5f, _data[i] - 0.5f);
                _x = ((GetSize().x / 256f) * i) + CamController.X - (GetSize().x / 2f);
                gl.Vertex(_x, GetPosition().y - _data[i] * _height / 10.0f);
                //gl.Vertex(_x, GetPosition().y + _data[i] * _height - 1.0f);
                gl.Color(_data[i], _data[i], _data[i]);
                gl.Vertex(_x, GetPosition().y);
            }
            gl.End();
        }
        private void openGLCtrl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            //  Get the OpenGL instance that's been passed to us.
            OpenGL gl = args.OpenGL;

            //  Clear the color and depth buffers.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Reset the modelview matrix.
            gl.LoadIdentity();

            //  Move the geometry into a fairly central position.
            gl.Translate(0f, 0.0f, -6.0f);

            axies.Render(gl, RenderMode.Design);

            switch(this.drawingMechanismCombo.SelectedIndex)
            {
                case 0:
                    RenderVertices_Immediate(args.OpenGL);
                    break;
                case 1:
                    RenderVertices_VertexArray(args.OpenGL);
                    break;
            }

            //  Flush OpenGL.
            gl.Flush();
            /*
            //  Clear the color and depth buffers.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Reset the modelview matrix.
            gl.LoadIdentity(); */
        }
        public void GenerateGeometry(SharpGL.OpenGL gl)
        {
            HighlightCube.GenerateGeometry(gl);

            const float spacing = 1 + CubeSpacing;

            for (int z = 0; z < Size; z++)
            {
                for (int y = 0; y < Size; y++)
                {
                    for (int x = 0; x < Size; x++)
                    {
                        var cube = new Cube(Colors.Black);
                        ColourCubeFromConfiguration(cube, x, y, z);
                        cube.GenerateGeometry(gl);

                        var position = new Vector3(x * spacing, y * spacing, z * spacing);
                        position += m_cubieCentre;  // Centre
                        string id = string.Format("{0},{1},{2}", x - 1, y - 1, z - 1);
                        var cubie = new Cubie(id, cube, position);
                        AddToConfiguration(cubie, x, y, z);
                        m_animators.Add(new CubieAnimator(cubie));
                    }
                }
            }

            CubeConfiguration.CheckValid();
        }
        public void BindBuffer(SharpGL.OpenGL gl, Action executeWhileBinded)
        {
            gl.BindVertexArray(BufferId.Value);

            executeWhileBinded.Invoke();

            gl.BindVertexArray(0); // Unbind.
        }
        public static void ApplySingleLightParameters(SharpGL.OpenGL gl, ExtShaderProgram esp, vec3 lp)
        {
            var prms = esp.Parameters as ISingleLightParameters;
            var p = esp.Program;

            // Set the light position.
            if (prms.LightPositionId != null)
                p.SetUniform3(gl, prms.LightPositionId, lp.x, lp.y, lp.z);
        }
Exemple #10
0
        public void RegenerateRubiksCube(SharpGL.OpenGL gl)
        {
            if (!m_regenerateRubiksCube) return;
            m_regenerateRubiksCube = false;

            RubiksCube.GenerateGeometry(gl);
            m_cubeAnimator.Setup();

            m_cubeResetTask.SetResult(null);
        }
Exemple #11
0
        public void GenerateGeometry(SharpGL.OpenGL gl)
        {
            m_vertexBuffer.Create(gl);
            m_vertexBuffer.Bind(gl);

            GenerateVertexBuffer(gl);
            GenerateColourBuffer(gl);

            m_vertexBuffer.Unbind(gl);
        }
 private void openGL_OpenGLDraw(object sender, SharpGL.OpenGLEventArgs args)
 {
     OpenGL gl = args.OpenGL;
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
     gl.LoadIdentity();
     gl.Translate(0.0f, 0.0f, -3.0f);
     gl.Rotate(rotate, 0.0f, 1.0f, 0.0f);
     if (mesh != null)
         mesh.draw(gl);
     gl.Flush();
     rotate += 0.3f;
 }
        private void capture_OpenGLDraw(object sender, SharpGL.OpenGLEventArgs args)
        {
            if (time == -1)
            {
                millis = DateTime.Now.Ticks;
                time = 0;
            }
            else
            {
                long newMillis = DateTime.Now.Ticks;
                time += 0.1*(double)(newMillis - millis) / 1000000;
                millis = newMillis;
                while (time > T)
                    time -= T;
            }

            OpenGL gl = args.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();
            gl.Translate(0, 0, -2);
            gl.Rotate(45, 1, 0, 0);

            gl.LineWidth(2);
            gl.Color(1.0, 0, 0);
            drawCircle(gl, R, 1 - x1_func(time));

            gl.LineWidth(1);
            gl.Color(0.0, 0, 1);
            drawCircle(gl, 0.01, 1 - x2_func(time));

            gl.Color(0, 0, 0);
            gl.Begin(OpenGL.GL_LINES);
            double angle1 = 0,angle2=Math.PI/3*2,angle3=-Math.PI / 3 * 2;
            gl.Vertex4d(0.01 * Math.Cos(angle1), 1, 0.01 * Math.Sin(angle1), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle1), 1 - x2_func(time), 0.01 * Math.Sin(angle1), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle2), 1, 0.01 * Math.Sin(angle2), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle2), 1 - x2_func(time), 0.01 * Math.Sin(angle2), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle3), 1, 0.01 * Math.Sin(angle3), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle3), 1 - x2_func(time), 0.01 * Math.Sin(angle3), 1);

            gl.Vertex4d(R * Math.Cos(angle1), 1- x1_func(time), R * Math.Sin(angle1), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle1), 1 - x2_func(time), 0.01 * Math.Sin(angle1), 1);
            gl.Vertex4d(R * Math.Cos(angle2), 1- x1_func(time), R * Math.Sin(angle2), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle2), 1 - x2_func(time), 0.01 * Math.Sin(angle2), 1);
            gl.Vertex4d(R * Math.Cos(angle3), 1- x1_func(time), R * Math.Sin(angle3), 1);
            gl.Vertex4d(0.01 * Math.Cos(angle3), 1 - x2_func(time), 0.01 * Math.Sin(angle3), 1);

            gl.End();

            gl.Flush();
        }
Exemple #14
0
        private void openGLControl1_Resized(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            //  Get the OpenGL instance.
            var gl = args.OpenGL;

            //  Create an orthographic projection.
            gl.MatrixMode(MatrixMode.Projection);
            gl.LoadIdentity();
            gl.Ortho(0, openGLControl1.ActualWidth, openGLControl1.ActualHeight, 0, -10, 10);

            //  Back to the modelview.
            gl.MatrixMode(MatrixMode.Modelview);
        }
Exemple #15
0
        public void Render(SharpGL.OpenGL gl, ShaderWrapper shader)
        {
             if (CancellationTokenSource != null && CancellationTokenSource.IsCancellationRequested)
            {
                m_cubeAnimator.AnimationFinished();
                return;
            }

            if (ShowAxes)
                m_axes.Render(gl, shader);

            m_cubeAnimator.Animate();
            RubiksCube.Render(gl, shader);
        }
        public void ResetOpenGL(SharpGL.OpenGL gl,int width,int height)
        {
            gl.Viewport(0, 0, width, height);

            gl.Color(1.0, 1.0, 1.0, 1.0); // reset gl color

            gl.MatrixMode(MatrixMode.Projection);
            gl.LoadIdentity();
            gl.Ortho(0, width, height, 0, -10, 10);

            gl.MatrixMode(MatrixMode.Modelview);

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
        }
Exemple #17
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            //  Get the OpenGL instance.
            var gl = args.OpenGL;

            gl.Color(1f, 0f, 0f);
            gl.PointSize(2.0f);

            //  Draw 10000 random points.
            gl.Begin(BeginMode.Points);
            Random random = new Random();
            for (int i = 0; i < 10000; i++)
            {
                gl.Vertex(random.Next(100, 500), random.Next(100, 500), random.Next(-100, 100));
            }
            

            gl.End();
        }
Exemple #18
0
        public void Render(SharpGL.OpenGL gl, ShaderWrapper shader)
        {
            m_vertexBuffer.Bind(gl);
            // TODO: CENTRE TUBES

            var rotation = Matrix4.CreateRotationY(MathEx.PiOver2);
            shader.SetModelMatrix(rotation);
            m_xCylinder.Render(gl, shader);

            rotation = Matrix4.CreateRotationX(-MathEx.PiOver2);
            shader.SetModelMatrix(rotation);
            m_yCylinder.Render(gl, shader);

            rotation = Matrix4.CreateRotationZ(MathEx.PiOver2);
            shader.SetModelMatrix(rotation);
            m_zCylinder.Render(gl, shader);

            m_vertexBuffer.Unbind(gl);

        }
Exemple #19
0
        public static void Draw3DInformation(SharpGL.OpenGL gl_object, float[] X, float[] Y, float[] Z)
        {
            double MaxDistance = 0;
            double r = 0, g = 0, b = 0;
            gl_object.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl_object.LoadIdentity();
            gl_object.Translate(_LX, _LY, _LZ);
            gl_object.Rotate(_RoX, 0.0, 1.0, 0.0);
            gl_object.Rotate(_RoY, 1.0, 0.0, 0.0);
            gl_object.Rotate(_RoZ, 0.0, 0.0, 1.0);

            //畫光達自己的位置
            gl_object.Begin(OpenGL.GL_TRIANGLES);
            gl_object.Color(1.0, 1.0, 1.0);
            gl_object.Vertex(-0.2, -0.15, 0);
            gl_object.Vertex(0, 0.2, 0);
            gl_object.Vertex(0.2, -0.15, 0);
            gl_object.End();

            drawAxis_3D(gl_object);

            //畫D場景
            gl_object.Begin(OpenGL.GL_POINTS);
            for (int i = 0; i < 23040; i++)
            {
                if (X[i] != 0 && Y[i] != 0 && Z[i] != 0)
                {
                    //用XY距離計算顯示顏色
                    double XYDistance = Math.Sqrt(X[i] * X[i] + Y[i] * Y[i]);
                    if (XYDistance > MaxDistance) MaxDistance = XYDistance;
                    if (XYDistance > 10) XYDistance = 10;
                    XYDistance = XYDistance / 10 * (360 - 30) + 30;
                    HsvToRgb(XYDistance, 1, 1, out r, out g, out b);
                    gl_object.Color(r, g, b);
                    //畫上點座標
                    gl_object.Vertex(X[i], Y[i], Z[i]);
                }
            }
            gl_object.End();
            gl_object.Flush();
        }
Exemple #20
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            //  If there aren't any shapes, create them.
            if (!shapes.Any())
                CreateShapes();

            //  Get the OpenGL instance.
            var gl = args.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.PointSize(2.0f);

            foreach(var shape in shapes)
            {
                gl.Color(shape.Red, shape.Green, shape.Blue);

                gl.Begin(BeginMode.LineLoop);
                shape.Points.ForEach(sp => gl.Vertex(sp.Position));
                gl.End();
            }

            Tick();
        }
Exemple #21
0
        public GLColor CalculateLighting(SharpGL.SceneGraph.Lights.Light light, float angle)
        {
            double angleRadians = angle * 3.14159 / 360.0;
            GLColor reflected = ambient * light.Ambient;
            reflected += diffuse * light.Diffuse * (float)Math.Cos(angleRadians);

            return reflected;
        }
        private void openGLCtrl_OpenGLInitialized(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            //  Create the vertices.
            vertices = GeometryGenerator.GenerateGeometry(Properties.Settings.Default.NumberOfVertices, 1f);

            //  Override with test values if needed.
            ProvideTestValues(vertices);

            vertexArrayValues = new float[vertices.Length * 3];
            uint counter = 0;
            for (uint i = 0; i < vertices.Length; i++)
            {
                vertexArrayValues[counter] = vertices[i].X;
                vertexArrayValues[counter++] = vertices[i].Y;
                vertexArrayValues[counter++] = vertices[i].Z;
            }

            args.OpenGL.PointSize(3.0f);
        }
 private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
 {
     //  Get the OpenGL instance that's been passed to us.
     ExternalFunctions.SetWindowsSize((int)this.ActualWidth, (int)this.ActualHeight);
     ExternalFunctions.OnPaint();
 }
        public static void drawAxis(SharpGL.OpenGL gl_object)
        {
            //畫Z軸
            gl_object.Color(1.0, 1.0, 1.0);
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(-0.02, -0.02, -0.02);
            gl_object.Vertex(-0.02, -0.02, 10);
            gl_object.Vertex(0.02, -0.02, -0.02);
            gl_object.Vertex(0.02, -0.02, 10);
            gl_object.Vertex(0.02, 0.02, -0.02);
            gl_object.Vertex(0.02, 0.02, 10);
            gl_object.Vertex(-0.02, 0.02, -0.02);
            gl_object.Vertex(-0.02, 0.02, 10);
            gl_object.Vertex(-0.02, -0.02, -0.02);
            gl_object.Vertex(-0.02, -0.02, 10);
            gl_object.End();
            //up
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(-0.02, -0.02, 10);
            gl_object.Vertex(0.02, -0.02, 10);
            gl_object.Vertex(-0.02, 0.02, 10);
            gl_object.Vertex(0.02, 0.02, 10);
            gl_object.End();

            //down
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(-0.02, -0.02, -0.02);
            gl_object.Vertex(0.02, -0.02, -0.02);
            gl_object.Vertex(-0.02, 0.02, -0.02);
            gl_object.Vertex(0.02, 0.02, -0.02);
            gl_object.End();

            //畫X軸
            gl_object.Color(0, 1.0, 0);
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(0.02, -0.02, -0.02);
            gl_object.Vertex(10, -0.02, -0.02);
            gl_object.Vertex(0.02, 0.02, -0.02);
            gl_object.Vertex(10, 0.02, -0.02);
            gl_object.Vertex(0.02, 0.02, 0.02);
            gl_object.Vertex(10, 0.02, 0.02);
            gl_object.Vertex(0.02, -0.02, 0.02);
            gl_object.Vertex(10, -0.02, 0.02);
            gl_object.Vertex(0.02, -0.02, -0.02);
            gl_object.Vertex(10, -0.02, -0.02);
            gl_object.End();
            //up
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(10, -0.02, -0.02);
            gl_object.Vertex(10, 0.02, -0.02);
            gl_object.Vertex(10, -0.02, 0.02);
            gl_object.Vertex(10, 0.02, 0.02);
            gl_object.End();

            //down
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(0.02, -0.02, -0.02);
            gl_object.Vertex(0.02, 0.02, -0.02);
            gl_object.Vertex(0.02, -0.02, 0.02);
            gl_object.Vertex(0.02, 0.02, 0.02);
            gl_object.End();

            //畫Y軸
            gl_object.Color(0, 0, 1.0);
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(-0.02, 0.02, -0.02);
            gl_object.Vertex(-0.02, 10, -0.02);
            gl_object.Vertex(0.02, 0.02, -0.02);
            gl_object.Vertex(0.02, 10, -0.02);
            gl_object.Vertex(0.02, 0.02, 0.02);
            gl_object.Vertex(0.02, 10, 0.02);
            gl_object.Vertex(-0.02, 0.02, 0.02);
            gl_object.Vertex(-0.02, 10, 0.02);
            gl_object.Vertex(-0.02, 0.02, -0.02);
            gl_object.Vertex(-0.02, 10, -0.02);
            gl_object.End();
            //up
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(-0.02, 10, -0.02);
            gl_object.Vertex(0.02, 10, -0.02);
            gl_object.Vertex(-0.02, 10, 0.02);
            gl_object.Vertex(0.02, 10, 0.02);
            gl_object.End();

            //down
            gl_object.Begin(OpenGL.GL_TRIANGLE_STRIP);
            gl_object.Vertex(-0.02, 0.02, -0.02);
            gl_object.Vertex(0.02, 0.02, -0.02);
            gl_object.Vertex(-0.02, 0.02, 0.02);
            gl_object.Vertex(0.02, 0.02, 0.02);
            gl_object.End();
        }
        public static void Trans3D(SharpGL.OpenGL gl_object, int x, int y)
        {
            //Console.Write(_RoX + ", " + _RoY + ", " + " => ");

            //	Create an array that will be the viewport.
            //3D顯示大小
            int[] viewport = new int[4];
            //	Get the viewport, then convert the mouse point to an opengl point.
            gl_object.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            double[] modelview = new double[16];
            gl_object.GetDouble(OpenGL.GL_MODELVIEW_MATRIX, modelview);
            double[] projection = new double[16];
            gl_object.GetDouble(OpenGL.GL_PROJECTION_MATRIX, projection);

            float winX, winY;
            winX = (x - viewport[2] / 2);
            winY = (y - viewport[3] / 2); //與範例不同的是 圖形原點是左上角
            //Console.Write(winX + ", " + winY + ", " + " => ");

            //(posX, posY, posZ) 轉換之前的座標
            /* double[] posX = new double[4];
             double[] posY = new double[4];
             double[] posZ = new double[4];*/
            double posX = new double();
            double posY = new double();
            double posZ = new double();
            gl_object.UnProject(x, y, 0, modelview, projection, viewport, ref posX, ref posY, ref posZ);

            isNav = 1;
            if (_RoX >= 165 && _RoX <= 200)
            {
                //if (winX * posX[0] < 0 && winY * posY[0] < 0) isNav = -1;
                if (winX * posX < 0 && winY * posY < 0) isNav = -1;
            }
            else if (_RoX >= 45 && _RoX <= 315)
            {
                //if (winX * posX[0] > 0) isNav = -1;
                if (winX * posX > 0) isNav = -1;
            }
            return;
        }
 public void ApplyTransformableParameters(SharpGL.OpenGL gl, ExtShaderProgram esp, GlmNet.mat4[] m)
 {
     throw new NotImplementedException();
 }
 public void ApplyTransformableParameters(SharpGL.OpenGL gl, ExtShaderProgram esp, GlmNet.mat4 m)
 {
     ParameterAppliers.JOG.ApplyTransformableParameters(gl, esp, m);
 }
        private static void Sender_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            var control = (OpenGLControl)sender;
            var mousePoint = Mouse.GetPosition(control);
            var gl = args.OpenGL;

            gl.ClearColor(1f, 1f, 1f, 1f);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.PointSize(2.0f);
            gl.Enable(OpenGL.GL_BLEND);

            var collection = GetRender(control);
            if (!collection.Any())
                return;

            double tpi = 2 * Math.PI;
            double t = Math.PI / 20;
            double r = 15;
            double ticksPerScale = 0;
            var refreshRate = GetScaleValue(control);
            var rateType = GetScaleType(control);
            switch (rateType)
            {
                case ScaleType.Milliseconds:
                    ticksPerScale = TimeSpan.FromMilliseconds(refreshRate).Ticks;
                    break;
                case ScaleType.Centiseconds:
                    ticksPerScale = TimeSpan.FromMilliseconds(refreshRate * 10).Ticks;
                    break;
                case ScaleType.Deciseconds:
                    ticksPerScale = TimeSpan.FromMilliseconds(refreshRate * 100).Ticks;
                    break;
                case ScaleType.Seconds:
                    ticksPerScale = TimeSpan.FromSeconds(refreshRate).Ticks;
                    break;
                case ScaleType.Minutes:
                    ticksPerScale = TimeSpan.FromMinutes(refreshRate).Ticks;
                    break;
                case ScaleType.Houers:
                    ticksPerScale = TimeSpan.FromHours(refreshRate).Ticks;
                    break;
                default:
                    break;
            }

            var props = typeof(Colors).GetProperties();
            int colorIndex = 0;
            var offsety = 20;

            foreach (var diagram in collection)
            {
                var color = (Color)props[colorIndex++].GetValue(null);
                gl.Color(color.ScR, color.ScG, color.ScB);

                if (offsety > control.ActualHeight)
                    break;

                foreach (var marble in diagram.Items)
                {
                    var offsetx = (double)marble.Offset.Ticks / ticksPerScale * r + 30;
                    if (offsetx > control.ActualWidth)
                        break;

                    var mlx = Math.Abs(mousePoint.X - offsetx);
                    var mly = Math.Abs(mousePoint.Y - offsety);
                    if (mlx <= r && mly <= r)
                    {
                        r = 20;

                        gl.DrawText((int)offsetx - 30, (int)control.ActualHeight - offsety - 30, 0, 0, 0, "Courier New", 12, marble.Value ?? "Marble");

                        gl.Color(color.ScR, color.ScG, color.ScB);
                    }

                    gl.Begin(BeginMode.Polygon);
                    for (double i = 0; i < tpi; i += t)
                        gl.Vertex(offsetx + Math.Cos(i) * r, offsety + Math.Sin(i) * r);
                    gl.End();

                    r = 15;
                }

                offsety += 60;
            }
        }
 private static void Sender_Resized(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
 {
     var control = (OpenGLControl)sender;
     var gl = args.OpenGL;
     InitView(control, gl);
 }
Exemple #30
-1
 private void GenerateColourBuffer(SharpGL.OpenGL gl)
 {
     var vertexDataBuffer = new VertexBuffer();
     vertexDataBuffer.Create(gl);
     vertexDataBuffer.Bind(gl);
     vertexDataBuffer.SetData(gl, 1, Colours, false, 3);
 }