Search in sources :

Example 6 with BoundingBox

use of org.rajawali3d.bounds.BoundingBox in project Rajawali by Rajawali.

the class A_nAABBTree method contains.

/*
	 * (non-Javadoc)
	 * @see rajawali.scenegraph.IGraphNode#contains(rajawali.bounds.IBoundingVolume)
	 */
public boolean contains(IBoundingVolume boundingVolume) {
    if (!(boundingVolume instanceof BoundingBox))
        return false;
    BoundingBox boundingBox = (BoundingBox) boundingVolume;
    Vector3 otherMin = boundingBox.getTransformedMin();
    Vector3 otherMax = boundingBox.getTransformedMax();
    Vector3 min = mTransformedMin;
    Vector3 max = mTransformedMax;
    return (max.x >= otherMax.x) && (min.x <= otherMin.x) && (max.y >= otherMax.y) && (min.y <= otherMin.y) && (max.z >= otherMax.z) && (min.z <= otherMin.z);
}
Also used : BoundingBox(org.rajawali3d.bounds.BoundingBox) Vector3(org.rajawali3d.math.vector.Vector3)

Example 7 with BoundingBox

use of org.rajawali3d.bounds.BoundingBox in project Rajawali by Rajawali.

the class A_nAABBTree method setBounds.

/**
	 * Sets the bounding volume of this node. This should only be called
	 * for a root node with no children. This sets the initial root node
	 * to have a volume ~8x the member, centered on the member.
	 * 
	 * @param object IGraphNodeMember the member we will be basing
	 * our bounds on. 
	 */
protected void setBounds(IGraphNodeMember member) {
    //RajLog.d("[" + this.getClass().getName() + "] Setting bounds based on member: " + member);
    if (mMembers.size() != 0 && mParent != null) {
        return;
    }
    IBoundingVolume volume = member.getTransformedBoundingVolume();
    BoundingBox bcube = null;
    BoundingSphere bsphere = null;
    Vector3 position = member.getScenePosition();
    double span_y = 0;
    double span_x = 0;
    double span_z = 0;
    if (volume == null) {
        span_x = 5.0;
        span_y = 5.0;
        span_z = 5.0;
    } else {
        if (volume instanceof BoundingBox) {
            bcube = (BoundingBox) volume;
            Vector3 min = bcube.getTransformedMin();
            Vector3 max = bcube.getTransformedMax();
            span_x = (max.x - min.x);
            span_y = (max.y - min.y);
            span_z = (max.z - min.z);
        } else if (volume instanceof BoundingSphere) {
            bsphere = (BoundingSphere) volume;
            span_x = 2.0 * bsphere.getScaledRadius();
            span_y = span_x;
            span_z = span_x;
        }
    }
    mMin.x = (float) (position.x - span_x);
    mMin.y = (float) (position.y - span_y);
    mMin.z = (float) (position.z - span_z);
    mMax.x = (float) (position.x + span_x);
    mMax.y = (float) (position.y + span_y);
    mMax.z = (float) (position.z + span_z);
    mTransformedMin.setAll(mMin);
    mTransformedMax.setAll(mMax);
    calculatePoints();
    calculateChildSideLengths();
}
Also used : BoundingSphere(org.rajawali3d.bounds.BoundingSphere) BoundingBox(org.rajawali3d.bounds.BoundingBox) Vector3(org.rajawali3d.math.vector.Vector3) IBoundingVolume(org.rajawali3d.bounds.IBoundingVolume)

Example 8 with BoundingBox

use of org.rajawali3d.bounds.BoundingBox in project Rajawali by Rajawali.

the class RayPickingVisitor method apply.

public void apply(INode node) {
    if (node instanceof Object3D) {
        Object3D o = (Object3D) node;
        if (!o.isVisible() || !o.isInFrustum())
            return;
        if (o.getGeometry().hasBoundingSphere()) {
            BoundingSphere bsphere = o.getGeometry().getBoundingSphere();
            bsphere.calculateBounds(o.getGeometry());
            bsphere.transform(o.getModelMatrix());
            if (intersectsWith(bsphere)) {
                if (mPickedObject == null || (mPickedObject != null && o.getPosition().z < mPickedObject.getPosition().z))
                    mPickedObject = o;
            }
        } else {
            // Assume bounding box if no bounding sphere found.
            BoundingBox bbox = o.getGeometry().getBoundingBox();
            bbox.calculateBounds(o.getGeometry());
            bbox.transform(o.getModelMatrix());
            if (intersectsWith(bbox)) {
                if (mPickedObject == null || (mPickedObject != null && o.getPosition().z < mPickedObject.getPosition().z))
                    mPickedObject = o;
            }
        }
    }
}
Also used : BoundingSphere(org.rajawali3d.bounds.BoundingSphere) BoundingBox(org.rajawali3d.bounds.BoundingBox) Object3D(org.rajawali3d.Object3D)

Aggregations

BoundingBox (org.rajawali3d.bounds.BoundingBox)8 Vector3 (org.rajawali3d.math.vector.Vector3)5 BoundingSphere (org.rajawali3d.bounds.BoundingSphere)3 IBoundingVolume (org.rajawali3d.bounds.IBoundingVolume)2 ATransformable3D (org.rajawali3d.ATransformable3D)1 Object3D (org.rajawali3d.Object3D)1 Material (org.rajawali3d.materials.Material)1 Matrix4 (org.rajawali3d.math.Matrix4)1