示例#1
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;

            // Clear The Screen And The Depth Buffer
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            // Move Left And Into The Screen
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -40.0f);

            lightCube.Draw(gl, 1, 0, 0);
            lightCube.ApplyForce(wind);
            lightCube.ApplyForce(gravity);

            mediumCube.Draw(gl, 0, 1, 0);
            mediumCube.ApplyForce(wind);
            mediumCube.ApplyForce(gravity);

            heavyCube.Draw(gl, 0, 0, 1);
            heavyCube.ApplyForce(wind);
            heavyCube.ApplyForce(gravity);

            if (heavyCube.Position.x >= rightBorder)
            {
                heavyCube.Velocity.x *= -1;
            }
            if (mediumCube.Position.x >= rightBorder)
            {
                mediumCube.Velocity.x *= -1;
            }
            if (lightCube.Position.x >= rightBorder)
            {
                lightCube.Velocity.x *= -1;
            }

            if (heavyCube.Position.y <= bottomBorder)
            {
                heavyCube.Velocity.y *= -1;
            }
            if (mediumCube.Position.y <= bottomBorder)
            {
                mediumCube.Velocity.y *= -1;
            }
            if (lightCube.Position.y <= bottomBorder)
            {
                lightCube.Velocity.y *= -1;
            }
        }
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.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, -40.0f);

            lightCube.Draw(gl);
            lightCube.ApplyForce(wind);
            lightCube.ApplyForce(gravity);
            if (lightCube.Position.x >= 27)
            {
                lightCube.Velocity.x = -1;
            }
            if (lightCube.Position.y <= -15)
            {
                lightCube.Velocity.y = 1;
            }

            mediumCube.Draw(gl);
            mediumCube.ApplyForce(wind);
            mediumCube.ApplyForce(gravity);
            if (mediumCube.Position.x >= 27)
            {
                mediumCube.Velocity.x = -1;
            }
            if (mediumCube.Position.y <= -15)
            {
                mediumCube.Velocity.y = 1;
            }

            heavyCube.Draw(gl);
            heavyCube.ApplyForce(wind);
            heavyCube.ApplyForce(gravity);
            if (heavyCube.Position.x >= 27)
            {
                heavyCube.Velocity.x = -1;
            }
            if (heavyCube.Position.y <= -15)
            {
                heavyCube.Velocity.y = 1;
            }
        }
        private void bounce(CubeMesh cube)
        {
            cube.ApplyForce(wind);
            cube.ApplyForce(gravity);

            if (cube.Position.y <= boxB)
            {
                cube.Velocity.y -= cube.Velocity.y * 2;
            }

            if (cube.Position.y >= boxT)
            {
                cube.Velocity.y -= cube.Velocity.y * 2;
            }
            if (cube.Position.x >= boxR)
            {
                cube.Velocity.x -= cube.Velocity.x * 2;
            }
            if (cube.Position.x <= boxL)
            {
                cube.Velocity.x -= cube.Velocity.x * 2;
            }
        }
