Beispiel #1
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            this.Title = "APLIMAT Final Exam";
            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, -100.0f);


            if (Keyboard.IsKeyDown(Key.W))
            {
                playerCube.ApplyForce(Vector3.Up * speed);
            }

            if (Keyboard.IsKeyDown(Key.D))
            {
                playerCube.ApplyForce(Vector3.Right * speed);
            }

            if (Keyboard.IsKeyDown(Key.A))
            {
                playerCube.ApplyForce(Vector3.Left * speed);
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                playerCube.ApplyForce(Vector3.Down * speed);
            }

            Console.WriteLine("X:" + playerCube.Position.x + " Y:" + playerCube.Position.y);


            gl.Color(0.196078f, 0.6f, 0.8f);
            sea.Draw(gl);

            gl.Color(1.0, 1.0, 1.0);
            playerCube.Draw(gl);


            if (sea.Contains(playerCube))
            {
                var dragForce = sea.CalculateDragForce(playerCube) * 1f;
                playerCube.ApplyForce(dragForce);
                sea.changeColor(gl, 0, 0, 61);

                if (playerCube.Position.y <= sea1)
                {
                    playerCube.Position.y  = sea1;
                    playerCube.Velocity.y *= -1;
                }

                if (playerCube.Position.x >= sea3)
                {
                    playerCube.Position.x  = sea3;
                    playerCube.Velocity.x *= -1;
                }

                if (playerCube.Position.x <= sea2)
                {
                    playerCube.Position.x  = sea2;
                    playerCube.Velocity.x *= -1;
                }
            }


            if (!sea.Contains(playerCube))
            {
                if (playerCube.Position.y <= sea4)
                {
                    if (playerCube.Position.x <= sea2)
                    {
                        playerCube.Position.y  = sea4;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }


                    if (playerCube.Position.x >= -54 && playerCube.Position.x <= -28)
                    {
                        playerCube.Position.y  = 3.5f;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }

                    if (playerCube.Position.x >= -13 && playerCube.Position.x <= 13)
                    {
                        playerCube.Position.y  = 3.5f;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }

                    if (playerCube.Position.x >= 28 && playerCube.Position.x <= 54)
                    {
                        playerCube.Position.y  = 3.5f;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }

                    if (playerCube.Position.x >= sea3)
                    {
                        playerCube.Position.y  = sea4;
                        playerCube.Velocity.y *= -1;
                        playerCube.Velocity.x *= -1;
                    }
                }


                if (playerCube.Position.x >= sea2 && playerCube.Position.x <= sea3)
                {
                    if (playerCube.Position.y <= sea4)
                    {
                        if (playerCube.Position.x <= sea2)
                        {
                            playerCube.Position.x  = sea2;
                            playerCube.Velocity.x *= -1;
                        }



                        if (playerCube.Position.x >= sea3)
                        {
                            playerCube.Position.x  = sea3;
                            playerCube.Velocity.x *= -1;
                        }
                    }
                }
            }

            //cliff and sea
            #region


            gl.Color(0.36, 0.25, 0.20);
            cliff1.Draw(gl);
            cliff1.Scale = new Vector3(1 * cliff1.Mass / 4, 1 * cliff1.Mass / 2, 0);

            cliff2.Draw(gl);
            cliff2.Scale = new Vector3(1 * cliff2.Mass / 4, 1 * cliff2.Mass / 2, 0);

            cliff3.Draw(gl);
            cliff3.Scale = new Vector3(1 * cliff3.Mass / 1, 1 * cliff3.Mass / 8, 0);

            //middle cliff
            cliff4.Draw(gl);
            cliff4.Scale = new Vector3(1 * cliff4.Mass / 8, 1 * cliff4.Mass / 4, 0);

            cliff5.Draw(gl);
            cliff5.Scale = new Vector3(1 * cliff5.Mass / 8, 1 * cliff5.Mass / 4, 0);

            cliff6.Draw(gl);
            cliff6.Scale = new Vector3(1 * cliff6.Mass / 8, 1 * cliff6.Mass / 4, 0);
            #endregion

            #region sample for testing

            #endregion


            #region idea2

            #endregion

            #region keypress

            if (Keyboard.IsKeyDown(Key.W))
            {
                myCube.ApplyForce(Vector3.Up * speed);
            }

            if (Keyboard.IsKeyDown(Key.D))
            {
                myCube.ApplyForce(Vector3.Right * speed);
            }

            if (Keyboard.IsKeyDown(Key.A))
            {
                myCube.ApplyForce(Vector3.Left * speed);
            }
            if (Keyboard.IsKeyDown(Key.S))
            {
                myCube.ApplyForce(Vector3.Down * speed);
            }

            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
            }

            #endregion
        }