Search in sources :

Example 1 with ATransformable3D

use of org.rajawali3d.ATransformable3D in project Rajawali by Rajawali.

the class A_nAABBTree method grow.

/**
	 * Grows the tree.
	 */
protected void grow() {
    RajLog.d("[" + this.getClass().getName() + "] Growing tree: " + this);
    Vector3 min = new Vector3(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
    Vector3 max = new Vector3(-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE);
    //Get a full list of all the members, including members in the children
    ArrayList<IGraphNodeMember> members = getAllMembersRecursively(true);
    int members_count = members.size();
    for (int i = 0; i < members_count; ++i) {
        IBoundingVolume volume = members.get(i).getTransformedBoundingVolume();
        Vector3 test_against_min = null;
        Vector3 test_against_max = null;
        if (volume == null) {
            ATransformable3D object = (ATransformable3D) members.get(i);
            test_against_min = object.getPosition();
            test_against_max = test_against_min;
        } else {
            if (volume instanceof BoundingBox) {
                BoundingBox bb = (BoundingBox) volume;
                test_against_min = bb.getTransformedMin();
                test_against_max = bb.getTransformedMax();
            } else if (volume instanceof BoundingSphere) {
                BoundingSphere bs = (BoundingSphere) volume;
                Vector3 bs_position = bs.getPosition();
                double radius = bs.getScaledRadius();
                Vector3 rad = new Vector3();
                rad.setAll(radius, radius, radius);
                test_against_min = Vector3.subtractAndCreate(bs_position, rad);
                test_against_max = Vector3.addAndCreate(bs_position, rad);
            } else {
                RajLog.e("[" + this.getClass().getName() + "] Received a bounding box of unknown type.");
                throw new IllegalArgumentException("Received a bounding box of unknown type.");
            }
        }
        if (test_against_min != null && test_against_max != null) {
            if (test_against_min.x < min.x)
                min.x = test_against_min.x;
            if (test_against_min.y < min.y)
                min.y = test_against_min.y;
            if (test_against_min.z < min.z)
                min.z = test_against_min.z;
            if (test_against_max.x > max.x)
                max.x = test_against_max.x;
            if (test_against_max.y > max.y)
                max.y = test_against_max.y;
            if (test_against_max.z > max.z)
                max.z = test_against_max.z;
        }
    }
    mMin.setAll(min);
    mMax.setAll(max);
    mTransformedMin.setAll(min);
    mTransformedMax.setAll(max);
    calculatePoints();
    calculateChildSideLengths();
    if (mSplit) {
        for (int i = 0; i < CHILD_COUNT; ++i) {
            ((Octree) mChildren[i]).setChildRegion(i, mChildLengths);
        }
    }
    for (int i = 0; i < members_count; ++i) {
        internalAddObject(members.get(i));
    }
}
Also used : BoundingSphere(org.rajawali3d.bounds.BoundingSphere) BoundingBox(org.rajawali3d.bounds.BoundingBox) Vector3(org.rajawali3d.math.vector.Vector3) ATransformable3D(org.rajawali3d.ATransformable3D) IBoundingVolume(org.rajawali3d.bounds.IBoundingVolume)

Aggregations

ATransformable3D (org.rajawali3d.ATransformable3D)1 BoundingBox (org.rajawali3d.bounds.BoundingBox)1 BoundingSphere (org.rajawali3d.bounds.BoundingSphere)1 IBoundingVolume (org.rajawali3d.bounds.IBoundingVolume)1 Vector3 (org.rajawali3d.math.vector.Vector3)1