/** Quick check whether the given {@link Ray} and {@link BoundingBox} intersect. * * @param ray The ray * @param box The bounding box * @return Whether the ray and the bounding box intersect. */ static public boolean intersectRayBoundsFast (Ray ray, BoundingBox box) { return intersectRayBoundsFast(ray, box.getCenter(tmp1), box.getDimensions(tmp2)); }
/** Quick check whether the given {@link Ray} and {@link BoundingBox} intersect. * * @param ray The ray * @param box The bounding box * @return Whether the ray and the bounding box intersect. */ static public boolean intersectRayBoundsFast (Ray ray, BoundingBox box) { return intersectRayBoundsFast(ray, box.getCenter(tmp1), box.getDimensions(tmp2)); }
/** Checks if entity is inside camera frustum. * * @param entity An entity * @return True if entity is inside camera frustum */ private boolean entityInFrustum (BulletEntity entity) { entity.modelInstance.transform.getTranslation(tmpV1); return frustumCam.frustum.sphereInFrustum(tmpV1.add(entity.boundingBox.getCenter(tmpV2)), entity.boundingBoxRadius); }
private void endpart () { if (part != null) { bounds.getCenter(part.center); bounds.getDimensions(part.halfExtents).scl(0.5f); part.radius = part.halfExtents.len(); bounds.inf(); part.offset = istart; part.size = indices.size - istart; istart = indices.size; part = null; } }
private void endpart () { if (part != null) { bounds.getCenter(part.center); bounds.getDimensions(part.halfExtents).scl(0.5f); part.radius = part.halfExtents.len(); bounds.inf(); part.offset = istart; part.size = indices.size - istart; istart = indices.size; part = null; } }
/** Calculates and updates the {@link #center}, {@link #halfExtents} and {@link #radius} values. This is considered a costly * operation and should not be called frequently. All vertices (points) of the shape are traversed to calculate the maximum and * minimum x, y and z coordinate of the shape. Note that MeshPart is not aware of any transformation that might be applied when * rendering. It calculates the untransformed (not moved, not scaled, not rotated) values. */ public void update () { mesh.calculateBoundingBox(bounds, offset, size); bounds.getCenter(center); bounds.getDimensions(halfExtents).scl(0.5f); radius = halfExtents.len(); }
/** Calculates and updates the {@link #center}, {@link #halfExtents} and {@link #radius} values. This is considered a costly * operation and should not be called frequently. All vertices (points) of the shape are traversed to calculate the maximum and * minimum x, y and z coordinate of the shape. Note that MeshPart is not aware of any transformation that might be applied when * rendering. It calculates the untransformed (not moved, not scaled, not rotated) values. */ public void update () { mesh.calculateBoundingBox(bounds, offset, size); bounds.getCenter(center); bounds.getDimensions(halfExtents).scl(0.5f); radius = halfExtents.len(); }
/** Compute final result. * @param bb BoundingBox encompassing instances * @param camera Camera to compute */ protected void computeResult (BoundingBox bb, Camera camera) { // Radius float radius = bb1.getDimensions(tmpV).len() * 0.5f; // Center bb1.getCenter(tmpV); // Computation float distance = tmpV.dst(camera.position); float near = distance - radius; float far = distance + radius; if (near <= 0) near = CAMERA_NEAR; if (far <= 0) far = CAMERA_FAR; camera.near = near; camera.far = far; camera.update(); } }
@Override protected void onLoaded () { super.onLoaded(); BoundingBox bounds = instances.get(0).calculateBoundingBox(new BoundingBox()); bounds.getCenter(center); radius = bounds.getDimensions(tmpV).len() * .5f; pointLight.position.set(0, radius, 0).add(transformedCenter.set(center).mul(transform)); pointLight.intensity = radius * radius; ((ColorAttribute)pLight.material.get(ColorAttribute.Diffuse)).color.set(pointLight.color); final float s = 0.2f * radius; pLight.worldTransform.setToScaling(s, s, s); }
@Override protected void onLoaded () { if (currentlyLoading == null || currentlyLoading.length() == 0) return; instances.clear(); animationControllers.clear(); final ModelInstance instance = new ModelInstance(assets.get(currentlyLoading, Model.class)); instance.transform = transform; instances.add(instance); if (instance.animations.size > 0) animationControllers.put(instance, new AnimationController(instance)); currentlyLoading = null; instance.calculateBoundingBox(bounds); cam.position.set(1, 1, 1).nor().scl(bounds.getDimensions(tmpV1).len() * 0.75f + bounds.getCenter(tmpV2).len()); cam.up.set(0, 1, 0); cam.lookAt(0, 0, 0); cam.far = 50f + bounds.getDimensions(tmpV1).len() * 2.0f; cam.update(); }
bb.getCenter(tmpV);
/** Quick check whether the given {@link Ray} and {@link BoundingBox} intersect. * * @param ray The ray * @param box The bounding box * @return Whether the ray and the bounding box intersect. */ static public boolean intersectRayBoundsFast (Ray ray, BoundingBox box) { return intersectRayBoundsFast(ray, box.getCenter(tmp1), box.getDimensions(tmp2)); }
private void init() { calculateBoundingBox(bounds); bounds.getCenter(center); bounds.getDimensions(dimensions); radius = dimensions.len() / 2f; }
/** Calculates and updates the {@link #center}, {@link #halfExtents} and {@link #radius} values. This is considered a costly * operation and should not be called frequently. All vertices (points) of the shape are traversed to calculate the maximum and * minimum x, y and z coordinate of the shape. Note that MeshPart is not aware of any transformation that might be applied when * rendering. It calculates the untransformed (not moved, not scaled, not rotated) values. */ public void update () { mesh.calculateBoundingBox(bounds, offset, size); bounds.getCenter(center); bounds.getDimensions(halfExtents).scl(0.5f); radius = halfExtents.len(); }
private void endpart () { if (part != null) { bounds.getCenter(part.center); bounds.getDimensions(part.halfExtents).scl(0.5f); part.radius = part.halfExtents.len(); bounds.inf(); part.offset = istart; part.size = indices.size - istart; istart = indices.size; part = null; } }
/** * Holds a an instance of the model. * * @param name Name of model * @param model Model to instantiate * @param location World position at which to place the model instance * @param rotation The rotation of the model instance in degrees * @param scale Scale of the model instance */ public GameModel(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale) { super(name); modelInstance = new ModelInstance(model); applyTransform(location, rotation, scale, modelInstance); try { modelInstance.calculateBoundingBox(boundingBox); } catch (Exception e) { Gdx.app.debug(TAG, "Error when calculating bounding box.", e); } boundingBox.getCenter(center); boundingBox.getDimensions(dimensions); boundingBoxRadius = dimensions.len() / 2f; modelTransform = modelInstance.transform; halfExtents.set(dimensions).scl(0.5f); }