コード例 #1
0
        private void ElasticCollision(basicCuboid w)
        {
            //Original code not needed
            //player.velocity *= -1;
            //player.position = player.storedPos;

            ///////////////////////////////////////////////////////////////////
            //
            // CODE FOR TASK 7 SHOULD BE ENTERED HERE

            // Need the perpendicular vector to the face of the box we hit
            // To do this we need 2 vectors on the face of the box we hit
            Vector3 faceVector1;
            Vector3 faceVector2;

            //Get the corners of the box we hit
            Vector3[] corners = w.collisionbox.GetCorners();
            //Corners of the box faces that are perpendicular to the z axis
            // 0 - 3 is the near face, 4 - 7 is the far face
            //Start upper left, then upper right, then lower right, then lower left (clockwise)

            //Move back our player to the previous position (so they aren't inside the box)
            player.position = player.storedPos;

            //Is the new players position overlapping in the X direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X ||
                (player.hitBox.Max.X - player.velocity.X) < w.collisionbox.Min.X)
            {
                //Overlapping from right or left
                //Line from top left to top right
                faceVector1 = corners[1] - corners[6];
                //line from front top left going to the front bottom right
                faceVector2 = corners[2] - corners[6];
            }
            // If we are not overlapping right or left we are overlapping front/back(z-axis)
            else
            {
                // Overlapping front or back
                //Line from top left to top right
                faceVector1 = corners[1] - corners[0];
                //line from front top left going to the front bottom right
                faceVector2 = corners[2] - corners[0];
            }
            //Ignoer possibility of a Y direction

            //Get a cross product between these two vector to define a normal perpendicular to the plane (face)
            Vector3 normal = Vector3.Cross(faceVector1, faceVector2);

            //Make it a unit Vector
            normal.Normalize();

            //Use this normal vector to reflect the player's velocity
            //(Uses a dot product equation internally)
            player.velocity = Vector3.Reflect(player.velocity, normal);

            //
            ///////////////////////////////////////////////////////////////////
        }
コード例 #2
0
        private void ElasticCollision(basicCuboid w)
        {
            //player.velocity *= -1;
            //player.position = player.storedPos;
            ///////////////////////////////////////////////////////////////////
            //
            // CODE FOR TASK 7 SHOULD BE ENTERED HERE
            //
            ///
            //we need the perpendicular vector to the face of the object we hit.
            //in order to do this we need two vectors from the face we hit.
            Vector3 faceVector1;
            Vector3 facevector2;

            //get the corners of the box we hit so we can calculate the face vector
            Vector3[] corners = w.collisionbox.GetCorners();
            //this returns the corners of the box faces that are perpendicular to the z axis
            // 0-3 is the near face and 4-7 is the far face.
            //start upper left then upper right then lower right then lower left (clockwise)

            //move back our player to their previous position (so they arent inside the box)
            player.position = player.storedPos;

            //is the players new position overlapping in the x direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X ||
                (player.hitBox.Max.X - player.velocity.X) < w.collisionbox.Min.X)
            {
                //over lapping front or back
                //line from front top left to the top right
                faceVector1 = corners[1] - corners[6];
                //line from front top left going to the front bottom right
                facevector2 = corners[2] - corners[6];
            }
            //if we are NOT overlapping right or left, we are overlapping front/back (zaxis)
            else
            {
                //over lapping front or back
                //line from back bottom right to the front top right
                faceVector1 = corners[1] - corners[0];
                //line from back bottom right going to the front bottom right
                facevector2 = corners[2] - corners[0];
            }
            //we ignore the posibility of a y direction

            //get a cross product between these two zectors to define a normal perpendicular to the plane
            Vector3 normal = Vector3.Cross(faceVector1, facevector2);

            //make it a unit vector (length 1)
            normal.Normalize();

            //use this normal vector to reflect the player's velocity
            //this uses cross product equation internally
            player.velocity = Vector3.Reflect(player.velocity, normal);

            ///////////////////////////////////////////////////////////////////
        }
コード例 #3
0
 private void ElasticCollision(basicCuboid w)
 {
     player.velocity *= -1;
     player.position  = player.storedPos;
     ///////////////////////////////////////////////////////////////////
     //
     // CODE FOR TASK 7 SHOULD BE ENTERED HERE
     //
     ///////////////////////////////////////////////////////////////////
 }
