public WorldEntity(String name, ModelInstance instance, btRigidBody btRigidBody, boolean disableDeactivation) { this.name = name; this.instance = instance; this.btRigidBody = btRigidBody; btRigidBody.userData = this; motionState = new MotionState(instance.transform); btRigidBody.setMotionState(motionState); logger.debug("Creating object '{}'", name); if (disableDeactivation) { logger.debug("Disabling deactivation for '{}'", name); btRigidBody.setActivationState(Collision.DISABLE_DEACTIVATION); } getDefaultColors(); }
@Override public void create () { super.create(); // Create the entities world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f); kinematicBox1 = world.add("staticbox", position1.x, position1.y, position1.z); kinematicBox1.setColor(Color.RED); kinematicBox1.body.setCollisionFlags(kinematicBox1.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); kinematicBox2 = world.add("staticbox", position2.x, position2.y, position2.z); kinematicBox2.setColor(Color.RED); kinematicBox2.body.setCollisionFlags(kinematicBox2.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); ; kinematicBox3 = world.add("staticbox", position3.x, position3.y, position3.z); kinematicBox3.setColor(Color.RED); kinematicBox3.body.setCollisionFlags(kinematicBox3.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); ; // This makes bullet call btMotionState#getWorldTransform on every update: kinematicBox3.body.setActivationState(Collision.DISABLE_DEACTIVATION); angle = 360f; }
@Override public void render () { angle = angle + Gdx.graphics.getDeltaTime() * 360f / 5f; kinematicBox3.transform.idt().rotate(Vector3.Y, 360f - 2f * angle).translate(position3); if (angle >= 360f) { angle = 0; kinematicBox = (kinematicBox == kinematicBox1) ? kinematicBox2 : kinematicBox1; position = (position == position1) ? position2 : position1; } kinematicBox.transform.idt().rotate(Vector3.Y, angle).translate(position); // This makes bullet call btMotionState#getWorldTransform once: kinematicBox.body.setActivationState(Collision.ACTIVE_TAG); super.render(); }
@Override public boolean touchUp (int screenX, int screenY, int pointer, int button) { boolean result = false; if (button == Buttons.LEFT) { if (pickConstraint != null) { ((btDynamicsWorld)world.collisionWorld).removeConstraint(pickConstraint); pickConstraint.dispose(); pickConstraint = null; result = true; } if (pickedBody != null) { pickedBody.forceActivationState(Collision.ACTIVE_TAG); pickedBody.setDeactivationTime(0f); pickedBody = null; } } return result ? result : super.touchUp(screenX, screenY, pointer, button); }
public VehicleComponent build(btDynamicsWorld world, btCollisionShape chassisShape, btRaycastVehicle.btVehicleTuning vehicleTuning, float mass, float friction, float restitution, short group, short[] masks) { this.vehicleTuning = vehicleTuning; build(chassisShape, mass, friction, restitution, group, masks); getBody().setActivationState(Collision.DISABLE_DEACTIVATION); vehicleRaycaster = new btDefaultVehicleRaycaster(world); vehicle = new btRaycastVehicle(vehicleTuning, getBody(), vehicleRaycaster); vehicle.setCoordinateSystem(0, 1, 2); return this; }
public VehicleComponent build(Assets assets, btDynamicsWorld world) { super.build(assets); getBody().setActivationState(Collision.DISABLE_DEACTIVATION); vehicleRaycaster = new btDefaultVehicleRaycaster(world); vehicle = new btRaycastVehicle(vehicleTuning, getBody(), vehicleRaycaster); vehicle.setCoordinateSystem(0, 1, 2); return this; }
public void setDynamic() { if(body == null) return; body.setCollisionFlags(CF_CUSTOM_MATERIAL_CALLBACK); body.activate(true); body.setActivationState(Collision.DISABLE_DEACTIVATION); physicsState = DYNAMIC; }
private static void buildCave(Matrix4 transform) { Model caveModel = Assets.get(CURR_MODEL, Model.class); if (WORLD.getConstructor("cave") == null) { for (Node n : caveModel.nodes) n.scale.set(.6f, .6f, .6f); btCollisionShape collisionShape = Bullet.obtainStaticNodeShape(caveModel.nodes); collisionShape.setLocalScaling(new Vector3(.6f, .6f, .6f)); WORLD.addConstructor("cave", new BulletConstructor(caveModel, 0, collisionShape)); } BulletEntity cave = WORLD.add("cave", transform); cave.body.setCollisionFlags(cave.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); cave.body.setActivationState(Collision.DISABLE_DEACTIVATION); cave.body.userData = new BulletUserData("cave", cave); }
public static BulletEntity createKinematicIsland(BulletWorld world, Vector3 position, boolean landscape) { BulletEntity island = world.add("island", position.x, position.y, position.z); island.radius = 5; // not really the radius, but this should be always in the frustum island.body.userData = new BulletUserData("island", island); island.body.setCollisionFlags(island.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); island.body.setActivationState(Collision.DISABLE_DEACTIVATION); if (landscape) { Vector3 islePosition = island.transform.getTranslation(new Vector3()); placeCave(islePosition); plantTrees(world, islePosition); } return island; }
private void createCloud() { float y, z; do { y = MathUtils.random(-40, 30); z = MathUtils.random(-80, 80); } while (y < 15 && y > -20 && z < 15 && z > -15); clouds.add(cloud = world.add("cloud", -120, y, z)); cloud.radius = 7; cloud.body.userData = new BulletUserData("cloud", cloud); cloud.transform.rotate(0, 1, 0, 90); cloud.body.setCollisionFlags(cloud.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT); cloud.body.setActivationState(Collision.DISABLE_DEACTIVATION); }
@Override public boolean touchDown (int screenX, int screenY, int pointer, int button) { boolean result = false; if (button == Buttons.LEFT) { Ray ray = camera.getPickRay(screenX, screenY); tmpV1.set(ray.direction).scl(10f).add(ray.origin); ClosestRayResultCallback cb = new ClosestRayResultCallback(ray.origin, tmpV1); world.collisionWorld.rayTest(ray.origin, tmpV1, cb); if (cb.hasHit()) { btRigidBody body = (btRigidBody)(cb.getCollisionObject()); if (body != null && !body.isStaticObject() && !body.isKinematicObject()) { pickedBody = body; body.setActivationState(Collision.DISABLE_DEACTIVATION); cb.getHitPointWorld(tmpV); tmpV.mul(body.getCenterOfMassTransform().inv()); pickConstraint = new btPoint2PointConstraint(body, tmpV); btConstraintSetting setting = pickConstraint.getSetting(); setting.setImpulseClamp(30f); setting.setTau(0.001f); pickConstraint.setSetting(setting); ((btDynamicsWorld)world.collisionWorld).addConstraint(pickConstraint); pickDistance = tmpV1.sub(camera.position).len(); result = true; } } cb.dispose(); } return result ? result : super.touchDown(screenX, screenY, pointer, button); }
public InvisibleBody(String name, btCollisionShape shape, float mass, Matrix4 transform, short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate) { super(name); this.mass = mass; this.shape = shape; this.belongsToFlag = belongsToFlag; this.collidesWithFlag = collidesWithFlag; if (mass > 0f) { shape.calculateLocalInertia(mass, localInertia); } else { localInertia.set(0, 0, 0); } this.constructionInfo = new btRigidBody.btRigidBodyConstructionInfo( mass, null, shape, localInertia); body = new btRigidBody(constructionInfo); body.setWorldTransform(transform); body.setContactCallbackFlag(belongsToFlag); if (callback) { body.setCollisionFlags(body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK); } if (noDeactivate) { body.setActivationState(Collision.DISABLE_DEACTIVATION); } }
public void calculateDistance (btCollisionObject colObjA, btCollisionObject colObjB) { DistanceInternalResultCallback result = new DistanceInternalResultCallback(); Collision.setGContactBreakingThreshold(100f); collisionWorld.contactPairTest(colObjA, colObjB, result); Collision.setGContactBreakingThreshold(0.02f); }
@Override public void onInit() { input = remoteInputProperty.getRemoteInput(); physicsProperty.getRigidBody().setActivationState(Collision.DISABLE_DEACTIVATION); physicsProperty.getRigidBody().activate(); }
public void setStatic() { if(body == null) return; body.setCollisionFlags(CF_STATIC_OBJECT); body.setActivationState(Collision.DISABLE_DEACTIVATION); physicsState = STATIC; }
public void setKinematic() { if(body == null) return; body.setCollisionFlags(CF_KINEMATIC_OBJECT); body.setActivationState(Collision.DISABLE_DEACTIVATION); physicsState = KINEMATIC; }
protected void setup(String name, Model model, btRigidBody.btRigidBodyConstructionInfo constructionInfo) { this.name = name; modelInstance = new ModelInstance(model); rigidBody = new btRigidBody(constructionInfo); rigidBody.userData = this; rigidBody.setActivationState(Collision.DISABLE_DEACTIVATION); motionState = new MotionState(modelInstance.transform); rigidBody.setMotionState(motionState); getDefaultColors(); }
@Override public void create () { super.create(); instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test"; final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj")); disposables.add(chassisModel); chassisModel.materials.get(0).clear(); chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE)); final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj")); disposables.add(wheelModel); wheelModel.materials.get(0).clear(); wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(128)); Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png")); final Model largeGroundModel = modelBuilder.createBox( 1000f, 2f, 1000f, new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute .createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates); largeGroundModel.manageDisposable(checkboard); disposables.add(largeGroundModel); world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f)); BoundingBox bounds = new BoundingBox(); Vector3 chassisHalfExtents = new Vector3(chassisModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f); Vector3 wheelHalfExtents = new Vector3(wheelModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f); world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents))); world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null)); world.add("largeground", 0, -1f, 0f); chassis = world.add("chassis", 0, 3f, 0); wheels[0] = world.add("wheel", 0, 0, 0); wheels[1] = world.add("wheel", 0, 0, 0); wheels[2] = world.add("wheel", 0, 0, 0); wheels[3] = world.add("wheel", 0, 0, 0); // Create the vehicle raycaster = new btDefaultVehicleRaycaster((btDynamicsWorld)world.collisionWorld); tuning = new btVehicleTuning(); vehicle = new btRaycastVehicle(tuning, (btRigidBody)chassis.body, raycaster); chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION); ((btDynamicsWorld)world.collisionWorld).addVehicle(vehicle); vehicle.setCoordinateSystem(0, 1, 2); btWheelInfo wheelInfo; Vector3 point = new Vector3(); Vector3 direction = new Vector3(0, -1, 0); Vector3 axis = new Vector3(-1, 0, 0); wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true); wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true); wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false); wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false); }
/** * Creates a model with rigid body * * @param model Model to instantiate * @param name Name of model * @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 * @param shape Collision shape with which to construct a rigid body * @param mass Mass of the body * @param belongsToFlag Flag for which collision layers this body belongs to * @param collidesWithFlag Flag for which collision layers this body collides with * @param callback If this body should trigger collision contact callbacks. * @param noDeactivate If this body should never 'sleep' */ public GameModelBody(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale, btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback, boolean noDeactivate) { super(model, name, location, rotation, scale); this.mass = mass; this.shape = shape; this.belongsToFlag = belongsToFlag; this.collidesWithFlag = collidesWithFlag; if (mass > 0f) { shape.calculateLocalInertia(mass, localInertia); } else { localInertia.set(0, 0, 0); } this.constructionInfo = new btRigidBody.btRigidBodyConstructionInfo( mass, null, shape, localInertia); body = new btRigidBody(constructionInfo); if (mass > 0f) { motionState = new PhysicsMotionState(modelInstance.transform); body.setMotionState(motionState); } else { motionState = null; } body.setContactCallbackFlag(belongsToFlag); if (callback) { body.setCollisionFlags(body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK); } if (noDeactivate) { body.setActivationState(Collision.DISABLE_DEACTIVATION); } body.setWorldTransform(modelInstance.transform); }
public ShipBehavior(GameObject gameObject) { super(gameObject); gameObject.rigidBody.forceActivationState(Collision.DISABLE_DEACTIVATION); }