예제 #1
0
 public Couch(Cushion body)
 {
     this.cushions = new List <Cushion> ();
     for (int i = 0; i < GameManager.maxBodyParts; i++)
     {
         cushions.Add(body);
     }
 }
예제 #2
0
    //Every cushion gathered in one
    public Cushion Aggregate()
    {
        Cushion result = new Cushion();

        for (int i = 0; i < GameManager.maxBodyParts; i++)
        {
            result.Part(i).amount += cushions.Select(x => x.Part(i).amount).ToList().Sum();
        }

        return(result);
    }
예제 #3
0
    public Vector3 CalculateImpulseVectorBallCushion(Ball A, Cushion B)
    {
        Vector3 AB      = B.center - A.getCenter();
        Vector3 n       = AB.normalized;
        float   Impulse = (-Vector3.Dot((1 + eRestituion) * AB, n)) / Vector3.Dot(n, (1 / mass + 1 / (mass * cushionMassMultiplier)) * n);

        Vector3 impulse = (offsetImpulseCorrection / 3F) * Impulse * n;

        //Removing the z component
        impulse.z = 0;
        return(impulse);
    }
예제 #4
0
    bool CollisionResolutionBallCushion(Ball ball, Cushion cushion)
    {
        //Closest point to sphere center by clamping
        float x_closest = Mathf.Max(cushion.MinX, Mathf.Min(ball.getCenter().x, cushion.MaxX));
        float y_closest = Mathf.Max(cushion.MinY, Mathf.Min(ball.getCenter().y, cushion.MaxY));
        float z_closest = Mathf.Max(cushion.MinZ, Mathf.Min(ball.getCenter().z, cushion.MaxZ));

        float distance = Mathf.Sqrt((x_closest - ball.getCenter().x) * (x_closest - ball.getCenter().x) +
                                    (y_closest - ball.getCenter().y) * (y_closest - ball.getCenter().y) +
                                    (z_closest - ball.getCenter().z) * (z_closest - ball.getCenter().z));

        return(distance < ball.getRadius());
    }
예제 #5
0
    // Repartit au hasard une liste de bodypart dans un couch
    private Couch Split(Cushion allParts)
    {
        Couch tmp = new Couch();

        for (int i = 0; i < GameManager.maxBodyParts; i++)     //Pour chaque type de bodypart
        {
            for (int j = 0; j < allParts.parts[i].amount; j++) //Pour chaque bodypart de ce type
            {
                int ran = Random.Range(0, GameManager.maxCushions);
                tmp.cushions[ran].parts[i].amount++;  //Ajouter le même bodypart a un coussin random du resultat
            }
        }

        return(tmp);
    }
예제 #6
0
    //Since the number of objects in play are low in number and all are spheres, we're gonna check each against the other in every fixed update

    void FixedUpdate()
    {
        if (balls != null && balls.Length > 0)
        {
            for (int i = 0; i < balls.Length; i++)
            {
                //Check for Cushion collision in here as well
                for (int k = 0; k < cushions.Length; k++)
                {
                    Ball    ball    = balls[i];
                    Cushion cushion = cushions[k];
                    //Vector3 possibleContactPoint = cushion.center - ball.getCenter();
                    //An early escape test, for if the ball isn't moving towards the cushion, there is no point in doing further collision checks between them
                    //if(Vector3.Dot(possibleContactPoint,ball.getVelocity())>0){
                    bool collisionHappened = CollisionResolutionBallCushion(ball, cushion);

                    if (collisionHappened)
                    {
                        //Calculate The Impulse between the cushion and the ball
                        Vector3 impulseVector = sheet.CalculateImpulseVectorBallCushion(ball, cushion);

                        //Apply the force to the ball
                        ball.AddForce(impulseVector);
                    }
                    // }
                }


                for (int j = i + 1; j < balls.Length; j++)
                {
                    Ball A = balls[i];
                    Ball B = balls[j];
                    checkForCollisionBetweenBalls(A, B);
                }
                //Check for whether the ball is in on the plane or has fell in a pocket
                if (hasBallFallenIntoAPocketOrGoneOutOfBounds(balls[i]))
                {
                    balls[i].putOutOfAction();
                }
            }
        }
    }
예제 #7
0
    // Generates a random body containing min to max bodyparts
    private Cushion RandomBody(int min, int max)
    {
        Cushion body = new Cushion(0, 2, 0, 0);  //2 feet for stability

        if (max > gm.maxParts.amountOfParts)
        {
            Debug.LogError("Error : You're trying to put too many body parts (" + max + ") in the couch (" +
                           gm.maxParts.amountOfParts + " body parts total)");
        }
        else
        {
            int amountOfPartsToSplit = Random.Range(min, max + 1) - body.amountOfParts;

            // List is {0, 1, 2, 3... }
            List <int> possibleParts = new List <int>();
            for (int i = 0; i < GameManager.maxBodyParts; i++)
            {
                possibleParts.Add(i);
            }

            for (int i = 0; i < amountOfPartsToSplit; i++)
            {
                int      randomPartIndex = Random.Range(0, possibleParts.Count);
                BodyPart randomPart      = body.parts[possibleParts[randomPartIndex]];

                randomPart.amount++;

                if (randomPart.amount >= gm.maxParts.AmountOf(randomPart.type))
                {
                    possibleParts.RemoveAt(randomPartIndex);
                }
            }
        }

        return(body);
    }