コード例 #4
0
        private void ElasticCollision(basicCuboid w)
        {
            //player.velocity *= -1;
            //player.position = player.storedPos;
            ///////////////////////////////////////////////////////////////////
            //
            // CODE FOR TASK 7 SHOULD BE ENTERED HERE
            //
            ///////////////////////////////////////////////////////////////////

            // need the perpendicular vector to the face of the box we hit
            // to do this, we need TWO vectors ON the face of the box we hit
            Vector3 faceVector1;
            Vector3 faceVector2;

            // get the corners of the box we hit so we can calculate the face vectors
            Vector3[] corners = w.collisionbox.GetCorners();
            // corners of the box faces that are perpendicular to the z axis (aka facing along the z axis)
            // 0-3 is the near face, 4-7 is the far face
            // Start upper left, upper right, then lower right, lower left clockwise

            // move back our player to their previous position (so they arent inside the box)
            player.position = player.storedPos;

            // is the player's new position overlapping in the X direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X || (player.hitBox.Max.X - player.velocity.X) > w.collisionbox.Min.X)
            {
                // overlapping from right or left!
                // line from back bottom right going to the front top right
                faceVector1 = corners[1] - corners[6];
                // line from back bottom right going to the front bottom right
                faceVector2 = corners[2] - corners[6];
            }
            else
            // if we are NOT overlapping right or left, we are overlapping front/back (z-axis)
            {
                // overlapping front or back!
                // line from front top left going to the top right
                faceVector1 = corners[1] - corners[0];
                // line from front top left going to the bottom right
                faceVector2 = corners[2] - corners[0];
            }
            // (we ignore the possibilty of a y direction

            // get a cross product between these two vectors to define a normal perpendicular to the plan
            Vector3 normal = Vector3.Cross(faceVector1, faceVector2);

            // make it a unit vector (length 1)
            normal.Normalize();

            // use this normal vector to reflect the player's velocity
            // this uses a dot product equation internally
            player.velocity = Vector3.Reflect(player.velocity, normal);
            velocityOld     = player.velocity;
        }
コード例 #5
0
        private void ElasticCollision(basicCuboid w)
        {
            //player.velocity *= -1;
            //player.position = player.storedPos;
            ///////////////////////////////////////////////////////////////////
            //

            // need the perpendicular vector to the face of the box we hit
            // to do this we need two vectors on the face of the box we hit
            Vector3 faceVector1;
            Vector3 faceVector2;

            // get the corners of the box we hit so we can calculate face vectors
            Vector3[] corners = w.collisionbox.GetCorners();
            // returns corners of the box that are perpendicular to the z axis(facing along the z axis)
            // 0-3 is the near face 4-7 is the far face
            //start upper left then clockwise to upper right, lower right, lower left


            // move back our player to previous position so they are not in the box
            player.position = player.storedPos;

            //is the players new position overlapping the X direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X || (player.hitBox.Max.X - player.velocity.X) < w.collisionbox.Min.X)
            {
                // overlapping from right/left
                //line from back bottom right to front top right
                faceVector1 = corners[1] - corners[6];
                //line from back bottom right to front bottom right
                faceVector2 = corners[2] - corners[6];
            }
            else // if we are not overlapping right/left, we are overlapping front/back (z axis)
            {
                //line from front top left to front top right
                faceVector1 = corners[1] - corners[0];
                //line from front top front left to front bottom right
                faceVector2 = corners[2] - corners[0];
            }
            // we ignore the possibility of y direction (no jumping

            // get a cross product between these two vectors to define a normal perpendicular to the plane (face)
            Vector3 normal = Vector3.Cross(faceVector1, faceVector2);

            normal.Normalize();

            //use this normal vector to reflect the player's velocity
            // this uses a dot product equation internally
            player.velocity = Vector3.Reflect(player.velocity, normal);


            // CODE FOR TASK 7 SHOULD BE ENTERED HERE
            //
            ///////////////////////////////////////////////////////////////////
        }