示例#4
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;

            // Clear The Screen And The Depth Buffer
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            // Move Left And Into The Screen
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -50.0f);

            lightCube.Draw(gl);
            lightCube.ApplyForce(wind);
            lightCube.ApplyForce(gravity);

            medCube.Draw(gl);
            medCube.ApplyForce(wind);
            medCube.ApplyForce(gravity);

            heavyCube.Draw(gl);
            heavyCube.ApplyForce(wind);
            heavyCube.ApplyForce(gravity);

            #region LightCube
            //LightCube
            if (lightCube.Position.x >= 16.0f)
            {
                lightCube.Acceleration.x -= 1.0f;
                this.wind.x -= 0.005f;
            }

            else if (lightCube.Position.x <= 6.0f)
            {
                lightCube.Acceleration.x += 0.1f;
                lightCube.Velocity.Clamp(1.0f);
            }

            if (lightCube.Position.y >= 10.0f)
            {
                lightCube.Acceleration.y -= 1.0f;
                this.gravity.y           -= 0.005f;
            }

            else if (lightCube.Position.y <= -5.0f)
            {
                lightCube.Acceleration.y += 0.1f;
                lightCube.Velocity.Clamp(0.0f);
            }
            #endregion
            #region MedCube
            //MedCube
            if (medCube.Position.x >= 16.0f)
            {
                medCube.Acceleration.x -= 1.0f;
                this.wind.x            -= 0.005f;
            }

            else if (medCube.Position.x <= 6.0f)
            {
                medCube.Acceleration.x += 0.1f;
                medCube.Velocity.Clamp(1.0f);
            }

            if (medCube.Position.y >= 10.0f)
            {
                medCube.Acceleration.y -= 1.0f;
                this.gravity.y         -= 0.005f;
            }

            else if (medCube.Position.y <= -5.0f)
            {
                medCube.Acceleration.y += 0.2f;
                medCube.Velocity.Clamp(0.0f);
            }
            #endregion
            #region HeavyCube
            //HeavyCube
            if (heavyCube.Position.x >= 15.0f)
            {
                heavyCube.Acceleration.x -= 1.0f;
                this.wind.x -= 0.005f;
            }

            else if (heavyCube.Position.x <= 6.0f)
            {
                heavyCube.Acceleration.x = 1.0f;
                heavyCube.Velocity.Clamp(1.0f);
            }

            if (heavyCube.Position.y >= 10.0f)
            {
                heavyCube.Acceleration.y -= 1.0f;
                this.gravity.y           -= 0.005f;
            }

            else if (heavyCube.Position.y <= -5.0f)
            {
                heavyCube.Acceleration.y += 0.2f;
                heavyCube.Velocity.Clamp(0.0f);
            }
            #endregion
            //if (mover.Position.x <= 25.0f)
            //{
            //    mover.Velocity += acceleration;
            //    mover.Velocity.Clamp(2.0f);
            //}
            //else if (mover.Velocity.x >= 0.0f)
            //{
            //    mover.Velocity += deceleration;
            //    mover.Velocity.Clamp(0.0f);
            //}


            //gl.DrawText(20, 20, 1, 0, 0, "Arial", 25, mover.Velocity.x + " ");
            //return;
            //mousePos.Normalize();
            //mousePos *= 10;

            //Line1
            //gl.LineWidth(30.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(1.0f, 0.0f, 0.0f);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();

            //gl.LineWidth(3.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(1.0f, 1.0f, 1.0f);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();
            ////Line 2
            //gl.LineWidth(30.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(0.0f, 1.0f, 0.0f);
            //gl.Vertex(50, 20, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();

            //gl.LineWidth(3.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(1.0f, 1.0f, 1.0f);
            //gl.Vertex(50, 20, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();
            ////Line 3
            //gl.LineWidth(30.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(0.0f, 0.0f, 1.0f);
            //gl.Vertex(-50, -20, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();

            //gl.LineWidth(3.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(1.0f, 1.0f, 1.0f);
            //gl.Vertex(-50, -20, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();
        }
