Exemple #1
0
        /// <summary>
        /// Initializes all the variables needed for Part One of the assignment
        /// </summary>
        private void PartOneInitialize()
        {
            moveOn = true;
            dragOn = false;
            gravityOn = false;
            kinecticOn = false;

            cubeSize = 10.0f;
            ballRadius = 1.0f;

            cubePosition = new Vector3(0.0f, 0.0f, 0.0f);
            ballPosition = new Vector3((float)randomNums.NextDouble(), (float)randomNums.NextDouble(), (float)randomNums.NextDouble());
            initialVelocity = new Vector3((float)randomNums.NextDouble(), (float)randomNums.NextDouble(), (float)randomNums.NextDouble());

            cube = new Shape(cubeModel, cubePosition, new Vector3(0.0f, 0.0f, 0.0f), 0.05f, cubeSize, Color.Firebrick.ToVector3());
            ball = new Shape(ballModel, ballPosition, initialVelocity, 1.0f, ballRadius, Color.Azure.ToVector3());

            //  camera settings
            cameraPosition = new Vector3(22.0f, 15.5f, -20.5f); //cameraPosition = {X:21.91004 Y:15.44271 Z:-20.90045}
            lookAt = new Vector3(9.0f, 6.5f, -12.0f); // lookAt = {X:9.221636 Y:6.635674 Z:-11.73702}
            view = Matrix.CreateLookAt(cameraPosition, lookAt, new Vector3(0.0f, 1.0f, 0.0f));
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90), 800f / 600f, 0.1f, 100f);
        }
Exemple #2
0
 private void InitializeInterpolation()
 {
     curve = new CurvePlotting(numberOfPoints);
     followThisBall = new Shape(ballModel, curve.GetPosition(0), Vector3.Zero, 1.0f, 0.75f, Color.Red.ToVector3());
     interpolationPoints = new Shape[numberOfPoints];
     for (int i = 0; i < numberOfPoints; i++)
     {
         interpolationPoints[i] = new Shape(ballModel, curve.midPoints[i], Vector3.Zero, 1.0f, 0.75f, Color.Green.ToVector3());
     }
 }
Exemple #3
0
 private void InitializePieceWise()
 {
     piecewisePoints = new Shape[numberOfPoints];
     for (int i = 0; i < numberOfPoints; i++)
     {
         Vector3 xyz = new Vector3((float)randomNums.Next(40), (float)randomNums.Next(40), (float)randomNums.Next(40));
         piecewisePoints[i] = new Shape(ballModel, xyz, Vector3.Zero, 1.0f, 0.5f, Color.Green.ToVector3());
     }
     followThisBall = new Shape(ballModel, piecewisePoints[0].position, Vector3.Zero, 1.0f, 0.75f, Color.Red.ToVector3());
     nextPoint = 1;
 }
Exemple #4
0
        /// <summary>
        /// Calculations for collision with respect to loss of kinectic energy if on
        /// </summary>
        /// <param name="aCube"></param>
        /// <param name="aBall"></param>
        private void Collision(Shape aCube, Shape aBall)
        {
            float boundary = cubeSize;
            float xVel = aBall.velocity.X;
            float yVel = aBall.velocity.Y;
            float zVel = aBall.velocity.Z;

            if (aBall.position.X + aBall.velocity.X + ballRadius > boundary || aBall.position.X + aBall.velocity.X - ballRadius < -boundary)
            {
                xVel = -xVel;
                if (kinecticOn)
                {
                    xVel *= 0.90f;
                }
                aBall.velocity = new Vector3(xVel, yVel, zVel);
            }

            if (aBall.position.Y + aBall.velocity.Y + ballRadius > boundary || aBall.position.Y + aBall.velocity.Y - ballRadius < -boundary)
            {
                timeSinceCollision = 0.0f;

                yVel = -yVel;
                if (kinecticOn)
                {
                    yVel *= 0.90f;
                }
                aBall.velocity = new Vector3(xVel, yVel, zVel);
                initialVelocity = aBall.velocity; // At a collision point, this defines a new initial velocity needed to compute the gravity velocity
            }

            if (aBall.position.Z + aBall.velocity.Z  + ballRadius > boundary || aBall.position.Z + aBall.velocity.Z - ballRadius < -boundary)
            {
                zVel = -zVel;
                if (kinecticOn)
                {
                    zVel *= 0.90f;
                }
                aBall.velocity = new Vector3(xVel, yVel, zVel);
            }
        }