Exemple #1
0
    override public Vector3 moveCamera()
    {
        distCovered = (Time.time - startTime) * speed;

        // Creating variables for the current set of the waypoints
        Vector3 p0 = wps[wp_id].transform.GetChild(0).position;
        Vector3 p1 = wps[wp_id + 1].transform.GetChild(0).position;
        Vector3 t0 = wps[wp_id].transform.GetChild(0).forward *angular_scalar;
        Vector3 t1 = -wps[wp_id + 1].transform.GetChild(0).forward *angular_scalar;

        // Calculating the current position along the curve
        Vector3 results = R_Curve.hermit(p0, p1, t0, t1, distCovered);

        //Check to see if the section has been done and move on to the next set of waypoints
        finishedSection(distCovered);

        return(results);
    }
    // Update is called once per frame
    void Update()
    {
        // Check for camera being close enough to recieve rotation influence from each point of interest
        float[] weights = new float[pois.Length + 1]; // Extra space for balancing weight
        weights[weights.Length - 1] = 0;              // Default the extra to 0 so it only influences if we need it
        int weightCount = 0;

        for (int i = 0; i < weights.Length - 1; i++)
        {
            float distanceFromPoI = Vector3.Magnitude(pois[i].transform.position - transform.position);

            if (distanceFromPoI <= pois[i].AreaOfInterestRadius())
            {
                weightCount++;
                float weight = distanceFromPoI / pois[i].AreaOfInterestRadius();
                // Use Hermet cuve Y value to 'cushion' the approach and exit from PoIs
                weight     = R_Curve.hermit(Vector3.zero, new Vector3(1, 1, 0), new Vector3(3f, 0, 0), new Vector3(-3f, 0, 0), weight).y;
                weight     = 1 - weight;
                weights[i] = weight;
            }
            else
            {
                weights[i] = 0;
            }
        }

        // Get the total amount of influence being cast upon the camera
        float weightTotal = 0;

        foreach (float weight in weights)
        {
            weightTotal += weight;
        }

//		if (weightCount == 1) {
//			if (onlyOnePoI == false) {
//				onlyOnePoI = true;
//				imagineryPoI = PoIBlob.transform.position;
//			}
//			else {
//				onlyOnePoI = false;
//			}
//
//			weights[weights.Length - 1] = weightTotal;
//			weightTotal += weightTotal;
//		}

        // Normalise the weights
        for (int i = 0; i < weights.Length; i++)
        {
            weights[i] = weights[i] / weightTotal;
        }

        // Create compound Vector3 to look at
        Mathd.Vector3 compoundPoI = Mathd.Vector3.zero;
        for (int i = 0; i < pois.Length; i++)
        {
            compoundPoI += new Mathd.Vector3(pois[i].transform.position * weights[i]);
        }

        // Look at the compound point
        PoIBlob.transform.position = compoundPoI.toUnityVec3;
        LookAt(compoundPoI);
    }