示例#5
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.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, -40.0f);
            //myVector = a - b;
            // myCube.Draw(gl);

            //Light Cube
            gl.Color(1.0f, 0.0f, 0.0f);
            lightCube.Draw(gl);
            lightCube.ApplyForce(wind);
            lightCube.ApplyForce(gravity);

            //Medium Cube
            gl.Color(0.0f, 1.0f, 0.0f);
            mediumCube.Draw(gl);
            mediumCube.ApplyForce(wind);
            mediumCube.ApplyForce(gravity);


            //Heavy Cube
            gl.Color(0.0f, 0.0f, 1.0f);
            heavyCube.Draw(gl);
            heavyCube.ApplyForce(wind);
            heavyCube.ApplyForce(gravity);



            //Right Border
            if (lightCube.Position.x >= 20.0f)
            {
                lightCube.Velocity.x -= 0.25f;
                lightCube.Velocity.x *= .25f;
            }
            //Bottom Border
            if (lightCube.Position.y <= -10.0f)
            {
                lightCube.Velocity.y *= -0.50f;
                lightCube.Velocity.y -= -0.50f;
            }

            if (mediumCube.Position.x >= 20.0f)
            {
                mediumCube.Velocity.x -= 0.25f;
                mediumCube.Velocity.x *= .25f;
            }
            //Bottom Border
            if (mediumCube.Position.y <= -10.0f)
            {
                mediumCube.Velocity.y *= -0.50f;
                mediumCube.Velocity.y -= -0.50f;
            }

            if (heavyCube.Position.x >= 20.0f)
            {
                heavyCube.Velocity.x -= 0.25f;
                heavyCube.Velocity.x *= .25f;
            }
            //Bottom Border
            if (heavyCube.Position.y <= -10.0f)
            {
                heavyCube.Velocity.y *= -0.50f;
                heavyCube.Velocity.y -= -0.50f;
            }

            ////Right Border
            //if (mediumCube.Position.x >= 20.0f)
            //{
            //    mediumCube.Velocity.x -= 0.25f;
            //    mediumCube.Velocity.x *= .25f;
            //}
            ////Bottom Border
            //if (mediumCube.Position.y <= -10.0f)
            //{
            //    mediumCube.Velocity.y *= -0.50f;
            //    mediumCube.Velocity.y -= -0.50f;
            //}

            ////Right Border
            //if (heavyCube.Position.x >= 20.0f)
            //{
            //    heavyCube.Velocity.x -= 0.25f;
            //    heavyCube.Velocity.x *= .25f;
            //}
            ////Bottom Border
            //if (heavyCube.Position.y <= -10.0f)
            //{
            //    heavyCube.Velocity.y *= -0.50f;
            //    heavyCube.Velocity.y -= -0.50f;
            //}

            gl.DrawText(20, 20, 1, 0, 0, "Arial", 25, myCube.Velocity.x + " ");
            #region velocityregion

            /*
             * CubeMesh myCube = new CubeMesh();
             * myCube.Position = new Vector3(Gaussian.Generate(0, 15), rng.GenerateInt(), 0);
             * myCubes.Add(myCube);
             * myCube.Draw(gl);
             * Seatwork
             *  myCube.Position += velocity * speed;
             * right
             *   if (myCube.Position.x >= 20)
             * {
             *  velocity.x = -1;
             *  velocity.y = 1;
             * }
             * left
             *   if (myCube.Position.x <= -15)
             * {
             *  velocity.x = 1;
             *  velocity.y = -1;
             * }
             * up
             *   if (myCube.Position.y >= 10)
             * {
             *  velocity.x = 1;
             *  velocity.y = -1;
             * }
             *
             * if (myCube.Position.y <= -15)
             * {
             *  velocity.y = -1;
             *  velocity.y = 1;
             * }
             *
             * gl.Color(1.0f, 0.0f, 0.0f);
             * gl.LineWidth(20);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(b.x, b.y);
             * gl.Vertex(a.x, a.y);
             * gl.End();
             *
             * gl.Color(1.0f, 1.0f, 1.0f);
             * gl.LineWidth(3);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(b.x, b.y);
             * gl.Vertex(a.x, a.y);
             * gl.End();
             */

            #endregion

            //This will make the line into 1

            #region lightsaber following mouse

            /* gl.Color(1.0f, 0.0f, 0.0f);
             * mousePos.Normalize();
             * mousePos *= 10;
             * gl.LineWidth(20);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(0, 0, 0);
             * gl.Vertex(mousePos.x, mousePos.y, 0);
             * gl.End();
             *
             * gl.Color(0.0f, 0.0f, 1.0f);
             * gl.LineWidth(3);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(0, 0, 0);
             * gl.Vertex(mousePos.x, mousePos.y, 0);
             * gl.End();
             *
             * gl.Color(0.0f, 1.0f, 0.0f);
             * gl.LineWidth(20);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(-10, 5, 0);
             * gl.Vertex(mousePos.x, mousePos.y, 0);
             * gl.End();
             *
             * gl.Color(0.0f, 1.0f, 1.0f);
             * gl.LineWidth(3);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(-10, 5, 0);
             * gl.Vertex(mousePos.x, mousePos.y, 0);
             * gl.End();
             *
             * gl.Color(0.0f, 1.0f, 0.0f);
             * gl.LineWidth(20);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(10, -5, 0);
             * gl.Vertex(mousePos.x, mousePos.y, 0);
             * gl.End();
             *
             * gl.Color(1.0f, 0.0f, 1.0f);
             * gl.LineWidth(3);
             * gl.Begin(OpenGL.GL_LINE_STRIP);
             * gl.Vertex(10, -5, 0);
             * gl.Vertex(mousePos.x, mousePos.y, 0);
             * gl.End();
             */
            #endregion
        }
        //private Vector3 deceleration = new Vector3(-0.01f, 0, 0);

        //private CubeMesh myCube = new CubeMesh();
        //private Randomizer rng = new Randomizer(-1, 1);
        ////private CubeMesh myCube = new CubeMesh();
        //private Vector3 velocity = new Vector3(1, 0, 0);
        //private float speed = 2.0f;

        //private Vector3 myVector = new Vector3();
        //private Vector3 a = new Vector3(5, 7, 0);
        //private Vector3 b = new Vector3(-7, -6, 0);



        //private List<CubeMesh> myCubes = new List<CubeMesh>();

        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;

            //this.Title = "Vectors";

            //myVector = a;

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

            gl.Translate(0.0f, 0.0f, -40.0f);

            lightCube.Draw(gl);
            lightCube.ApplyForce(wind);
            lightCube.ApplyForce(gravity);
            gl.Color(1.0f, 0.0f, 0.0f);


            middleWeightCube.Draw(gl);
            middleWeightCube.ApplyForce(wind);
            middleWeightCube.ApplyForce(gravity);
            gl.Color(0.0f, 0.0f, 1.0f);

            heavyCube.Draw(gl);
            heavyCube.ApplyForce(wind);
            heavyCube.ApplyForce(gravity);
            gl.Color(0.0f, 1.0f, 0.0f);



            //mover.Draw(gl);
            //mover.Velocity += acceleration;
            ////mover.Velocity -= deceleration;
            //mover.Velocity.Clamp(2.0f);

            if (lightCube.Position.x >= 25.0f)
            {
                lightCube.Position.y = -25;
            }
            else if (mover.Position.x >= 25.0f)
            {
                lightCube.Position.y = 0;
            }

            //gl.DrawText(20, 20, 1, 0, 0, "Arial", 25, mover.Velocity.x + " ");


            //OpenGL.GL_LINE_WIDTH(1.0f, 1.0f, 0);
            //gl.Color(0.0f, 0.0f, 1.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Vertex(15, 0);
            //gl.Vertex(a.x, a.y);
            //gl.End();
            //mousePos.Normalize();
            //mousePos *= 10;

            //gl.LineWidth(30.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(1.0f, 0.0f, 0.0f);
            //gl.Color(0.0f, 1.0f, 0.0f);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();

            //gl.LineWidth(3.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Color(1.0f, 1.0f, 1.0f);
            //gl.Vertex(0, 0, 0);
            //gl.Vertex(mousePos.x, mousePos.y, 0);
            //gl.End();

            //gl.Color(1.0f, 0.0f, 0.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Vertex(0, 0);
            //gl.Vertex(a.x, a.y);
            //gl.End();

            //gl.Color(0.0f, 1.0f, 0.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Vertex(0, 0);
            //gl.Vertex(a.x, a.y);
            //gl.Vertex(b.x, b.y);
            //gl.End();

            //gl.Color(0.0f, 0.0f, 1.0f);
            //gl.Begin(OpenGL.GL_LINE_STRIP);
            //gl.Vertex(b.x, b.y);
            //gl.Vertex(0,0);
            //gl.End();

            //gl.DrawText(0, 0, 1, 1, 1 "Arial", 15, "myVector magnitude");

            //CubeMesh myCube = new CubeMesh();
            //myCube.Position = new Vector3(Gaussian.Generate(0, 15), yAxis.GenerateDouble(), 0);
            //myCubes.Add(myCube);

            //myCube.Draw(gl);
            //myCube.Position += velocity * speed;

            //if (myCube.Position.x >= 25.0f)
            //{
            //    velocity.x = -1;
            //}
            //else if (myCube.Position.x <= -25.0f)
            //{
            //    velocity.x = 1;
            //}
            // if (myCube.Position.y >= 10.0f)
            // {
            //     velocity.y = -1;
            // }
            // else if (myCube.Position.y <= -10.0f)
            // {
            //     velocity.y = 1;
            // }
            //if (myCube.Position.y >= 30.0f)
            //{
            //    velocity.x = -1;
            //}
            //if (myCube.Position.y <= 30.0f)
            //{
            //    velocity.y = 1;
            //}
            //CubeMesh myCube2 = new CubeMesh();
            //myCube2.Position = new Vector3(Generate(-20, 20),0);
            //myCubes.Add(myCube2);

            //foreach (var cube in myCubes)
            //{
            ////    //gl.Color(RGB.Generate(), RGB.Generate(), RGB.Generate());
            //    cube.Draw(gl);
            //}
        }
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;

            // Clear The Screen And The Depth Buffer
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            // Move Left And Into The Screen
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -80.0f);

            lightCube.Draw(gl);
            gl.Color(1.0f, 0.0f, 0.0f);
            lightCube.ApplyForce(wind);

            if (lightCube.Position.x >= rightWall)
            {
                lightCube.ApplyForce(gravity);
            }
            if (lightCube.Position.y >= rightWall)
            {
                lightCube.ApplyForce(wind);
            }
            //bounce up
            if (lightCube.Position.y <= rightWall)
            {
                lightCube.Velocity.y -= lightCube.Velocity.y * 2;
            }
            //bounce right
            if (lightCube.Position.x >= 15 && lightCube.Position.x >= 20)
            {
                lightCube.Velocity.x -= lightCube.Velocity.x * 2;
            }

            heavyCube.Draw(gl);
            gl.Color(0.0f, 1.0f, 0.0f);
            heavyCube.ApplyForce(wind);
            if (heavyCube.Position.x >= rightWall)
            {
                heavyCube.ApplyForce(gravity);
            }
            if (heavyCube.Position.y >= rightWall)
            {
                lightCube.ApplyForce(wind);
            }
            //bounce up
            if (heavyCube.Position.y <= rightWall)
            {
                heavyCube.Velocity.y -= heavyCube.Velocity.y * 2;
            }
            //bounce right
            if (heavyCube.Position.x >= 15)
            {
                heavyCube.Velocity.x -= heavyCube.Velocity.x * 2;
            }

            moderateCube.Draw(gl);
            gl.Color(0.0f, 0.0f, 1.0f);
            moderateCube.ApplyForce(wind);
            if (moderateCube.Position.x >= rightWall)
            {
                moderateCube.ApplyForce(gravity);
            }
            if (moderateCube.Position.y >= rightWall)
            {
                lightCube.ApplyForce(wind);
            }
            //bounce up
            if (moderateCube.Position.y <= rightWall)
            {
                moderateCube.Velocity.y -= moderateCube.Velocity.y * 2;
            }
            //bounce right
            if (moderateCube.Position.x >= 15)
            {
                moderateCube.Velocity.x -= moderateCube.Velocity.x * 2;
            }
        }