Exemple #1
0
    public static Prism getPrismFromBlobs(BlobManager blob1, BlobManager blob2)
    {
        /*
        returns a Prism that just barely contains all of blob1 and blob2
        */
        Prism p1 = blob1.genPrism ();
        Prism p2 = blob2.genPrism ();

        int i = Mathf.Min (p1.x, p2.x);
        int j = Mathf.Min (p1.y, p2.y);
        int k = Mathf.Min (p1.z, p2.z);

        int iCorner = Mathf.Max (p1.x + p1.width, p2.x + p2.width);
        int jCorner = Mathf.Max (p1.y + p1.height, p2.y + p2.height);
        int kCorner = Mathf.Max (p1.z + p1.depth, p2.z + p2.depth);

        int width = iCorner - i;
        int height = jCorner - j;
        int depth = kCorner - k;

        return new Prism (i, j, k, width, height, depth);
    }
Exemple #2
0
    private void setStart()
    {
        //only one collisionManager should be in progress at the same time for the whole scene
        isStarted = true;

        blobs = new ArrayList ();

        if (blobName1 == "main blob")
            blobName1 = worldManager.getMainBlobName ();
        blob1 = (BlobManager)worldManager.blobs [blobName1];
        blob2 = (BlobManager)worldManager.blobs [blobName2];

        blob1.setName (true);
        blob2.setName (true);
        if (newBlobManager != null)
            newBlobManager.setName (true);

        blobs.Add (blob2);

        if (isBlob2InsideBlob1) {
            //case: when blob2 collided with blob1, it was completely within blob1 bounds
            //Debug.Log ("inside collision");
            newBlobManager = blob1;

            iterPrism = blob2.genPrism ();
            combinedPrism = blob1.getPrism ();

            iterOffset = new IntVector3 (iterPrism.x - combinedPrism.x, iterPrism.y - combinedPrism.y, iterPrism.z - combinedPrism.z);

            //ZTools.show ("combinedPrism ", combinedPrism);
            newMapData = blob1.mapData;
            newVoxelGrid = blob1.voxels;
            newContagiousList = blob1.getContagiousList ();
        } else {
            //case: blob2 hit the outside of blob1. newblob bounds must become larger
            //Debug.Log ("outside collision");
            blobs.Add (blob1);
            iterPrism = getPrismFromBlobs (blob1, blob2);
            iterOffset = new IntVector3 (0, 0, 0);

            combinedPrism = iterPrism;
            newMapData = new int[iterPrism.width, iterPrism.height, iterPrism.depth];
            newVoxelGrid = new GameObject[iterPrism.width, iterPrism.height, iterPrism.depth];
            newContagiousList = new ArrayList ();
            newBlobManager.gameObject.transform.position = new Vector3 (iterPrism.x, iterPrism.y, iterPrism.z);
        }
        //ZTools.show("combined prism",combinedPrism);
    }