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);
}
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();
}
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;
}
}
}
}
Aggregations