コード例 #6
0
        private void ElasticCollision(basicCuboid w)
        {
            //player.velocity *= -1;
            //player.position = player.storedPos;
            ///////////////////////////////////////////////////////////////////
            //
            // CODE FOR TASK 7 SHOULD BE ENTERED HERE
            //
            ///////////////////////////////////////////////////////////////////

            //Need the perpendicular vector to the face of the box we hit.
            //To do this we need TWO vectors ON the face of the box we hit
            Vector3 faceVector1;
            Vector3 faceVector2;

            //Get the corners of the box we hit so we can calculate the face vectors
            Vector3[] corners = w.collisionbox.GetCorners();
            //Corners of the box faces that are perpendicular to the z axis (facing along the z axis)
            //0-3 (so 4 corners) is the near face, 4-7 is the far face
            //Start upper left, then upper right, then lower left, then lower right. So clockwise

            //Move back our player to their previous position (so we aren't inside the box)
            player.position = player.storedPos;

            //Is the player's new position overlapping in the x direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X ||
                (player.hitBox.Max.X - player.velocity.X) < w.collisionbox.Min.X)
            {
                //Overlapping from right or left
                //Line  from back bottom right going to the front top right point
                faceVector1 = corners[1] - corners[6];

                //Line from back bottom right to front bottom right
                faceVector2 = corners[2] - corners[6];
            }
            else //If we are NOT overlapping left or right, ARE overlapping front/back (z axis)
            {
                //Line  from front top left going to the front top right point
                faceVector1 = corners[1] - corners[0];

                //Line from front top left to front bottom right
                faceVector2 = corners[2] - corners[0];
            }
            //Ignore the possibility of a y direction

            //Get a cross product between these two vectors to define a normal perdendicular to the plane (face)
            Vector3 normal = Vector3.Cross(faceVector1, faceVector2);

            normal.Normalize();

            //Use this normal vector to reflect the player's velocity
            //uses a dot product equation internally
            player.velocity = Vector3.Reflect(player.velocity, normal);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            BoundingRenderer.InitializeGraphics(graphics.GraphicsDevice);
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player.LoadModel(Content, "Ship");
            player.rotation   = new Vector3(0f, 0f, 0f);
            player.position.X = 0;
            player.position.Y = 0;
            player.position.Z = 0;
            player.scale      = 0.1f;
            rock.LoadModel(Content, "Meteor");
            rock.scale    = 0.1f;
            rock.position = new Vector3(25, 60, -50);
            for (int c = 0; c < walls.Length; c++)
            {
                walls[c] = new basicCuboid(GraphicsDevice);
                walls[c].LoadContent(Content, "WallTexture");
                walls[c].scale = new Vector3(5, 30, 60);
                if (c < 5)
                {
                    walls[c].SetUpVertices(new Vector3(-70, 0, 60 * (c + 1)));
                }
                else if (c < 10)
                {
                    walls[c].SetUpVertices(new Vector3(-70, 0, -60 * (c - 4)));
                }
                else
                {
                    walls[c].scale = new Vector3(60, 30, 5);
                    walls[c].SetUpVertices(new Vector3(-70 + (c - 10) * 60, 0, -300));
                }
            }

            door = new basicCuboid(GraphicsDevice);
            door.LoadContent(Content, "WallTexture");
            door.scale = new Vector3(5, 30, 60);
            door.SetUpVertices(new Vector3(-70, 0, 0));
            TriggerBoxDoorOpen = new BoundingBox(new Vector3(-95, 0, 0), new Vector3(-
                                                                                     45, 10, 60));
            TriggerBoxRockFall = new BoundingBox(new Vector3(-5, -5, -55), new
                                                 Vector3(55, 5, -45));
            sunlight.diffuseColor  = new Vector3(10);
            sunlight.specularColor = new Vector3(1f, 1f, 1f);
            sunlight.direction     = Vector3.Normalize(new Vector3(1.5f, -1.5f, -1.5f));

            //music
            this.BGM = Content.Load <Song>("GameofBlades-TrailsofCold SteelOST");
            MediaPlayer.Play(BGM);
            //the following line will also loop the song
            MediaPlayer.IsRepeating        = true;
            MediaPlayer.MediaStateChanged += MediaPlayer_MediaStateChanged;
        }
        private void ElasticCollision(basicCuboid w)
        {
            /////////////////////
            // CODE FOR TASK 7 //
            /////////////////////
            // Need the perpendicular vector to the face of the box we hit
            // To do this, we need TWO vectors ON the face of the box we hit
            Vector3 faceVector1;
            Vector3 faceVector2;

            // Get the corner of the box we hit so that we can calculate the face vectors
            Vector3[] corners = w.collisionbox.GetCorners();
            // returns the corners of the box faces that are perpendicular to the z axis (facing along the z axis)
            // 0-3 is the near, 4-7 is the far face
            // Start upper left, then upper right, then lower right, then lower left (clockwise)

            // Move back our player to their previous position (so they aren't inside the box)
            player.position = player.storedPos;

            // If the player's new position overlappin in the X direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X || (player.hitBox.Max.X - player.velocity.X) < w.collisionbox.Min.X)
            {
                // Overlapping from right or left!
                // Line from back bottom right going to the front top right
                faceVector1 = corners[1] - corners[6];
                // line from back bottom right going to the front bottom right
                faceVector2 = corners[2] - corners[6];
            }
            else // If we are not overlapping right or left, we are overlapping front/back (z axis)
            {
                // Overlapping front or back!
                // Line from front top left going to the front top right
                faceVector1 = corners[1] - corners[0];
                // line from front top left going to the front bottom right
                faceVector2 = corners[2] - corners[0];
            }
            // (we ignore the possibility of a y direction

            // Get a cross product between these two vectors to define a normal perpendicular to the plane (face)
            Vector3 normal = Vector3.Cross(faceVector1, faceVector2);

            // Make it a unit vector (length 1)
            normal.Normalize();

            // Use this normal vector to reflect the player's velocity
            // (this uses a dot product equation internally)
            player.velocity = Vector3.Reflect(player.velocity, normal);
        }
