/** 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)); }
/** 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(); }
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; } }
/** 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(); } }
public BulletEntity (final ModelInstance modelInstance, final btCollisionObject body) { this.modelInstance = modelInstance; this.transform = this.modelInstance.transform; this.body = body; modelInstance.calculateBoundingBox(boundingBox); boundingBoxRadius = boundingBox.getDimensions(new Vector3()).len() * 0.5f; if (body != null) { body.userData = this; if (body instanceof btRigidBody) { this.motionState = new MotionState(this.modelInstance.transform); ((btRigidBody)this.body).setMotionState(motionState); } else body.setWorldTransform(transform); } }
@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(); }
cam.position.set(1, 1, 1).nor().scl(bounds.getDimensions(tmpV).len() * 0.75f).add(bounds.getCenter(tmpV)); cam.up.set(0, 1, 0); cam.lookAt(inputController.target.set(bounds.getCenter(tmpV))); cam.far = Math.max(100f, bounds.getDimensions(tmpV).len() * 2.0f); cam.update(); moveRadius = bounds.getDimensions(tmpV).len() * 0.25f;
@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); }
/** Adds an occludee entity of random type at a random place on the ground. * * @param dynamic If true, entity body will be dynamic (mass > 0) * @return The added entity */ private BulletEntity addRandomOccludee (boolean dynamic) { // Add occludee to world BulletEntity entity = world.add(getRandomOccludeeType(dynamic), 0, 0, 0); entity.setColor(Color.WHITE); // Random rotation float rotationY = rng.nextFloat() * 360f; // Random ground position Vector3 position = tmpV1; int maxDstX = (int)(GROUND_DIM.x * 0.49f); position.x = rng.nextInt(maxDstX) * ((rng.nextBoolean()) ? 1 : -1); position.z = rng.nextInt(maxDstX) * ((rng.nextBoolean()) ? 1 : -1); position.y = entity.boundingBox.getDimensions(tmpV2).y * 0.5f; entity.modelInstance.transform.setToRotation(Vector3.Y, rotationY).setTranslation(position); entity.body.setWorldTransform(entity.modelInstance.transform); return entity; }
float radius = bb.getDimensions(tmpV).len() * 0.5f;
Vector3 chassisHalfExtents = chassisModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f); Vector3 wheelHalfExtents = wheelModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
Model model = assets.get(modelPath, Model.class); if (!model.materials.first().has(TextureAttribute.Diffuse)) model.materials.first().set(defaultTexture); Vector3 dim = model.calculateBoundingBox(bb).getDimensions(tmpV1); float scaleFactor = OCCLUDEE_MAX_EXTENT / Math.max(dim.x, Math.max(dim.y, dim.z)); for (Node node : model.nodes)
/** 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); }