コード例 #9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            BoundingRenderer.InitializeGraphics(graphics.GraphicsDevice);
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player.LoadModel(Content, "Ship");
            player.rotation   = new Vector3(1.5f, 0f, 0f);
            player.position.X = 0;
            player.position.Y = 0;
            player.position.Z = 0;
            player.scale      = 0.1f;
            //player.collisionOffset = new Vector3(0, 100.0f, 0);
            rock.LoadModel(Content, "Meteor");
            rock.scale    = 0.1f;
            rock.position = new Vector3(25, 60, -50);
            for (int c = 0; c < walls.Length; c++)
            {
                walls[c] = new basicCuboid(GraphicsDevice);
                walls[c].LoadContent(Content, "WallTexture");
                walls[c].scale = new Vector3(5, 30, 60);
                if (c < 5)
                {
                    walls[c].SetUpVertices(new Vector3(-70, 0, 60 * (c + 1)));
                }
                else if (c < 10)
                {
                    walls[c].SetUpVertices(new Vector3(-70, 0, -60 * (c - 4)));
                }
                else
                {
                    walls[c].scale = new Vector3(60, 30, 5);
                    walls[c].SetUpVertices(new Vector3(-70 + (c - 10) * 60, 0, -300));
                }
            }

            door = new basicCuboid(GraphicsDevice);
            door.LoadContent(Content, "WallTexture");
            door.scale = new Vector3(5, 30, 60);
            door.SetUpVertices(new Vector3(-70, 0, 0));
            TriggerBoxDoorOpen = new BoundingBox(new Vector3(-95, 0, 0), new Vector3(-
                                                                                     45, 10, 60));
            TriggerBoxRockFall = new BoundingBox(new Vector3(-5, -5, -55), new
                                                 Vector3(55, 5, -45));
            sunlight.diffuseColor  = new Vector3(10);
            sunlight.specularColor = new Vector3(1f, 1f, 1f);
            sunlight.direction     = Vector3.Normalize(new Vector3(1.5f, -1.5f, -1.5f));
        }
        private void ElasticCollision(basicCuboid w)
        {
            //old collision data
            //player.velocity *= -1;
            //player.position = player.storedPos;
            ///////////////////////////////////////////////////////////////////
            //
            // TASK 7 HERE
            //
            ///////////////////////////////////////////////////////////////////
            ///

            //declare necessary variables
            //we need the perpendicular vector to the face of the box we hit
            //to do this, we need TWO vectors ON the face of the box we hit
            Vector3 faceVector1;
            Vector3 faceVector2;

            //get the corners of the box we hit
            //so we can calculate the face vectors

            Vector3[] corners = w.collisionbox.GetCorners();
            //This returns the corners of the box, faces that are perpendicular(90') to the Z axis
            //0-3 is the near face and 4-7 is the far face of the cube
            //starts in the upper left, upper right, lower right, lower left (clockwise formation)

            //move back our player to their previous position
            //so they aren't inside the box
            player.position = player.storedPos;

            //is the players new position overlapping in the X direction
            if ((player.hitBox.Min.X - player.velocity.X) > w.collisionbox.Max.X ||
                (player.hitBox.Max.X - player.velocity.X) > w.collisionbox.Min.X)
            {
                // overlapping from Right or Left

                //line from back bottom right the front top right point
                faceVector1 = corners[1] - corners[6];
                //line from back bottom right going to front bottom right
                faceVector2 = corners[2] - corners[6];
            }
            //if we are not overlapping, right or left
            else
            {//we are overlapping in the front or back (Z-axis)
                //line from front top left to the front top right point
                faceVector1 = corners[1] - corners[0];
                //line from front top left going to front bottom right
                faceVector2 = corners[2] - corners[0];
            }
            //we ignore the possibility of a y-direction

            //get a cross product between these two vectors to define a normal perpendicular to the plane (face)
            Vector3 normal = Vector3.Cross(faceVector1, faceVector2);

            //make into a unit vector(of length 1)
            normal.Normalize(); // divide normal by it's own magnitude

            //use this normal vector to reflect the players velocity
            // (this uses a dot product equation internally)
            player.velocity = Vector3.Reflect(player.velocity, normal);
        }